diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/usbh_driver_hub.c | 30 | ||||
-rw-r--r-- | src/usbh_driver_hub_private.h | 4 |
2 files changed, 25 insertions, 9 deletions
diff --git a/src/usbh_driver_hub.c b/src/usbh_driver_hub.c index 7678dd7..305a8f3 100644 --- a/src/usbh_driver_hub.c +++ b/src/usbh_driver_hub.c @@ -29,7 +29,6 @@ static hub_device_t hub_device[USBH_MAX_HUBS];
-static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data);
static bool initialized = false;
@@ -224,19 +223,21 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) }
break;
- case 2:
+ case EMPTY_PACKET_READ_STATE:
{
LOG_PRINTF("|empty packet read|");
switch (cb_data.status) {
case USBH_PACKET_CALLBACK_STATUS_OK:
device_xfer_control_read(0, 0, event, dev);
- hub->state++;
+ hub->state = hub->state_after_empty_read;
+ hub->state_after_empty_read = 0;
break;
case USBH_PACKET_CALLBACK_STATUS_EFATAL:
case USBH_PACKET_CALLBACK_STATUS_EAGAIN:
case USBH_PACKET_CALLBACK_STATUS_ERRSIZ:
- ERROR(cb_data.status);
+ hub->state = hub->state_after_empty_read;
+ event(dev, cb_data);
break;
}
}
@@ -378,6 +379,9 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) setup_data.wIndex = hub->index;
setup_data.wLength = 0;
+ hub->state_after_empty_read = hub->state;
+ hub->state = EMPTY_PACKET_READ_STATE;
+
device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
} else {
hub->state++;
@@ -575,7 +579,9 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) setup_data.wIndex = port;
setup_data.wLength = 0;
- hub->state = 33;
+ hub->state_after_empty_read = 33;
+ hub->state = EMPTY_PACKET_READ_STATE;
+
device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
} else if(stc & (1<<HUB_FEATURE_PORT_RESET)) {
@@ -589,7 +595,8 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) setup_data.wIndex = port;
setup_data.wLength = 0;
- hub->state = 35;
+ hub->state_after_empty_read = 35;
+ hub->state = EMPTY_PACKET_READ_STATE;
LOG_PRINTF("RESET");
device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
@@ -630,7 +637,9 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) setup_data.wIndex = port;
setup_data.wLength = 0;
- hub->state = 11;
+ hub->state_after_empty_read = 11;
+ hub->state = EMPTY_PACKET_READ_STATE;
+
LOG_PRINTF("CONN");
hub->busy = 1;
@@ -694,7 +703,9 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) setup_data.wLength = 0;
// After write process another devices, poll for events
- hub->state = 11;//Expecting all ports are powered (constant/non-changeable after init)
+ hub->state_after_empty_read = 11;//Expecting all ports are powered (constant/non-changeable after init)
+ hub->state = EMPTY_PACKET_READ_STATE;
+
hub->current_port = CURRENT_PORT_NONE;
device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
} else if (!(sts & (1<<(HUB_FEATURE_PORT_LOWSPEED))) &&
@@ -785,7 +796,8 @@ static void poll(void *drvdata, uint32_t time_curr_us) setup_data.wIndex = 0;
setup_data.wLength = 0;
- hub->state += 2;
+ hub->state = EMPTY_PACKET_READ_STATE;
+ hub->state_after_empty_read = 3;
device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
}
diff --git a/src/usbh_driver_hub_private.h b/src/usbh_driver_hub_private.h index 4b98880..df38243 100644 --- a/src/usbh_driver_hub_private.h +++ b/src/usbh_driver_hub_private.h @@ -61,6 +61,8 @@ #define CURRENT_PORT_NONE -1 +#define EMPTY_PACKET_READ_STATE 255 + struct _hub_device { usbh_device_t *device[USBH_HUB_MAX_DEVICES + 1]; uint8_t buffer[USBH_HUB_BUFFER_SIZE]; @@ -68,6 +70,8 @@ struct _hub_device { uint8_t endpoint_in_address; uint8_t endpoint_in_toggle; uint8_t state; + uint8_t state_after_empty_read; + uint8_t desc_len; uint16_t ports_num; int8_t index; |