diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/e300/battery/pmu.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/firmware/e300/battery/pmu.c b/firmware/e300/battery/pmu.c index afd5036fa..59ba171a3 100644 --- a/firmware/e300/battery/pmu.c +++ b/firmware/e300/battery/pmu.c @@ -58,11 +58,14 @@ static io_pin_t AVR_IRQ = IO_PD(5); static io_pin_t PS_POR = IO_PD(6); static io_pin_t PS_SRST = IO_PD(7); static io_pin_t OVERTEMP = IO_PC(2); +static io_pin_t PANICn = IO_PC(1); static uint16_t last_full_charge; static uint16_t charge_on_last_unplug; static bool battery_present_last; +static bool panic_last; + static const uint8_t PMU_BLINK_ERROR_DELAY_MS = 250; static const uint8_t PMU_BLINK_ERROR_TICKS_PER_BLINK = 10; @@ -224,6 +227,10 @@ int8_t pmu_init(void) state = OFF; + /* make panic button an input */ + io_input_pin(PANICn); + panic_last = io_test_pin(PANICn); + /* make the LED outputs */ io_output_pin(CHARGE); io_output_pin(POWER_LED); @@ -525,6 +532,7 @@ void pmu_handle_events(void) bool is_charging = false; bool is_full = false; bool overtemp = io_test_pin(OVERTEMP); + bool panic = io_test_pin(PANICn); /* check if someone plugged the battery late, * if so init gauge */ @@ -537,6 +545,10 @@ void pmu_handle_events(void) } battery_present_last = battery_present; + if (panic != panic_last) + pmu_power_down(); + panic_last = panic; + if (overtemp) { fpga_set_gauge_status(BIT(6)); pmu_error = PMU_ERROR_GLOBAL_TEMP; |