diff --git a/source/arm11/main.c b/source/arm11/main.c index 6014f76..d769595 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -59,7 +59,7 @@ if(hidstate & MCU_HID_POWER_BUTTON_PRESSED) { if(poweroff_allowed) // direct power off allowed? - turn_off(); + power_off(); PXI_trySendWord(PXI_RPL_POWER_PRESSED); } diff --git a/source/arm11/power.c b/source/arm11/power.c new file mode 100644 index 0000000..ca2eee2 --- /dev/null +++ b/source/arm11/power.c @@ -0,0 +1,47 @@ +#include "types.h" +#include "util.h" +#include "arm11/i2c.h" + +bool battery_ok(void) +{ + u8 state; + + if(!i2cmcu_readregdata(0xF, &state, 1)) + return false; + + // battery charging, this should be fine + if((state >> 4) & 1) + return true; + + if(!i2cmcu_readregdata(0xB, &state, 1)) + return false; + + if(state >= 10) // 10% should be enough + return true; + + return false; +} + +void power_off(void) +{ + i2cmcu_lcd_poweroff(); + i2cmcu_lcd_backlight_poweroff(); + + for(;;) + { + i2c_writeregdata(3, 0x20, 0xff); + wait(0x200000); + } +} + +void power_reboot(void) +{ + i2cmcu_lcd_poweroff(); + i2cmcu_lcd_backlight_poweroff(); + + for(;;) + { + i2c_writeregdata(3, 0x20, 0x04); + wait(0x200000); + } +}