* hub.c
* - Basic hub driver
*/
+#define DEBUG 1
#include <usb_hub.h>
#define MAX_PORTS 32 // Not actually a max, but used for DeviceRemovable
+
#define GET_STATUS 0
+#define CLEAR_FEATURE 1
+// resvd
#define SET_FEATURE 3
#define PORT_CONNECTION 0
#define PORT_ENABLE 1
+#define PORT_SUSPEND 2
+#define PORT_OVER_CURRENT 3
#define PORT_RESET 4
#define PORT_POWER 8
+#define PORT_LOW_SPEED 9
+#define C_PORT_CONNECTION 16
+#define C_PORT_ENABLE 17
+#define C_PORT_SUSPEND 18
+#define C_PORT_OVER_CURRENT 19
+#define C_PORT_RESET 20
+#define PORT_TEST 21
+#define PORT_INDICATOR 21
struct sHubDescriptor
{
// === PROTOTYPES ===
void Hub_Connected(tUSBInterface *Dev);
void Hub_Disconnected(tUSBInterface *Dev);
-void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data);
+void Hub_PortStatusChange(tUSBInterface *Dev, int Endpoint, int Length, void *Data);
void Hub_int_HandleChange(tUSBInterface *Dev, int Port);
// === GLOBALS ===
struct sHubDescriptor hub_desc;
struct sHubInfo *info;
- // Read hub descriptor
- USB_ReadDescriptor(Dev, 0x29, 0, sizeof(hub_desc), &hub_desc);
+ // Read hub descriptor (Class descriptor 0x29)
+ USB_ReadDescriptor(Dev, 0x129, 0, sizeof(hub_desc), &hub_desc);
LOG("%i Ports", hub_desc.NbrPorts);
LOG("Takes %i ms for power to stabilise", hub_desc.PwrOn2PwrGood*2);
free(info);
}
-void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data)
+void Hub_PortStatusChange(tUSBInterface *Dev, int Endpoint, int Length, void *Data)
{
Uint8 *status = Data;
struct sHubInfo *info = USB_GetDeviceDataPtr(Dev);
// Get port status
USB_Request(Dev, 0, 0xA3, GET_STATUS, 0, Port, 4, status);
+
+ LOG("Port %i: status = {0b%b, 0b%b}", Port, status[0], status[1]);
// Handle connections / disconnections
if( status[1] & 0x0001 )
// Disconnected
USB_DeviceDisconnected(info->HubPtr, Port);
}
+
+ USB_Request(Dev, 0, 0x23, CLEAR_FEATURE, C_PORT_CONNECTION, Port, 0, NULL);
+ }
+
+ // Reset change
+ if( status[1] & 0x0010 )
+ {
+ if( status[0] & 0x0010 ) {
+ // Reset complete
+ }
+ else {
+ // Useful?
+ }
+ // ACK
+ USB_Request(Dev, 0, 0x23, CLEAR_FEATURE, C_PORT_RESET, Port, 0, NULL);
}
}
-