mirror of
https://github.com/gdsports/USBHost_t36
synced 2025-02-16 06:50:14 -05:00
Hub driver (finally) creates devices
This commit is contained in:
parent
05582c91a0
commit
2e1e9748e0
@ -347,6 +347,7 @@ protected:
|
|||||||
USBDriverTimer resettimer;
|
USBDriverTimer resettimer;
|
||||||
setup_t setup;
|
setup_t setup;
|
||||||
Pipe_t *changepipe;
|
Pipe_t *changepipe;
|
||||||
|
Device_t *devicelist[MAXPORTS];
|
||||||
uint32_t changebits;
|
uint32_t changebits;
|
||||||
uint32_t statusbits;
|
uint32_t statusbits;
|
||||||
uint8_t hub_desc[16];
|
uint8_t hub_desc[16];
|
||||||
@ -356,6 +357,9 @@ protected:
|
|||||||
uint8_t characteristics;
|
uint8_t characteristics;
|
||||||
uint8_t powertime;
|
uint8_t powertime;
|
||||||
uint8_t sending_control_transfer;
|
uint8_t sending_control_transfer;
|
||||||
|
uint8_t port_doing_reset;
|
||||||
|
uint8_t port_doing_reset_speed;
|
||||||
|
uint8_t portstate[MAXPORTS];
|
||||||
portbitmask_t send_pending_poweron;
|
portbitmask_t send_pending_poweron;
|
||||||
portbitmask_t send_pending_getstatus;
|
portbitmask_t send_pending_getstatus;
|
||||||
portbitmask_t send_pending_clearstatus_connect;
|
portbitmask_t send_pending_clearstatus_connect;
|
||||||
@ -365,7 +369,6 @@ protected:
|
|||||||
portbitmask_t send_pending_clearstatus_reset;
|
portbitmask_t send_pending_clearstatus_reset;
|
||||||
portbitmask_t send_pending_setreset;
|
portbitmask_t send_pending_setreset;
|
||||||
portbitmask_t debounce_in_use;
|
portbitmask_t debounce_in_use;
|
||||||
uint8_t portstate[MAXPORTS];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class KeyboardController : public USBDriver {
|
class KeyboardController : public USBDriver {
|
||||||
|
47
hub.cpp
47
hub.cpp
@ -81,7 +81,9 @@ bool USBHub::claim(Device_t *dev, int type, const uint8_t *descriptors, uint32_t
|
|||||||
changepipe = NULL;
|
changepipe = NULL;
|
||||||
changebits = 0;
|
changebits = 0;
|
||||||
sending_control_transfer = 0;
|
sending_control_transfer = 0;
|
||||||
|
port_doing_reset = 0;
|
||||||
memset(portstate, 0, sizeof(portstate));
|
memset(portstate, 0, sizeof(portstate));
|
||||||
|
memset(devicelist, 0, sizeof(devicelist));
|
||||||
|
|
||||||
mk_setup(setup, 0xA0, 6, 0x2900, 0, sizeof(hub_desc));
|
mk_setup(setup, 0xA0, 6, 0x2900, 0, sizeof(hub_desc));
|
||||||
queue_Control_Transfer(dev, &setup, hub_desc, this);
|
queue_Control_Transfer(dev, &setup, hub_desc, this);
|
||||||
@ -349,8 +351,10 @@ void USBHub::new_port_status(uint32_t port, uint32_t status)
|
|||||||
// enumeration process... stay in debounce
|
// enumeration process... stay in debounce
|
||||||
// and add to wait list if enumeration busy
|
// and add to wait list if enumeration busy
|
||||||
stop_debounce_timer(port);
|
stop_debounce_timer(port);
|
||||||
|
state = PORT_RESET;
|
||||||
println("sending reset");
|
println("sending reset");
|
||||||
send_setreset(port);
|
send_setreset(port);
|
||||||
|
port_doing_reset = port;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state = PORT_DISCONNECT;
|
state = PORT_DISCONNECT;
|
||||||
@ -359,31 +363,20 @@ void USBHub::new_port_status(uint32_t port, uint32_t status)
|
|||||||
case PORT_RESET:
|
case PORT_RESET:
|
||||||
if (status & 0x0002) {
|
if (status & 0x0002) {
|
||||||
// port is now enabled
|
// port is now enabled
|
||||||
//while (1) ;
|
|
||||||
//send_clearstatus_enable(port);
|
|
||||||
//send_clearstatus_connect(port);
|
|
||||||
send_clearstatus_reset(port);
|
send_clearstatus_reset(port);
|
||||||
|
state = PORT_RECOVERY;
|
||||||
|
uint8_t speed=0;
|
||||||
|
if (status & 0x0200) speed = 1;
|
||||||
|
else if (status & 0x0400) speed = 2;
|
||||||
|
port_doing_reset_speed = speed;
|
||||||
|
resettimer.start(25000);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case PORT_RECOVERY:
|
case PORT_RECOVERY:
|
||||||
|
break;
|
||||||
case PORT_ACTIVE:
|
case PORT_ACTIVE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if ((status & 0x0001) && !(priorstatus & 0x0001)) {
|
|
||||||
println(" connect");
|
|
||||||
// 100 ms debounce (USB 2.0: TATTDB, page 150 & 188)
|
|
||||||
//delay(100); // TODO: horribly bad... need timing events
|
|
||||||
//reset(port);
|
|
||||||
// TODO... reset timer?
|
|
||||||
|
|
||||||
} else if (!(status & 0x0001) && (priorstatus & 0x0001)) {
|
|
||||||
println(" disconnect");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -399,12 +392,26 @@ void USBHub::timer_event(USBDriverTimer *timer)
|
|||||||
println(", timer = ", (uint32_t)timer, HEX);
|
println(", timer = ", (uint32_t)timer, HEX);
|
||||||
if (timer == &debouncetimer) {
|
if (timer == &debouncetimer) {
|
||||||
uint32_t in_use = debounce_in_use;
|
uint32_t in_use = debounce_in_use;
|
||||||
if (in_use != 0) {
|
if (in_use) {
|
||||||
for (uint32_t i=1; i < numports; i++) {
|
for (uint32_t i=1; i < numports; i++) {
|
||||||
if (in_use & (1 << i)) send_getstatus(i);
|
if (in_use & (1 << i)) send_getstatus(i);
|
||||||
}
|
}
|
||||||
debouncetimer.start(20000);
|
debouncetimer.start(20000);
|
||||||
}
|
}
|
||||||
|
} else if (timer == &resettimer) {
|
||||||
|
uint8_t port = port_doing_reset;
|
||||||
|
println("port_doing_reset = ", port);
|
||||||
|
if (port_doing_reset) {
|
||||||
|
uint8_t &state = portstate[port-1];
|
||||||
|
if (state == PORT_RECOVERY) {
|
||||||
|
port_doing_reset = 0;
|
||||||
|
println("PORT_RECOVERY");
|
||||||
|
// begin enumeration process
|
||||||
|
uint8_t speed = port_doing_reset_speed;
|
||||||
|
devicelist[port-1] = new_Device(speed, device->address, port);
|
||||||
|
state = PORT_ACTIVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user