prenticedavid / MCUFRIEND_kbv

MCUFRIEND_kbv Library for Uno 2.4, 2.8, 3.5, 3.6, 3.95 inch mcufriend Shields
Other
363 stars 181 forks source link

Teensy4.0 new macros .. #229

Closed jox1a closed 1 year ago

jox1a commented 1 year ago

Hi all I wrote a new macro for T4.0 However, it does not work, probably somewhere there is a mistake that I do not see. Maybe Someone with More Experience Can Have A Closer Look and Tell Me What Is Wrong.

//####################################### TEENSY 4.0 ############################

elif defined(IMXRT1062)

//jox1//////////////////////////////////////////////////////////////////////////// RD-WR Analog-Digital //LCD pins |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST |
// T4.0 pin |32 |30 |31 |28 |29 |33 |3 |2 | |24 |25 |26 |27 |21 |
// MXRT pin |7.12 |8.23 |8.22|8.18|9.31|9.7 |9.5|9.4| |6.12|6.13|6.30|6.21|6.27|

define RD_PORT GPIO6

define RD_PIN 12

define WR_PORT GPIO6

define WR_PIN 13

define CD_PORT GPIO6

define CD_PIN 30 //rs

define CS_PORT GPIO6

define CS_PIN 21

define RESET_PORT GPIO6

define RESET_PIN 27

if 0

elif defined(IMXRT1062)

define WRITE_DELAY { WR_ACTIVE8;WR_ACTIVE8; }

define IDLE_DELAY { WR_IDLE2;WR_IDLE; }

define READ_DELAY { RD_ACTIVE16;RD_ACTIVE16; }

else

error unspecified delays

endif

define RD_PORT GPIO6

define RD_PIN 12

define WR_PORT GPIO6

define WR_PIN 13

define CD_PORT GPIO6

define CD_PIN 30 //rs

define CS_PORT GPIO6

define CS_PIN 21

define RESET_PORT GPIO6

define RESET_PIN 27

// configure macros for the data pins // D0 D1 D2 D3

define GMASK ((1<<4)|(1<<5)|(1<<7)|(1<<31)) //gipo9

// D4 D5 D6

define HMASK ((1<<18)|(1<<22)|(1<<23)) //gipo8

// D7

define IMASK ((1<<12)) //gipo7

define write_8(d) { \

    GIPO9_DR_CLEAR = GMASK; GIPO8_DR_CLEAR = HMASK; GIPO7_DR_CLEAR = IMASK;\
        GIP09_DR_SET = (((d) & (1 << 0)) << 4 )\
                          | (((d) & (1 << 1)) << 4 )\
                      | (((d) & (1 << 2)) << 5 )\
                      | (((d) & (1 << 3)) << 28);\
  GIPO8_DR_SET = (((d) & (1 << 4)) << 14)\
                         | (((d) & (1 << 5)) << 17)\
                     | (((d) & (1 << 6)) << 17);\
     GIPO7_DR_SET = (((d) & (1 << 7)) <<  5); \
    }

define read_8() ((((GIPO9_PSR & (1 << 4)) >> 4)\

                         | ((GIPO9_PSR & (1 << 5)) >> 4)\
             | ((GIPO9_PSR & (1 << 7)) >> 5)\
                 | ((GIPO9_PSR & (1 << 31)) >> 28)\
                 | ((GIPO8_PSR & (1 << 18)) >> 14)\
                         | ((GIPO8_PSR & (1 << 22)) >> 17)\
                         | ((GIPO8_PSR & (1 << 23)) >> 17)\
                         | ((GIPO7_PSR & (1 << 12)) >> 7)))           

define setWriteDir() {GPIO7_GDIR |= IMASK; GPIO8_GDIR |= HMASK; GIPO9_GDIR |= GMASK }

define setReadDir() {GPIO7_GDIR &= ~IMASK; GIPO8_GDIT &= ~HMASK; GPIO9_GDIR &= ~GMASK; }

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; READ_DELAY; dst = read_8(); RD_IDLE2; RD_IDLE; }

define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }

define GPIO_INIT() {for (int i = 2; i <= 3; i++) pinMode(i, OUTPUT); \

                              for (int i = 28; i <= 33; i++) pinMode(i, OUTPUT);\
               for (int i = A10; i <= A13; i++) pinMode (i, OUTPUT);\
                   pinMode(A7, OUTPUT);\
               }

define PASTE(x, y) x ## y

define PIN_LOW(port, pin) PASTE(port, _DR_CLEAR) = (1<<(pin))

define PIN_HIGH(port, pin) PASTE(port, _DR_SET) = (1<<(pin))

define PIN_OUTPUT(port, pin) PASTE(port, _GDIR) |= (1<<(pin))

Thanks.

jox1a commented 1 year ago

new macro works well T4 + Open smart 3.0" R61509v should work fine with other TFTs feel free to use``

//####################################### TEENSY 4.0 ############################

elif defined(IMXRT1062) // regular UNO shield on a Teensy 4.x

//#warning regular UNO shield on a Teensy 4.0 //LCD pins |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST |
//MXRT pin |9.31|9.7|9.8|9.6|9.5|9.4|7.11|7.12| |6.31|6.30|6.13|6.12|8.18| //4.x pins |29 |33 |5 |4 |3 |2 |9 |32 | |27 |26 |25 |24 |28 |

if 0

elif defined(IMXRT1062)

define WRITE_DELAY { WR_ACTIVE8;WR_ACTIVE8; }

define IDLE_DELAY { WR_IDLE2;WR_IDLE; }

define READ_DELAY { RD_ACTIVE16;RD_ACTIVE16; }

else

error unspecified delays

endif

define RD_PORT GPIO6

define RD_PIN 31

define WR_PORT GPIO6

define WR_PIN 30

define CD_PORT GPIO6

define CD_PIN 13 //rs

define CS_PORT GPIO6

define CS_PIN 12

define RESET_PORT GPIO8

define RESET_PIN 18

// configure macros for the data pins

define GMASK ((1<<12)|(1<<11))

define IMASK ((1<<31)|(1<<7)|(1<<8)|(1<<6)|(1<<5)|(1<<4))

define write_8(d) { \

    GPIO7_DR_CLEAR = GMASK; GPIO9_DR_CLEAR = IMASK; \
    GPIO7_DR_SET = (((d) & (1 << 0)) << 12) \
                 | (((d) & (1 << 1)) << 10); \
    GPIO9_DR_SET = (((d) & (1 << 2)) << 2) \
                 | (((d) & (1 << 3)) << 2) \
                 | (((d) & (1 << 4)) << 2) \
                 | (((d) & (1 << 5)) << 3) \
                 | (((d) & (1 << 6)) << 1) \
                 | (((d) & (1 << 7)) << 24);\
    }

define read_8() ((((GPIO7_PSR & (1 << 12)) >> 12) \

               | ((GPIO7_PSR & (1 << 11)) >> 10) \
               | ((GPIO9_PSR & (1 << 4)) >> 2) \
               | ((GPIO9_PSR & (1 << 5)) >> 2) \
               | ((GPIO9_PSR & (1 << 6)) >> 2) \
               | ((GPIO9_PSR & (1 << 8)) >> 3) \
               | ((GPIO9_PSR & (1 << 7)) >> 1) \
               | ((GPIO9_PSR & (1 << 31)) >> 24)))

define setWriteDir() {GPIO7_GDIR |= GMASK;GPIO9_GDIR |= IMASK; }

define setReadDir() {GPIO7_GDIR &= ~GMASK;GPIO9_GDIR &= ~IMASK; }

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; READ_DELAY; dst = read_8(); RD_IDLE2; RD_IDLE; }

define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }

define GPIO_INIT() {for (int i = 2; i <= 5; i++) pinMode(i, OUTPUT);\

                 for (int i = 32; i <= 33; i++) pinMode(i, OUTPUT); \
                 for (int i = A10; i <= A13; i++) pinMode(i, OUTPUT);\
                 pinMode(28, OUTPUT);pinMode(29, OUTPUT);pinMode(9, OUTPUT);\
                }

define PASTE(x, y) x ## y

define PIN_LOW(port, pin) PASTE(port, _DR_CLEAR) = (1<<(pin))

define PIN_HIGH(port, pin) PASTE(port, _DR_SET) = (1<<(pin))

define PIN_OUTPUT(port, pin) PASTE(port, _GDIR) |= (1<<(pin))