From df48d083f74ae3375ab57e4280f8c19dbd0bf0d0 Mon Sep 17 00:00:00 2001 From: prenticedavid Date: Fri, 26 Aug 2016 18:09:25 +0100 Subject: [PATCH] support macros for Uno shield on Teensy 3.x --- mcufriend_shield.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/mcufriend_shield.h b/mcufriend_shield.h index 5817f36..53357fb 100644 --- a/mcufriend_shield.h +++ b/mcufriend_shield.h @@ -232,6 +232,57 @@ void write_8(uint8_t x) #define PIN_HIGH(p, b) (p) |= (1<<(b)) #define PIN_OUTPUT(p, b) *(&p-1) |= (1<<(b)) +#elif defined(__MK20DX128__) || defined(__MK20DX256__) // regular UNO shield on a Teensy 3.x +#warning regular UNO shield on a Teensy 3.x +#define RD_PORT GPIOD +#define RD_PIN 1 +#define WR_PORT GPIOC +#define WR_PIN 0 +#define CD_PORT GPIOB +#define CD_PIN 0 +#define CS_PORT GPIOB +#define CS_PIN 1 +#define RESET_PORT GPIOB +#define RESET_PIN 3 + +// configure macros for the data pins +#define AMASK ((1<<12)|(1<<13)) +#define CMASK ((1<<3)) +#define DMASK ((1<<0)|(1<<2)|(1<<3)|(1<<4)|(1<<7)) + + #define write_8(d) { \ + GPIOA_PCOR = AMASK; GPIOC_PCOR = CMASK; GPIOD_PCOR = DMASK; \ + GPIOA_PSOR = (((d) & (1<<3)) << 9) \ + | (((d) & (1<<4)) << 9); \ + GPIOC_PSOR = (((d) & (1<<1)) << 2); \ + GPIOD_PSOR = (((d) & (1<<0)) << 3) \ + | (((d) & (1<<2)) >> 2) \ + | (((d) & (1<<5)) << 2) \ + | (((d) & (1<<6)) >> 2) \ + | (((d) & (1<<7)) >> 5); \ + } + #define read_8() ( (((GPIOD_PDIR & (1<<3)) >> 3) \ + | ((GPIOC_PDIR & (1<<3)) >> 2) \ + | ((GPIOD_PDIR & (1<<0)) << 2) \ + | ((GPIOA_PDIR & (1<<12)) >> 9) \ + | ((GPIOA_PDIR & (1<<13)) >> 9) \ + | ((GPIOD_PDIR & (1<<7)) >> 2) \ + | ((GPIOD_PDIR & (1<<4)) << 2) \ + | ((GPIOD_PDIR & (1<<2)) << 5))) + #define setWriteDir() {GPIOA_PDDR |= AMASK;GPIOC_PDDR |= CMASK;GPIOD_PDDR |= DMASK; } + #define setReadDir() {GPIOA_PDDR &= ~AMASK;GPIOC_PDDR &= ~CMASK;GPIOD_PDDR &= ~DMASK; } + +#define write8(x) { write_8(x); WR_STROBE; } +#define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); } +#define READ_8(dst) { RD_STROBE; dst = read_8(); RD_IDLE; } +#define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); } + +#define PASTE(x, y) x ## y + +#define PIN_LOW(port, pin) PASTE(port, _PCOR) = (1<<(pin)) +#define PIN_HIGH(port, pin) PASTE(port, _PSOR) = (1<<(pin)) +#define PIN_OUTPUT(port, pin) PASTE(port, _PDDR) |= (1<<(pin)) + #else #error MCU unsupported #endif // regular UNO shields on Arduino boards