diff --git a/extras/unused/mcufriend_special_2.h b/extras/unused/mcufriend_special_2.h index c08edaf..4488de8 100644 --- a/extras/unused/mcufriend_special_2.h +++ b/extras/unused/mcufriend_special_2.h @@ -1789,4 +1789,127 @@ static void setReadDir() #define PIN_HIGH(p, b) (digitalWrite(b, HIGH)) #define PIN_OUTPUT(p, b) (pinMode(b, OUTPUT)) +//#### UNTESTED ############### COOCOX_STM32 on STM32103RB ############################## +//#define USE_COOCOX_STM32 +#elif defined(USE_COOCOX_STM32) && (defined(ARDUINO_GENERIC_STM32F103R)||defined(ARDUINO_GENERIC_F103RBTX)) +#warning Uno Shield on USE_COOCOX_STM32 + +//LCD pins |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST| |SD_SS|SD_DI|SD_DO|SD_SCK| |SDA|SCL| +//STM32 pin |PD2|PC9|PC8|PC7|PC6|PC12|PA8|PA15| |PC0|PC1|PC2|PC3|PB7| |PB12 |PB15 |PB14 |PB13 | |PB7|PB6| + +#if defined(ARDUINO_GENERIC_F103RBTX) //regular CMSIS libraries +#define REGS(x) x +#define GPIO_INIT() { RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN | RCC_APB2ENR_AFIOEN; \ + AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_1;} +#else //weird Maple libraries +#define REGS(x) regs->x +#endif + +#define WRITE_DELAY { } +#define READ_DELAY { RD_ACTIVE4; } +#define GROUP_MODE(port, reg, mask, val) {port->REGS(reg) = (port->REGS(reg) & ~(mask)) | ((mask)&(val)); } +#define GP_OUT(port, reg, mask) GROUP_MODE(port, reg, mask, 0x33333333) +#define GP_INP(port, reg, mask) GROUP_MODE(port, reg, mask, 0x44444444) +#define PIN_OUTPUT(port, pin) {\ + if (pin < 8) {GP_OUT(port, CRL, 0xF<<((pin)<<2));} \ + else {GP_OUT(port, CRH, 0xF<<((pin&7)<<2));} \ + } +#define PIN_INPUT(port, pin) { \ + if (pin < 8) { GP_INP(port, CRL, 0xF<<((pin)<<2)); } \ + else { GP_INP(port, CRH, 0xF<<((pin&7)<<2)); } \ + } +#define PIN_HIGH(port, pin) (port)-> REGS(BSRR) = (1<<(pin)) +#define PIN_LOW(port, pin) (port)-> REGS(BSRR) = (1<<((pin)+16)) + +#define RD_PORT GPIOC +#define RD_PIN 0 +#define WR_PORT GPIOC +#define WR_PIN 1 +#define CD_PORT GPIOC +#define CD_PIN 2 +#define CS_PORT GPIOC +#define CS_PIN 3 +#define RESET_PORT GPIOB +#define RESET_PIN 7 + +// configure macros for the data pins +#define AMASK ((1<<8)|(1<<15)) +#define CMASK ((15<<6)|(1<<12)) +#define DMASK (1<<2) +#define write_8(d) { GPIOA->REGS(BSRR) = AMASK << 16; GPIOC->REGS(BSRR) = CMASK << 16;\ + GPIOD->REGS(BSRR) = DMASK << 16; \ + GPIOA->REGS(BSRR) = (((d) & (1<<0)) << 15); \ + GPIOA->REGS(BSRR) = (((d) & (1<<1)) << 4); \ + GPIOC->REGS(BSRR) = (((d) & (1<<2)) << 10); \ + GPIOC->REGS(BSRR) = (((d) &(15<<3)) << 3); \ + GPIOD->REGS(BSRR) = (((d) & (1<<7)) >> 5); \ + } +#define read_8() ( ((GPIOA->REGS(IDR) & (1<<15)) >> 15) \ + | ((GPIOA->REGS(IDR) & (1<<8)) >> 7) \ + | ((GPIOC->REGS(IDR) & (1<<12)) >> 10) \ + | ((GPIOC->REGS(IDR) & (15<<6)) >> 3) \ + | ((GPIOD->REGS(IDR) & (1<<2)) << 5) \ + ) +// PA15,PA8 PC12,PC9-PC8 PC7,PC6 PD2 +#define setWriteDir() {GP_OUT(GPIOA, CRH, 0xF000000F); GP_OUT(GPIOC, CRH, 0xF00FF); GP_OUT(GPIOC, CRL, 0xFF000000); GP_OUT(GPIOD, CRL, 0xF00); } +#define setReadDir() {GP_INP(GPIOA, CRH, 0xF000000F); GP_INP(GPIOC, CRH, 0xF00FF); GP_INP(GPIOC, CRL, 0xFF000000); GP_INP(GPIOD, CRL, 0xF00); } + +#define write8(x) { write_8(x); WRITE_DELAY; WR_STROBE; } +#define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); } +#define READ_8(dst) { RD_STROBE; READ_DELAY; dst = read_8(); RD_IDLE; } +#define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); } + +//#### UNTESTED ############# MKR2UNO ############################ +//#define USE_MKR2UNO +#elif defined(__SAMD21G18A__) && defined(USE_MKR2UNO) //regular UNO shield on MKE2UNO Adapter +//LCD pins |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST | |SDCS|SDDI|SDDO|SDSCK| +//SAMD21 pin |PA21|PA20|PB11|PB10|PA11|PA10|PA17|PA16| |PA2|PB2|PB3 |PA4 |PA5 | |PA23|PA8 |PA9 |PA22 | +//MKR2UNO pin|7 |6 |5 |4 |3 |2 |9 |8 | |A0 |A1 |A2 |A3 |A4 | |10 |11 |12 |13 | +#include "sam.h" + // configure macros for the control pins +#define RD_PORT PORT->Group[0] +#define RD_PIN 2 +#define WR_PORT PORT->Group[1] +#define WR_PIN 2 +#define CD_PORT PORT->Group[1] +#define CD_PIN 3 +#define CS_PORT PORT->Group[0] +#define CS_PIN 4 +#define RESET_PORT PORT->Group[0] +#define RESET_PIN 5 + // configure macros for data bus +#define AMASK ((3<<20)|(3<<10)|(3<<16)) //|PA21|PA20|PA11|PA10|PA17|PA16| +#define BMASK ((1<<11)|(1<<10)) //|PB11|PB10| +#define WRMASK ((0<<22) | (1<<28) | (1<<30)) // +#define RDMASK ((1<<17) | (1<<28) | (1<<30)) // +#define write_8(x) {\ + PORT->Group[0].OUTCLR.reg = AMASK;PORT->Group[1].OUTCLR.reg = BMASK;\ + PORT->Group[0].OUTSET.reg = (((x) & (3<<0)) << 16)\ + |(((x) & (3<<2)) << 8)\ + |(((x) & (3<<6)) << 14);\ + PORT->Group[1].OUTSET.reg = (((x) & (3<<4)) << 6);\ + } +#define read_8() (((PORT->Group[0].IN.reg >> 16) & (3<<0))\ + |((PORT->Group[0].IN.reg >> 8) & (3<<2))\ + |((PORT->Group[1].IN.reg >> 6) & (3<<4))\ + |((PORT->Group[0].IN.reg >> 14) & (3<<6))) +#define setWriteDir() { PORT->Group[0].DIRSET.reg = AMASK;PORT->Group[0].DIRSET.reg = BMASK; \ + PORT->Group[0].WRCONFIG.reg = (AMASK & 0xFFFF) | WRMASK; \ + PORT->Group[1].WRCONFIG.reg = (BMASK & 0xFFFF) | WRMASK; \ + PORT->Group[0].WRCONFIG.reg = (AMASK>>16) | WRMASK | (1<<31); \ + } +#define setReadDir() { PORT->Group[0].DIRCLR.reg = AMASK;PORT->Group[1].DIRCLR.reg = BMASK; \ + PORT->Group[0].WRCONFIG.reg = (AMASK & 0xFFFF) | RDMASK; \ + PORT->Group[1].WRCONFIG.reg = (BMASK & 0xFFFF) | RDMASK; \ + PORT->Group[0].WRCONFIG.reg = (AMASK>>16) | RDMASK | (1<<31); \ + } +#define write8(x) { write_8(x); WR_ACTIVE; 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); } + // Shield Control macros. +#define PIN_LOW(port, pin) (port).OUTCLR.reg = (1<<(pin)) +#define PIN_HIGH(port, pin) (port).OUTSET.reg = (1<<(pin)) +#define PIN_OUTPUT(port, pin) (port).DIR.reg |= (1<<(pin)) + // ######################### ################### diff --git a/utility/mcufriend_special.h b/utility/mcufriend_special.h index bb40a56..3c92809 100644 --- a/utility/mcufriend_special.h +++ b/utility/mcufriend_special.h @@ -19,6 +19,9 @@ //#define USE_MIKROELEKTRONIKA //#define USE_XPRO_MEGA4809 //#define USE_MY_PICO +//#define USE_CURIOSITY_AVR128DA48 +//#define USE_CURIOSITY_AVR128DB48 + /* HX8347A tWC =100ns tWRH = 35ns tRCFM = 450ns tRC = ? ns @@ -43,6 +46,86 @@ ST7796S tWC = 66ns tWRH = 15ns tRCFM = 450ns tRC = 160ns #if 0 +//################################### Curiosity AVR128DA48 ############################## +#elif defined(__AVR_AVR128DA48__) && defined(USE_CURIOSITY_AVR128DA48) // +#warning Curiosity AVR128DA48 +//LCD pins |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST| |SDA0|SCL0| |SDA1|SCL1| +//DA48 pin |PA3|PA2|PB5|PB4|PB3|PB2|PB1|PB0| |PD0|PD1|PD2|PD3|PD4| |PC2 |PC3 | |PF2 |PF3 | +//DB48 pin |PC7|PC6|PC5|PC4|PC3|PC2|PC1|PC0| |PD0|PD1|PD2|PD4|PD5| |PA2 |PA3 | |PF2 |PF3 | +//Curiosity |37 |36 |35 |34 |23 |22 |21 |20 | |46 |47 |48 |43 |44 | |9 |10 | |18 |19 | +//UNO pins |7 |6 |5 |4 |3 |2 |9 |8 | |A0 |A1 |A2 |A3 |A4 | |18 |19 | +//LCD pins |CS |MOSI|MISO|SCK | |SDA|SCL| +//128DA pin |PA7 |PA4 |PA5 |PA6 | |PF2|GP7| +//UNO pins |10 |11 |12 |13 | |18 |19 | + +#define WRITE_DELAY { } +#define READ_DELAY { RD_ACTIVE2; } + +#define RD_PORT VPORTD +#define RD_PIN 0 +#define WR_PORT VPORTD +#define WR_PIN 1 +#define CD_PORT VPORTD +#define CD_PIN 2 +#define CS_PORT VPORTD +#define CS_PIN 3 +#define RESET_PORT VPORTD +#define RESET_PIN 4 + +#define BMASK 0x3F +#define AMASK 0x0C +//#define write_8(x) { VPORTB.OUT = ((x) & BMASK) | (VPORTB.OUT & 0xC0); VPORTA.OUT = (((x) & 0xC0) >> 4) | (VPORTA.OUT & ~AMASK);} +//#define write_8(x) { PORTB.OUTCLR = BMASK; PORTB.OUTSET =((x) & BMASK); PORTA.OUTCLR = AMASK; PORTA.OUTSET = ((x) >> 4) & AMASK;} +#define write_8(x) { PORTB.OUTCLR = BMASK; PORTA.OUTCLR = AMASK; PORTB.OUTSET =((x) & BMASK); PORTA.OUTSET = ((x) >> 4) & AMASK;} +#define read_8() ( (VPORTB_IN & BMASK) | ((VPORTA_IN & AMASK) << 4) ) +#define setWriteDir() { VPORTB.DIR |= BMASK; VPORTA.DIR |= AMASK; } +#define setReadDir() { VPORTB.DIR &= ~BMASK; VPORTA.DIR &= ~AMASK; } +#define write8(x) { write_8(x); WRITE_DELAY; WR_STROBE; } +#define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); } +#define READ_8(dst) { RD_STROBE; READ_DELAY; dst = read_8(); RD_IDLE; } +#define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); } + +#define PIN_LOW(p, b) (p).OUT &= ~(1<<(b)) +#define PIN_HIGH(p, b) (p).OUT |= (1<<(b)) +#define PIN_OUTPUT(p, b) (p).DIR |= (1<<(b)) + +//################################### Curiosity AVR128DB48 ############################## +#elif defined(__AVR_AVR128DB48__) && defined(USE_CURIOSITY_AVR128DB48) // +#warning Curiosity AVR128DB48 +//LCD pins |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST| +//DA48 pin |PA3|PA2|PB5|PB4|PB3|PB2|PB1|PB0| |PD0|PD1|PD2|PD3|PD4| +//DB48 pin |PC7|PC6|PC5|PC4|PC3|PC2|PC1|PC0| |PD0|PD1|PD2|PD4|PD5| +//Curiosity |37 |36 |35 |34 |23 |22 |21 |20 | |46 |47 |48 |43 |44 | +//UNO pins |7 |6 |5 |4 |3 |2 |9 |8 | |A0 |A1 |A2 |A3 |A4 | + +#define WRITE_DELAY { } +#define READ_DELAY { RD_ACTIVE2; } + +#define RD_PORT VPORTD +#define RD_PIN 0 +#define WR_PORT VPORTD +#define WR_PIN 1 +#define CD_PORT VPORTD +#define CD_PIN 2 +#define CS_PORT VPORTD +#define CS_PIN 4 +#define RESET_PORT VPORTD +#define RESET_PIN 5 + +#define CMASK 0xFF +#define write_8(x) { PORTC.OUT = x; } +#define read_8() ( (PORTC.IN) ) +#define setWriteDir() { VPORTC.DIR |= CMASK; } +#define setReadDir() { VPORTC.DIR &= ~CMASK; } +#define write8(x) { write_8(x); WRITE_DELAY; WR_STROBE; } +#define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); } +#define READ_8(dst) { RD_STROBE; READ_DELAY; dst = read_8(); RD_IDLE; } +#define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); } + +#define PIN_LOW(p, b) (p).OUT &= ~(1<<(b)) +#define PIN_HIGH(p, b) (p).OUT |= (1<<(b)) +#define PIN_OUTPUT(p, b) (p).DIR |= (1<<(b)) + //################################### RP2040 ############################## #elif defined(USE_MY_PICO) && defined(ARDUINO_ARCH_RP2040) //regular UNO shield on PICO //LCD pins |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST | | @@ -136,11 +219,15 @@ ST7796S tWC = 66ns tWRH = 15ns tRCFM = 450ns tRC = 160ns #define RESET_PIN 1 #elif defined(__AVR_ATxmega128A1__) -#warning Home made shield with Xplained A1 CTL=J4 (PC), DATA=J2 (PA) #define VPMAP10 0x50 // VPORT0=A, 1=F, 2=C, 3=D #define VPMAP32 0x32 // VPORT0=A, 1=F, 2=C, 3=D #define DATPORT VPORT0 //PORTA -#define CTLPORT VPORT2 //PORTC +#define CTLPORT VPORT1 //PORTF i.e. CTL=J1 (PF), DATA=J2 (PA) +#warning Home made shield with Xplained A1 CTL=J1 (PF), DATA=J2 (PA) +//#define CTLPORT VPORT2 //PORTC i.e. CTL=J4 (PC), DATA=J2 (PA) upsets Serial on PC2,PC3 +//#warning Home made shield with Xplained A1 CTL=J4 (PC), DATA=J2 (PA) upsets Serial on PC2,PC3 +//#define CTLPORT VPORT3 //PORTD i.e. CTL=J3 (PD), DATA=J2 (PA) note J3 VCC pin=5V0 +//#warning Home made shield with Xplained A1 CTL=J3 (PD), DATA=J2 (PA) note J3 VCC pin=5V0 #define RD_PORT CTLPORT //PC0. #define RD_PIN 0 #define WR_PORT CTLPORT @@ -216,6 +303,11 @@ ST7796S tWC = 66ns tWRH = 15ns tRCFM = 450ns tRC = 160ns //################################# XPRO-4809 with XPRO-Shield_Adapter ############################ #elif defined(__AVR_ATmega4809__) && !defined(USE_BLD_BST_MEGA4809) && defined(USE_XPRO_MEGA4809) // XPRO-4809 with XPRO-Shield_Adapter +//LCD pins |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST| |CS |DI | +//4809 pin |PE1|PB3|PF6|PC7|PC6|PB2|PA3|PA2| |PD2|PD3|PD4|PD5|PC2| |PA7]PA4| +//XPRO |215|210|206|110|109|209|106|105| |103|104|203|204|111| |115|116| +//UNO pins |7 |6 |5 |4 |3 |2 |9 |8 | |A0 |A1 |A2 |A3 |A4 | |10 |11 | +//XPRO Shield Adapter SW100=down for D11=EXT1.16. SW101=up for D3=EXT1.9 #warning XPRO-4809 with XPRO-Shield_Adapter using PORT.OUTSET #define RD_PORT PORTD // #define RD_PIN 2 @@ -827,6 +919,9 @@ static __attribute((always_inline)) void write_8(uint8_t val) //Due pins |43 |39 |38 |40 |41 | #warning USE_MEGA_16BIT_SHIELD #define USES_16BIT_BUS +#define WRITE_DELAY { WR_ACTIVE4; WR_ACTIVE2; } +#define IDLE_DELAY { } +#define READ_DELAY { RD_ACTIVE4; } // configure macros for the control pins #define RD_PORT PIOA #define RD_PIN 20 //D43 @@ -894,8 +989,8 @@ static __attribute((always_inline)) void write_8(uint8_t val) } #define write8(x) { write16(x & 0xFF); } // ILI9486 is slower than ILI9481 -#define write16(x) { write_16(x); WR_ACTIVE8; WR_STROBE; WR_IDLE4;} -#define READ_16(dst) { RD_STROBE; RD_ACTIVE4; dst = read_16(); RD_IDLE; RD_IDLE; RD_IDLE; } +#define write16(x) { write_16(x); WRITE_DELAY; WR_STROBE; IDLE_DELAY;} +#define READ_16(dst) { RD_STROBE; READ_DELAY; dst = read_16(); RD_IDLE2; } #define READ_8(dst) { READ_16(dst); dst &= 0xFF; } // Shield Control macros. @@ -908,6 +1003,9 @@ static __attribute((always_inline)) void write_8(uint8_t val) //SAM3XE pin |PD6 |PD3 |PD2 |PD1 |PD0 |PA15|PA14|PB26| |PA20|PC7 |PC6 |PC8 |PC9 | //Due pins |29 |28 |27 |26 |25 |24 |23 |22 | |43 |39 |38 |40 |41 | #warning USE_MEGA_8BIT_SHIELD for peloxp +#define WRITE_DELAY { WR_ACTIVE4; } +#define IDLE_DELAY { } +#define READ_DELAY { RD_ACTIVE4; } // configure macros for the control pins #define RD_PORT PIOA #define RD_PIN 20 //D43 @@ -952,9 +1050,9 @@ static __attribute((always_inline)) void write_8(uint8_t val) } // ILI9486 is slower than ILI9481. HX8357-D is slower -#define write8(x) { write_8(x); WR_ACTIVE4; WR_STROBE; WR_IDLE; WR_IDLE; } +#define write8(x) { write_8(x); WRITE_DELAY; WR_STROBE; IDLE_DELAY; } #define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); } -#define READ_8(dst) { RD_STROBE; RD_ACTIVE4; dst = read_8(); RD_IDLE; RD_IDLE; RD_IDLE; } +#define READ_8(dst) { RD_STROBE; READ_DELAY; dst = read_8(); RD_IDLE2; } #define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); } // Shield Control macros. @@ -967,6 +1065,9 @@ static __attribute((always_inline)) void write_8(uint8_t val) //SAM3XE pin |PD9 |PA7 |PD10|PC1 |PC2 |PC3 |PC4 |PC5 | |PA20|PC7 |PC6 |PC8 |PC9 | //Due pins |30 |31 |32 |33 |34 |35 |36 |37 | |43 |39 |38 |40 |41 | #warning USE_MEGA_8BIT_PORTC_SHIELD on DUE +#define WRITE_DELAY { } +#define IDLE_DELAY { } +#define READ_DELAY { RD_ACTIVE4; } // configure macros for the control pins #define RD_PORT PIOA #define RD_PIN 20 //D43 @@ -1018,9 +1119,9 @@ static __attribute((always_inline)) void write_8(uint8_t val) } // ILI9486 is slower than ILI9481. HX8357-D is slower -#define write8(x) { write_8(x); WR_ACTIVE4; WR_STROBE; WR_IDLE; WR_IDLE; } +#define write8(x) { write_8(x); WRITE_DELAY; WR_STROBE; IDLE_DELAY; } #define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); } -#define READ_8(dst) { RD_STROBE; RD_ACTIVE4; dst = read_8(); RD_IDLE; RD_IDLE; RD_IDLE; } +#define READ_8(dst) { RD_STROBE; READ_DELAY; dst = read_8(); RD_IDLE2; } #define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); } // Shield Control macros.