Changing data pins used by TFT display

Status
Not open for further replies.

jmbernardi

New member
Hello, I'm working on a Teensy 4.1 project and was able to make a 8 bit serial TFT display work with it. Now I want to add I2S audio input and output, but the 8 bit serial display uses the pins 7 and 8, which are I2S OUT1A and IN1. I thought it would be easier to switch 2 pins in the 8 bit serial than to figure out how to use the I2S alternate pins, as Paul mentioned in a different post that that is possible but difficult to do. I use the MCUFRIEND library (https://github.com/prenticedavid/MCUFRIEND_kbv) to interface with the display. Below is the original bit mask for using pins 2 through 8 for the 8 bit serial, followed by my attempted modification, in which I try to modify the serial to use pin 31 instead of pin 7 and pin 30 instead of pin 8.

If it helps this is the datasheet of the display: https://www.buydisplay.com/download/manual/ER-TFTM035-6_Datasheet.pdf

###########
#Original code:
############

#define GMASK ((1<<17)|(1<<10)|(1<<11)|(1<<16))
#define IMASK ((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)) << 16) \
| (((d) & (1 << 1)) << 10) \
| (((d) & (1 << 6)) << 4) \
| (((d) & (1 << 7)) << 10); \
GPIO9_DR_SET = (((d) & (1 << 2)) << 2) \
| (((d) & (1 << 3)) << 2) \
| (((d) & (1 << 4)) << 2) \
| (((d) & (1 << 5)) << 3); \
}

#define read_8() ((((GPIO7_PSR & (1 << 16)) >> 16) \
| ((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) \
| ((GPIO7_PSR & (1 << 10)) >> 4) \
| ((GPIO7_PSR & (1 << 17)) >> 10)))

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

##############
#My modification:
##############

#define GMASK ((1<<10)|(1<<11))
#define HMASK ( (1<<22) | (1<<23))
#define IMASK ((1<<8)|(1<<6)|(1<<5)|(1<<4))

#define write_8(d) { \
GPIO7_DR_CLEAR = GMASK; GPIO8_DR_CLEAR = HMASK; GPIO9_DR_CLEAR = IMASK; \
GPIO7_DR_SET = (((d) & (1 << 1)) << 10) \
| (((d) & (1 << 6)) << 4) ; \
GPIO8_DR_SET = (((d) & (1 << 0)) << 16) \
| (((d) & (1 << 7)) << 10) ; \
GPIO9_DR_SET = (((d) & (1 << 2)) << 2) \
| (((d) & (1 << 3)) << 2) \
| (((d) & (1 << 4)) << 2) \
| (((d) & (1 << 5)) << 3); \
}

#define read_8() (( ((GPIO8_PSR & (1 << 23)) >> 16) \
| ((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) \
| ((GPIO7_PSR & (1 << 10)) >> 4) \
| ((GPIO8_PSR & (1 << 22)) >> 10)))

#define setWriteDir() {GPIO7_GDIR |= GMASK; GPIO8_GDIR |= HMASK; GPIO9_GDIR |= IMASK; }
#define setReadDir() {GPIO7_GDIR &= ~GMASK; GPIO8_GDIR &= ~GMASK; GPIO9_GDIR &= ~IMASK; }

#########

I think my problem is in the last bitshift in the read_8 and write_8 lines, I don't understand exactly what it is doing. For instance, on the line GPIO7_DR_SET = (((d) & (1 << 1)) << 10), what is that 10 bit shift doing? Can anyone help me with either this or setting the alternate I2S OUT1A and IN1 pins to be pin 39 and 38?
 
I actually figured out how to change I2S IN1 and OUT1A to the alternates, posting here if it helps anyone.

Code to change in the Audio library:
input_i2s.cpp (change IN1 to pin 38)
CORE_PIN38_CONFIG = 3; //1:RX_DATA0
IOMUXC_SAI1_RX_DATA0_SELECT_INPUT = 1;

output_i2s.cpp (change OUT1A to pin 39)
CORE_PIN39_CONFIG = 3; //1:TX_DATA0
 
Status
Not open for further replies.
Back
Top