aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/custom_quantum_functions.md35
-rw-r--r--tmk_core/common/avr/suspend.c33
-rw-r--r--tmk_core/common/chibios/suspend.c33
-rw-r--r--tmk_core/common/suspend.h5
4 files changed, 104 insertions, 2 deletions
diff --git a/docs/custom_quantum_functions.md b/docs/custom_quantum_functions.md
index 6d741b6cb..9a1c486df 100644
--- a/docs/custom_quantum_functions.md
+++ b/docs/custom_quantum_functions.md
@@ -135,9 +135,11 @@ void led_set_user(uint8_t usb_led) {
135* Keyboard/Revision: `void led_set_kb(uint8_t usb_led)` 135* Keyboard/Revision: `void led_set_kb(uint8_t usb_led)`
136* Keymap: `void led_set_user(uint8_t usb_led)` 136* Keymap: `void led_set_user(uint8_t usb_led)`
137 137
138
138# Matrix Initialization Code 139# Matrix Initialization Code
139 140
140Before a keyboard can be used the hardware must be initialized. QMK handles initialization of the keyboard matrix itself, but if you have other hardware like LED's or i²c controllers you will need to set up that hardware before it can be used. 141Before a keyboard can be used the hardware must be initialized. QMK handles initialization of the keyboard matrix itself, but if you have other hardware like LED's or i²c controllers you will need to set up that hardware before it can be used.
142
141 143
142### Example `matrix_init_user()` Implementation 144### Example `matrix_init_user()` Implementation
143 145
@@ -177,9 +179,38 @@ This function gets called at every matrix scan, which is basically as often as t
177You should use this function if you need custom matrix scanning code. It can also be used for custom status output (such as LED's or a display) or other functionality that you want to trigger regularly even when the user isn't typing. 179You should use this function if you need custom matrix scanning code. It can also be used for custom status output (such as LED's or a display) or other functionality that you want to trigger regularly even when the user isn't typing.
178 180
179 181
182# Keyboard Idling/Wake Code
183
184If the board supports it, it can be "idled", by stopping a number of functions. A good example of this is RGB lights or backlights. This can save on power consumption, or may be better behavior for your keyboard.
185
186This is controlled by two functions: `suspend_power_down_*` and `suspend_wakeup_init_*`, which are called when the system is board is idled and when it wakes up, respectively.
187
188
189### Example suspend_power_down_user() and suspend_wakeup_init_user() Implementation
190
191This example, at the keyboard level, sets up B1, B2, and B3 as LED pins.
192
193```
194void suspend_power_down_user(void)
195{
196 rgb_matrix_set_suspend_state(true);
197}
198
199void suspend_wakeup_init_user(void)
200{
201 rgb_matrix_set_suspend_state(false);
202}
203
204```
205
206### `keyboard_init_*` Function Documentation
207
208* Keyboard/Revision: `void suspend_power_down_kb(void)` and `void suspend_wakeup_init_user(void)`
209* Keymap: `void suspend_power_down_kb(void)` and `void suspend_wakeup_init_user(void)`
210
180# Layer Change Code 211# Layer Change Code
181 212
182Thir runs code every time that the layers get changed. This can be useful for layer indication, or custom layer handling. 213This runs code every time that the layers get changed. This can be useful for layer indication, or custom layer handling.
183 214
184### Example `layer_state_set_*` Implementation 215### Example `layer_state_set_*` Implementation
185 216
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index 3aa3d1247..dfa1af273 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -72,6 +72,21 @@ void suspend_idle(uint8_t time)
72 */ 72 */
73static uint8_t wdt_timeout = 0; 73static uint8_t wdt_timeout = 0;
74 74
75/** \brief Run keyboard level Power down
76 *
77 * FIXME: needs doc
78 */
79__attribute__ ((weak))
80void suspend_power_down_user (void) { }
81/** \brief Run keyboard level Power down
82 *
83 * FIXME: needs doc
84 */
85__attribute__ ((weak))
86void suspend_power_down_kb(void) {
87 suspend_power_down_user();
88}
89
75/** \brief Power down 90/** \brief Power down
76 * 91 *
77 * FIXME: needs doc 92 * FIXME: needs doc
@@ -103,6 +118,8 @@ static void power_down(uint8_t wdto)
103#endif 118#endif
104 rgblight_disable_noeeprom(); 119 rgblight_disable_noeeprom();
105#endif 120#endif
121 suspend_power_down_kb();
122
106 // TODO: more power saving 123 // TODO: more power saving
107 // See PicoPower application note 124 // See PicoPower application note
108 // - I/O port input with pullup 125 // - I/O port input with pullup
@@ -144,6 +161,21 @@ bool suspend_wakeup_condition(void)
144 return false; 161 return false;
145} 162}
146 163
164/** \brief run user level code immediately after wakeup
165 *
166 * FIXME: needs doc
167 */
168__attribute__ ((weak))
169void suspend_wakeup_init_user(void) { }
170
171/** \brief run keyboard level code immediately after wakeup
172 *
173 * FIXME: needs doc
174 */
175__attribute__ ((weak))
176void suspend_wakeup_init_kb(void) {
177 suspend_wakeup_init_user();
178}
147/** \brief run immediately after wakeup 179/** \brief run immediately after wakeup
148 * 180 *
149 * FIXME: needs doc 181 * FIXME: needs doc
@@ -162,6 +194,7 @@ void suspend_wakeup_init(void)
162 rgblight_timer_enable(); 194 rgblight_timer_enable();
163#endif 195#endif
164#endif 196#endif
197 suspend_wakeup_init_kb();
165} 198}
166 199
167#ifndef NO_SUSPEND_POWER_DOWN 200#ifndef NO_SUSPEND_POWER_DOWN
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index 32ef773e2..4a119ccef 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -21,6 +21,21 @@ void suspend_idle(uint8_t time) {
21 wait_ms(time); 21 wait_ms(time);
22} 22}
23 23
24/** \brief Run keyboard level Power down
25 *
26 * FIXME: needs doc
27 */
28__attribute__ ((weak))
29void suspend_power_down_user (void) { }
30/** \brief Run keyboard level Power down
31 *
32 * FIXME: needs doc
33 */
34__attribute__ ((weak))
35void suspend_power_down_kb(void) {
36 suspend_power_down_user();
37}
38
24/** \brief suspend power down 39/** \brief suspend power down
25 * 40 *
26 * FIXME: needs doc 41 * FIXME: needs doc
@@ -30,6 +45,7 @@ void suspend_power_down(void) {
30 // shouldn't power down TPM/FTM if we want a breathing LED 45 // shouldn't power down TPM/FTM if we want a breathing LED
31 // also shouldn't power down USB 46 // also shouldn't power down USB
32 47
48 suspend_power_down_kb();
33 // on AVR, this enables the watchdog for 15ms (max), and goes to 49 // on AVR, this enables the watchdog for 15ms (max), and goes to
34 // SLEEP_MODE_PWR_DOWN 50 // SLEEP_MODE_PWR_DOWN
35 51
@@ -53,6 +69,22 @@ bool suspend_wakeup_condition(void)
53 return false; 69 return false;
54} 70}
55 71
72/** \brief run user level code immediately after wakeup
73 *
74 * FIXME: needs doc
75 */
76__attribute__ ((weak))
77void suspend_wakeup_init_user(void) { }
78
79/** \brief run keyboard level code immediately after wakeup
80 *
81 * FIXME: needs doc
82 */
83__attribute__ ((weak))
84void suspend_wakeup_init_kb(void) {
85 suspend_power_down_user();
86}
87
56/** \brief suspend wakeup condition 88/** \brief suspend wakeup condition
57 * 89 *
58 * run immediately after wakeup 90 * run immediately after wakeup
@@ -79,4 +111,5 @@ void suspend_wakeup_init(void)
79#ifdef BACKLIGHT_ENABLE 111#ifdef BACKLIGHT_ENABLE
80 backlight_init(); 112 backlight_init();
81#endif /* BACKLIGHT_ENABLE */ 113#endif /* BACKLIGHT_ENABLE */
114 suspend_wakeup_init_kb();
82} 115}
diff --git a/tmk_core/common/suspend.h b/tmk_core/common/suspend.h
index 80617a824..c3e444708 100644
--- a/tmk_core/common/suspend.h
+++ b/tmk_core/common/suspend.h
@@ -10,4 +10,9 @@ void suspend_power_down(void);
10bool suspend_wakeup_condition(void); 10bool suspend_wakeup_condition(void);
11void suspend_wakeup_init(void); 11void suspend_wakeup_init(void);
12 12
13void suspend_wakeup_init_user(void);
14void suspend_wakeup_init_kb(void);
15void suspend_power_down_user (void);
16void suspend_power_down_kb(void);
17
13#endif 18#endif