diff options
Diffstat (limited to 'hid/lib/drivers-stm32/board-stm32.h')
-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; }; } |