From 6331bd41433d34919897dca483c0b5a060606598 Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Tue, 26 Oct 2021 17:05:08 +0100 Subject: [PATCH] Add STVV89V2 + Pimoroni Display HAT Mini * Add general support for the ST7789V2. * Add the ST7789V2-based 320x240 Display HAT Mini. Configure: cmake .. -DPIMORONI_DISPLAY_HAT_MINI=true -DSPI_BUS_CLOCK_DIVISOR=40 -DDISPLAY_BREAK_ASPECT_RATIO_WHEN_SCALING=ON --- CMakeLists.txt | 3 +++ display.h | 2 +- pimoroni_display_hat_mini.h | 22 ++++++++++++++++++++++ st7735r.cpp | 9 +++++++-- st7735r.h | 9 +++++++-- 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 pimoroni_display_hat_mini.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2308cf6..86c3ada 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,9 @@ elseif(WAVESHARE_ST7789VW_HAT) elseif(WAVESHARE_ST7735S_HAT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DST7735S -DWAVESHARE_ST7735S_HAT") message(STATUS "Targeting WaveShare 128x128 1.44inch LCD Hat with ST7735S controller") +elseif(PIMORONI_DISPLAY_HAT_MINI) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DST7789V2 -DPIMORONI_DISPLAY_HAT_MINI") + message(STATUS "Targeting Pimoroni Display HAT mini 320x240 IPS LCD Hat with ST7789 controller") elseif(PIRATE_AUDIO_ST7789_HAT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DST7789 -DPIRATE_AUDIO_ST7789_HAT") message(STATUS "Targeting Pirate Audio 240x240 1.3inch IPS LCD Hat with ST7789 controller") diff --git a/display.h b/display.h index ff0bd72..5b7bc6f 100644 --- a/display.h +++ b/display.h @@ -15,7 +15,7 @@ #include "ili9486.h" #elif defined(HX8357D) #include "hx8357d.h" -#elif defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7789VW) +#elif defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7789VW) || defined(ST7789V2) #include "st7735r.h" #elif defined(SSD1351) #include "ssd1351.h" diff --git a/pimoroni_display_hat_mini.h b/pimoroni_display_hat_mini.h new file mode 100644 index 0000000..044ed92 --- /dev/null +++ b/pimoroni_display_hat_mini.h @@ -0,0 +1,22 @@ +#pragma once + +// Data specific to the Pimoroni Display HAT mini +// 320x240 2.0" ST7789V2 HAT +// https://shop.pimoroni.com/products/display-hat-mini + +#ifdef PIMORONI_DISPLAY_HAT_MINI + +#if !defined(GPIO_TFT_DATA_CONTROL) +#define GPIO_TFT_DATA_CONTROL 9 +#endif + +#if !defined(GPIO_TFT_BACKLIGHT) +#define GPIO_TFT_BACKLIGHT 13 +#endif + +#define DISPLAY_USES_CS1 + +// CS1 line is for the LCD +#define DISPLAY_SPI_DRIVE_SETTINGS (1) + +#endif diff --git a/st7735r.cpp b/st7735r.cpp index ceac386..30a70b8 100644 --- a/st7735r.cpp +++ b/st7735r.cpp @@ -1,6 +1,6 @@ #include "config.h" -#if defined(ST7735R) || defined(ST7735S) || defined(ST7789) +#if defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7789V2) #include "spi.h" @@ -62,6 +62,11 @@ void InitST7735R() madctl ^= MADCTL_ROTATE_180_DEGREES; #endif +#if defined(ST7789V2) && defined(DISPLAY_OUTPUT_LANDSCAPE) +// Required for 320x240 display HAT mini to avoid a left offset and run as 320x240 (native) rather than 240x320 +madctl ^= MADCTL_ROW_COLUMN_EXCHANGE; +#endif + #ifdef DISPLAY_ROTATE_180_DEGREES madctl ^= MADCTL_ROTATE_180_DEGREES; #endif @@ -69,7 +74,7 @@ void InitST7735R() SPI_TRANSFER(0x36/*MADCTL: Memory Access Control*/, madctl); usleep(10*1000); -#ifdef ST7789 +#if defined(ST7789V2) || defined(ST7789) SPI_TRANSFER(0xBA/*DGMEN: Enable Gamma*/, 0x04); bool invertColors = true; #else diff --git a/st7735r.h b/st7735r.h index 6875252..773f696 100644 --- a/st7735r.h +++ b/st7735r.h @@ -1,6 +1,6 @@ #pragma once -#if defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7789VW) +#if defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7789VW) || defined(ST7789V2) // On Arduino "A000096" 160x128 ST7735R LCD Screen, the following speed configurations have been tested (on a Pi 3B): // core_freq=355: CDIV=6, results in 59.167MHz, works @@ -21,6 +21,9 @@ #elif defined(ST7735R) #define DISPLAY_NATIVE_WIDTH 128 #define DISPLAY_NATIVE_HEIGHT 160 +#elif defined(ST7789V2) +#define DISPLAY_NATIVE_WIDTH 320 +#define DISPLAY_NATIVE_HEIGHT 240 #elif defined(ST7735S) // ST7735S displays are 128x128 pixels, but they have a somewhat odd offset that X,Y=(0,0) is not top-left corner pixel, but X,Y=(2,1) is. // Therefore consider the display two pixels wider and one pixel higher, and add a constant offset of X=+2, Y=+1 via the DISPLAY_COVERED_* mechanism. @@ -39,6 +42,8 @@ #include "waveshare_st7789vw_hat.h" #elif defined(WAVESHARE_ST7735S_HAT) #include "waveshare_st7735s_hat.h" +#elif defined(PIMORONI_DISPLAY_HAT_MINI) +#include "pimoroni_display_hat_mini.h" #elif defined(PIRATE_AUDIO_ST7789_HAT) #include "pirate_audio_st7789_hat.h" #endif @@ -50,7 +55,7 @@ void InitST7735R(void); void TurnDisplayOn(void); void TurnDisplayOff(void); -#if defined(ST7789) || defined(ST7789VW) +#if defined(ST7789) || defined(ST7789VW) || defined(ST7789V2) // Unlike all other displays developed so far, Adafruit 1.54" 240x240 ST7789 display // actually needs to observe the CS line toggle during execution, it cannot just be always activated. // (ST7735R does not care about this)