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.
This commit is contained in:
Rayyan Ansari
2022-02-18 15:32:46 +00:00
committed by Arisotura
parent c3adf6f606
commit 2569c67a13
16 changed files with 1360 additions and 0 deletions

View File

@ -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");