Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ST7789V2: Add Pimoroni Display HAT Mini 2.0" 320x240 LCD #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions pimoroni_display_hat_mini.h
Original file line number Diff line number Diff line change
@@ -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
Copy link
Owner

@juj juj Nov 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might there ever be mini display hats from Pimoroni based on other controller technology? If there's a possibility, then maybe this might better be #ifdef PIMORONI_ST7789V2_DISPLAY_HAT_MINI?

If not, then the name lgtm.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a possibility. Good point!


#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
9 changes: 7 additions & 2 deletions st7735r.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -62,14 +62,19 @@ void InitST7735R()
madctl ^= MADCTL_ROTATE_180_DEGREES;
#endif

#if defined(ST7789V2) && defined(DISPLAY_OUTPUT_LANDSCAPE)
juj marked this conversation as resolved.
Show resolved Hide resolved
// 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

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
Expand Down
9 changes: 7 additions & 2 deletions st7735r.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,6 +21,9 @@
#elif defined(ST7735R)
juj marked this conversation as resolved.
Show resolved Hide resolved
#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.
Expand All @@ -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
Expand All @@ -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)
Expand Down