X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=main.c;h=37be879abdb44ae28a01ec53d38bc89520eeed26;hb=1ad7d1ddee4bb654f8b8a8420516fcc39fc0f68d;hp=8287fb5f845eb843815f020417e749dcf1465a74;hpb=9c4f55f45a932dd6c79f99c5e5471d902c72ae9e;p=megadrive.git diff --git a/main.c b/main.c index 8287fb5..37be879 100644 --- a/main.c +++ b/main.c @@ -26,11 +26,7 @@ void yield(void) { } -static void pin0_irq(void) -{ -} - -void portb_isr(void) +static void my_portb_isr(void) { uint32_t isfr; @@ -44,7 +40,9 @@ void portb_isr(void) int main(void) { - //int ret; + char buf[64]; + int timeout; + int ret; delay(1000); // wait for usb.. @@ -56,7 +54,8 @@ int main(void) // t pin 0 20 6 8 7 14 2 // * - note: tl/tr mixed in most docs pinMode(0, INPUT); - attachInterrupt(0, pin0_irq, CHANGE); + attachInterrupt(0, my_portb_isr, CHANGE); + attachInterruptVector(IRQ_PORTB, my_portb_isr); pinMode( 2, OUTPUT); pinMode(14, OUTPUT); @@ -75,16 +74,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; }