Modules/USB - Working on driver support, little headache
[tpg/acess2.git] / Modules / USB / Core / hub.c
1 /*
2  * Acess2 USB Stack
3  * - By John Hodge (thePowersGang)
4  *
5  * hub.c
6  * - Basic hub driver
7  */
8 #include <usb_hub.h>
9
10 struct sHubInfo
11 {
12          int    nPorts;
13 };
14
15 // === PROTOTYPES ===
16 void    Hub_Connected(tUSBInterface *Dev);
17 void    Hub_Disconnected(tUSBInterface *Dev);
18 void    Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data);
19
20 // === GLOBALS ===
21 tUSBDriver      gUSBHub_Driver = {
22         .Name = "Hub",
23         .Match = {.Class = {0x090000, 0xFF0000}},
24         .Connected = Hub_Connected,
25         .Disconnected = Hub_Disconnected,
26         .MaxEndpoints = 1,
27         .Endpoints = {
28                 {0x83, Hub_PortStatusChange}
29         };
30 };
31
32 // === CODE ===
33 void Hub_Connected(tUSBInterface *Dev)
34 {
35         // Register poll on endpoint
36         USB_PollEndpoint(Dev, 0);
37         
38         USB_RegisterHub(Dev, nPorts);
39 }
40
41 void Hub_Disconnected(tUSBInterface *Dev)
42 {
43 }
44
45 void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data)
46 {
47          int    i;
48         Uint8   *status = Data;
49         for( i = 0; i < info->nPorts; i += 8, status ++ )
50         {
51                 if( i/8 >= Length )     break;
52                 if( *status == 0 )      continue;
53         
54                 for( int j = 0; j < 8; j ++ )
55                         if( *status & (1 << j) )
56                                 Hub_int_HandleChange(Dev, i+j);
57         }
58 }
59
60 void Hub_int_HandleChange(tUSBInterface *Dev, int Port)
61 {
62         Uint16  status[2];      // Status, Change
63         // Get change status
64         USB_Request(Dev, 0, 0xA3, 0, 0, Port, 4, status);
65 }
66

UCC git Repository :: git.ucc.asn.au