clean up enum task

This commit is contained in:
hathach 2020-09-05 20:34:45 +07:00
parent 828f720207
commit 9a6d7c648e
4 changed files with 14 additions and 25 deletions

View File

@ -326,6 +326,9 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
// attach TD
qhd->qtd_overlay.next.address = (uint32_t) qtd;
}else
{
// TODO implement later
}
return true;

View File

@ -122,11 +122,8 @@ static osal_queue_t _usbh_q;
CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_HOST_ENUM_BUFFER_SIZE];
//------------- Reporter Task Data -------------//
//------------- Helper Function Prototypes -------------//
static inline uint8_t get_new_address(void);
static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc);
//--------------------------------------------------------------------+
// PUBLIC API (Parameter Verification is required)
@ -557,19 +554,22 @@ bool enum_task(hcd_event_t* event)
TU_ASSERT(usbh_control_xfer(new_addr, &request, _usbh_ctrl_buf));
// update device info TODO alignment issue
new_dev->vendor_id = ((tusb_desc_device_t*) _usbh_ctrl_buf)->idVendor;
new_dev->product_id = ((tusb_desc_device_t*) _usbh_ctrl_buf)->idProduct;
new_dev->configure_count = ((tusb_desc_device_t*) _usbh_ctrl_buf)->bNumConfigurations;
tusb_desc_device_t const * desc_device = (tusb_desc_device_t const*) _usbh_ctrl_buf;
uint8_t const configure_selected = get_configure_number_for_device((tusb_desc_device_t*) _usbh_ctrl_buf);
TU_ASSERT(configure_selected <= new_dev->configure_count); // TODO notify application when invalid configuration
if (tuh_attach_cb) tuh_attach_cb((tusb_desc_device_t*) _usbh_ctrl_buf);
new_dev->vendor_id = desc_device->idVendor;
new_dev->product_id = desc_device->idProduct;
TU_ASSERT(desc_device->bNumConfigurations > 0);
enum { CONFIG_NUM = 1 }; // default to use configuration 1
//------------- Get 9 bytes of configuration descriptor -------------//
TU_LOG2("Get 9 bytes of Configuration Descriptor\r\n");
request = (tusb_control_request_t ) {
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN },
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
.wValue = (TUSB_DESC_CONFIGURATION << 8) | (configure_selected - 1),
.wValue = (TUSB_DESC_CONFIGURATION << 8) | (CONFIG_NUM - 1),
.wIndex = 0,
.wLength = 9
};
@ -591,7 +591,7 @@ bool enum_task(hcd_event_t* event)
request = (tusb_control_request_t ) {
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_OUT },
.bRequest = TUSB_REQ_SET_CONFIGURATION,
.wValue = configure_selected,
.wValue = CONFIG_NUM,
.wIndex = 0,
.wLength = 0
};
@ -702,17 +702,4 @@ static inline uint8_t get_new_address(void)
return CFG_TUSB_HOST_DEVICE_MAX+1;
}
static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc)
{
uint8_t config_num = 1;
// invoke callback to ask user which configuration to select
if (tuh_device_attached_cb)
{
config_num = tu_min8(1, tuh_device_attached_cb(dev_desc) );
}
return config_num;
}
#endif

View File

@ -90,7 +90,7 @@ static inline bool tuh_device_is_configured(uint8_t dev_addr)
//--------------------------------------------------------------------+
// APPLICATION CALLBACK
//--------------------------------------------------------------------+
TU_ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device);
TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
/** Callback invoked when device is mounted (configured) */
TU_ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr);

View File

@ -53,7 +53,6 @@ typedef struct {
//------------- device descriptor -------------//
uint16_t vendor_id;
uint16_t product_id;
uint8_t configure_count; // bNumConfigurations alias
//------------- configuration descriptor -------------//
uint8_t interface_count; // bNumInterfaces alias