diff options
author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tmk_core/common/avr/suspend.c | |
parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip |
clang-format changes
Diffstat (limited to 'tmk_core/common/avr/suspend.c')
-rw-r--r-- | tmk_core/common/avr/suspend.c | 171 |
1 files changed, 80 insertions, 91 deletions
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 2259201b5..574000fcd 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c | |||
@@ -13,37 +13,36 @@ | |||
13 | #include "rgblight_reconfig.h" | 13 | #include "rgblight_reconfig.h" |
14 | 14 | ||
15 | #ifdef PROTOCOL_LUFA | 15 | #ifdef PROTOCOL_LUFA |
16 | #include "lufa.h" | 16 | # include "lufa.h" |
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | #ifdef AUDIO_ENABLE | 19 | #ifdef AUDIO_ENABLE |
20 | #include "audio.h" | 20 | # include "audio.h" |
21 | #endif /* AUDIO_ENABLE */ | 21 | #endif /* AUDIO_ENABLE */ |
22 | 22 | ||
23 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 23 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
24 | #include "rgblight.h" | 24 | # include "rgblight.h" |
25 | extern rgblight_config_t rgblight_config; | 25 | extern rgblight_config_t rgblight_config; |
26 | static bool rgblight_enabled; | 26 | static bool rgblight_enabled; |
27 | static bool is_suspended; | 27 | static bool is_suspended; |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | 30 | #define wdt_intr_enable(value) \ | |
31 | #define wdt_intr_enable(value) \ | 31 | __asm__ __volatile__("in __tmp_reg__,__SREG__" \ |
32 | __asm__ __volatile__ ( \ | 32 | "\n\t" \ |
33 | "in __tmp_reg__,__SREG__" "\n\t" \ | 33 | "cli" \ |
34 | "cli" "\n\t" \ | 34 | "\n\t" \ |
35 | "wdr" "\n\t" \ | 35 | "wdr" \ |
36 | "sts %0,%1" "\n\t" \ | 36 | "\n\t" \ |
37 | "out __SREG__,__tmp_reg__" "\n\t" \ | 37 | "sts %0,%1" \ |
38 | "sts %0,%2" "\n\t" \ | 38 | "\n\t" \ |
39 | : /* no outputs */ \ | 39 | "out __SREG__,__tmp_reg__" \ |
40 | : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ | 40 | "\n\t" \ |
41 | "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ | 41 | "sts %0,%2" \ |
42 | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ | 42 | "\n\t" \ |
43 | _BV(WDIE) | (value & 0x07)) ) \ | 43 | : /* no outputs */ \ |
44 | : "r0" \ | 44 | : "M"(_SFR_MEM_ADDR(_WD_CONTROL_REG)), "r"(_BV(_WD_CHANGE_BIT) | _BV(WDE)), "r"((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00) | _BV(WDIE) | (value & 0x07))) \ |
45 | ) | 45 | : "r0") |
46 | |||
47 | 46 | ||
48 | /** \brief Suspend idle | 47 | /** \brief Suspend idle |
49 | * | 48 | * |
@@ -58,23 +57,18 @@ void suspend_idle(uint8_t time) { | |||
58 | sleep_disable(); | 57 | sleep_disable(); |
59 | } | 58 | } |
60 | 59 | ||
61 | |||
62 | // TODO: This needs some cleanup | 60 | // TODO: This needs some cleanup |
63 | 61 | ||
64 | /** \brief Run keyboard level Power down | 62 | /** \brief Run keyboard level Power down |
65 | * | 63 | * |
66 | * FIXME: needs doc | 64 | * FIXME: needs doc |
67 | */ | 65 | */ |
68 | __attribute__ ((weak)) | 66 | __attribute__((weak)) void suspend_power_down_user(void) {} |
69 | void suspend_power_down_user (void) { } | ||
70 | /** \brief Run keyboard level Power down | 67 | /** \brief Run keyboard level Power down |
71 | * | 68 | * |
72 | * FIXME: needs doc | 69 | * FIXME: needs doc |
73 | */ | 70 | */ |
74 | __attribute__ ((weak)) | 71 | __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } |
75 | void suspend_power_down_kb(void) { | ||
76 | suspend_power_down_user(); | ||
77 | } | ||
78 | 72 | ||
79 | #ifndef NO_SUSPEND_POWER_DOWN | 73 | #ifndef NO_SUSPEND_POWER_DOWN |
80 | /** \brief Power down MCU with watchdog timer | 74 | /** \brief Power down MCU with watchdog timer |
@@ -98,43 +92,43 @@ static uint8_t wdt_timeout = 0; | |||
98 | * FIXME: needs doc | 92 | * FIXME: needs doc |
99 | */ | 93 | */ |
100 | static void power_down(uint8_t wdto) { | 94 | static void power_down(uint8_t wdto) { |
101 | #ifdef PROTOCOL_LUFA | 95 | # ifdef PROTOCOL_LUFA |
102 | if (USB_DeviceState == DEVICE_STATE_Configured) return; | 96 | if (USB_DeviceState == DEVICE_STATE_Configured) return; |
103 | #endif | 97 | # endif |
104 | wdt_timeout = wdto; | 98 | wdt_timeout = wdto; |
105 | 99 | ||
106 | // Watchdog Interrupt Mode | 100 | // Watchdog Interrupt Mode |
107 | wdt_intr_enable(wdto); | 101 | wdt_intr_enable(wdto); |
108 | 102 | ||
109 | #ifdef BACKLIGHT_ENABLE | 103 | # ifdef BACKLIGHT_ENABLE |
110 | backlight_set(0); | 104 | backlight_set(0); |
111 | #endif | 105 | # endif |
112 | 106 | ||
113 | // Turn off LED indicators | 107 | // Turn off LED indicators |
114 | uint8_t leds_off = 0; | 108 | uint8_t leds_off = 0; |
115 | #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | 109 | # if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) |
116 | if (is_backlight_enabled()) { | 110 | if (is_backlight_enabled()) { |
117 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off | 111 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off |
118 | leds_off |= (1<<USB_LED_CAPS_LOCK); | 112 | leds_off |= (1 << USB_LED_CAPS_LOCK); |
119 | } | 113 | } |
120 | #endif | 114 | # endif |
121 | led_set(leds_off); | 115 | led_set(leds_off); |
122 | 116 | ||
123 | #ifdef AUDIO_ENABLE | 117 | # ifdef AUDIO_ENABLE |
124 | // This sometimes disables the start-up noise, so it's been disabled | 118 | // This sometimes disables the start-up noise, so it's been disabled |
125 | // stop_all_notes(); | 119 | // stop_all_notes(); |
126 | #endif /* AUDIO_ENABLE */ | 120 | # endif /* AUDIO_ENABLE */ |
127 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 121 | # if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
128 | #ifdef RGBLIGHT_ANIMATIONS | 122 | # ifdef RGBLIGHT_ANIMATIONS |
129 | rgblight_timer_disable(); | 123 | rgblight_timer_disable(); |
130 | #endif | 124 | # endif |
131 | if (!is_suspended) { | 125 | if (!is_suspended) { |
132 | is_suspended = true; | 126 | is_suspended = true; |
133 | rgblight_enabled = rgblight_config.enable; | 127 | rgblight_enabled = rgblight_config.enable; |
134 | rgblight_disable_noeeprom(); | 128 | rgblight_disable_noeeprom(); |
135 | } | 129 | } |
136 | #endif | 130 | # endif |
137 | suspend_power_down_kb(); | 131 | suspend_power_down_kb(); |
138 | 132 | ||
139 | // TODO: more power saving | 133 | // TODO: more power saving |
140 | // See PicoPower application note | 134 | // See PicoPower application note |
@@ -158,40 +152,36 @@ static void power_down(uint8_t wdto) { | |||
158 | * FIXME: needs doc | 152 | * FIXME: needs doc |
159 | */ | 153 | */ |
160 | void suspend_power_down(void) { | 154 | void suspend_power_down(void) { |
161 | suspend_power_down_kb(); | 155 | suspend_power_down_kb(); |
162 | 156 | ||
163 | #ifndef NO_SUSPEND_POWER_DOWN | 157 | #ifndef NO_SUSPEND_POWER_DOWN |
164 | power_down(WDTO_15MS); | 158 | power_down(WDTO_15MS); |
165 | #endif | 159 | #endif |
166 | } | 160 | } |
167 | 161 | ||
168 | __attribute__ ((weak)) void matrix_power_up(void) {} | 162 | __attribute__((weak)) void matrix_power_up(void) {} |
169 | __attribute__ ((weak)) void matrix_power_down(void) {} | 163 | __attribute__((weak)) void matrix_power_down(void) {} |
170 | bool suspend_wakeup_condition(void) { | 164 | bool suspend_wakeup_condition(void) { |
171 | matrix_power_up(); | 165 | matrix_power_up(); |
172 | matrix_scan(); | 166 | matrix_scan(); |
173 | matrix_power_down(); | 167 | matrix_power_down(); |
174 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | 168 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { |
175 | if (matrix_get_row(r)) return true; | 169 | if (matrix_get_row(r)) return true; |
176 | } | 170 | } |
177 | return false; | 171 | return false; |
178 | } | 172 | } |
179 | 173 | ||
180 | /** \brief run user level code immediately after wakeup | 174 | /** \brief run user level code immediately after wakeup |
181 | * | 175 | * |
182 | * FIXME: needs doc | 176 | * FIXME: needs doc |
183 | */ | 177 | */ |
184 | __attribute__ ((weak)) | 178 | __attribute__((weak)) void suspend_wakeup_init_user(void) {} |
185 | void suspend_wakeup_init_user(void) { } | ||
186 | 179 | ||
187 | /** \brief run keyboard level code immediately after wakeup | 180 | /** \brief run keyboard level code immediately after wakeup |
188 | * | 181 | * |
189 | * FIXME: needs doc | 182 | * FIXME: needs doc |
190 | */ | 183 | */ |
191 | __attribute__ ((weak)) | 184 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } |
192 | void suspend_wakeup_init_kb(void) { | ||
193 | suspend_wakeup_init_user(); | ||
194 | } | ||
195 | /** \brief run immediately after wakeup | 185 | /** \brief run immediately after wakeup |
196 | * | 186 | * |
197 | * FIXME: needs doc | 187 | * FIXME: needs doc |
@@ -202,18 +192,18 @@ void suspend_wakeup_init(void) { | |||
202 | #ifdef BACKLIGHT_ENABLE | 192 | #ifdef BACKLIGHT_ENABLE |
203 | backlight_init(); | 193 | backlight_init(); |
204 | #endif | 194 | #endif |
205 | led_set(host_keyboard_leds()); | 195 | led_set(host_keyboard_leds()); |
206 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 196 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
207 | is_suspended = false; | 197 | is_suspended = false; |
208 | if (rgblight_enabled) { | 198 | if (rgblight_enabled) { |
209 | #ifdef BOOTLOADER_TEENSY | 199 | # ifdef BOOTLOADER_TEENSY |
210 | wait_ms(10); | 200 | wait_ms(10); |
211 | #endif | 201 | # endif |
212 | rgblight_enable_noeeprom(); | 202 | rgblight_enable_noeeprom(); |
213 | } | 203 | } |
214 | #ifdef RGBLIGHT_ANIMATIONS | 204 | # ifdef RGBLIGHT_ANIMATIONS |
215 | rgblight_timer_enable(); | 205 | rgblight_timer_enable(); |
216 | #endif | 206 | # endif |
217 | #endif | 207 | #endif |
218 | suspend_wakeup_init_kb(); | 208 | suspend_wakeup_init_kb(); |
219 | } | 209 | } |
@@ -226,8 +216,7 @@ ISR(WDT_vect) { | |||
226 | case WDTO_15MS: | 216 | case WDTO_15MS: |
227 | timer_count += 15 + 2; // WDTO_15MS + 2(from observation) | 217 | timer_count += 15 + 2; // WDTO_15MS + 2(from observation) |
228 | break; | 218 | break; |
229 | default: | 219 | default:; |
230 | ; | ||
231 | } | 220 | } |
232 | } | 221 | } |
233 | #endif | 222 | #endif |