From 68271a27e658e0d1ee6c70010cc1d469edd5f7d9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 14 May 2018 16:53:45 +1000 Subject: [PATCH] stm32/usb: Make CDC endpoint definitions private to core usbdev driver. --- ports/stm32/usbd_cdc_interface.c | 2 +- ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h | 6 +----- ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c | 9 +++++++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ports/stm32/usbd_cdc_interface.c b/ports/stm32/usbd_cdc_interface.c index a987646e7a..f6590ade52 100644 --- a/ports/stm32/usbd_cdc_interface.c +++ b/ports/stm32/usbd_cdc_interface.c @@ -165,7 +165,7 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) { // doing other things and we must give it a chance to read our data. if (cdc->tx_buf_ptr_wait_count < 500) { USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; - if (USBx_INEP(CDC_IN_EP & 0x7f)->DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ) { + if (USBx_INEP(cdc->base.in_ep & 0x7f)->DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ) { // USB in-endpoint is still reading the data cdc->tx_buf_ptr_wait_count++; return; diff --git a/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h b/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h index 18c2c56c3c..b9671ef3a6 100644 --- a/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h +++ b/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h @@ -39,17 +39,13 @@ #define MSC_IN_EP (0x81) #define MSC_OUT_EP (0x01) -// Need to define here for usbd_cdc_interface.c (it needs CDC_IN_EP) -#define CDC_IN_EP (0x83) -#define CDC_OUT_EP (0x03) -#define CDC_CMD_EP (0x82) - struct _usbd_cdc_msc_hid_state_t; typedef struct { struct _usbd_cdc_msc_hid_state_t *usbd; // The parent USB device uint32_t ctl_packet_buf[CDC_DATA_MAX_PACKET_SIZE / 4]; // Force 32-bit alignment uint8_t iface_num; + uint8_t in_ep; uint8_t cur_request; uint8_t cur_length; volatile uint8_t tx_in_progress; diff --git a/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c index 9ef92a1a6e..c2030043fb 100644 --- a/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c +++ b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c @@ -61,6 +61,11 @@ #define MSC_IFACE_NUM_WITH_CDC (0) #define HID_IFACE_NUM_WITH_CDC (0) #define HID_IFACE_NUM_WITH_MSC (1) + +#define CDC_IN_EP (0x83) +#define CDC_OUT_EP (0x03) +#define CDC_CMD_EP (0x82) + #define HID_IN_EP_WITH_CDC (0x81) #define HID_OUT_EP_WITH_CDC (0x01) #define HID_IN_EP_WITH_MSC (0x83) @@ -650,6 +655,10 @@ int USBD_SelectMode(usbd_cdc_msc_hid_state_t *usbd, uint32_t mode, USBD_HID_Mode return -1; } + if (usbd->usbd_mode & USBD_MODE_CDC) { + usbd->cdc->in_ep = CDC_IN_EP; + } + // configure the HID descriptor, if needed if (usbd->usbd_mode & USBD_MODE_HID) { uint8_t *hid_desc = usbd->hid->desc;