Wolfvak 9ecb90a2ba make interrupt handlers more lazy, most processing is done in interruptible context now
- completely moved MCU interrupt handling outside of the critical section
- refactored a bit of the PXI code and command names
- merge the I2C read and write cmds to be one
- remove SET_VMODE cmd, now it's always initialized to BGR565 on boot and to RGB565 on firmlaunch
- atomic-ize more stuff
2021-02-21 14:40:33 +01:00

46 lines
945 B
C

#include "arm.h"
#include "power.h"
#include "i2c.h"
#include "pxi.h"
u32 SetScreenBrightness(int level) {
u32 arg;
if (level != BRIGHTNESS_AUTOMATIC) {
arg = clamp(level, BRIGHTNESS_MIN, BRIGHTNESS_MAX);
} else {
arg = 0;
}
return PXI_DoCMD(PXICMD_SET_BRIGHTNESS, &arg, 1);
}
u32 GetBatteryPercent() {
u8 battery = 0;
I2C_readRegBuf(I2C_DEV_MCU, 0x0B, &battery, 1);
return battery;
}
bool IsCharging() {
u8 flags = 0;
I2C_readRegBuf(I2C_DEV_MCU, 0x0F, &flags, 1);
return flags & (1<<4);
}
void Reboot() {
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
ARM_WbDC();
ARM_DSB();
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 2);
while(true);
}
void PowerOff()
{
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
ARM_WbDC();
ARM_DSB();
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 0);
while(true);
}