diff options
author | Konstantin Đorđević <vomindoraan@gmail.com> | 2019-01-21 05:16:36 +0100 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-01-20 20:16:36 -0800 |
commit | 0f8431a57f4b1ce50528e4c1689e810ba9554e17 (patch) | |
tree | e2c1b5b0cd41ded3d91c880adf4d4ee313a20f87 | |
parent | 58993d3cde0d52addb4a503daf1ded36b26b8abc (diff) | |
download | qmk_firmware-0f8431a57f4b1ce50528e4c1689e810ba9554e17.tar.gz qmk_firmware-0f8431a57f4b1ce50528e4c1689e810ba9554e17.zip |
Tidy up IS_{,HOST_}LED_{ON,OFF} macros (#4894)
* Tidy up IS_{,HOST_}LED_{ON,OFF} macros
* Tweak LED control docs
-rw-r--r-- | docs/custom_quantum_functions.md | 27 | ||||
-rw-r--r-- | tmk_core/common/host.h | 17 |
2 files changed, 15 insertions, 29 deletions
diff --git a/docs/custom_quantum_functions.md b/docs/custom_quantum_functions.md index 3397bf2d4..d44786e2d 100644 --- a/docs/custom_quantum_functions.md +++ b/docs/custom_quantum_functions.md | |||
@@ -106,10 +106,8 @@ There are two ways to get the host LED state: | |||
106 | 106 | ||
107 | ## `led_set_user()` | 107 | ## `led_set_user()` |
108 | 108 | ||
109 | This function will be called when the state of one of those 5 LEDs changes. | 109 | This function will be called when the state of one of those 5 LEDs changes. It receives the LED state as a parameter. |
110 | It receives the LED state as parameter. | 110 | Use the `IS_LED_ON(usb_led, led_name)` and `IS_LED_OFF(usb_led, led_name)` macros to check the LED status. |
111 | Use the `IS_LED_ON(USB_LED, LED_NAME)` and `IS_LED_OFF(USB_LED, LED_NAME)` | ||
112 | macros to check the LED status. | ||
113 | 111 | ||
114 | !> `host_keyboard_leds()` may already reflect a new value before `led_set_user()` is called. | 112 | !> `host_keyboard_leds()` may already reflect a new value before `led_set_user()` is called. |
115 | 113 | ||
@@ -152,27 +150,20 @@ void led_set_user(uint8_t usb_led) { | |||
152 | 150 | ||
153 | ## `host_keyboard_leds()` | 151 | ## `host_keyboard_leds()` |
154 | 152 | ||
155 | Call this function to get the last received LED state. | 153 | Call this function to get the last received LED state. This is useful for reading the LED state outside `led_set_*`, e.g. in [`matrix_scan_user()`](#matrix-scanning-code). |
156 | This is useful for reading the LED state outside `led_set_*`, e.g. in [`matrix_scan_user()`](#matrix-scanning-code). | 154 | For convenience, you can use the `IS_HOST_LED_ON(led_name)` and `IS_HOST_LED_OFF(led_name)` macros instead of calling and checking `host_keyboard_leds()` directly. |
157 | 155 | ||
158 | For convenience, you can use the `IS_HOST_LED_ON(LED_NAME)` and `IS_HOST_LED_OFF(LED_NAME)` macros instead of calling `host_keyboard_leds()` directly. | 156 | ## Setting Physical LED State |
159 | |||
160 | ## Setting physical LED state | ||
161 | 157 | ||
162 | Some keyboard implementations provide convenience methods for setting the state of the physical LEDs. | 158 | Some keyboard implementations provide convenience methods for setting the state of the physical LEDs. |
163 | 159 | ||
164 | ### Ergodox and Ergodox EZ | 160 | ### Ergodox Boards |
165 | 161 | ||
166 | The Ergodox EZ implementation provides `ergodox_right_led_``1`/`2`/`3_on`/`off()` | 162 | The Ergodox implementations provide `ergodox_right_led_1`/`2`/`3_on`/`off()` to turn individual LEDs on or off, as well as `ergodox_right_led_on`/`off(uint8_t led)` to turn them on or off by their index. |
167 | to turn individual LEDs on and off, as well as | ||
168 | `ergodox_right_led_on`/`off(uint8_t led)` | ||
169 | to turn them on and off by their number. | ||
170 | 163 | ||
171 | In addition, it is possible to specify the brightness level with `ergodox_led_all_set(uint8_t n)`, | 164 | In addition, it is possible to specify the brightness level of all LEDs with `ergodox_led_all_set(uint8_t n)`; of individual LEDs with `ergodox_right_led_1`/`2`/`3_set(uint8_t n)`; or by index with `ergodox_right_led_set(uint8_t led, uint8_t n)`. |
172 | for individual LEDs with `ergodox_right_led_1`/`2`/`3_set(uint8_t n)` | ||
173 | or by their number using `ergodox_right_led_set(uint8_t led, uint8_t n)`. | ||
174 | 165 | ||
175 | It defines `LED_BRIGHTNESS_LO` for the lowest brightness and `LED_BRIGHTNESS_HI` for the highest brightness, which is also the default. | 166 | Ergodox boards also define `LED_BRIGHTNESS_LO` for the lowest brightness and `LED_BRIGHTNESS_HI` for the highest brightness (which is the default). |
176 | 167 | ||
177 | # Matrix Initialization Code | 168 | # Matrix Initialization Code |
178 | 169 | ||
diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h index e70bb6853..3d172eed6 100644 --- a/tmk_core/common/host.h +++ b/tmk_core/common/host.h | |||
@@ -15,14 +15,18 @@ You should have received a copy of the GNU General Public License | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #ifndef HOST_H | 18 | #pragma once |
19 | #define HOST_H | ||
20 | 19 | ||
21 | #include <stdint.h> | 20 | #include <stdint.h> |
22 | #include <stdbool.h> | 21 | #include <stdbool.h> |
23 | #include "report.h" | 22 | #include "report.h" |
24 | #include "host_driver.h" | 23 | #include "host_driver.h" |
25 | 24 | ||
25 | #define IS_LED_ON(leds, led_name) ( (leds) & (1 << (led_name))) | ||
26 | #define IS_LED_OFF(leds, led_name) (~(leds) & (1 << (led_name))) | ||
27 | |||
28 | #define IS_HOST_LED_ON(led_name) IS_LED_ON(host_keyboard_leds(), led_name) | ||
29 | #define IS_HOST_LED_OFF(led_name) IS_LED_OFF(host_keyboard_leds(), led_name) | ||
26 | 30 | ||
27 | #ifdef __cplusplus | 31 | #ifdef __cplusplus |
28 | extern "C" { | 32 | extern "C" { |
@@ -31,7 +35,6 @@ extern "C" { | |||
31 | extern uint8_t keyboard_idle; | 35 | extern uint8_t keyboard_idle; |
32 | extern uint8_t keyboard_protocol; | 36 | extern uint8_t keyboard_protocol; |
33 | 37 | ||
34 | |||
35 | /* host driver */ | 38 | /* host driver */ |
36 | void host_set_driver(host_driver_t *driver); | 39 | void host_set_driver(host_driver_t *driver); |
37 | host_driver_t *host_get_driver(void); | 40 | host_driver_t *host_get_driver(void); |
@@ -46,14 +49,6 @@ void host_consumer_send(uint16_t data); | |||
46 | uint16_t host_last_system_report(void); | 49 | uint16_t host_last_system_report(void); |
47 | uint16_t host_last_consumer_report(void); | 50 | uint16_t host_last_consumer_report(void); |
48 | 51 | ||
49 | #define IS_LED_ON(USB_LED, LED_NAME) ((USB_LED) & (1 << (LED_NAME))) | ||
50 | #define IS_LED_OFF(USB_LED, LED_NAME) (~(USB_LED) & (1 << (LED_NAME))) | ||
51 | |||
52 | #define IS_HOST_LED_ON(LED_NAME) IS_LED_ON(host_keyboard_leds(), (LED_NAME)) | ||
53 | #define IS_HOST_LED_OFF(LED_NAME) IS_LED_OFF(host_keyboard_leds(), (LED_NAME)) | ||
54 | |||
55 | #ifdef __cplusplus | 52 | #ifdef __cplusplus |
56 | } | 53 | } |
57 | #endif | 54 | #endif |
58 | |||
59 | #endif | ||