Skip to content

Commit 0e92646

Browse files
KurtEladyada
authored andcommitted
Teensy T4.0 support (#232)
The Teensy T4 (__IMXRT1062__) port registers need to be 32 bits unlike the Teensy 3.x which are 8 bits. adafruit_ili9341 and adafruit_st7735 libraries graphic test Removed compiler warning that PROGMEM was previously defined. So undefine it first... Note: Thought of simply doing nothing here (do neither the #undef nor the #define). But that gives compiler error Teensy T4 - Make Bit Bang version work. With T4, the Port/Set registers are masks not single value. So need to setup those class variables: Also found that bitbang of T4, was too fast for display, so put in same slow down that ESP32 has, which gets the clock down to mayby 12.5mhz Tried these changes out with both: adafruit_ili9341 and adafruit_st7735 libraries graphic test Update comments
1 parent f7a1e47 commit 0e92646

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Adafruit_SPITFT.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
120120
#if defined(CORE_TEENSY)
121121
#if !defined(KINETISK)
122122
dcPinMask = digitalPinToBitMask(dc);
123+
swspi.sckPinMask = digitalPinToBitMask(sck);
124+
swspi.mosiPinMask = digitalPinToBitMask(mosi);
123125
#endif
124126
dcPortSet = portSetRegister(dc);
125127
dcPortClr = portClearRegister(dc);
@@ -142,6 +144,9 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
142144
}
143145
if(miso >= 0) {
144146
swspi.misoPort = portInputRegister(miso);
147+
#if !defined(KINETISK)
148+
swspi.misoPinMask = digitalPinToBitMask(miso);
149+
#endif
145150
} else {
146151
swspi.misoPort = portInputRegister(dc);
147152
}
@@ -1981,6 +1986,9 @@ inline void Adafruit_SPITFT::SPI_SCK_HIGH(void) {
19811986
*swspi.sckPortSet = 1;
19821987
#else // !KINETISK
19831988
*swspi.sckPortSet = swspi.sckPinMask;
1989+
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
1990+
for(volatile uint8_t i=0; i<1; i++);
1991+
#endif
19841992
#endif
19851993
#else // !HAS_PORT_SET_CLR
19861994
*swspi.sckPort |= swspi.sckPinMaskSet;
@@ -2003,6 +2011,9 @@ inline void Adafruit_SPITFT::SPI_SCK_LOW(void) {
20032011
*swspi.sckPortClr = 1;
20042012
#else // !KINETISK
20052013
*swspi.sckPortClr = swspi.sckPinMask;
2014+
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
2015+
for(volatile uint8_t i=0; i<1; i++);
2016+
#endif
20062017
#endif
20072018
#else // !HAS_PORT_SET_CLR
20082019
*swspi.sckPort &= swspi.sckPinMaskClr;

Adafruit_SPITFT.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@
4040
#define USE_FAST_PINIO ///< Use direct PORT register access
4141
#define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
4242
#elif defined(CORE_TEENSY)
43+
// PJRC Teensy 4.x
44+
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
45+
typedef uint32_t PORT_t; ///< PORT values are 32-bit
4346
// PJRC Teensy 3.x
47+
#else
4448
typedef uint8_t PORT_t; ///< PORT values are 8-bit
49+
#endif
4550
#define USE_FAST_PINIO ///< Use direct PORT register access
4651
#define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
4752
#else
@@ -428,13 +433,24 @@ class Adafruit_SPITFT : public Adafruit_GFX {
428433
} swspi; ///< Software SPI values
429434
struct { // Values specific to 8-bit parallel:
430435
#if defined(USE_FAST_PINIO)
436+
437+
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
438+
volatile uint32_t *writePort; ///< PORT register for DATA WRITE
439+
volatile uint32_t *readPort; ///< PORT (PIN) register for DATA READ
440+
#else
431441
volatile uint8_t *writePort; ///< PORT register for DATA WRITE
432442
volatile uint8_t *readPort; ///< PORT (PIN) register for DATA READ
443+
#endif
433444
#if defined(HAS_PORT_SET_CLR)
434445
// Port direction register pointers are always 8-bit regardless of
435446
// PORTreg_t -- even if 32-bit port, we modify a byte-aligned 8 bits.
447+
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
448+
volatile uint32_t *dirSet; ///< PORT byte data direction SET
449+
volatile uint32_t *dirClr; ///< PORT byte data direction CLEAR
450+
#else
436451
volatile uint8_t *dirSet; ///< PORT byte data direction SET
437452
volatile uint8_t *dirClr; ///< PORT byte data direction CLEAR
453+
#endif
438454
PORTreg_t wrPortSet; ///< PORT register for write strobe SET
439455
PORTreg_t wrPortClr; ///< PORT register for write strobe CLEAR
440456
PORTreg_t rdPortSet; ///< PORT register for read strobe SET

glcdfont.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include <avr/pgmspace.h>
1010
#elif defined(ESP8266)
1111
#include <pgmspace.h>
12+
#elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
13+
// PROGMEM is defefind for T4 to place data in specific memory section
14+
#undef PROGMEM
15+
#define PROGMEM
1216
#else
1317
#define PROGMEM
1418
#endif

0 commit comments

Comments
 (0)