X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=main.c;h=37be879abdb44ae28a01ec53d38bc89520eeed26;hb=a773ac06cdc55be51ebc0bc61aa6066b54746c7d;hp=511a599267265fc5397f3300ea38fe5697c67deb;hpb=0c1e003e9d6aa58868c13de9618a9114181f921c;p=teensytas.git diff --git a/main.c b/main.c index 511a599..37be879 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,9 @@ #include "teensy3/usb_seremu.h" #include "teensy3/usb_rawhid.h" +/* ?0SA 00DU, ?1CB RLDU */ +static uint8_t fixed_state[4] = { 0x33, 0x3f }; + ssize_t _write(int fd, const void *buf, size_t nbyte) { char tbuf[64]; @@ -23,25 +26,75 @@ void yield(void) { } +static void my_portb_isr(void) +{ + uint32_t isfr; + + //printf("irq, GPIOB_PDIR: %08x\n", GPIOB_PDIR); + + GPIOD_PDOR = fixed_state[(GPIOB_PDIR >> CORE_PIN0_BIT) & 1]; + + isfr = PORTB_ISFR; + PORTB_ISFR = isfr; +} + int main(void) { + char buf[64]; + int timeout; int ret; delay(1000); // wait for usb.. printf("starting, rawhid: %d\n", usb_rawhid_available()); - // ret = usb_rawhid_recv(buf, 2000); - // ret = usb_rawhid_send(buf, 2000); + // md pin th tr tl r l d u + // md bit* 6 5 4 3 2 1 0 + // t bit b16 d5 d4 d3 d2 d1 d0 + // t pin 0 20 6 8 7 14 2 + // * - note: tl/tr mixed in most docs + pinMode(0, INPUT); + attachInterrupt(0, my_portb_isr, CHANGE); + attachInterruptVector(IRQ_PORTB, my_portb_isr); - pinMode(13, OUTPUT); + pinMode( 2, OUTPUT); pinMode(14, OUTPUT); + pinMode( 7, OUTPUT); + pinMode( 8, OUTPUT); + pinMode( 6, OUTPUT); + pinMode(20, OUTPUT); + + // led + pinMode(13, OUTPUT); + // CORE_PIN13_PORTSET = CORE_PIN13_BITMASK; + // CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK; + + // CORE_PIN0_PORTSET CORE_PIN0_BITMASK PORTB_PCR16 + printf("GPIOC PDDR, PDIR: %08x %08x\n", GPIOC_PDIR, GPIOC_PDDR); + printf("GPIOD PDDR, PDIR: %08x %08x\n", GPIOD_PDIR, GPIOD_PDDR); + printf("PORTB_PCR16: %08x\n", PORTB_PCR16); + + // ret = usb_rawhid_send(buf, 2000); + + timeout = 1000; + while (1) { - CORE_PIN13_PORTSET = CORE_PIN13_BITMASK; - CORE_PIN14_PORTSET = CORE_PIN14_BITMASK; - delay(500*4); - CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK; - CORE_PIN14_PORTCLEAR = CORE_PIN14_BITMASK; - delay(500*4); + 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; }