Please, I’d like to ask your help.
I’ve been avoiding the use of home made “.h” libraries for a long time because of my own missunderstanding about concepts like depencencies. Nevertheless I’m aware spliting the code among my own libraries can make the program much easier for reading and debugging.
Now I’m trying produce new libraries that might be reused in further projects, particularly in those with the same pieces of hardware.
Moreover, since some libraries are shared by several projects (TFT_eSPI, for example), commenting and uncommenting pieces of definitions within their codes is very work intensive and causes troubles to projects that use distinct definitions.
In the present project, an ESP32 will manage a TFT display, touch panel, serial communications and hardware pin IOs. So far, I’m focussing on the setup of ESP32 and the TFT display.
Then, the program comprehends now:
- main.c;
- Hardware.h/.cpp for declaring and defining properties of any hardware interfaces present in the project;
- H24-1015_TFT.h/.cpp for holding all content display funcions related to this application;
- TFT_eSPI.h/.c is the one distributed by github;
- TFT_eSPI_ESP32.h/.c, User_Setup.h, User_Setup_Select.h are headers called by TFT_eSPI.h.
The configuraton and dependencies are:
Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
---------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.5.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-arduinoespressif32 @ 3.20014.231204 (2.0.14)
- tool-esptoolpy @ 1.40501.0 (4.5.1)
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 38 compatible libraries
Scanning dependencies...
Dependency Graph
|-- TFT_eSPI @ 2.5.43
|-- Adafruit GFX Library @ 1.11.9
|-- Adafruit BusIO @ 1.15.0
|-- H24-1015_TFT
|-- Hardware
|-- SPI @ 2.0.0
Building in release mode
Compiling .pio/build/esp32dev/src/main.cpp.o
Compiling .pio/build/esp32dev/lib619/TFT_eSPI/TFT_eSPI.cpp.o
Archiving .pio/build/esp32dev/lib5c7/libAdafruit BusIO.a
Compiling .pio/build/esp32dev/libf19/Adafruit GFX Library/Adafruit_GrayOLED.cpp.o
Indexing .pio/build/esp32dev/lib5c7/libAdafruit BusIO.a
Compiling .pio/build/esp32dev/libf19/Adafruit GFX Library/Adafruit_SPITFT.cpp.o
Let me give you some pieces of code:
From main.c:
#include "Hardware.h"
#include <SPI.h>
#include "H24-1015_TFT.h"
void setup()
{
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0, 4);
tft.setTextColor(TFT_WHITE);
tft.println("Hello World!");
}
void loop()
{
// put your main code here, to run repeatedly:
}
From Hardware.h:
#if !defined(_Hardware_H)
#define _Hardware_H
// Config SPI (VSPI) TFT
#define TFT_DC
#define TFT_SCLK
#define TFT_MOSI
#define TFT_MISO // Manter desconectado caso o MISO seja compartilhado com outro dispositivo
#define TFT_CS // Pino de seleção do TFT no barramento SPI
#define TFT_RST // Pino de RESET
// Config Display
extern int TFT_largura,
TFT_altura;
// Config SPI (VSPI) TOUCH
#define TOUCH_DC
#define TOUCH_SCLK
#define TOUCH_MOSI
#define TOUCH_MISO
#define TOUCH_CS // Pino de seleção do TOUCH no barramento SPI
#define SPI_FREQUENCY // Da biblioteca Setup21_ILI9488.h
#define SPI_READ_FREQUENCY //
#define SPI_TOUCH_FREQUENCY //
#endif
From Hardware.cpp:
// Config SPI (VSPI) TFT
#define TFT_DC 33
#define TFT_SCLK 18
#define TFT_MOSI 23
#define TFT_MISO 19 // Manter desconectado caso o MISO seja compartilhado com outro dispositivo
#define TFT_CS 5 // Pino de seleção do TFT no barramento SPI
#define TFT_RST -1 // Pino de RESET
// Config Display
int TFT_largura = 320,
TFT_altura = 480;
// Config SPI (VSPI) TOUCH
#define TOUCH_DC 33
#define TOUCH_SCLK 18
#define TOUCH_MOSI 23
#define TOUCH_MISO 19
#define TOUCH_CS 32 // Pino de seleção do TOUCH no barramento SPI
#define SPI_FREQUENCY 27000000 // Da biblioteca Setup21_ILI9488.h
#define SPI_READ_FREQUENCY 16000000 //
#define SPI_TOUCH_FREQUENCY 2500000 //
From H24-1015_TFT.h:
// Config for User_Setup.h
#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
#define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high)
#pragma once
#include "Hardware.h"
#include "TFT_eSPI.h"
#include "Adafruit_GFX.h"
// #include "Adafruit_GrayOLED.h"
#include "Adafruit_SPITFT.h"
#include "Adafruit_SPITFT_Macros.h"
#include "gfxfont.h"
#include "User_Setup.h" // Default setup is root library folder
#include "User_Setups/Setup21_ILI9488.h" // Configurações do arquivo Setup21_ILI9488.h
// > TFT ILI9488 em bus SPI para ESP32
// "tft" as a TFT_eSPI instance
TFT_eSPI tft;
From H24-1015_TFT.cpp:
#include "H24-1015_TFT.h"
// TFT_eSPI tft = TFT_eSPI(TFT_lartura, TFT_altura);
TFT_eSPI tft = TFT_eSPI(TFT_largura, TFT_altura);
When compiling, dozens of warning and error messages are listed. Here you are some exemples:
In file included from .pio/libdeps/esp32dev/TFT_eSPI/TFT_eSPI.h:104,
from lib/H24-1015_TFT/H24-1015_TFT.h:30,
from src/main.cpp:95:
.pio/libdeps/esp32dev/TFT_eSPI/Processors/TFT_eSPI_ESP32.h:164:17: error: operator '>=' has no left operand
#if (TFT_DC >= 32)
^~
.pio/libdeps/esp32dev/TFT_eSPI/Processors/TFT_eSPI_ESP32.h:174:19: error: operator '>=' has no left operand
#elif (TFT_DC >= 0)
In file included from .pio/libdeps/esp32dev/TFT_eSPI/TFT_eSPI.cpp:16:
.pio/libdeps/esp32dev/TFT_eSPI/TFT_eSPI.h:976:8: warning: #warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available! [-Wcpp]
#warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available!
^~~~~~~
In file included from .pio/libdeps/esp32dev/TFT_eSPI/TFT_eSPI.cpp:16:
.pio/libdeps/esp32dev/TFT_eSPI/TFT_eSPI.h:435:25: error: 'TFT_WIDTH' was not declared in this scope
TFT_eSPI(int16_t _W = TFT_WIDTH, int16_t _H = TFT_HEIGHT);
^~~~~~~~~
.pio/libdeps/esp32dev/TFT_eSPI/TFT_eSPI.h:435:25: note: suggested alternative: 'TFT_WHITE'
TFT_eSPI(int16_t _W = TFT_WIDTH, int16_t _H = TFT_HEIGHT);
^~~~~~~~~
TFT_WHITE
.pio/libdeps/esp32dev/TFT_eSPI/TFT_eSPI.h:435:49: error: 'TFT_HEIGHT' was not declared in this scope
TFT_eSPI(int16_t _W = TFT_WIDTH, int16_t _H = TFT_HEIGHT);
^~~~~~~~~~
Your contribution will be very usefull for me.
Thak you all.
Best regards,
Ciro Bruno