diff options
author | Rayyan Ansari <rayyan@ansari.sh> | 2022-02-18 15:32:46 +0000 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2022-03-07 21:08:54 +0100 |
commit | 2569c67a13a6ce855d27821cc6863ebea82c429d (patch) | |
tree | 6eb326bfadb2dc28999bb722731c006c4dc327f9 /src/DSi_I2C.cpp | |
parent | c3adf6f606c694221342111a850e7b76ac77a56d (diff) |
Add support for changing the DS and DSi battery level
The DS battery level is configured via the SPI Power Management Device,
and the DSi's is configured via the I2C BPTWL. Add support for changing
these registers and add the "Power Management" dialog in the UI.
Diffstat (limited to 'src/DSi_I2C.cpp')
-rw-r--r-- | src/DSi_I2C.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index a421430..5d13b2a 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -22,6 +22,7 @@ #include "DSi_I2C.h" #include "DSi_Camera.h" #include "ARM.h" +#include "SPI.h" namespace DSi_BPTWL @@ -82,6 +83,19 @@ void DoSavestate(Savestate* file) u8 GetBootFlag() { return Registers[0x70]; } +bool GetBatteryCharging() { return Registers[0x20] >> 7; } +void SetBatteryCharging(bool charging) +{ + Registers[0x20] = (((charging ? 0x8 : 0x0) << 4) | (Registers[0x20] & 0x0F)); +} + +u8 GetBatteryLevel() { return Registers[0x20] & 0xF; } +void SetBatteryLevel(u8 batteryLevel) +{ + Registers[0x20] = ((Registers[0x20] & 0xF0) | (batteryLevel & 0x0F)); + SPI_Powerman::SetBatteryLevelOkay(batteryLevel > batteryLevel_Low ? true : false); +} + void Start() { //printf("BPTWL: start\n"); |