stm32/usb: Expose USB HID device instance via usbd_hid_get().
This is needed to implement a HID device in user C modules.
This commit is contained in:
parent
3ce21945b1
commit
432b65f178
@ -367,6 +367,24 @@ usbd_cdc_itf_t *usb_vcp_get(int idx) {
|
|||||||
return &usb_device.usbd_cdc_itf[idx];
|
return &usb_device.usbd_cdc_itf[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MICROPY_HW_USB_HID
|
||||||
|
|
||||||
|
// return hid interface if hid is configured, NULL otherwise
|
||||||
|
usbd_hid_itf_t *usbd_hid_get(void) {
|
||||||
|
#if defined(USE_HOST_MODE)
|
||||||
|
return NULL;
|
||||||
|
#else
|
||||||
|
uint8_t usb_mode = USBD_GetMode(&usb_device.usbd_cdc_msc_hid_state) & USBD_MODE_IFACE_MASK;
|
||||||
|
if (usb_mode == USBD_MODE_HID || usb_mode == USBD_MODE_CDC_HID || usb_mode == USBD_MODE_MSC_HID) {
|
||||||
|
return &usb_device.usbd_hid_itf;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
// MicroPython bindings for USB
|
// MicroPython bindings for USB
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ typedef struct _usbd_hid_itf_t {
|
|||||||
uint8_t report_in_buf[HID_DATA_FS_MAX_PACKET_SIZE];
|
uint8_t report_in_buf[HID_DATA_FS_MAX_PACKET_SIZE];
|
||||||
} usbd_hid_itf_t;
|
} usbd_hid_itf_t;
|
||||||
|
|
||||||
|
usbd_hid_itf_t *usbd_hid_get(void);
|
||||||
|
|
||||||
static inline int usbd_hid_rx_num(usbd_hid_itf_t *hid) {
|
static inline int usbd_hid_rx_num(usbd_hid_itf_t *hid) {
|
||||||
return hid->report_in_len != USBD_HID_REPORT_INVALID;
|
return hid->report_in_len != USBD_HID_REPORT_INVALID;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user