From 2f8301d36a9eb4f63f345403ffc1624fbb958bad Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 29 Mar 2020 23:05:42 +0200 Subject: [PATCH] M5 display support (experimental) --- include/display.h | 2 -- platformio.ini | 4 ++-- src/display.cpp | 33 +++++++++++++++++++++++---------- src/hal/m5core.h | 11 +++-------- src/hal/m5fire.h | 4 ++-- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/include/display.h b/include/display.h index 75f95eff..f7c66407 100644 --- a/include/display.h +++ b/include/display.h @@ -34,8 +34,6 @@ // settings for TFT display library #elif (HAS_DISPLAY == 2) -#define ESP32 - #define MY_FONT_SMALL 1 #define MY_FONT_NORMAL 2 #define MY_FONT_LARGE 4 diff --git a/platformio.ini b/platformio.ini index f2d0801e..5dffe51b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -63,7 +63,7 @@ lib_deps_display = https://github.com/bitbank2/ss_oled.git BitBang_I2C@2.0.1 QRCode@>=0.0.1 - TFT_eSPI + TFT_eSPI@>=2.1.9 lib_deps_matrix_display = Ultrathin_LED_Matrix@>=1.0.0 lib_deps_rgbled = @@ -98,7 +98,7 @@ build_flags_basic = '-DCORE_DEBUG_LEVEL=${common.debug_level}' '-DLOG_LOCAL_LEVEL=${common.debug_level}' '-DPROGVERSION="${common.release_version}"' - '-DUSER_SETUP_LOADED=1' + '-DUSER_SETUP_LOADED=1' ; needed for TFT_eSPI library build_flags_sensors = -Llib/Bosch-BSEC/src/esp32/ diff --git a/src/display.cpp b/src/display.cpp index 6f132423..4a640ba1 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -51,7 +51,7 @@ QRCode qrcode; #if (HAS_DISPLAY) == 1 SSOLED ssoled; #elif (HAS_DISPLAY) == 2 -TFT_eSPI tft = TFT_eSPI(MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT); // Invoke library +TFT_eSPI tft = TFT_eSPI(); #endif void dp_setup(int contrast) { @@ -70,13 +70,9 @@ void dp_setup(int contrast) { tft.init(); - if (MY_DISPLAY_FLIP) - tft.setRotation(0); - else - tft.setRotation(2); // portrait - - if (MY_DISPLAY_INVERT) - tft.invertDisplay(true); // Tell TFT to invert all displayed colours + tft.setRotation(MY_DISPLAY_FLIP ? true : false); + tft.invertDisplay(MY_DISPLAY_INVERT ? true : false); + tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); #endif @@ -437,7 +433,24 @@ void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, #if (HAS_DISPLAY) == 1 oledWriteString(&ssoled, 0, x, y, temp, font, inv, false); #elif (HAS_DISPLAY) == 2 - tft.drawString(temp, x, y, font); + uint8_t myfont; + switch (font) { + case MY_FONT_SMALL: + myfont = 6; + break; + case MY_FONT_NORMAL: + case MY_FONT_LARGE: + myfont = 8; + break; + case MY_FONT_STRETCHED: + myfont = 16; + break; + default: + myfont = 8; + } + tft.drawString(temp, x * tft.textWidth("_", font) / myfont, + y * tft.fontHeight(font), font); + #endif if (temp != loc_buf) { free(temp); @@ -456,7 +469,7 @@ void dp_clear() { #if (HAS_DISPLAY) == 1 oledFill(&ssoled, 0, 1); #elif (HAS_DISPLAY) == 2 - tft.fillScreen(TFT_WHITE); + tft.fillScreen(MY_DISPLAY_BGCOLOR); #endif } diff --git a/src/hal/m5core.h b/src/hal/m5core.h index d70839ea..06df0a0e 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -48,6 +48,7 @@ // Display Settings #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 +#define MY_DISPLAY_INVERT 1 // setting for M5 display #define ILI9341_DRIVER 1 @@ -61,10 +62,7 @@ #define TFT_RST GPIO_NUM_33 // Reset #define TFT_BL GPIO_NUM_32 // LED back-light -//#define USE_HSPI_PORT -#define TFT_SDA_READ -#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue -//#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red +#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red #define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH #define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters @@ -76,9 +74,6 @@ #define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts #define SMOOTH_FONT -#define SPI_FREQUENCY 27000000 - -// Optional reduced SPI frequency for reading TFT -#define SPI_READ_FREQUENCY 5000000 +#define SPI_FREQUENCY 40000000 #endif \ No newline at end of file diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index 0c110328..bb9c8229 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -49,6 +49,7 @@ // Display Settings #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 +#define MY_DISPLAY_INVERT 1 // setting for M5 display #define ILI9341_DRIVER 1 @@ -62,8 +63,7 @@ #define TFT_RST GPIO_NUM_33 // Reset #define TFT_BL GPIO_NUM_32 // LED back-light -//#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue -//#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red +#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red #define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH #define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters