Dear Stackoverflowers,
I am trying to add support for the esp32 to the HX8357D 3.5" TFT display from Adafruit (link). I made a fork of the library from Adafruit (link) that handles the 8-bit parallel interface and added an esp32 branch. I figured out most of the components needed, but I'm having trouble to get the code to compile. Could someone help me with getting it to work?
I made an Arduino sketch with the code that has to be implemented into the library:
//Not used in this sketch, but these are the 5 control pins for the TFT display
#define LCD_CS 27
#define LCD_CD 26
#define LCD_WR 25
#define LCD_RD 14
#define LCD_RESET 13
//8 data pins (random, but made sure they are all ardressable with one register)
#define DATA_PIN0 3
#define DATA_PIN1 18
#define DATA_PIN2 5
#define DATA_PIN3 17
#define DATA_PIN4 16
#define DATA_PIN5 4
#define DATA_PIN6 2
#define DATA_PIN7 15
#define DELAY 200
gpio_config_t io_conf;
//Some random data to write to the gpio pins, creates a pattern to the LED's that I connected
uint32_t data[] {
0b00000000000000001000000000001000,
0b00000000000001000000000000000100,
0b00000000000000000000000000110000,
0b00000000000000110000000000000000,
0b00000000000000000000000000000000,
0b00000000000000110000000000000000,
0b00000000000000000000000000110000,
0b00000000000001000000000000000100,
0b00000000000000001000000000001000
};
void setup() {
Serial.begin(115200);
setReadDir();
print32Bits(GPIO.in);
setWriteDir();
}
void loop() {
for (int i = 0; i < 9; i++) {
GPIO.out_w1tc = 0xFFFFFFFF;
GPIO.out_w1ts = data[i];
delay(DELAY);
}
}
//Set 8 data pins to OUTPUT
void setWriteDir() {
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
io_conf.pin_bit_mask = ((1ULL << DATA_PIN0 ) | (1ULL << DATA_PIN1) | (1ULL << DATA_PIN2) | (1ULL << DATA_PIN3) | (1ULL << DATA_PIN4) | (1ULL << DATA_PIN5) | (1ULL << DATA_PIN6) | (1ULL << DATA_PIN7)); // of course, do like this all the pins
gpio_config(&io_conf);
}
//Set 8 data pins to INPUT
void setReadDir() {
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
io_conf.pin_bit_mask = ((1ULL << LCD_CS ) | (1ULL << LCD_CD) | (1ULL << LCD_WR) | (1ULL << LCD_RD) | (1ULL << LCD_RESET)); // of course, do like this all the pins
gpio_config(&io_conf);
}
//Function to print 32 bit interger to Serial, just for convenience
void print32Bits(uint32_t myByte) {
for (uint32_t mask = 0x80000000; mask; mask >>= 1) {
if (mask & myByte) {
Serial.print('1');
} else {
Serial.print('0');
}
}
Serial.println();
}
I added the necessary code to ADAFRUIT_TFTLCD.h
, ADAFRUIT_TFTLCD.cpp
and pin_magic.h
The functions in pin_magic.h
(write8inlin
and read8inlin
) are not completely done yet. I tried to compile the code to test whether the stuff I had done so far would compile correctly, but I am getting a lot of ....was not declared in this scope
errors.
In pin_magic.h
I have:
#define RD_ACTIVE GPIO.out_w1tc |= rdPinset
#define RD_IDLE GPIO.out_w1ts |= rdPinSet
#define WR_ACTIVE GPIO.out_w1tc |= wrPinset
#define WR_IDLE GPIO.out_w1ts |= wrPinSet
#define CD_COMMAND GPIO.out_w1tc |= cdPinset
#define CD_DATA GPIO.out_w1ts |= cdPinSet
#define CS_ACTIVE GPIO.out_w1tc |= csPinset
#define CS_IDLE GPIO.out_w1ts |= csPinSet
The first part of the error that I get:
D:\ProgramData\Arduino\libraries\TFTLCD-Library\pin_magic.h:389:42: error: 'csPinset' was not declared in this scope
#define CS_ACTIVE GPIO.out_w1tc |= csPinset
^
D:\ProgramData\Arduino\libraries\TFTLCD-Library\Adafruit_TFTLCD.cpp:268:5: note: in expansion of macro 'CS_ACTIVE'
CS_ACTIVE;
^
If someone with more experience in C/C++ could have a look at it I would be super grateful.
I took a look at your code, are you compiling it in your PC? Looks like the compiler is ignoring the declaration of the csPinset etc due to you #ifdef block -
I'm not familiar with AVR environment, but I recommend compiling your code with the correct compiler(eg AVR compliant) in the intended environment. Alternatively, you can also define __ AVR __ at compile time using the -D option:
g++ < file_name.cpp > -D__AVR__
To make sure the variables you need are declared for all environment, you can change the header file to something like this-
#ifndef USE_ADAFRUIT_SHIELD_PINOUT
#ifdef AVR
// "Variable declaration for AVR goes here"
#elif defined SAM
//"Variable declaration for SAM goes here"
/*else block, in case ESP32 is not the correct macro name*/
#else
//"General Variables for everything else other than SAM or AVR."
#endif
//in case the ADA SHIELD PINOUT is defined
#else
//"General Variables for when USE_ADAFRUIT_SHIELD_PINOUT is defined."
#endif
This should fix the "variable not declared" error. You can explore or ask in https://arduino.stackexchange.com the right way to customise this header for the ESP32 env.
User contributions licensed under CC BY-SA 3.0