From 73d209a18bbc91764f7e7250b8a996e7d2b68b30 Mon Sep 17 00:00:00 2001 From: Gavin Higham Date: Wed, 3 Feb 2021 00:06:50 -0800 Subject: [PATCH] Add support for Adafruit PiTFT 1.14" --- CMakeLists.txt | 3 +++ display.h | 2 +- pitft_114r_st7789.h | 18 ++++++++++++++++++ st7735r.cpp | 6 +++--- st7735r.h | 13 ++++++++++++- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 pitft_114r_st7789.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 235c70f..899739d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,9 @@ elseif(FREEPLAYTECH_WAVESHARE32B) elseif(ADAFRUIT_HX8357D_PITFT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHX8357D -DADAFRUIT_HX8357D_PITFT") message(STATUS "Targeting Adafruit 3.5 inch PiTFT with HX8357D") +elseif (ADAFRUIT_ST7789_PITFT_114) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DADAFRUIT_ST7789_PITFT_114") + message(STATUS "Targeting Adafruit 1.14 inch PiTFT with ST7789") elseif(WAVESHARE_ST7789VW_HAT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DST7789 -DST7789VW -DWAVESHARE_ST7789VW_HAT") message(STATUS "Targeting WaveShare 240x240 1.3inch IPS LCD Hat with ST7789VW controller") diff --git a/display.h b/display.h index ff0bd72..dd0bdf6 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(ADAFRUIT_ST7789_PITFT_114) #include "st7735r.h" #elif defined(SSD1351) #include "ssd1351.h" diff --git a/pitft_114r_st7789.h b/pitft_114r_st7789.h new file mode 100644 index 0000000..f4ff191 --- /dev/null +++ b/pitft_114r_st7789.h @@ -0,0 +1,18 @@ +#pragma once + +// Data specific to Adafruit's PiTFT 1.14" display +#ifdef ADAFRUIT_ST7789_PITFT_114 + +#if !defined(GPIO_TFT_DATA_CONTROL) +// Adafruit 1.14" 135x240 has display control on pin 25: https://learn.adafruit.com/adafruit-mini-pitft-135x240-color-tft-add-on-for-raspberry-pi/pinouts +#define GPIO_TFT_DATA_CONTROL 25 +#endif + +#if !defined(GPIO_TFT_BACKLIGHT) +// Adafruit 1.14" 135x240 has backlight on pin 22: https://learn.adafruit.com/adafruit-mini-pitft-135x240-color-tft-add-on-for-raspberry-pi/pinouts +#define GPIO_TFT_BACKLIGHT 22 +#endif + +#define DISPLAY_SPI_DRIVE_SETTINGS (1 | BCM2835_SPI0_CS_CPOL | BCM2835_SPI0_CS_CPHA) + +#endif diff --git a/st7735r.cpp b/st7735r.cpp index ceac386..f1ee8d5 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(ADAFRUIT_ST7789_PITFT_114) #include "spi.h" @@ -69,7 +69,7 @@ void InitST7735R() SPI_TRANSFER(0x36/*MADCTL: Memory Access Control*/, madctl); usleep(10*1000); -#ifdef ST7789 +#if defined(ST7789) || defined(ADAFRUIT_ST7789_PITFT_114) SPI_TRANSFER(0xBA/*DGMEN: Enable Gamma*/, 0x04); bool invertColors = true; #else @@ -86,7 +86,7 @@ void InitST7735R() SPI_TRANSFER(0x13/*NORON: Partial off (normal)*/); usleep(10*1000); -#ifdef ST7789 +#if defined(ST7789) || defined(ADAFRUIT_ST7789_PITFT_114) // The ST7789 controller is actually a unit with 320x240 graphics memory area, but only 240x240 portion // of it is displayed. Therefore if we wanted to swap row address mode above, writes to Y=0...239 range will actually land in // memory in row addresses Y = 319-(0...239) = 319...80 range. To view this range, we must scroll the view by +80 units in Y diff --git a/st7735r.h b/st7735r.h index 789b4b6..5941b7e 100644 --- a/st7735r.h +++ b/st7735r.h @@ -1,6 +1,7 @@ + #pragma once -#if defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7789VW) +#if defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7789VW) || defined(ADAFRUIT_ST7789_PITFT_114) // 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 @@ -30,6 +31,16 @@ #define DISPLAY_NATIVE_COVERED_LEFT_SIDE 2 #define DISPLAY_NATIVE_COVERED_TOP_SIDE 1 +#elif defined(ADAFRUIT_ST7789_PITFT_114) +// The Adafruit PiTFT 1.14" uses ST7789, but it has some quirks, such as not working with the chip select signal toggle, +// and having a unique offset in display memory. +#include "pitft_114r_st7789.h" +#define DISPLAY_NATIVE_WIDTH 240 +#define DISPLAY_NATIVE_HEIGHT 320 +#define DISPLAY_NATIVE_COVERED_TOP_SIDE 40 +#define DISPLAY_NATIVE_COVERED_BOTTOM_SIDE 40 +#define DISPLAY_NATIVE_COVERED_LEFT_SIDE 53 +#define DISPLAY_NATIVE_COVERED_RIGHT_SIDE 52 #else #error Unknown display controller!