clean up enum task
This commit is contained in:
parent
828f720207
commit
9a6d7c648e
|
@ -326,6 +326,9 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
|
||||||
|
|
||||||
// attach TD
|
// attach TD
|
||||||
qhd->qtd_overlay.next.address = (uint32_t) qtd;
|
qhd->qtd_overlay.next.address = (uint32_t) qtd;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
// TODO implement later
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -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];
|
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 -------------//
|
//------------- Helper Function Prototypes -------------//
|
||||||
static inline uint8_t get_new_address(void);
|
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)
|
// 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));
|
TU_ASSERT(usbh_control_xfer(new_addr, &request, _usbh_ctrl_buf));
|
||||||
|
|
||||||
// update device info TODO alignment issue
|
// update device info TODO alignment issue
|
||||||
new_dev->vendor_id = ((tusb_desc_device_t*) _usbh_ctrl_buf)->idVendor;
|
tusb_desc_device_t const * desc_device = (tusb_desc_device_t const*) _usbh_ctrl_buf;
|
||||||
new_dev->product_id = ((tusb_desc_device_t*) _usbh_ctrl_buf)->idProduct;
|
|
||||||
new_dev->configure_count = ((tusb_desc_device_t*) _usbh_ctrl_buf)->bNumConfigurations;
|
|
||||||
|
|
||||||
uint8_t const configure_selected = get_configure_number_for_device((tusb_desc_device_t*) _usbh_ctrl_buf);
|
if (tuh_attach_cb) tuh_attach_cb((tusb_desc_device_t*) _usbh_ctrl_buf);
|
||||||
TU_ASSERT(configure_selected <= new_dev->configure_count); // TODO notify application when invalid configuration
|
|
||||||
|
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 -------------//
|
//------------- Get 9 bytes of configuration descriptor -------------//
|
||||||
TU_LOG2("Get 9 bytes of Configuration Descriptor\r\n");
|
TU_LOG2("Get 9 bytes of Configuration Descriptor\r\n");
|
||||||
request = (tusb_control_request_t ) {
|
request = (tusb_control_request_t ) {
|
||||||
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN },
|
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN },
|
||||||
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
|
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
|
||||||
.wValue = (TUSB_DESC_CONFIGURATION << 8) | (configure_selected - 1),
|
.wValue = (TUSB_DESC_CONFIGURATION << 8) | (CONFIG_NUM - 1),
|
||||||
.wIndex = 0,
|
.wIndex = 0,
|
||||||
.wLength = 9
|
.wLength = 9
|
||||||
};
|
};
|
||||||
|
@ -591,7 +591,7 @@ bool enum_task(hcd_event_t* event)
|
||||||
request = (tusb_control_request_t ) {
|
request = (tusb_control_request_t ) {
|
||||||
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_OUT },
|
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_OUT },
|
||||||
.bRequest = TUSB_REQ_SET_CONFIGURATION,
|
.bRequest = TUSB_REQ_SET_CONFIGURATION,
|
||||||
.wValue = configure_selected,
|
.wValue = CONFIG_NUM,
|
||||||
.wIndex = 0,
|
.wIndex = 0,
|
||||||
.wLength = 0
|
.wLength = 0
|
||||||
};
|
};
|
||||||
|
@ -702,17 +702,4 @@ static inline uint8_t get_new_address(void)
|
||||||
return CFG_TUSB_HOST_DEVICE_MAX+1;
|
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
|
#endif
|
||||||
|
|
|
@ -90,7 +90,7 @@ static inline bool tuh_device_is_configured(uint8_t dev_addr)
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// APPLICATION CALLBACK
|
// 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) */
|
/** Callback 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 dev_addr);
|
||||||
|
|
|
@ -53,7 +53,6 @@ typedef struct {
|
||||||
//------------- device descriptor -------------//
|
//------------- device descriptor -------------//
|
||||||
uint16_t vendor_id;
|
uint16_t vendor_id;
|
||||||
uint16_t product_id;
|
uint16_t product_id;
|
||||||
uint8_t configure_count; // bNumConfigurations alias
|
|
||||||
|
|
||||||
//------------- configuration descriptor -------------//
|
//------------- configuration descriptor -------------//
|
||||||
uint8_t interface_count; // bNumInterfaces alias
|
uint8_t interface_count; // bNumInterfaces alias
|
||||||
|
|
Loading…
Reference in New Issue