migrate cdc_device to new control_xfer_cb
This commit is contained in:
		| @@ -315,38 +315,10 @@ uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1 | ||||
|   return drv_len; | ||||
| } | ||||
|  | ||||
| // Invoked when class request DATA stage is finished. | ||||
| // return false to stall control endpoint (e.g Host send non-sense DATA) | ||||
| bool cdcd_control_complete(uint8_t rhport, tusb_control_request_t const * request) | ||||
| { | ||||
|   (void) rhport; | ||||
|  | ||||
|   //------------- Class Specific Request -------------// | ||||
|   TU_VERIFY (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS); | ||||
|  | ||||
|   uint8_t itf = 0; | ||||
|   cdcd_interface_t* p_cdc = _cdcd_itf; | ||||
|  | ||||
|   // Identify which interface to use | ||||
|   for ( ; ; itf++, p_cdc++) | ||||
|   { | ||||
|     if (itf >= TU_ARRAY_SIZE(_cdcd_itf)) return false; | ||||
|  | ||||
|     if ( p_cdc->itf_num == request->wIndex ) break; | ||||
|   } | ||||
|  | ||||
|   // Invoke callback | ||||
|   if ( CDC_REQUEST_SET_LINE_CODING == request->bRequest ) | ||||
|   { | ||||
|     if ( tud_cdc_line_coding_cb ) tud_cdc_line_coding_cb(itf, &p_cdc->line_coding); | ||||
|   } | ||||
|  | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| // Handle class control request | ||||
| // Invoked when a control transfer occurred on an interface of this class | ||||
| // Driver response accordingly to the request and the transfer stage (setup/data/ack) | ||||
| // return false to stall control endpoint (e.g unsupported request) | ||||
| bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request) | ||||
| bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) | ||||
| { | ||||
|   // Handle class request only | ||||
|   TU_VERIFY(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS); | ||||
| @@ -365,34 +337,47 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request | ||||
|   switch ( request->bRequest ) | ||||
|   { | ||||
|     case CDC_REQUEST_SET_LINE_CODING: | ||||
|       TU_LOG2("  Set Line Coding\r\n"); | ||||
|       tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); | ||||
|       if (stage == CONTROL_STAGE_SETUP) | ||||
|       { | ||||
|         TU_LOG2("  Set Line Coding\r\n"); | ||||
|         tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); | ||||
|       } | ||||
|       else if ( stage == CONTROL_STAGE_ACK) | ||||
|       { | ||||
|         if ( tud_cdc_line_coding_cb ) tud_cdc_line_coding_cb(itf, &p_cdc->line_coding); | ||||
|       } | ||||
|     break; | ||||
|  | ||||
|     case CDC_REQUEST_GET_LINE_CODING: | ||||
|       TU_LOG2("  Get Line Coding\r\n"); | ||||
|       tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); | ||||
|       if (stage == CONTROL_STAGE_SETUP) | ||||
|       { | ||||
|         TU_LOG2("  Get Line Coding\r\n"); | ||||
|         tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); | ||||
|       } | ||||
|     break; | ||||
|  | ||||
|     case CDC_REQUEST_SET_CONTROL_LINE_STATE: | ||||
|     { | ||||
|       // CDC PSTN v1.2 section 6.3.12 | ||||
|       // Bit 0: Indicates if DTE is present or not. | ||||
|       //        This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR (Data Terminal Ready) | ||||
|       // Bit 1: Carrier control for half-duplex modems. | ||||
|       //        This signal corresponds to V.24 signal 105 and RS-232 signal RTS (Request to Send) | ||||
|       bool const dtr = tu_bit_test(request->wValue, 0); | ||||
|       bool const rts = tu_bit_test(request->wValue, 1); | ||||
|       if (stage == CONTROL_STAGE_SETUP) | ||||
|       { | ||||
|         tud_control_status(rhport, request); | ||||
|       } | ||||
|       else if (stage == CONTROL_STAGE_ACK) | ||||
|       { | ||||
|         // CDC PSTN v1.2 section 6.3.12 | ||||
|         // Bit 0: Indicates if DTE is present or not. | ||||
|         //        This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR (Data Terminal Ready) | ||||
|         // Bit 1: Carrier control for half-duplex modems. | ||||
|         //        This signal corresponds to V.24 signal 105 and RS-232 signal RTS (Request to Send) | ||||
|         bool const dtr = tu_bit_test(request->wValue, 0); | ||||
|         bool const rts = tu_bit_test(request->wValue, 1); | ||||
|  | ||||
|       p_cdc->line_state = (uint8_t) request->wValue; | ||||
|         p_cdc->line_state = (uint8_t) request->wValue; | ||||
|  | ||||
|       TU_LOG2("  Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts); | ||||
|         TU_LOG2("  Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts); | ||||
|  | ||||
|       tud_control_status(rhport, request); | ||||
|  | ||||
|       // Invoke callback | ||||
|       if ( tud_cdc_line_state_cb ) tud_cdc_line_state_cb(itf, dtr, rts); | ||||
|     } | ||||
|         // Invoke callback | ||||
|         if ( tud_cdc_line_state_cb ) tud_cdc_line_state_cb(itf, dtr, rts); | ||||
|       } | ||||
|     break; | ||||
|  | ||||
|     default: return false; // stall unsupported request | ||||
|   | ||||
| @@ -236,12 +236,11 @@ static inline uint32_t tud_cdc_write_available(void) | ||||
| //--------------------------------------------------------------------+ | ||||
| // INTERNAL USBD-CLASS DRIVER API | ||||
| //--------------------------------------------------------------------+ | ||||
| void     cdcd_init             (void); | ||||
| void     cdcd_reset            (uint8_t rhport); | ||||
| uint16_t cdcd_open             (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); | ||||
| bool     cdcd_control_request  (uint8_t rhport, tusb_control_request_t const * request); | ||||
| bool     cdcd_control_complete (uint8_t rhport, tusb_control_request_t const * request); | ||||
| bool     cdcd_xfer_cb          (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); | ||||
| void     cdcd_init            (void); | ||||
| void     cdcd_reset           (uint8_t rhport); | ||||
| uint16_t cdcd_open            (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); | ||||
| bool     cdcd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request); | ||||
| bool     cdcd_xfer_cb         (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
|  } | ||||
|   | ||||
| @@ -158,11 +158,11 @@ TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun); | ||||
| //--------------------------------------------------------------------+ | ||||
| // Internal Class Driver API | ||||
| //--------------------------------------------------------------------+ | ||||
| void     mscd_init             (void); | ||||
| void     mscd_reset            (uint8_t rhport); | ||||
| uint16_t mscd_open             (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); | ||||
| bool     mscd_control_xfer_cb  (uint8_t rhport, uint8_t stage, tusb_control_request_t const * p_request); | ||||
| bool     mscd_xfer_cb          (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); | ||||
| void     mscd_init            (void); | ||||
| void     mscd_reset           (uint8_t rhport); | ||||
| uint16_t mscd_open            (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); | ||||
| bool     mscd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * p_request); | ||||
| bool     mscd_xfer_cb         (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
|  } | ||||
|   | ||||
| @@ -97,8 +97,7 @@ static usbd_class_driver_t const _usbd_driver[] = | ||||
|       .init             = cdcd_init, | ||||
|       .reset            = cdcd_reset, | ||||
|       .open             = cdcd_open, | ||||
|       .control_xfer_cb  = cdcd_control_request, | ||||
|       .control_complete = cdcd_control_complete, | ||||
|       .control_xfer_cb  = cdcd_control_xfer_cb, | ||||
|       .xfer_cb          = cdcd_xfer_cb, | ||||
|       .sof              = NULL | ||||
|   }, | ||||
|   | ||||
| @@ -171,7 +171,16 @@ bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result | ||||
|   if ( tu_edpt_dir(ep_addr) != _ctrl_xfer.request.bmRequestType_bit.direction ) | ||||
|   { | ||||
|     TU_ASSERT(0 == xferred_bytes); | ||||
|  | ||||
|     // invoke optional dcd hook if available | ||||
|     if (dcd_edpt0_status_complete) dcd_edpt0_status_complete(rhport, &_ctrl_xfer.request); | ||||
|  | ||||
|     if (_ctrl_xfer.complete_cb) | ||||
|     { | ||||
|       // TODO refactor with usbd_driver_print_control_complete_name | ||||
|       _ctrl_xfer.complete_cb(rhport, CONTROL_STAGE_ACK, &_ctrl_xfer.request); | ||||
|     } | ||||
|  | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach