ErrorCode_t CDC_ep0_override_hdlr(USBD_HANDLE_T hUsb, void* data, uint32_t event) { USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*) hUsb; USB_CDC_CTRL_T* pCdcCtrl = (USB_CDC_CTRL_T*) data; ErrorCode_t ret = ERR_USBD_UNHANDLED; if(event == USB_EVT_OUT) { if (pCtrl->SetupPacket.bmRequestType.BM.Type == REQUEST_CLASS) { if (pCtrl->SetupPacket.bmRequestType.BM.Recipient == REQUEST_TO_INTERFACE) { if ((pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->cif_num ) || /* IF number correct? */ (pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->dif_num)) { pCtrl->EP0Data.pData -= pCtrl->SetupPacket.wLength; ret = pCdcCtrl->CIC_SetRequest(pCdcCtrl, &pCtrl->SetupPacket,&pCtrl->EP0Data.pData,pCtrl->SetupPacket.wLength); if ( ret == LPC_OK) { USBD_API->core->StatusInStage(pCtrl); /* send Acknowledge */ } } else { ret = g_defaultCdcHdlr(hUsb, data, event); } } else { ret = g_defaultCdcHdlr(hUsb, data, event); } } else { ret = g_defaultCdcHdlr(hUsb, data, event); } } else { ret = g_defaultCdcHdlr(hUsb, data, event); } return ret; } |
ret = USBD_API->cdc->init(hUsb, &cdc_param, &g_vCOM.hCdc); { // Code to fix the STALL Bug in the ROM lib when requesting line breaks // This code must be placed immediately after the call to USBD_API->cdc->init() USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*) hUsb; /* store the default CDC handler and replace it with ours */ g_defaultCdcHdlr = pCtrl->ep0_hdlr_cb[pCtrl->num_ep0_hdlrs - 1]; pCtrl->ep0_hdlr_cb[pCtrl->num_ep0_hdlrs - 1] = CDC_ep0_override_hdlr; |
if ((pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->cif_num ) || /* IF number correct? */ (pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->dif_num)) |
typedef struct _CDC0_CTRL_T { USB_CORE_CTRL_T* pUsbCtrl; /* notification buffer */ uint8_t notice_buf[12]; CDC_LINE_CODING line_coding; uint8_t cif_num; /* control interface number */ uint8_t dif_num; /* data interface number */ uint8_t epin_num; /* BULK IN endpoint number */ uint8_t epout_num; /* BULK OUT endpoint number */ uint8_t epint_num; /* Interrupt IN endpoint number */ /* user defined functions */ ErrorCode_t (*SendEncpsCmd) (USBD_HANDLE_T hCDC, uint8_t* buffer, uint16_t len); ErrorCode_t (*GetEncpsResp) (USBD_HANDLE_T hCDC, uint8_t** buffer, uint16_t* len); ErrorCode_t (*SetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t* buffer, uint16_t len); ErrorCode_t (*GetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t** pBuffer, uint16_t* len); ErrorCode_t (*ClrCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature); ErrorCode_t (*SetCtrlLineState) (USBD_HANDLE_T hCDC, uint16_t state); ErrorCode_t (*SendBreak) (USBD_HANDLE_T hCDC, uint16_t state); ErrorCode_t (*SetLineCode) (USBD_HANDLE_T hCDC, CDC_LINE_CODING* line_coding); /* virtual functions */ ErrorCode_t (*CIC_GetRequest)( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* length); ErrorCode_t (*CIC_SetRequest)( USBD_HANDLE_T hCdc, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length); } USB_CDC0_CTRL_T; |
ErrorCode_t CDC_ep0_override_hdlr(USBD_HANDLE_T hUsb, void *data, uint32_t event) { USB_CORE_CTRL_T *pCtrl = (USB_CORE_CTRL_T *) hUsb; USB_CDC0_CTRL_T *pCdcCtrl = (USB_CDC0_CTRL_T *) data; ErrorCode_t ret = ERR_USBD_UNHANDLED; if ( (event == USB_EVT_OUT) && (pCtrl->SetupPacket.bmRequestType.BM.Type == REQUEST_CLASS) && (pCtrl->SetupPacket.bmRequestType.BM.Recipient == REQUEST_TO_INTERFACE) && ((pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->cif_num) ||/* IF number correct? */ (pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->dif_num)) ) { pCtrl->EP0Data.pData -= pCtrl->SetupPacket.wLength; ret = pCdcCtrl->CIC_SetRequest(pCdcCtrl, &pCtrl->SetupPacket, &pCtrl->EP0Data.pData, pCtrl->SetupPacket.wLength); if ( ret == LPC_OK) { USBD_API->core->StatusInStage(pCtrl);/* send Acknowledge */ } } else { ret = g_defaultCdcHdlr(hUsb, data, event); } return ret; } |