remove legacy blocking usbh_control_xfer()
reworking cdc host driver
This commit is contained in:
		| @@ -51,9 +51,14 @@ typedef struct { | ||||
| //--------------------------------------------------------------------+ | ||||
| static cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; | ||||
|  | ||||
| static inline cdch_data_t* get_itf(uint8_t dev_addr) | ||||
| { | ||||
|   return &cdch_data[dev_addr-1]; | ||||
| } | ||||
|  | ||||
| bool tuh_cdc_mounted(uint8_t dev_addr) | ||||
| { | ||||
|   cdch_data_t* cdc = &cdch_data[dev_addr-1]; | ||||
|   cdch_data_t* cdc = get_itf(dev_addr); | ||||
|   return cdc->ep_in && cdc->ep_out; | ||||
| } | ||||
|  | ||||
| @@ -61,7 +66,7 @@ bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) | ||||
| { | ||||
|   if ( !tuh_cdc_mounted(dev_addr) ) return false; | ||||
|  | ||||
|   cdch_data_t const * p_cdc = &cdch_data[dev_addr-1]; | ||||
|   cdch_data_t const * p_cdc = get_itf(dev_addr); | ||||
|  | ||||
|   switch (pipeid) | ||||
|   { | ||||
| @@ -111,6 +116,27 @@ bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is | ||||
|   return hcd_pipe_xfer(dev_addr, ep_in, p_buffer, length, is_notify); | ||||
| } | ||||
|  | ||||
| bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_control_complete_cb_t complete_cb) | ||||
| { | ||||
|   cdch_data_t const * p_cdc = get_itf(dev_addr); | ||||
|   tusb_control_request_t const request = | ||||
|   { | ||||
|     .bmRequestType_bit = | ||||
|     { | ||||
|       .recipient = TUSB_REQ_RCPT_INTERFACE, | ||||
|       .type      = TUSB_REQ_TYPE_CLASS, | ||||
|       .direction = TUSB_DIR_OUT | ||||
|     }, | ||||
|     .bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE, | ||||
|     .wValue   = (rts ? 2 : 0) | (dtr ? 1 : 0), | ||||
|     .wIndex   = p_cdc->itf_num, | ||||
|     .wLength  = 0 | ||||
|   }; | ||||
|  | ||||
|   TU_ASSERT( tuh_control_xfer(dev_addr, &request, NULL, complete_cb) ); | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // USBH-CLASS DRIVER API | ||||
| //--------------------------------------------------------------------+ | ||||
| @@ -132,7 +158,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it | ||||
|   cdch_data_t * p_cdc; | ||||
|  | ||||
|   p_desc = tu_desc_next(itf_desc); | ||||
|   p_cdc  = &cdch_data[dev_addr-1]; | ||||
|   p_cdc  = get_itf(dev_addr); | ||||
|  | ||||
|   p_cdc->itf_num   = itf_desc->bInterfaceNumber; | ||||
|   p_cdc->itf_protocol = itf_desc->bInterfaceProtocol; // TODO 0xff is consider as rndis candidate, other is virtual Com | ||||
| @@ -194,18 +220,12 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // FIXME move to seperate API : connect | ||||
|   tusb_control_request_t request = | ||||
|   { | ||||
|     .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_INTERFACE, .type = TUSB_REQ_TYPE_CLASS, .direction = TUSB_DIR_OUT }, | ||||
|     .bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE, | ||||
|     .wValue = 0x03, // dtr on, cst on | ||||
|     .wIndex = p_cdc->itf_num, | ||||
|     .wLength = 0 | ||||
|   }; | ||||
|  | ||||
|   TU_ASSERT( usbh_control_xfer(dev_addr, &request, NULL) ); | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| bool cdch_set_config(uint8_t dev_addr, uint8_t itf_num) | ||||
| { | ||||
|   (void) dev_addr; (void) itf_num; | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| @@ -218,7 +238,7 @@ bool cdch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32 | ||||
|  | ||||
| void cdch_close(uint8_t dev_addr) | ||||
| { | ||||
|   cdch_data_t * p_cdc = &cdch_data[dev_addr-1]; | ||||
|   cdch_data_t * p_cdc = get_itf(dev_addr); | ||||
|   tu_memclr(p_cdc, sizeof(cdch_data_t)); | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach