diff --git a/CMakeLists.txt b/CMakeLists.txt index 235c70f..dcff5f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/display.h b/display.h index ff0bd72..b3a2c5a 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(ST7796S) #include "st7735r.h" #elif defined(SSD1351) #include "ssd1351.h" diff --git a/st7735r.cpp b/st7735r.cpp index ceac386..9e174ba 100644 --- a/st7735r.cpp +++ b/st7735r.cpp @@ -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" @@ -62,6 +61,10 @@ void InitST7735R() madctl ^= MADCTL_ROTATE_180_DEGREES; #endif +#if defined(ST7796S) + madctl ^= MADCTL_COLUMN_ADDRESS_ORDER_SWAP; +#endif + #ifdef DISPLAY_ROTATE_180_DEGREES madctl ^= MADCTL_ROTATE_180_DEGREES; #endif @@ -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) // 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. +#ifdef ST7796S + SPI_TRANSFER(0xB1, 0x80, 0x10); +#endif SPI_TRANSFER(/*Display ON*/0x29); usleep(100 * 1000); diff --git a/st7735r.h b/st7735r.h index 789b4b6..032420f 100644 --- a/st7735r.h +++ b/st7735r.h @@ -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 @@ -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 @@ -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)