37#define USB_XFER_TIMEOUT 100
60 ret = usbh_ctrl_xfer(cdev->
udev,
61 REQ_TYPE_IN | REQ_TYPE_CLASS_DEV | REQ_TYPE_TO_IFACE,
67 &xfer_len, CDC_CMD_TIMEOUT);
69 if((ret < 0) || (xfer_len != 7))
71 CDC_DBGMSG(
"GET_LINE_CODIN command failed. %d, %d\n", ret, xfer_len);
98 if((line_code->stop_bits != 0) && (line_code->stop_bits != 1) &&
99 (line_code->stop_bits != 2))
102 if(line_code->parity > 4)
105 if((line_code->data_bits != 5) && (line_code->data_bits != 6) &&
106 (line_code->data_bits != 7) && (line_code->data_bits != 8) &&
107 (line_code->data_bits != 16))
110 ret = usbh_ctrl_xfer(cdev->
udev,
111 REQ_TYPE_OUT | REQ_TYPE_CLASS_DEV | REQ_TYPE_TO_IFACE,
116 (uint8_t *)line_code,
117 &xfer_len, CDC_CMD_TIMEOUT);
121 CDC_DBGMSG(
"SET_LINE_CODIN command failed. %d\n", ret);
141 uint16_t ctrl_bitmap = 0;
155 ret = usbh_ctrl_xfer(cdev->
udev,
156 REQ_TYPE_OUT | REQ_TYPE_CLASS_DEV | REQ_TYPE_TO_IFACE,
157 CDC_SET_CONTROL_LINE_STATE,
162 &xfer_len, CDC_CMD_TIMEOUT);
166 CDC_DBGMSG(
"SET_CONTROL_LINE_STATE command failed. %d\n", ret);
176static void cdc_int_in_irq(UTR_T *utr)
187 CDC_DBGMSG(
"cdc_int_in_irq - has error: 0x%x\n", utr->status);
192 cdev->
sts_func(cdev, utr->buff, utr->xfer_len);
195 ret = usbh_int_xfer(utr);
198 CDC_DBGMSG(
"cdc_int_in_irq - failed to submit interrupt-in request (%d)", ret);
229 ep = usbh_iface_find_ep(cdev->
iface_cdc, 0, EP_ADDR_DIR_IN | EP_ATTR_TT_INT);
232 CDC_DBGMSG(
"Interrupt-in endpoint not found in this CDC device!\n");
238 utr = alloc_utr(cdev->
udev);
241 CDC_DBGMSG(
"Failed to allocated UTR!\n");
245 utr->buff = (uint8_t *)cdev->
sts_buff;
248 utr->data_len = ep->wMaxPacketSize;
249 if(utr->data_len > CDC_STATUS_BUFF_SIZE)
251 CDC_DBGMSG(
"Warning! CDC_STATUS_BUFF_SIZE %d is smaller than max. packet size %d!\n", CDC_STATUS_BUFF_SIZE, ep->wMaxPacketSize);
252 utr->data_len = CDC_STATUS_BUFF_SIZE;
255 utr->func = cdc_int_in_irq;
260 ret = usbh_int_xfer(utr);
263 CDC_DBGMSG(
"Error - failed to submit interrupt read request (%d)", ret);
285 CDC_DBGMSG(
"cdc_bulk_in_irq - has error: 0x%x\n", utr->status);
290 cdev->
rx_func(cdev, utr->buff, utr->xfer_len);
322 ep = usbh_iface_find_ep(cdev->
iface_data, 0, EP_ADDR_DIR_IN | EP_ATTR_TT_BULK);
325 CDC_DBGMSG(
"Bulk-in endpoint not found in this CDC device!\n");
331 utr = alloc_utr(cdev->
udev);
334 CDC_DBGMSG(
"Failed to allocated UTR!\n");
338 utr->buff = (uint8_t *)cdev->
rx_buff;
341 utr->data_len = ep->wMaxPacketSize;
342 if(utr->data_len > CDC_RX_BUFF_SIZE)
344 CDC_DBGMSG(
"Warning! CDC_RX_BUFF_SIZE %d is smaller than max. packet size %d!\n", CDC_RX_BUFF_SIZE, ep->wMaxPacketSize);
345 utr->data_len = CDC_RX_BUFF_SIZE;
354 ret = usbh_bulk_xfer(utr);
357 CDC_DBGMSG(
"Error - failed to submit bulk in request (%d)", ret);
397 ep = usbh_iface_find_ep(cdev->
iface_data, 0, EP_ADDR_DIR_OUT | EP_ATTR_TT_BULK);
400 CDC_DBGMSG(
"Bulk-out endpoint not found in this CDC device!\n");
406 utr = alloc_utr(cdev->
udev);
409 CDC_DBGMSG(
"Failed to allocated UTR!\n");
416 utr->data_len = buff_len;
421 ret = usbh_bulk_xfer(utr);
424 CDC_DBGMSG(
"Error - failed to submit bulk in request (%d)", ret);
NuMicro peripheral access layer header file.
int32_t usbh_cdc_set_line_coding(CDC_DEV_T *cdev, LINE_CODING_T *line_code)
SET_LINE_CODING request.
int32_t usbh_cdc_start_to_receive_data(CDC_DEV_T *cdev, CDC_CB_FUNC *func)
HIDDEN_SYMBOLS.
int32_t usbh_cdc_set_control_line_state(CDC_DEV_T *cdev, int active_carrier, int DTE_present)
SET_CONTROL_LINE_STATE request.
int32_t usbh_cdc_send_data(CDC_DEV_T *cdev, uint8_t *buff, int buff_len)
Send a block of data via CDC device's bulk-out transfer pipe.
HIDDEN_SYMBOLS int32_t usbh_cdc_start_polling_status(CDC_DEV_T *cdev, CDC_CB_FUNC *func)
Start purge the CDC device's interrupt-in transfer pipe.
static void cdc_bulk_in_irq(UTR_T *utr)
static volatile int bulk_out_done
int32_t usbh_cdc_get_line_coding(CDC_DEV_T *cdev, LINE_CODING_T *line_code)
GET_LINE_CODING request.
static void cdc_bulk_out_irq(UTR_T *utr)
#define USBH_ERR_EP_NOT_FOUND
#define USBH_ERR_INVALID_PARAM
#define USBH_ERR_NOT_FOUND
#define USBH_ERR_MEMORY_OUT
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.