add tuh_descriptor_get() and tuh_descriptor_device_get()

This commit is contained in:
hathach
2022-03-04 19:26:54 +07:00
parent 3a7d1cfead
commit e08a875d52
4 changed files with 58 additions and 47 deletions

View File

@@ -39,7 +39,7 @@
//--------------------------------------------------------------------+
typedef bool (*tuh_complete_cb_t)(xfer_result_t result);
typedef bool (*tuh_control_complete_cb_t)(uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result);
typedef bool (*tuh_control_complete_cb_t)(uint8_t daddr, tusb_control_request_t const * request, xfer_result_t result);
//--------------------------------------------------------------------+
// APPLICATION API
@@ -58,40 +58,49 @@ void tuh_task(void);
extern void hcd_int_handler(uint8_t rhport);
#define tuh_int_handler hcd_int_handler
bool tuh_vid_pid_get(uint8_t dev_addr, uint16_t* vid, uint16_t* pid);
//------------- descriptors -------------//
// Get an descriptor
bool tuh_descriptor_get(uint8_t daddr, uint8_t type, uint8_t index,
void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
// Get device descriptor
bool tuh_descriptor_device_get(uint8_t daddr, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
bool tuh_vid_pid_get(uint8_t daddr, uint16_t* vid, uint16_t* pid);
// Gets the string indices for common device descriptor data.
uint8_t tuh_i_manufacturer_get(uint8_t dev_addr);
uint8_t tuh_i_serial_get(uint8_t dev_addr);
uint8_t tuh_i_product_get(uint8_t dev_addr);
uint8_t tuh_i_manufacturer_get(uint8_t daddr);
uint8_t tuh_i_serial_get(uint8_t daddr);
uint8_t tuh_i_product_get(uint8_t daddr);
// Reads the string descriptor at the string index into the buffer. This is the
// full response so the first entry is the length and the constant 0x03 for
// string descriptor type.
bool tuh_string_get(uint8_t dev_addr, uint8_t string_index, uint16_t* buf, size_t len, tuh_complete_cb_t complete_cb);
bool tuh_string_get(uint8_t daddr, uint8_t string_index, uint16_t* buf, size_t len, tuh_complete_cb_t complete_cb);
tusb_speed_t tuh_speed_get(uint8_t dev_addr);
tusb_speed_t tuh_speed_get(uint8_t daddr);
// Check if device is connected and configured
bool tuh_mounted(uint8_t dev_addr);
bool tuh_mounted(uint8_t daddr);
// Check if device is suspended
static inline bool tuh_suspended(uint8_t dev_addr)
static inline bool tuh_suspended(uint8_t daddr)
{
// TODO implement suspend & resume on host
(void) dev_addr;
(void) daddr;
return false;
}
// Check if device is ready to communicate with
TU_ATTR_ALWAYS_INLINE
static inline bool tuh_ready(uint8_t dev_addr)
static inline bool tuh_ready(uint8_t daddr)
{
return tuh_mounted(dev_addr) && !tuh_suspended(dev_addr);
return tuh_mounted(daddr) && !tuh_suspended(daddr);
}
// Carry out control transfer
bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb);
bool tuh_control_xfer (uint8_t daddr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK
@@ -99,10 +108,10 @@ bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request,
//TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
// Invoked when device is mounted (configured)
TU_ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr);
TU_ATTR_WEAK void tuh_mount_cb (uint8_t daddr);
/// Invoked when device is unmounted (bus reset/unplugged)
TU_ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr);
TU_ATTR_WEAK void tuh_umount_cb(uint8_t daddr);
#ifdef __cplusplus
}