From 7c4a05aabc1d88e22eb126ccb18835ebfbd28853 Mon Sep 17 00:00:00 2001 From: Ricardo Matsui Date: Sun, 28 Mar 2021 01:33:22 -0700 Subject: [PATCH] Add support for Pirate Audio ST7789 HAT (#203) --- CMakeLists.txt | 3 +++ README.md | 2 ++ pirate_audio_st7789_hat.h | 19 +++++++++++++++++++ spi.cpp | 4 ++++ st7735r.h | 2 ++ 5 files changed, 30 insertions(+) create mode 100644 pirate_audio_st7789_hat.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 235c70f..dacb629 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(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") elseif(ILI9340) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DILI9340") message(STATUS "Targeting ILI9340") diff --git a/README.md b/README.md index cfe85d1..ca35168 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ The following LCD displays have been tested: - [Arduino A000096 1.77" 160x128 LCD Screen](https://store.arduino.cc/arduino-lcd-screen) with ST7735R controller - [Tontec 3.5" 320x480 LCD Display](https://www.ebay.com/p/Tontec-3-5-Inches-Touch-Screen-for-Raspberry-Pi-Display-TFT-Monitor-480x320-LCD/1649448059) with MZ61581-PI-EXT 2016.1.28 controller - [Adafruit 1.54" 240x240 Wide Angle TFT LCD Display with MicroSD](https://www.adafruit.com/product/3787) with ST7789 controller + - [Pirate Audio 240x240, 1.3inch IPS LCD display HAT for Raspberry Pi](https://shop.pimoroni.com/collections/pirate-audio) with ST7789 controller - [WaveShare 240x240, 1.3inch IPS LCD display HAT for Raspberry Pi](https://www.waveshare.com/1.3inch-lcd-hat.htm) with ST7789VW controller - [WaveShare 128x128, 1.44inch LCD display HAT for Raspberry Pi](https://www.waveshare.com/1.44inch-lcd-hat.htm) with ST7735S controller - [KeDei 3.5 inch SPI TFTLCD 480*320 16bit/18bit version 6.3 2018/4/9](https://github.com/juj/fbcp-ili9341/issues/40) with MPI3501 controller @@ -115,6 +116,7 @@ When using one of the displays that stack on top of the Pi that are already reco - `-DFREEPLAYTECH_WAVESHARE32B=ON`: If you are running on the [Freeplay CM3 or Zero](https://www.freeplaytech.com/product/freeplay-cm3-diy-kit/) device, pass this flag. (this is not a hat, but still a preconfigured pin assignment) - `-DWAVESHARE35B_ILI9486=ON`: If specified, targets a [Waveshare 3.5" 480x320 ILI9486](https://www.amazon.co.uk/dp/B01N48NOXI/ref=pe_3187911_185740111_TE_item) display. - `-DTONTEC_MZ61581=ON`: If you are running on the [Tontec 3.5" 320x480 LCD Display](https://www.ebay.com/p/Tontec-3-5-Inches-Touch-Screen-for-Raspberry-Pi-Display-TFT-Monitor-480x320-LCD/1649448059) display, pass this. +- `-DPIRATE_AUDIO_ST7789_HAT=ON`: If specified, targets a [Pirate Audio 240x240, 1.3inch IPS LCD display HAT for Raspberry Pi](https://shop.pimoroni.com/collections/pirate-audio) with ST7789 display controller - `-DWAVESHARE_ST7789VW_HAT=ON`: If specified, targets a [240x240, 1.3inch IPS LCD display HAT for Raspberry Pi](https://www.waveshare.com/1.3inch-lcd-hat.htm) with ST7789VW display controller. - `-DWAVESHARE_ST7735S_HAT=ON`: If specified, targets a [128x128, 1.44inch LCD display HAT for Raspberry Pi](https://www.waveshare.com/1.3inch-lcd-hat.htm) with ST7735S display controller. - `-DKEDEI_V63_MPI3501=ON`: If specified, targets a [KeDei 3.5 inch SPI TFTLCD 480*320 16bit/18bit version 6.3 2018/4/9](https://github.com/juj/fbcp-ili9341/issues/40) display with MPI3501 display controller. diff --git a/pirate_audio_st7789_hat.h b/pirate_audio_st7789_hat.h new file mode 100644 index 0000000..88fc6f7 --- /dev/null +++ b/pirate_audio_st7789_hat.h @@ -0,0 +1,19 @@ +#pragma once + +// Data specific to Pirate Audio series 240x240, 1.3inch IPS LCD ST7789 hat, https://shop.pimoroni.com/collections/pirate-audio +#ifdef PIRATE_AUDIO_ST7789_HAT + +#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/spi.cpp b/spi.cpp index 80dbe22..d156f2d 100644 --- a/spi.cpp +++ b/spi.cpp @@ -532,7 +532,11 @@ int InitSPI() #ifdef GPIO_TFT_DATA_CONTROL SET_GPIO_MODE(GPIO_TFT_DATA_CONTROL, 0x01); // Data/Control pin to output (0x01) #endif + // The Pirate Audio hat ST7789 based display has Data/Control on the MISO pin, so only initialize the pin as MISO if the + // Data/Control pin does not use it. +#if !defined(GPIO_TFT_DATA_CONTROL) || GPIO_TFT_DATA_CONTROL != GPIO_SPI0_MISO SET_GPIO_MODE(GPIO_SPI0_MISO, 0x04); +#endif SET_GPIO_MODE(GPIO_SPI0_MOSI, 0x04); SET_GPIO_MODE(GPIO_SPI0_CLK, 0x04); diff --git a/st7735r.h b/st7735r.h index 789b4b6..6875252 100644 --- a/st7735r.h +++ b/st7735r.h @@ -39,6 +39,8 @@ #include "waveshare_st7789vw_hat.h" #elif defined(WAVESHARE_ST7735S_HAT) #include "waveshare_st7735s_hat.h" +#elif defined(PIRATE_AUDIO_ST7789_HAT) +#include "pirate_audio_st7789_hat.h" #endif #define InitSPIDisplay InitST7735R