X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=main.c;h=5c99ee35dabd444e7a93e2b765c087ec642e2da0;hb=1cb2822f8f829a2197843a60e1aa250730ae00e3;hp=8287fb5f845eb843815f020417e749dcf1465a74;hpb=252ad0c605098ea61ba140ac3be89a6f056b5d8c;p=megadrive.git diff --git a/main.c b/main.c index 8287fb5..5c99ee3 100644 --- a/main.c +++ b/main.c @@ -44,7 +44,9 @@ void portb_isr(void) int main(void) { - //int ret; + char buf[64]; + int timeout; + int ret; delay(1000); // wait for usb.. @@ -75,16 +77,27 @@ int main(void) printf("GPIOD PDDR, PDIR: %08x %08x\n", GPIOD_PDIR, GPIOD_PDDR); printf("PORTB_PCR16: %08x\n", PORTB_PCR16); - // ret = usb_rawhid_recv(buf, 2000); // ret = usb_rawhid_send(buf, 2000); - while (1) { - delay(4000); - fixed_state[1] &= ~0x20; - CORE_PIN13_PORTSET = CORE_PIN13_BITMASK; + timeout = 1000; - delay(700); - fixed_state[1] |= 0x20; - CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK; + while (1) { + ret = usb_rawhid_recv(buf, timeout); + if (ret == 64) { + CORE_PIN13_PORTSET = CORE_PIN13_BITMASK; + + memcpy(fixed_state, buf, sizeof(fixed_state)); + timeout = 20; + } + else if (ret == 0) { + CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK; + timeout = 1000; + } + else { + printf("usb_rawhid_recv: %d\n", ret); + timeout = 1000; + } } + + return 0; }