34#define USB_XFER_TIMEOUT 100
57 ret = usbh_ctrl_xfer(cdev->
udev,
58 REQ_TYPE_IN | REQ_TYPE_CLASS_DEV | REQ_TYPE_TO_IFACE,
64 &xfer_len, CDC_CMD_TIMEOUT);
67 if ((ret < 0) || (xfer_len != 7))
69 CDC_DBGMSG(
"GET_LINE_CODIN command failed. %d, %d\n", ret, xfer_len);
96 if ((line_code->stop_bits != 0) && (line_code->stop_bits != 1) &&
97 (line_code->stop_bits != 2))
100 if (line_code->parity > 4)
103 if ((line_code->data_bits != 5) && (line_code->data_bits != 6) &&
104 (line_code->data_bits != 7) && (line_code->data_bits != 8) &&
105 (line_code->data_bits != 16))
108 ret = usbh_ctrl_xfer(cdev->
udev,
109 REQ_TYPE_OUT | REQ_TYPE_CLASS_DEV | REQ_TYPE_TO_IFACE,
114 (uint8_t *)line_code,
115 &xfer_len, CDC_CMD_TIMEOUT);
119 CDC_DBGMSG(
"SET_LINE_CODIN command failed. %d\n", ret);
139 uint16_t ctrl_bitmap = 0;
153 ret = usbh_ctrl_xfer(cdev->
udev,
154 REQ_TYPE_OUT | REQ_TYPE_CLASS_DEV | REQ_TYPE_TO_IFACE,
155 CDC_SET_CONTROL_LINE_STATE,
160 &xfer_len, CDC_CMD_TIMEOUT);
165 CDC_DBGMSG(
"SET_CONTROL_LINE_STATE command failed. %d\n", ret);
175static void cdc_int_in_irq(UTR_T *utr)
186 CDC_DBGMSG(
"cdc_int_in_irq - has error: 0x%x\n", utr->status);
190 if (cdev->
sts_func && utr->xfer_len)
191 cdev->
sts_func(cdev, utr->buff, utr->xfer_len);
194 ret = usbh_int_xfer(utr);
197 CDC_DBGMSG(
"cdc_int_in_irq - failed to submit interrupt-in request (%d)", ret);
228 ep = usbh_iface_find_ep(cdev->
iface_cdc, 0, EP_ADDR_DIR_IN | EP_ATTR_TT_INT);
231 CDC_DBGMSG(
"Interrupt-in endpoint not found in this CDC device!\n");
237 utr = alloc_utr(cdev->
udev);
240 CDC_DBGMSG(
"Failed to allocated UTR!\n");
244 utr->buff = (uint8_t *)cdev->
sts_buff;
247 utr->data_len = ep->wMaxPacketSize;
248 if (utr->data_len > CDC_STATUS_BUFF_SIZE)
250 CDC_DBGMSG(
"Warning! CDC_STATUS_BUFF_SIZE %d is smaller than max. packet size %d!\n", CDC_STATUS_BUFF_SIZE, ep->wMaxPacketSize);
251 utr->data_len = CDC_STATUS_BUFF_SIZE;
254 utr->func = cdc_int_in_irq;
259 ret = usbh_int_xfer(utr);
262 CDC_DBGMSG(
"Error - failed to submit interrupt read request (%d)", ret);
274static void cdc_bulk_in_irq(UTR_T *utr)
284 CDC_DBGMSG(
"cdc_bulk_in_irq - has error: 0x%x\n", utr->status);
289 cdev->
rx_func(cdev, utr->buff, utr->xfer_len);
321 ep = usbh_iface_find_ep(cdev->
iface_data, 0, EP_ADDR_DIR_IN | EP_ATTR_TT_BULK);
324 CDC_DBGMSG(
"Bulk-in endpoint not found in this CDC device!\n");
330 utr = alloc_utr(cdev->
udev);
333 CDC_DBGMSG(
"Failed to allocated UTR!\n");
337 utr->buff = (uint8_t *)cdev->
rx_buff;
340 utr->data_len = ep->wMaxPacketSize;
341 if (utr->data_len > CDC_RX_BUFF_SIZE)
343 CDC_DBGMSG(
"Warning! CDC_RX_BUFF_SIZE %d is smaller than max. packet size %d!\n", CDC_RX_BUFF_SIZE, ep->wMaxPacketSize);
344 utr->data_len = CDC_RX_BUFF_SIZE;
347 utr->func = cdc_bulk_in_irq;
353 ret = usbh_bulk_xfer(utr);
356 CDC_DBGMSG(
"Error - failed to submit bulk in request (%d)", ret);
368static volatile int bulk_out_done;
369static void cdc_bulk_out_irq(UTR_T *utr)
396 ep = usbh_iface_find_ep(cdev->
iface_data, 0, EP_ADDR_DIR_OUT | EP_ATTR_TT_BULK);
399 CDC_DBGMSG(
"Bulk-out endpoint not found in this CDC device!\n");
405 utr = alloc_utr(cdev->
udev);
408 CDC_DBGMSG(
"Failed to allocated UTR!\n");
415 utr->data_len = buff_len;
417 utr->func = cdc_bulk_out_irq;
420 ret = usbh_bulk_xfer(utr);
423 CDC_DBGMSG(
"Error - failed to submit bulk in request (%d)", ret);
429 while (bulk_out_done == 0)
NuMicro peripheral access layer header file.
#define NULL
NULL pointer.
#define USBH_ERR_EP_NOT_FOUND
#define USBH_ERR_INVALID_PARAM
#define USBH_ERR_NOT_FOUND
#define USBH_ERR_MEMORY_OUT
int32_t usbh_cdc_start_to_receive_data(struct cdc_dev_t *cdev, CDC_CB_FUNC *func)
Make CDC device start to receive data from bulk-in transfer pipe.
int32_t usbh_cdc_set_line_coding(CDC_DEV_T *cdev, LINE_CODING_T *line_code)
SET_LINE_CODING request.
HIDDEN_SYMBOLS int32_t usbh_cdc_set_control_line_state(struct cdc_dev_t *cdev, int active_carrier, int DTE_present)
SET_CONTROL_LINE_STATE request.
int32_t usbh_cdc_send_data(struct cdc_dev_t *cdev, uint8_t *buff, int buff_len)
Send a block of data via CDC device's bulk-out transfer pipe.
int32_t usbh_cdc_start_polling_status(struct cdc_dev_t *cdev, CDC_CB_FUNC *func)
Start purge the CDC device's interrupt-in transfer pipe.
int32_t usbh_cdc_get_line_coding(CDC_DEV_T *cdev, LINE_CODING_T *line_code)
GET_LINE_CODING request.
uint32_t get_ticks(void)
A function return current tick count.
uint32_t sts_buff[CDC_STATUS_BUFF_SIZE/4]
uint32_t rx_buff[CDC_RX_BUFF_SIZE/4]
void() CDC_CB_FUNC(struct cdc_dev_t *cdev, uint8_t *rdata, int data_len)
USB Host library header file.
USB Host CDC(Communication Device Class) driver header file.
USB Host library exported header file.