4 #include "teensy3/core_pins.h"
5 #include "teensy3/usb_seremu.h"
6 #include "teensy3/usb_rawhid.h"
8 /* ?0SA 00DU, ?1CB RLDU */
9 static uint8_t fixed_state[4] = { 0x33, 0x3f };
11 ssize_t _write(int fd, const void *buf, size_t nbyte)
16 if (fd != 1 && fd != 2) {
17 snprintf(tbuf, sizeof(tbuf), "write to fd %d\n", fd);
18 usb_seremu_write(tbuf, strlen(tbuf));
21 ret = usb_seremu_write(buf, nbyte);
22 return ret < 0 ? ret : nbyte;
29 static void pin0_irq(void)
37 //printf("irq, GPIOB_PDIR: %08x\n", GPIOB_PDIR);
39 GPIOD_PDOR = fixed_state[(GPIOB_PDIR >> CORE_PIN0_BIT) & 1];
49 delay(1000); // wait for usb..
51 printf("starting, rawhid: %d\n", usb_rawhid_available());
53 // md pin th tr tl r l d u
54 // md bit* 6 5 4 3 2 1 0
55 // t bit b16 d5 d4 d3 d2 d1 d0
56 // t pin 0 20 6 8 7 14 2
57 // * - note: tl/tr mixed in most docs
59 attachInterrupt(0, pin0_irq, CHANGE);
70 // CORE_PIN13_PORTSET = CORE_PIN13_BITMASK;
71 // CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK;
73 // CORE_PIN0_PORTSET CORE_PIN0_BITMASK PORTB_PCR16
74 printf("GPIOC PDDR, PDIR: %08x %08x\n", GPIOC_PDIR, GPIOC_PDDR);
75 printf("GPIOD PDDR, PDIR: %08x %08x\n", GPIOD_PDIR, GPIOD_PDDR);
76 printf("PORTB_PCR16: %08x\n", PORTB_PCR16);
78 // ret = usb_rawhid_recv(buf, 2000);
79 // ret = usb_rawhid_send(buf, 2000);
83 fixed_state[1] &= ~0x20;
84 CORE_PIN13_PORTSET = CORE_PIN13_BITMASK;
87 fixed_state[1] |= 0x20;
88 CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK;