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

Added ST7796S Support #169

Open
wants to merge 5 commits 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 @@ -232,6 +232,9 @@ elseif(ST7735R)
elseif(ST7735S)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DST7735S")
message(STATUS "Targeting ST7735S")
elseif(ST7796S)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DST7796S")
message(STATUS "Targeting ST7796S")
elseif(SSD1351)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSSD1351")
message(STATUS "Targeting SSD1351")
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(ST7796S)
#include "st7735r.h"
#elif defined(SSD1351)
#include "ssd1351.h"
Expand Down
14 changes: 11 additions & 3 deletions st7735r.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "config.h"

#if defined(ST7735R) || defined(ST7735S) || defined(ST7789)
#if defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7796S)

#include "spi.h"

Expand Down Expand Up @@ -62,6 +61,10 @@ void InitST7735R()
madctl ^= MADCTL_ROTATE_180_DEGREES;
#endif

#if defined(ST7796S)
madctl ^= MADCTL_COLUMN_ADDRESS_ORDER_SWAP;
#endif
Copy link
Owner

Choose a reason for hiding this comment

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

Needing to have this in here seems odd. Is this making the display landscape by default? Or portrait? The panel is a portrait scaning panel, according to the DISPLAY_NATIVE_WIDTH/HEIGHT fields from below?

Copy link
Author

Choose a reason for hiding this comment

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

It's been a few weeks, but I believe that I added this because without it the display was mirrored.


#ifdef DISPLAY_ROTATE_180_DEGREES
madctl ^= MADCTL_ROTATE_180_DEGREES;
#endif
Expand Down Expand Up @@ -96,10 +99,15 @@ void InitST7735R()
#endif

// TODO: The 0xB1 command is not Frame Rate Control for ST7789VW, 0xB3 is (add support to it)
#ifndef ST7789VW
#if !defined(ST7789VW) || !defined(ST7796S)
Copy link
Owner

Choose a reason for hiding this comment

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

This should be #if !defined(ST7789VW) && !defined(ST7796S) (in the current form, it will always resolve as true)

// Frame rate = 850000 / [ (2*RTNA+40) * (162 + FPA+BPA)]
SPI_TRANSFER(0xB1/*FRMCTR1:Frame Rate Control*/, /*RTNA=*/6, /*FPA=*/1, /*BPA=*/1); // This should set frame rate = 99.67 Hz
#endif
// The frame rate control on the ST7796S needs different values in order to work correctly. Borrowing these values
// from the device tree files of the MHS-4.0 inch hat device tree files. They fix all the problems I was having.
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps change this comment to

// The ST7796S does not work with the frame rate control from above for other ST77* displays. This value taken from MHS-4.0" device tree files, meaning unknown.

since a comment They fix all the problems I was having. is useful for a PR comment, but it has no value after having landed in the tree.

#ifdef ST7796S
SPI_TRANSFER(0xB1, 0x80, 0x10);
#endif

SPI_TRANSFER(/*Display ON*/0x29);
usleep(100 * 1000);
Expand Down
8 changes: 5 additions & 3 deletions st7735r.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#if defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7789VW)
#if defined(ST7735R) || defined(ST7735S) || defined(ST7789) || defined(ST7789VW) || defined(ST7796S)

// 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 @@ -18,6 +17,9 @@
#if defined(ST7789) || defined(ST7789VW)
#define DISPLAY_NATIVE_WIDTH 240
#define DISPLAY_NATIVE_HEIGHT 240
#elif defined(ST7796S)
#define DISPLAY_NATIVE_WIDTH 320
#define DISPLAY_NATIVE_HEIGHT 480
#elif defined(ST7735R)
#define DISPLAY_NATIVE_WIDTH 128
#define DISPLAY_NATIVE_HEIGHT 160
Expand Down Expand Up @@ -48,7 +50,7 @@ void InitST7735R(void);
void TurnDisplayOn(void);
void TurnDisplayOff(void);

#if defined(ST7789) || defined(ST7789VW)
#if defined(ST7789) || defined(ST7789VW) || defined(ST7796S)
// 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