diff --git a/include/arm11/hardware/mcu.h b/include/arm11/hardware/mcu.h new file mode 100644 index 0000000..370068c --- /dev/null +++ b/include/arm11/hardware/mcu.h @@ -0,0 +1,24 @@ +#pragma once + +/* + * This file is part of fastboot 3DS + * Copyright (C) 2017 derrek, profi200 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "types.h" + +void MCU_disableLEDs(void); +u8 MCU_readBatteryLevel(void); diff --git a/source/arm11/hardware/mcu.c b/source/arm11/hardware/mcu.c new file mode 100644 index 0000000..e52eb55 --- /dev/null +++ b/source/arm11/hardware/mcu.c @@ -0,0 +1,50 @@ +/* + * This file is part of fastboot 3DS + * Copyright (C) 2017 derrek, profi200 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * Based on code from https://github.com/smealum/ctrulib + */ + +#include "mem_map.h" +#include "arm11/hardware/i2c.h" +#include "arm11/hardware/mcu.h" + +enum McuRegisters { + RegBattery = 0x0B, + RegWifiLED = 0x2A, + Reg3DLED = 0x2C, +}; + +void MCU_disableLEDs(void) +{ + // disable wifi LED + I2C_writeReg(I2C_DEV_MCU, RegWifiLED, 0); + + // disable 3D LED + I2C_writeReg(I2C_DEV_MCU, Reg3DLED, 0); +} + +u8 MCU_readBatteryLevel(void) +{ + u8 state; + + if(!I2C_readRegBuf(I2C_DEV_MCU, RegBattery, &state, 1)) + return 0; + + return state; +} diff --git a/source/arm11/power.c b/source/arm11/power.c index 57aca7e..18bd354 100644 --- a/source/arm11/power.c +++ b/source/arm11/power.c @@ -24,28 +24,6 @@ #include "ipc_handler.h" #include "hardware/pxi.h" - - -bool battery_ok(void) -{ - u8 state; - - if(!I2C_readRegBuf(I2C_DEV_MCU, 0xF, &state, 1)) - return false; - - // battery charging, this should be fine - if((state >> 4) & 1) - return true; - - if(!I2C_readRegBuf(I2C_DEV_MCU, 0xB, &state, 1)) - return false; - - if(state >= 10) // 10% should be enough - return true; - - return false; -} - noreturn void power_off(void) { PXI_sendCmd(IPC_CMD9_PREPARE_POWER, NULL, 0); diff --git a/source/arm11/system.c b/source/arm11/system.c index 6b2edb7..79e1b1e 100644 --- a/source/arm11/system.c +++ b/source/arm11/system.c @@ -17,14 +17,18 @@ */ #include "types.h" +#include "hardware/pxi.h" #include "arm11/start.h" #include "arm11/hardware/interrupt.h" #include "arm11/hardware/timer.h" #include "arm11/hardware/i2c.h" -#include "hardware/pxi.h" +#include "arm11/hardware/mcu.h" #include "arm11/hardware/hid.h" - +static void systemRestoreHwState(void) +{ + MCU_disableLEDs(); +} void systemInit(void) { @@ -36,6 +40,7 @@ I2C_init(); hidInit(); PXI_init(); + systemRestoreHwState(); } else { @@ -46,3 +51,4 @@ __asm__ __volatile__("cpsie i" : : : "memory"); // Enables interrupts } +