From 43cd92f3bbd214d8dfc83358ad37d585eeeb32e1 Mon Sep 17 00:00:00 2001 From: Simon Kueppers Date: Sun, 21 May 2023 13:56:14 +0200 Subject: [PATCH] Added functionality to send back HID button presses to host --- stm32/aioc-fw/Src/usb_hid.c | 14 +++++++++++--- stm32/aioc-fw/Src/usb_hid.h | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/stm32/aioc-fw/Src/usb_hid.c b/stm32/aioc-fw/Src/usb_hid.c index dc23053..97c932d 100644 --- a/stm32/aioc-fw/Src/usb_hid.c +++ b/stm32/aioc-fw/Src/usb_hid.c @@ -6,23 +6,24 @@ #define USB_HID_INOUT_REPORT_LEN 4 +static uint8_t buttonState = 0x00; static uint8_t gpioState = 0x00; static void MakeReport(uint8_t * buffer) { /* TODO: Read the actual states of the GPIO input hardware pins. */ - buffer[0] = 0x00; + buffer[0] = buttonState & 0x0F; buffer[1] = gpioState; buffer[2] = 0x00; buffer[3] = 0x00; } -static void SendReport(void) +static bool SendReport(void) { uint8_t reportBuffer[USB_HID_INOUT_REPORT_LEN]; MakeReport(reportBuffer); - tud_hid_report(0, reportBuffer, sizeof(reportBuffer)); + return tud_hid_report(0, reportBuffer, sizeof(reportBuffer)); } static void ControlPTT(uint8_t gpio) @@ -160,3 +161,10 @@ void USB_HIDInit(void) } + +bool USB_HIDSendButtonState(uint8_t buttonMask) +{ + buttonState = buttonMask; + + return SendReport(); +} diff --git a/stm32/aioc-fw/Src/usb_hid.h b/stm32/aioc-fw/Src/usb_hid.h index 661cf20..817cd7d 100644 --- a/stm32/aioc-fw/Src/usb_hid.h +++ b/stm32/aioc-fw/Src/usb_hid.h @@ -1,6 +1,15 @@ #ifndef USB_HID_H_ #define USB_HID_H_ +#include +#include + +#define USB_HID_BUTTON_VOLUP 0x01 +#define USB_HID_BUTTON_VOLDN 0x02 +#define USB_HID_BUTTON_PLAYMUTE 0x04 +#define USB_HID_BUTTON_RECMUTE 0x08 + void USB_HIDInit(void); +bool USB_HIDSendButtonState(uint8_t inputsMask); #endif /* USB_HID_H_ */