diff options
author | tomaszduda23 <[email protected]> | 2022-09-13 11:58:08 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2022-09-13 12:58:08 +0300 |
commit | 967361f775dfba46ef0219e7f5d56d0f8253ef3d (patch) | |
tree | 13f6bc1e7720798d4473fc3e5fb4c2be36e8d264 /hid/lib/drivers-stm32 | |
parent | fa01d92dde2d4c199c8f6b394a72a4f41c28cfe9 (diff) |
Status led (#109)
* add SW reset
* adds watchdog
* add status led
Diffstat (limited to 'hid/lib/drivers-stm32')
-rw-r--r-- | hid/lib/drivers-stm32/board-stm32.h | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/hid/lib/drivers-stm32/board-stm32.h b/hid/lib/drivers-stm32/board-stm32.h index 118138ad..b4164766 100644 --- a/hid/lib/drivers-stm32/board-stm32.h +++ b/hid/lib/drivers-stm32/board-stm32.h @@ -32,14 +32,73 @@ namespace DRIVERS { BoardStm32() : Board(BOARD){ //2 sec timeout iwdg_init(IWDG_PRE_16, 0xFFF); + pinMode(LED_BUILTIN, OUTPUT); } void reset() override { nvic_sys_reset(); } - void periodic() { + void periodic() override { iwdg_feed(); + if (is_micros_timed_out(_prev_ts, 100000)) { + switch(_state) + { + case 0: + digitalWrite(LED_BUILTIN, LOW); + break; + case 2: + if(_rx_data) { + _rx_data = false; + digitalWrite(LED_BUILTIN, LOW); + } + break; + case 4: + if(_keyboard_online) { + _keyboard_online = false; + digitalWrite(LED_BUILTIN, LOW); + } + break; + case 8: + if(_mouse_online) { + _mouse_online = false; + digitalWrite(LED_BUILTIN, LOW); + } + break; + case 1: // heartbeat off + case 3: // _rx_data off + case 7: // _keyboard_online off + case 11: // _mouse_online off + digitalWrite(LED_BUILTIN, HIGH); + break; + case 19: + _state = -1; + break; + } + ++_state; + _prev_ts = micros(); + } } + + void updateStatus(status status) override { + switch (status) + { + case RX_DATA: + _rx_data = true; + break; + case KEYBOARD_ONLINE: + _keyboard_online = true; + break; + case MOUSE_ONLINE: + _mouse_online = true; + break; + } + } + private: + unsigned long _prev_ts = 0; + uint8_t _state = 0; + bool _rx_data = false; + bool _keyboard_online = false; + bool _mouse_online = false; }; } |