From dfb78d2a086daa2ceb3fd043afce03785abfa23a Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 6 Nov 2019 11:42:16 +1100 Subject: New and improved lock LED callbacks (#7215) * New and improved lock LED callbacks * Include stdbool * Update documentation * Use full function signatures and add keyboard-level example --- tmk_core/common/host.c | 6 ++++++ tmk_core/common/host.h | 2 ++ tmk_core/common/led.h | 13 +++++++++++++ 3 files changed, 21 insertions(+) (limited to 'tmk_core') diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c index ce39760a5b..713b0d9456 100644 --- a/tmk_core/common/host.c +++ b/tmk_core/common/host.c @@ -39,6 +39,12 @@ uint8_t host_keyboard_leds(void) { if (!driver) return 0; return (*driver->keyboard_leds)(); } + +led_t host_keyboard_led_state(void) { + if (!driver) return (led_t) {0}; + return (led_t)((*driver->keyboard_leds)()); +} + /* send report */ void host_keyboard_send(report_keyboard_t *report) { if (!driver) return; diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h index b2a7f98427..2cffef6e15 100644 --- a/tmk_core/common/host.h +++ b/tmk_core/common/host.h @@ -21,6 +21,7 @@ along with this program. If not, see . #include #include "report.h" #include "host_driver.h" +#include "led.h" #define IS_LED_ON(leds, led_name) ((leds) & (1 << (led_name))) #define IS_LED_OFF(leds, led_name) (~(leds) & (1 << (led_name))) @@ -41,6 +42,7 @@ host_driver_t *host_get_driver(void); /* host driver interface */ uint8_t host_keyboard_leds(void); +led_t host_keyboard_led_state(void); void host_keyboard_send(report_keyboard_t *report); void host_mouse_send(report_mouse_t *report); void host_system_send(uint16_t data); diff --git a/tmk_core/common/led.h b/tmk_core/common/led.h index 2c28fe5401..daf974bed4 100644 --- a/tmk_core/common/led.h +++ b/tmk_core/common/led.h @@ -18,6 +18,7 @@ along with this program. If not, see . #ifndef LED_H #define LED_H #include "stdint.h" +#include "stdbool.h" /* FIXME: Add doxygen comments here. */ @@ -32,6 +33,18 @@ along with this program. If not, see . extern "C" { #endif +typedef union { + uint8_t raw; + struct { + bool num_lock : 1; + bool caps_lock : 1; + bool scroll_lock : 1; + bool compose : 1; + bool kana : 1; + uint8_t reserved : 3; + }; +} led_t; + void led_set(uint8_t usb_led); void led_init_ports(void); -- cgit v1.2.3