From: notaz Date: Sun, 14 Sep 2014 23:04:09 +0000 (+0300) Subject: working C button 'presser' X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c4f55f45a932dd6c79f99c5e5471d902c72ae9e;p=megadrive.git working C button 'presser' --- diff --git a/Makefile b/Makefile index d934bba..338782c 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ TARGET = test # CPPFLAGS += -DUSB_SERIAL -DLAYOUT_US_ENGLISH CPPFLAGS += -D__MK20DX256__ -DF_CPU=48000000 CPPFLAGS += -DUSB_RAWHID -CPPFLAGS += -Wall -g -Os -mcpu=cortex-m4 -mthumb -nostdlib # -MMD +CPPFLAGS += -Wall -Wno-format -g -Os +CPPFLAGS += -mcpu=cortex-m4 -mtune=cortex-m4 -mthumb -nostdlib # -MMD CXXFLAGS += -std=gnu++0x -felide-constructors -fno-exceptions -fno-rtti LDFLAGS = -Os -Wl,--gc-sections -mcpu=cortex-m4 -mthumb -Tteensy3/mk20dx256.ld LDLIBS += -lm diff --git a/main.c b/main.c index 511a599..8287fb5 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,65 @@ void yield(void) { } +static void pin0_irq(void) +{ +} + +void 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) { - int ret; + //int ret; delay(1000); // wait for usb.. printf("starting, rawhid: %d\n", usb_rawhid_available()); + // 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, pin0_irq, CHANGE); + + 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_recv(buf, 2000); // ret = usb_rawhid_send(buf, 2000); - pinMode(13, OUTPUT); - pinMode(14, OUTPUT); while (1) { + delay(4000); + fixed_state[1] &= ~0x20; CORE_PIN13_PORTSET = CORE_PIN13_BITMASK; - CORE_PIN14_PORTSET = CORE_PIN14_BITMASK; - delay(500*4); + + delay(700); + fixed_state[1] |= 0x20; CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK; - CORE_PIN14_PORTCLEAR = CORE_PIN14_BITMASK; - delay(500*4); } } diff --git a/teensy3/pins_teensy.c b/teensy3/pins_teensy.c index de2d56f..ec6bf03 100644 --- a/teensy3/pins_teensy.c +++ b/teensy3/pins_teensy.c @@ -165,7 +165,7 @@ void porta_isr(void) if ((isfr & CORE_PIN33_BITMASK) && intFunc[33]) intFunc[33](); } -void portb_isr(void) +void portb_isr_orig(void) { uint32_t isfr = PORTB_ISFR; PORTB_ISFR = isfr;