8000 stm32/usb: Expose USB HID device instance via usbd_hid_get(). · DucRP/micropython@432b65f · GitHub
[go: up one dir, main page]

Skip to content

Commit 432b65f

Browse files
koendvdpgeorge
authored andcommitted
stm32/usb: Expose USB HID device instance via usbd_hid_get().
This is needed to implement a HID device in user C modules.
1 parent 3ce2194 commit 432b65f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ports/stm32/usb.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,24 @@ usbd_cdc_itf_t *usb_vcp_get(int idx) {
367367
return &usb_device.usbd_cdc_itf[idx];
368368
}
369369

370+
#if MICROPY_HW_USB_HID
371+
372+
// return hid interface if hid is configured, NULL otherwise
373+
usbd_hid_itf_t *usbd_hid_get(void) {
374+
#if defined(USE_HOST_MODE)
375+
return NULL;
376+
#else
377+
uint8_t usb_mode = USBD_GetMode(&usb_device.usbd_cdc_msc_hid_state) & USBD_MODE_IFACE_MASK;
378+
if (usb_mode == USBD_MODE_HID || usb_mode == USBD_MODE_CDC_HID || usb_mode == USBD_MODE_MSC_HID) {
379+
return &usb_device.usbd_hid_itf;
380+
} else {
381+
return NULL;
382+
}
383+
#endif
384+
}
385+
386+
#endif
387+
370388
/******************************************************************************/
371389
// MicroPython bindings for USB
372390

ports/stm32/usbd_hid_interface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ typedef struct _usbd_hid_itf_t {
1616
uint8_t report_in_buf[HID_DATA_FS_MAX_PACKET_SIZE];
1717
} usbd_hid_itf_t;
1818

19+
usbd_hid_itf_t *usbd_hid_get(void);
20+
1921
static inline int usbd_hid_rx_num(usbd_hid_itf_t *hid) {
2022
return hid->report_in_len != USBD_HID_REPORT_INVALID;
2123
}

0 commit comments

Comments
 (0)
0