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

Add support for Adafruit PiTFT 1.14" #187

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 @@ -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")
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of duplicating in all places below defined(ST7789) || defined(ADAFRUIT_ST7789_PITFT_114), let's instead add here

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DADAFRUIT_ST7789_PITFT_114 -DST7789")

since ADAFRUIT_ST7789_PITFT_114 uses ST7789. Then all ST7789 code blocks will automatically apply to ADAFRUIT_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")
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(ADAFRUIT_ST7789_PITFT_114)
#include "st7735r.h"
#elif defined(SSD1351)
#include "ssd1351.h"
Expand Down
18 changes: 18 additions & 0 deletions pitft_114r_st7789.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
Copy link
Owner

Choose a reason for hiding this comment

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

Now I realize that the naming of these adafruit specific files has not been that consistent. Would you mind renaming this file and the two existing files to have adafruit_ prefix? (like waveshare_, tontec_ and freeplaytech_ also have). I.e.

adafruit_pitft_114r_st7789.h
adafruit_pitft_28r_ili9341.h
adafruit_pitft_35r_hx8357d.h
```


// 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
6 changes: 3 additions & 3 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(ADAFRUIT_ST7789_PITFT_114)

#include "spi.h"

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion st7735r.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

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

This reads like you chose in /boot/config.txt to have hdmi_cvt=320 240 60 1 0 0 0 for a 320x240 display mode, and then here are opting to crop a centered subrectangle of 240x135 pixels in size to display? This means that the full display output buffer will not be displayed, but only a centered subrectangle will be. What if a user wanted to display the full display area?

Would it be better to have here by default

#define DISPLAY_NATIVE_WIDTH 135
#define DISPLAY_NATIVE_HEIGHT 240

and no cropping. And then in /boot/config.txt have

hdmi_cvt=240 135 60 1 0 0 0

to get the full screen display outputted? For e.g. console use cases, that would probably be a sensible default?


#else
#error Unknown display controller!
Expand Down