usbh make TU_API_SYNC() public, to implement sync() API, change return of sync API from uint8_t to tusb_xfer_result_t
This commit is contained in:
		| @@ -278,6 +278,8 @@ typedef enum { | ||||
|   XFER_RESULT_INVALID | ||||
| } xfer_result_t; | ||||
|  | ||||
| #define tusb_xfer_result_t xfer_result_t | ||||
|  | ||||
| // TODO remove | ||||
| enum { | ||||
|   DESC_OFFSET_LEN  = 0, | ||||
|   | ||||
| @@ -1092,8 +1092,9 @@ TU_ATTR_FAST_FUNC void hcd_event_handler(hcd_event_t const* event, bool in_isr) | ||||
|  | ||||
| // generic helper to get a descriptor | ||||
| // if blocking, user_data is pointed to xfer_result | ||||
| static bool _get_descriptor(uint8_t daddr, uint8_t type, uint8_t index, uint16_t language_id, void* buffer, uint16_t len, | ||||
|                             tuh_xfer_cb_t complete_cb, uintptr_t user_data) { | ||||
| TU_ATTR_ALWAYS_INLINE static inline | ||||
| bool _get_descriptor(uint8_t daddr, uint8_t type, uint8_t index, uint16_t language_id, void* buffer, uint16_t len, | ||||
|                     tuh_xfer_cb_t complete_cb, uintptr_t user_data) { | ||||
|   tusb_control_request_t const request = { | ||||
|     .bmRequestType_bit = { | ||||
|       .recipient = TUSB_REQ_RCPT_DEVICE, | ||||
| @@ -1134,7 +1135,6 @@ bool tuh_descriptor_get_configuration(uint8_t daddr, uint8_t index, void* buffer | ||||
| } | ||||
|  | ||||
| //------------- String Descriptor -------------// | ||||
|  | ||||
| bool tuh_descriptor_get_string(uint8_t daddr, uint8_t index, uint16_t language_id, void* buffer, uint16_t len, | ||||
|                                tuh_xfer_cb_t complete_cb, uintptr_t user_data) { | ||||
|   return _get_descriptor(daddr, TUSB_DESC_STRING, index, language_id, buffer, len, complete_cb, user_data); | ||||
| @@ -1272,47 +1272,6 @@ bool tuh_interface_set(uint8_t daddr, uint8_t itf_num, uint8_t itf_alt, | ||||
|   return tuh_control_xfer(&xfer); | ||||
| } | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // Descriptor Sync | ||||
| //--------------------------------------------------------------------+ | ||||
|  | ||||
| #define _CONTROL_SYNC_API(_async_func, ...) \ | ||||
|   xfer_result_t result = XFER_RESULT_INVALID;\ | ||||
|   TU_VERIFY(_async_func(__VA_ARGS__, NULL, (uintptr_t) &result), XFER_RESULT_TIMEOUT); \ | ||||
|   return (uint8_t) result | ||||
|  | ||||
| uint8_t tuh_descriptor_get_sync(uint8_t daddr, uint8_t type, uint8_t index, void* buffer, uint16_t len) { | ||||
|   _CONTROL_SYNC_API(tuh_descriptor_get, daddr, type, index, buffer, len); | ||||
| } | ||||
|  | ||||
| uint8_t tuh_descriptor_get_device_sync(uint8_t daddr, void* buffer, uint16_t len) { | ||||
|   _CONTROL_SYNC_API(tuh_descriptor_get_device, daddr, buffer, len); | ||||
| } | ||||
|  | ||||
| uint8_t tuh_descriptor_get_configuration_sync(uint8_t daddr, uint8_t index, void* buffer, uint16_t len) { | ||||
|   _CONTROL_SYNC_API(tuh_descriptor_get_configuration, daddr, index, buffer, len); | ||||
| } | ||||
|  | ||||
| uint8_t tuh_descriptor_get_hid_report_sync(uint8_t daddr, uint8_t itf_num, uint8_t desc_type, uint8_t index, void* buffer, uint16_t len) { | ||||
|   _CONTROL_SYNC_API(tuh_descriptor_get_hid_report, daddr, itf_num, desc_type, index, buffer, len); | ||||
| } | ||||
|  | ||||
| uint8_t tuh_descriptor_get_string_sync(uint8_t daddr, uint8_t index, uint16_t language_id, void* buffer, uint16_t len) { | ||||
|   _CONTROL_SYNC_API(tuh_descriptor_get_string, daddr, index, language_id, buffer, len); | ||||
| } | ||||
|  | ||||
| uint8_t tuh_descriptor_get_manufacturer_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len) { | ||||
|   _CONTROL_SYNC_API(tuh_descriptor_get_manufacturer_string, daddr, language_id, buffer, len); | ||||
| } | ||||
|  | ||||
| uint8_t tuh_descriptor_get_product_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len) { | ||||
|   _CONTROL_SYNC_API(tuh_descriptor_get_product_string, daddr, language_id, buffer, len); | ||||
| } | ||||
|  | ||||
| uint8_t tuh_descriptor_get_serial_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len) { | ||||
|   _CONTROL_SYNC_API(tuh_descriptor_get_serial_string, daddr, language_id, buffer, len); | ||||
| } | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // Detaching | ||||
| //--------------------------------------------------------------------+ | ||||
|   | ||||
| @@ -234,8 +234,18 @@ bool tuh_bus_info_get(uint8_t daddr, tuh_bus_info_t* bus_info); | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // Transfer API | ||||
| // Each Function will make a USB transfer request to device. If | ||||
| // - complete_cb != NULL, the function will return immediately and invoke the callback when request is complete. | ||||
| // - complete_cb == NULL, the function will block until request is complete. | ||||
| // In this case, user_data should be tusb_xfer_result_t* to hold the transfer result. | ||||
| //--------------------------------------------------------------------+ | ||||
|  | ||||
| // Helper to make Sync API from async one | ||||
| #define TU_API_SYNC(_async_api, ...) \ | ||||
|    xfer_result_t result = XFER_RESULT_INVALID;\ | ||||
|    TU_VERIFY(_async_api(__VA_ARGS__, NULL, (uintptr_t) &result), XFER_RESULT_TIMEOUT); \ | ||||
|    return result | ||||
|  | ||||
| // Submit a control transfer | ||||
| //  - async: complete callback invoked when finished. | ||||
| //  - sync : blocking if complete callback is NULL. | ||||
| @@ -327,45 +337,54 @@ bool tuh_descriptor_get_serial_string(uint8_t daddr, uint16_t language_id, void* | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // Descriptors Synchronous (blocking) | ||||
| // Sync API which is blocking until transfer is complete. | ||||
| // return transfer result | ||||
| //--------------------------------------------------------------------+ | ||||
|  | ||||
| // Sync (blocking) version of tuh_descriptor_get() | ||||
| // return transfer result | ||||
| uint8_t tuh_descriptor_get_sync(uint8_t daddr, uint8_t type, uint8_t index, void* buffer, uint16_t len); | ||||
| // Sync version of tuh_descriptor_get() | ||||
| TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_descriptor_get_sync(uint8_t daddr, uint8_t type, uint8_t index, void* buffer, uint16_t len) { | ||||
|   TU_API_SYNC(tuh_descriptor_get, daddr, type, index, buffer, len); | ||||
| } | ||||
|  | ||||
| // Sync (blocking) version of tuh_descriptor_get_device() | ||||
| // return transfer result | ||||
| uint8_t tuh_descriptor_get_device_sync(uint8_t daddr, void* buffer, uint16_t len); | ||||
| // Sync version of tuh_descriptor_get_device() | ||||
| TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_descriptor_get_device_sync(uint8_t daddr, void* buffer, uint16_t len) { | ||||
|   TU_API_SYNC(tuh_descriptor_get_device, daddr, buffer, len); | ||||
| } | ||||
|  | ||||
| // Sync (blocking) version of tuh_descriptor_get_configuration() | ||||
| // return transfer result | ||||
| uint8_t tuh_descriptor_get_configuration_sync(uint8_t daddr, uint8_t index, void* buffer, uint16_t len); | ||||
| // Sync version of tuh_descriptor_get_configuration() | ||||
| TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_descriptor_get_configuration_sync(uint8_t daddr, uint8_t index, void* buffer, uint16_t len) { | ||||
|   TU_API_SYNC(tuh_descriptor_get_configuration, daddr, index, buffer, len); | ||||
| } | ||||
|  | ||||
| // Sync (blocking) version of tuh_descriptor_get_hid_report() | ||||
| // return transfer result | ||||
| uint8_t tuh_descriptor_get_hid_report_sync(uint8_t daddr, uint8_t itf_num, uint8_t desc_type, uint8_t index, void* buffer, uint16_t len); | ||||
| // Sync version of tuh_descriptor_get_hid_report() | ||||
| TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_descriptor_get_hid_report_sync(uint8_t daddr, uint8_t itf_num, uint8_t desc_type, uint8_t index, void* buffer, uint16_t len) { | ||||
|   TU_API_SYNC(tuh_descriptor_get_hid_report, daddr, itf_num, desc_type, index, buffer, len); | ||||
| } | ||||
|  | ||||
| // Sync (blocking) version of tuh_descriptor_get_string() | ||||
| // return transfer result | ||||
| uint8_t tuh_descriptor_get_string_sync(uint8_t daddr, uint8_t index, uint16_t language_id, void* buffer, uint16_t len); | ||||
| // Sync version of tuh_descriptor_get_string() | ||||
| TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_descriptor_get_string_sync(uint8_t daddr, uint8_t index, uint16_t language_id, void* buffer, uint16_t len) { | ||||
|   TU_API_SYNC(tuh_descriptor_get_string, daddr, index, language_id, buffer, len); | ||||
| } | ||||
|  | ||||
| // Sync (blocking) version of tuh_descriptor_get_string_langid() | ||||
| TU_ATTR_ALWAYS_INLINE static inline | ||||
| uint8_t tuh_descriptor_get_string_langid_sync(uint8_t daddr, void* buffer, uint16_t len) { | ||||
| // Sync version of tuh_descriptor_get_string_langid() | ||||
| TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_descriptor_get_string_langid_sync(uint8_t daddr, void* buffer, uint16_t len) { | ||||
|   return tuh_descriptor_get_string_sync(daddr, 0, 0, buffer, len); | ||||
| } | ||||
|  | ||||
| // Sync (blocking) version of tuh_descriptor_get_manufacturer_string() | ||||
| // return transfer result | ||||
| uint8_t tuh_descriptor_get_manufacturer_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len); | ||||
| // Sync version of tuh_descriptor_get_manufacturer_string() | ||||
| TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_descriptor_get_manufacturer_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len) { | ||||
|   TU_API_SYNC(tuh_descriptor_get_manufacturer_string, daddr, language_id, buffer, len); | ||||
| } | ||||
|  | ||||
| // Sync (blocking) version of tuh_descriptor_get_product_string() | ||||
| // return transfer result | ||||
| uint8_t tuh_descriptor_get_product_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len); | ||||
| // Sync version of tuh_descriptor_get_product_string() | ||||
| TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_descriptor_get_product_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len) { | ||||
|   TU_API_SYNC(tuh_descriptor_get_product_string, daddr, language_id, buffer, len); | ||||
| } | ||||
|  | ||||
| // Sync (blocking) version of tuh_descriptor_get_serial_string() | ||||
| // return transfer result | ||||
| uint8_t tuh_descriptor_get_serial_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len); | ||||
| // Sync version of tuh_descriptor_get_serial_string() | ||||
| TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_descriptor_get_serial_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len) { | ||||
|   TU_API_SYNC(tuh_descriptor_get_serial_string, daddr, language_id, buffer, len); | ||||
| } | ||||
|  | ||||
| #ifdef __cplusplus | ||||
|  } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach