diff options
Diffstat (limited to 'platforms/chibios/suspend.c')
| -rw-r--r-- | platforms/chibios/suspend.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/platforms/chibios/suspend.c b/platforms/chibios/suspend.c new file mode 100644 index 000000000..9310a9992 --- /dev/null +++ b/platforms/chibios/suspend.c | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* TODO */ | ||
| 2 | |||
| 3 | #include <ch.h> | ||
| 4 | #include <hal.h> | ||
| 5 | |||
| 6 | #include "matrix.h" | ||
| 7 | #include "action.h" | ||
| 8 | #include "action_util.h" | ||
| 9 | #include "mousekey.h" | ||
| 10 | #include "programmable_button.h" | ||
| 11 | #include "host.h" | ||
| 12 | #include "suspend.h" | ||
| 13 | #include "led.h" | ||
| 14 | #include "wait.h" | ||
| 15 | |||
| 16 | /** \brief suspend idle | ||
| 17 | * | ||
| 18 | * FIXME: needs doc | ||
| 19 | */ | ||
| 20 | void suspend_idle(uint8_t time) { | ||
| 21 | // TODO: this is not used anywhere - what units is 'time' in? | ||
| 22 | wait_ms(time); | ||
| 23 | } | ||
| 24 | |||
| 25 | /** \brief suspend power down | ||
| 26 | * | ||
| 27 | * FIXME: needs doc | ||
| 28 | */ | ||
| 29 | void suspend_power_down(void) { | ||
| 30 | suspend_power_down_quantum(); | ||
| 31 | // on AVR, this enables the watchdog for 15ms (max), and goes to | ||
| 32 | // SLEEP_MODE_PWR_DOWN | ||
| 33 | |||
| 34 | wait_ms(17); | ||
| 35 | } | ||
| 36 | |||
| 37 | /** \brief suspend wakeup condition | ||
| 38 | * | ||
| 39 | * FIXME: needs doc | ||
| 40 | */ | ||
| 41 | __attribute__((weak)) void matrix_power_up(void) {} | ||
| 42 | __attribute__((weak)) void matrix_power_down(void) {} | ||
| 43 | bool suspend_wakeup_condition(void) { | ||
| 44 | matrix_power_up(); | ||
| 45 | matrix_scan(); | ||
| 46 | matrix_power_down(); | ||
| 47 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | ||
| 48 | if (matrix_get_row(r)) return true; | ||
| 49 | } | ||
| 50 | return false; | ||
| 51 | } | ||
| 52 | |||
| 53 | /** \brief run user level code immediately after wakeup | ||
| 54 | * | ||
| 55 | * FIXME: needs doc | ||
| 56 | */ | ||
| 57 | __attribute__((weak)) void suspend_wakeup_init_user(void) {} | ||
| 58 | |||
| 59 | /** \brief run keyboard level code immediately after wakeup | ||
| 60 | * | ||
| 61 | * FIXME: needs doc | ||
| 62 | */ | ||
| 63 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } | ||
| 64 | |||
| 65 | /** \brief suspend wakeup condition | ||
| 66 | * | ||
| 67 | * run immediately after wakeup | ||
| 68 | * FIXME: needs doc | ||
| 69 | */ | ||
| 70 | void suspend_wakeup_init(void) { | ||
| 71 | // clear keyboard state | ||
| 72 | // need to do it manually, because we're running from ISR | ||
| 73 | // and clear_keyboard() calls print | ||
| 74 | // so only clear the variables in memory | ||
| 75 | // the reports will be sent from main.c afterwards | ||
| 76 | // or if the PC asks for GET_REPORT | ||
| 77 | clear_mods(); | ||
| 78 | clear_weak_mods(); | ||
| 79 | clear_keys(); | ||
| 80 | #ifdef MOUSEKEY_ENABLE | ||
| 81 | mousekey_clear(); | ||
| 82 | #endif /* MOUSEKEY_ENABLE */ | ||
| 83 | #ifdef PROGRAMMABLE_BUTTON_ENABLE | ||
| 84 | programmable_button_clear(); | ||
| 85 | #endif /* PROGRAMMABLE_BUTTON_ENABLE */ | ||
| 86 | #ifdef EXTRAKEY_ENABLE | ||
| 87 | host_system_send(0); | ||
| 88 | host_consumer_send(0); | ||
| 89 | #endif /* EXTRAKEY_ENABLE */ | ||
| 90 | |||
| 91 | suspend_wakeup_init_quantum(); | ||
| 92 | } | ||
