From 58fec7a17ceb6814d64e702e7829556c3ece01e4 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Mon, 5 Sep 2016 19:48:56 +0200 Subject: Drop need for the set configuration request in dev drivers Signed-off-by: Amir Hammad --- src/usbh_driver_hid.c | 81 ++++++++++----------------------------------------- 1 file changed, 15 insertions(+), 66 deletions(-) (limited to 'src/usbh_driver_hid.c') diff --git a/src/usbh_driver_hid.c b/src/usbh_driver_hid.c index 21fa262..b9b95d7 100644 --- a/src/usbh_driver_hid.c +++ b/src/usbh_driver_hid.c @@ -37,8 +37,6 @@ enum STATES { STATE_READING_REQUEST, STATE_READING_COMPLETE_AND_CHECK_REPORT, STATE_SET_REPORT_EMPTY_READ, - STATE_SET_CONFIGURATION_REQUEST, - STATE_SET_CONFIGURATION_EMPTY_READ, STATE_GET_REPORT_DESCRIPTOR_READ_SETUP,// configuration is complete at this point. We write request STATE_GET_REPORT_DESCRIPTOR_READ, STATE_GET_REPORT_DESCRIPTOR_READ_COMPLETE,// after the read finishes, we parse that descriptor @@ -204,7 +202,7 @@ static bool analyze_descriptor(void *drvdata, void *descriptor) } if (hid->endpoint_in_address && hid->report0_length) { - hid->state_next = STATE_SET_CONFIGURATION_REQUEST; + hid->state_next = STATE_GET_REPORT_DESCRIPTOR_READ_SETUP; return true; } @@ -294,62 +292,6 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) } break; - case STATE_SET_CONFIGURATION_EMPTY_READ: - { - LOG_PRINTF("|empty packet read|"); - switch (cb_data.status) { - case USBH_PACKET_CALLBACK_STATUS_OK: - hid->state_next = STATE_GET_REPORT_DESCRIPTOR_READ_SETUP; - device_xfer_control_read(0, 0, event, dev); - break; - - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - ERROR(cb_data.status); - hid->state_next = STATE_INACTIVE; - break; - } - } - break; - - case STATE_GET_REPORT_DESCRIPTOR_READ_SETUP: - { - switch (cb_data.status) { - case USBH_PACKET_CALLBACK_STATUS_OK: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: - { - hid->endpoint_in_toggle = 0; - // We support only the first report descriptor with index 0 - - // limit the size of the report descriptor! - if (hid->report0_length > USBH_HID_BUFFER) { - hid->report0_length = USBH_HID_BUFFER; - } - - struct usb_setup_data setup_data; - - setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_INTERFACE; - setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; - setup_data.wValue = USB_DT_REPORT << 8; - setup_data.wIndex = 0; - setup_data.wLength = hid->report0_length; - - hid->state_next = STATE_GET_REPORT_DESCRIPTOR_READ; - device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev); - - } - break; - - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - ERROR(cb_data.status); - hid->state_next = STATE_INACTIVE; - break; - } - } - break; - case STATE_GET_REPORT_DESCRIPTOR_READ: { switch (cb_data.status) { @@ -434,18 +376,25 @@ static void poll(void *drvdata, uint32_t time_curr_us) } break; - case STATE_SET_CONFIGURATION_REQUEST: + case STATE_GET_REPORT_DESCRIPTOR_READ_SETUP: { + hid->endpoint_in_toggle = 0; + // We support only the first report descriptor with index 0 + + // limit the size of the report descriptor! + if (hid->report0_length > USBH_HID_BUFFER) { + hid->report0_length = USBH_HID_BUFFER; + } + struct usb_setup_data setup_data; - setup_data.bmRequestType = USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; - setup_data.bRequest = USB_REQ_SET_CONFIGURATION; - setup_data.wValue = hid->configuration_value; + setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_INTERFACE; + setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; + setup_data.wValue = USB_DT_REPORT << 8; setup_data.wIndex = 0; - setup_data.wLength = 0; - - hid->state_next = STATE_SET_CONFIGURATION_EMPTY_READ; + setup_data.wLength = hid->report0_length; + hid->state_next = STATE_GET_REPORT_DESCRIPTOR_READ; device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev); } break; -- cgit