summaryrefslogtreecommitdiff
path: root/examples/device/hid_composite/src
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2021-07-17 12:10:35 +0200
committerGitHub <[email protected]>2021-07-17 12:10:35 +0200
commitb194aa240bba9211e01dd9eaf4562e00a7215666 (patch)
treeb9ef8962f6fdac517e7fc8575526f6cdec8467c1 /examples/device/hid_composite/src
parent475742984f4d0f2b95c9c78dfff71814117feb90 (diff)
parent21bfd11683c4bb6e0996130bd1061a97d3049121 (diff)
Merge branch 'master' into dcd_same70
Diffstat (limited to 'examples/device/hid_composite/src')
-rw-r--r--examples/device/hid_composite/src/main.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c
index 512f6f9d9..d2a8a28fa 100644
--- a/examples/device/hid_composite/src/main.c
+++ b/examples/device/hid_composite/src/main.c
@@ -255,12 +255,31 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
{
- // TODO set LED based on CAPLOCK, NUMLOCK etc...
(void) itf;
- (void) report_id;
- (void) report_type;
- (void) buffer;
- (void) bufsize;
+
+ if (report_type == HID_REPORT_TYPE_OUTPUT)
+ {
+ // Set keyboard LED e.g Capslock, Numlock etc...
+ if (report_id == REPORT_ID_KEYBOARD)
+ {
+ // bufsize should be (at least) 1
+ if ( bufsize < 1 ) return;
+
+ uint8_t const kbd_leds = buffer[0];
+
+ if (kbd_leds & KEYBOARD_LED_CAPSLOCK)
+ {
+ // Capslock On: disable blink, turn led on
+ blink_interval_ms = 0;
+ board_led_write(true);
+ }else
+ {
+ // Caplocks Off: back to normal blink
+ board_led_write(false);
+ blink_interval_ms = BLINK_MOUNTED;
+ }
+ }
+ }
}
//--------------------------------------------------------------------+
@@ -271,6 +290,9 @@ void led_blinking_task(void)
static uint32_t start_ms = 0;
static bool led_state = false;
+ // blink is disabled
+ if (!blink_interval_ms) return;
+
// Blink every interval ms
if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
start_ms += blink_interval_ms;