From 3cb616a6977d8cf71d439a4a632c9321211a69c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20A=CC=81ngel?= Date: Sat, 7 Aug 2021 11:30:56 -0500 Subject: [PATCH 1/4] feat(logic): read usb report leds --- app/Kconfig | 4 ++++ app/include/zmk/usb.h | 3 +++ app/src/usb.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/app/Kconfig b/app/Kconfig index f23930b4..708ae386 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -424,6 +424,10 @@ choice CBPRINTF_IMPLEMENTATION endchoice +config ZMK_USB_REPORT_LEDS + bool "Enable usb report leds" + select ENABLE_HID_INT_OUT_EP + module = ZMK module-str = zmk source "subsys/logging/Kconfig.template.log_config" diff --git a/app/include/zmk/usb.h b/app/include/zmk/usb.h index 62a7e3cb..93bd3c40 100644 --- a/app/include/zmk/usb.h +++ b/app/include/zmk/usb.h @@ -26,4 +26,7 @@ static inline bool zmk_usb_is_hid_ready() { return zmk_usb_get_conn_state() == Z #ifdef CONFIG_ZMK_USB int zmk_usb_hid_send_report(const uint8_t *report, size_t len); +#ifdef CONFIG_ZMK_USB_REPORT_LEDS +int zmk_usb_hid_receive_report(uint8_t *report, size_t len); +#endif /* CONFIG_ZMK_USB_REPORT_LEDS */ #endif /* CONFIG_ZMK_USB */ \ No newline at end of file diff --git a/app/src/usb.c b/app/src/usb.c index 2f0fa439..857a6ef3 100644 --- a/app/src/usb.c +++ b/app/src/usb.c @@ -38,6 +38,22 @@ static const struct hid_ops ops = { .int_in_ready = in_ready_cb, }; +#ifdef CONFIG_ZMK_USB_REPORT_LEDS + +int zmk_usb_hid_receive_report(uint8_t *report, size_t len) { + k_sem_take(&hid_sem, K_MSEC(30)); + int err = hid_int_ep_read(hid_dev, report, len, NULL); + + if (err) { + k_sem_give(&hid_sem); + LOG_ERR("Error receive report %d", err); + } + + return err; +} + +#endif /* CONFIG_ZMK_USB_REPORT_LEDS */ + int zmk_usb_hid_send_report(const uint8_t *report, size_t len) { switch (usb_status) { case USB_DC_SUSPEND: From 4b78c125db042d20e4f6bad2300f8dfbc2647050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20A=CC=81ngel?= Date: Sat, 7 Aug 2021 11:33:02 -0500 Subject: [PATCH 2/4] feat(config): report config to leds --- app/include/zmk/hid.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/include/zmk/hid.h b/app/include/zmk/hid.h index 5aa004c2..9afe009b 100644 --- a/app/include/zmk/hid.h +++ b/app/include/zmk/hid.h @@ -135,6 +135,38 @@ static const uint8_t zmk_hid_report_desc[] = { ZMK_HID_CONSUMER_NKRO_SIZE, HID_MI_INPUT, 0x00, + +#ifdef CONFIG_ZMK_USB_REPORT_LEDS + /* LED */ + 0x85, 0x01, + /* REPORT_COUNT (5) */ + HID_GI_REPORT_COUNT, + 0x05, + /* REPORT_SIZE (1) */ + HID_GI_REPORT_SIZE, + 0x01, + /* USAGE_PAGE (Page# for LEDs) */ + HID_GI_USAGE_PAGE, + 0x08, + /* USAGE_MINIMUM (1) */ + 0x19, 0x01, + /* USAGE_MAXIMUM (5) */ + 0x29, 0x05, + /* OUTPUT (Data, Variable, Absolute), */ + HID_MI_OUTPUT, + 0x02, + /* LED REPORT */ + /* REPORT_COUNT (1) */ + HID_GI_REPORT_COUNT, + 0x01, + /* REPORT_SIZE (3) */ + HID_GI_REPORT_SIZE, + 0x03, + /* OUTPUT (Data, Variable, Absolute), */ + HID_MI_OUTPUT, + 0x01, +#endif /* CONFIG_ZMK_USB_REPORT_LEDS */ + /* END COLLECTION */ HID_MI_COLLECTION_END, }; From 866c9dd96e22c3f14dc64d1994b8fa453f666b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20A=CC=81ngel?= Date: Sat, 30 Oct 2021 18:47:15 +0000 Subject: [PATCH 3/4] Format code --- app/include/zmk/hid.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/include/zmk/hid.h b/app/include/zmk/hid.h index 9afe009b..29696b0e 100644 --- a/app/include/zmk/hid.h +++ b/app/include/zmk/hid.h @@ -138,32 +138,35 @@ static const uint8_t zmk_hid_report_desc[] = { #ifdef CONFIG_ZMK_USB_REPORT_LEDS /* LED */ - 0x85, 0x01, + 0x85, + 0x01, /* REPORT_COUNT (5) */ HID_GI_REPORT_COUNT, 0x05, /* REPORT_SIZE (1) */ - HID_GI_REPORT_SIZE, + HID_GI_REPORT_SIZE, 0x01, /* USAGE_PAGE (Page# for LEDs) */ - HID_GI_USAGE_PAGE, + HID_GI_USAGE_PAGE, 0x08, /* USAGE_MINIMUM (1) */ - 0x19, 0x01, + 0x19, + 0x01, /* USAGE_MAXIMUM (5) */ - 0x29, 0x05, + 0x29, + 0x05, /* OUTPUT (Data, Variable, Absolute), */ - HID_MI_OUTPUT, + HID_MI_OUTPUT, 0x02, - /* LED REPORT */ + /* LED REPORT */ /* REPORT_COUNT (1) */ - HID_GI_REPORT_COUNT, + HID_GI_REPORT_COUNT, 0x01, /* REPORT_SIZE (3) */ - HID_GI_REPORT_SIZE, + HID_GI_REPORT_SIZE, 0x03, /* OUTPUT (Data, Variable, Absolute), */ - HID_MI_OUTPUT, + HID_MI_OUTPUT, 0x01, #endif /* CONFIG_ZMK_USB_REPORT_LEDS */ From 9ecacd47e2fccdcdb5f468efae213af45f295cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20A=CC=81ngel?= Date: Sat, 30 Oct 2021 18:48:27 +0000 Subject: [PATCH 4/4] Position of fuction in file and remove sem_take --- app/src/usb.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/src/usb.c b/app/src/usb.c index 857a6ef3..570f0b20 100644 --- a/app/src/usb.c +++ b/app/src/usb.c @@ -38,22 +38,6 @@ static const struct hid_ops ops = { .int_in_ready = in_ready_cb, }; -#ifdef CONFIG_ZMK_USB_REPORT_LEDS - -int zmk_usb_hid_receive_report(uint8_t *report, size_t len) { - k_sem_take(&hid_sem, K_MSEC(30)); - int err = hid_int_ep_read(hid_dev, report, len, NULL); - - if (err) { - k_sem_give(&hid_sem); - LOG_ERR("Error receive report %d", err); - } - - return err; -} - -#endif /* CONFIG_ZMK_USB_REPORT_LEDS */ - int zmk_usb_hid_send_report(const uint8_t *report, size_t len) { switch (usb_status) { case USB_DC_SUSPEND: @@ -75,6 +59,20 @@ int zmk_usb_hid_send_report(const uint8_t *report, size_t len) { } } +#ifdef CONFIG_ZMK_USB_REPORT_LEDS + +int zmk_usb_hid_receive_report(uint8_t *report, size_t len) { + int err = hid_int_ep_read(hid_dev, report, len, NULL); + + if (err) { + LOG_ERR("Error receive report %d", err); + } + + return err; +} + +#endif /* CONFIG_ZMK_USB_REPORT_LEDS */ + #endif /* CONFIG_ZMK_USB */ enum usb_dc_status_code zmk_usb_get_status() { return usb_status; }