int main(void) { SetupHardware(); LED(RED); state = init; switch_port(0); for (;;) { if (port_cur == 0) HUB_Task(); if (port_cur == 5) JIG_Task(); USB_USBTask(); // connect 1 if (state == hub_ready && expire == 0) { LED(GREEN); expire_led = 10; connect_port(1); state = p1_wait_reset; } if (state == p1_wait_reset && last_port_reset_clear == 1) { LED(GREEN); expire_led = 10; switch_port(1); state = p1_wait_enumerate; } // connect 2 if (state == p1_ready && expire == 0) { switch_port(0); connect_port(2); state = p2_wait_reset; } if (state == p2_wait_reset && last_port_reset_clear == 2) { LED(GREEN); expire_led = 10; switch_port(2); state = p2_wait_enumerate; } // connect 3 if (state == p2_ready && expire == 0) { LED(GREEN); expire_led = 10; switch_port(0); connect_port(3); state = p3_wait_reset; } if (state == p3_wait_reset && last_port_reset_clear == 3) { LED(GREEN); expire_led = 10; switch_port(3); state = p3_wait_enumerate; } // disconnect 2 if (state == p3_ready && expire == 0) { LED(GREEN); expire_led = 10; switch_port(0); disconnect_port(2); state = p2_wait_disconnect; } if (state == p2_wait_disconnect && last_port_conn_clear == 2) { LED(GREEN); expire_led = 10; state = p4_wait_connect; expire = 15; } // connect 4 if (state == p4_wait_connect && expire == 0) { LED(GREEN); expire_led = 10; connect_port(4); state = p4_wait_reset; } if (state == p4_wait_reset && last_port_reset_clear == 4) { LED(GREEN); expire_led = 10; switch_port(4); state = p4_wait_enumerate; } // connect 5 if (state == p4_ready && expire == 0) { LED(GREEN); expire_led = 10; switch_port(0); /* When first connecting port 5, we need to have the wrong data toggle for the PS3 to respond */ hub_int_force_data0 = 1; connect_port(5); state = p5_wait_reset; } if (state == p5_wait_reset && last_port_reset_clear == 5) { LED(GREEN); expire_led = 10; switch_port(5); state = p5_wait_enumerate; } // disconnect 3 if (state == p5_responded && expire == 0) { LED(GREEN); expire_led = 10; switch_port(0); /* Need wrong data toggle again */ hub_int_force_data0 = 1; disconnect_port(3); state = p3_wait_disconnect; } if (state == p3_wait_disconnect && last_port_conn_clear == 3) { LED(GREEN); expire_led = 10; state = p3_disconnected; expire = 45; } // disconnect 5 if (state == p3_disconnected && expire == 0) { LED(GREEN); expire_led = 10; switch_port(0); disconnect_port(5); state = p5_wait_disconnect; } if (state == p5_wait_disconnect && last_port_conn_clear == 5) { LED(GREEN); expire_led = 10; state = p5_disconnected; expire = 20; } // disconnect 4 if (state == p5_disconnected && expire == 0) { LED(GREEN); expire_led = 10; switch_port(0); disconnect_port(4); state = p4_wait_disconnect; } if (state == p4_wait_disconnect && last_port_conn_clear == 4) { LED(GREEN); expire_led = 10; state = p4_disconnected; expire = 20; } // disconnect 1 if (state == p4_disconnected && expire == 0) { LED(GREEN); expire_led = 10; switch_port(0); disconnect_port(1); state = p1_wait_disconnect; } if (state == p1_wait_disconnect && last_port_conn_clear == 1) { state = p1_disconnected; expire = 20; } // connect 6 if (state == p1_disconnected && expire == 0) { switch_port(0); connect_port(6); state = p6_wait_reset; //expire = 0; // nuevo } if (state == p6_wait_reset && last_port_reset_clear == 6 /*&& expire == 0*/) { switch_port(6); // esto es por que ya no tenemos respuesta state = p6_wait_enumerate; //disconnect_port(6); //state = done; } // done if (state == done) { LED(GREEN); } } }
int main(void) { SetupHardware(); setLed(RED); state = init; switch_port(0); DBGMSG1("Ready."); // Copy the hub descriptor into ram, vusb's // usbFunctionSetup() callback can't handle stuff // from FLASH memcpy_P(HUB_Hub_Descriptor_ram, HUB_Hub_Descriptor, sizeof(HUB_Hub_Descriptor)); for (;;) { if (port_cur == 0) HUB_Task(); if (port_cur == 5) JIG_Task(); usbPoll(); // connect 1 if (state == hub_ready && expire == 0) { DBG1(0x00, "\x1", 1); setLed(NONE); connect_port(1); state = p1_wait_reset; } if (state == p1_wait_reset && last_port_reset_clear == 1) { DBG1(0x00, "\x2", 1); setLed(RED); switch_port(1); state = p1_wait_enumerate; } // connect 2 if (state == p1_ready && expire == 0) { DBG1(0x00, "\x3", 1); setLed(NONE); switch_port(0); connect_port(2); state = p2_wait_reset; } if (state == p2_wait_reset && last_port_reset_clear == 2) { DBG1(0x00, "\x4", 1); setLed(RED); switch_port(2); state = p2_wait_enumerate; } // connect 3 if (state == p2_ready && expire == 0) { DBG1(0x00, "\x5", 1); setLed(NONE); switch_port(0); connect_port(3); state = p3_wait_reset; } if (state == p3_wait_reset && last_port_reset_clear == 3) { DBG1(0x00, "\x6", 1); setLed(RED); switch_port(3); state = p3_wait_enumerate; } // disconnect 2 if (state == p3_ready && expire == 0) { DBG1(0x00, "\x7", 1); setLed(NONE); switch_port(0); disconnect_port(2); state = p2_wait_disconnect; } if (state == p2_wait_disconnect && last_port_conn_clear == 2) { DBG1(0x00, "\x8", 1); setLed(RED); state = p4_wait_connect; expire = 15; } // connect 4 if (state == p4_wait_connect && expire == 0) { DBG1(0x00, "\x9", 1); setLed(NONE); connect_port(4); state = p4_wait_reset; } if (state == p4_wait_reset && last_port_reset_clear == 4) { DBG1(0x00, "\x10", 1); setLed(RED); switch_port(4); state = p4_wait_enumerate; } // connect 5 if (state == p4_ready && expire == 0) { DBG1(0x00, "\x11", 1); setLed(NONE); switch_port(0); /* When first connecting port 5, we need to have the wrong data toggle for the PS3 to respond */ hub_int_force_data0 = 1; connect_port(5); state = p5_wait_reset; } if (state == p5_wait_reset && last_port_reset_clear == 5) { DBG1(0x00, "\x12", 1); setLed(RED); switch_port(5); state = p5_wait_enumerate; } // disconnect 3 if (state == p5_responded && expire == 0) { DBG1(0x00, "\x13", 1); setLed(NONE); switch_port(0); /* Need wrong data toggle again */ hub_int_force_data0 = 1; disconnect_port(3); state = p3_wait_disconnect; } if (state == p3_wait_disconnect && last_port_conn_clear == 3) { DBG1(0x00, "\x14", 1); setLed(RED); state = p3_disconnected; expire = 45; } // disconnect 5 if (state == p3_disconnected && expire == 0) { DBG1(0x00, "\x15", 1); setLed(NONE); switch_port(0); disconnect_port(5); state = p5_wait_disconnect; } if (state == p5_wait_disconnect && last_port_conn_clear == 5) { DBG1(0x00, "\x16", 1); setLed(RED); state = p5_disconnected; expire = 20; } // disconnect 4 if (state == p5_disconnected && expire == 0) { DBG1(0x00, "\x17", 1); setLed(NONE); switch_port(0); disconnect_port(4); state = p4_wait_disconnect; } if (state == p4_wait_disconnect && last_port_conn_clear == 4) { DBG1(0x00, "\x18", 1); setLed(RED); state = p4_disconnected; expire = 20; } // disconnect 1 if (state == p4_disconnected && expire == 0) { DBG1(0x00, "\x19", 1); setLed(NONE); switch_port(0); disconnect_port(1); state = p1_wait_disconnect; } if (state == p1_wait_disconnect && last_port_conn_clear == 1) { DBG1(0x00, "\x20", 1); setLed(RED); state = p1_disconnected; expire = 20; } // connect 6 if (state == p1_disconnected && expire == 0) { DBG1(0x00, "\x21", 1); setLed(NONE); switch_port(0); connect_port(6); state = p6_wait_reset; } if (state == p6_wait_reset && last_port_reset_clear == 6) { DBG1(0x00, "\x22", 1); setLed(RED); switch_port(6); state = p6_wait_enumerate; } // done if (state == done) { setLed(GREEN); } } }