From abb59b4a2682fc8d5945039b27e92b8be01e4481 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 7 Sep 2024 19:02:31 +0800 Subject: [PATCH] add CO5300 display support --- src/Arduino_GFX_Library.h | 1 + src/display/Arduino_CO5300.cpp | 178 ++++++++++++++++++++++++++++++++ src/display/Arduino_CO5300.h | 180 +++++++++++++++++++++++++++++++++ 3 files changed, 359 insertions(+) create mode 100644 src/display/Arduino_CO5300.cpp create mode 100644 src/display/Arduino_CO5300.h diff --git a/src/Arduino_GFX_Library.h b/src/Arduino_GFX_Library.h index 8c68a2d..96a0241 100644 --- a/src/Arduino_GFX_Library.h +++ b/src/Arduino_GFX_Library.h @@ -49,6 +49,7 @@ #endif // !defined(LITTLE_FOOT_PRINT) #include "display/Arduino_AXS15231B.h" +#include "display/Arduino_CO5300.h" #include "display/Arduino_GC9A01.h" #include "display/Arduino_GC9106.h" #include "display/Arduino_GC9107.h" diff --git a/src/display/Arduino_CO5300.cpp b/src/display/Arduino_CO5300.cpp new file mode 100644 index 0000000..8a3aab1 --- /dev/null +++ b/src/display/Arduino_CO5300.cpp @@ -0,0 +1,178 @@ +/* + * start rewrite from: + * https://github.com/Xinyuan-LilyGO/T-Display-AMOLED-1.64.git + */ +#include "Arduino_CO5300.h" + +Arduino_CO5300::Arduino_CO5300( + Arduino_DataBus *bus, int8_t rst, uint8_t r, + bool ips, int16_t w, int16_t h, + uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2) + : Arduino_TFT(bus, rst, r, ips, w, h, col_offset1, row_offset1, col_offset2, row_offset2) +{ +} + +bool Arduino_CO5300::begin(int32_t speed) +{ + return Arduino_TFT::begin(speed); +} + +/**************************************************************************/ +/*! + @brief Set origin of (0,0) and orientation of TFT display + @param m The index for rotation, from 0-3 inclusive +*/ +/**************************************************************************/ +void Arduino_CO5300::setRotation(uint8_t r) +{ + // CO5300 does not support rotation + Arduino_TFT::setRotation(r); + switch (_rotation) + { + case 1: + r = CO5300_MADCTL_COLOR_ORDER | CO5300_MADCTL_X_AXIS_FLIP; + break; + case 2: + r = CO5300_MADCTL_COLOR_ORDER | CO5300_MADCTL_X_AXIS_FLIP | CO5300_MADCTL_Y_AXIS_FLIP; // flip horizontal and flip vertical + break; + case 3: + r = CO5300_MADCTL_COLOR_ORDER | CO5300_MADCTL_Y_AXIS_FLIP; + break; + default: // case 0: + r = CO5300_MADCTL_COLOR_ORDER; + break; + } + _bus->beginWrite(); + _bus->writeC8D8(CO5300_W_MADCTL, r); + _bus->endWrite(); +} + +void Arduino_CO5300::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) +{ + if ((x != _currentX) || (w != _currentW) || (y != _currentY) || (h != _currentH)) + { + _currentX = x; + _currentY = y; + _currentW = w; + _currentH = h; + + x += _xStart; + _bus->writeC8D16D16(CO5300_W_CASET, x, x + w - 1); + y += _yStart; + _bus->writeC8D16D16(CO5300_W_PASET, y, y + h - 1); + } + + _bus->writeCommand(CO5300_W_RAMWR); // write to RAM +} + +void Arduino_CO5300::invertDisplay(bool i) +{ + _bus->sendCommand((_ips ^ i) ? CO5300_C_INVON : CO5300_C_INVOFF); +} + +void Arduino_CO5300::displayOn(void) +{ + _bus->sendCommand(CO5300_C_DISPON); + delay(CO5300_SLPIN_DELAY); + _bus->sendCommand(CO5300_C_SLPOUT); + // _bus->writeC8D8(CO5300_W_DEEPSTMODE, 0x00); + delay(CO5300_SLPOUT_DELAY); +} + +void Arduino_CO5300::displayOff(void) +{ + _bus->sendCommand(CO5300_C_DISPOFF); + delay(CO5300_SLPIN_DELAY); + _bus->sendCommand(CO5300_C_SLPIN); + // _bus->writeC8D8(CO5300_W_DEEPSTMODE, 0x01); + delay(CO5300_SLPIN_DELAY); +} + +void Arduino_CO5300::setBrightness(uint8_t brightness) +{ + _bus->beginWrite(); + _bus->writeC8D8(CO5300_W_WDBRIGHTNESSVALNOR, brightness); + _bus->endWrite(); +} + +void Arduino_CO5300::setContrast(uint8_t Contrast) +{ + switch (Contrast) + { + case CO5300_ContrastOff: + _bus->beginWrite(); + _bus->writeC8D8(CO5300_W_WCE, 0x00); + _bus->endWrite(); + break; + case CO5300_LowContrast: + _bus->beginWrite(); + _bus->writeC8D8(CO5300_W_WCE, 0x05); + _bus->endWrite(); + break; + case CO5300_MediumContrast: + _bus->beginWrite(); + _bus->writeC8D8(CO5300_W_WCE, 0x06); + _bus->endWrite(); + break; + case CO5300_HighContrast: + _bus->beginWrite(); + _bus->writeC8D8(CO5300_W_WCE, 0x07); + _bus->endWrite(); + break; + + default: + break; + } +} + +// Companion code to the above tables. Reads and issues +// a series of LCD commands stored in PROGMEM byte array. +void Arduino_CO5300::tftInit() +{ + if (_rst != GFX_NOT_DEFINED) + { + pinMode(_rst, OUTPUT); + digitalWrite(_rst, HIGH); + delay(10); + digitalWrite(_rst, LOW); + delay(CO5300_RST_DELAY); + digitalWrite(_rst, HIGH); + delay(CO5300_RST_DELAY); + } + else + { + // Software Rest + _bus->sendCommand(CO5300_C_SWRESET); + delay(CO5300_RST_DELAY); + } + + _bus->batchOperation(co5300_init_operations, sizeof(co5300_init_operations)); + + invertDisplay(false); + + // _bus->beginWrite(); + + // _bus->writeCommand(CO5300_C_SLPOUT); + // delay(CO5300_SLPOUT_DELAY); + + // _bus->writeCommand(CO5300_W_SETTSL); + // _bus->write(0x01); + // _bus->write(0xD1); + + // _bus->writeC8D8(CO5300_WC_TEARON, 0x00); + // _bus->writeC8D8(CO5300_W_PIXFMT, 0x55); + // _bus->writeC8D8(CO5300_W_WCTRLD1, 0x20); + // _bus->writeCommand(CO5300_C_DISPON); // Display on + // _bus->writeC8D8(CO5300_W_WDBRIGHTNESSVALNOR, 0x00); // Brightest brightness + + // _bus->endWrite(); + + // delay(1000); + // displayOff(); + // delay(1000); + // displayOn(); + // delay(1000); + // displayOff(); + // delay(1000); + // displayOn(); +} diff --git a/src/display/Arduino_CO5300.h b/src/display/Arduino_CO5300.h new file mode 100644 index 0000000..899ce41 --- /dev/null +++ b/src/display/Arduino_CO5300.h @@ -0,0 +1,180 @@ +#pragma once + +/* + * start rewrite from: + * https://github.com/Xinyuan-LilyGO/T-Display-AMOLED-1.64.git + */ + +#include "../Arduino_GFX.h" +#include "../Arduino_TFT.h" + +#define CO5300_MAXWIDTH 480 ///< CO5300 max TFT width +#define CO5300_MAXHEIGHT 480 ///< CO5300 max TFT width + +#define CO5300_RST_DELAY 200 ///< delay ms wait for reset finish +#define CO5300_SLPIN_DELAY 120 ///< delay ms wait for sleep in finish +#define CO5300_SLPOUT_DELAY 120 ///< delay ms wait for sleep out finish + +// User Command +#define CO5300_C_NOP 0x00 // nop +#define CO5300_C_SWRESET 0x01 // Software Reset +#define CO5300_R_RDID 0x04 // Read Display Identification Information ID/1/2/3 +#define CO5300_R_RDNERRORSDSI 0x05 // Read Number of Errors on DSI +#define CO5300_R_RDPOWERMODE 0x0A // Read Display Power Mode +#define CO5300_R_RDMADCTL 0x0B // Read Display MADCTL +#define CO5300_R_RDPIXFMT 0x0C // Read Display Pixel Format +#define CO5300_R_RDIMGFMT 0x0D // Read Display Image Mode +#define CO5300_R_RDSIGMODE 0x0E // Read Display Signal Mode +#define CO5300_R_RDSELFDIAG 0x0F // Read Display Self-Diagnostic Result + +#define CO5300_C_SLPIN 0x10 // Sleep In +#define CO5300_C_SLPOUT 0x11 // Sleep Out +#define CO5300_C_PTLON 0x12 // Partial Display On +#define CO5300_C_NORON 0x13 // Normal Display mode on + +#define CO5300_C_INVOFF 0x20 // Inversion Off +#define CO5300_C_INVON 0x21 // Inversion On +#define CO5300_C_ALLPOFF 0x22 // All pixels off +#define CO5300_C_ALLPON 0x23 // All pixels on +#define CO5300_C_DISPOFF 0x28 // Display off +#define CO5300_C_DISPON 0x29 // Display on +#define CO5300_W_CASET 0x2A // Column Address Set +#define CO5300_W_PASET 0x2B // Page Address Set +#define CO5300_W_RAMWR 0x2C // Memory Write Start + +#define CO5300_W_PTLAR 0x30 // Partial Area Row Set +#define CO5300_W_PTLAC 0x31 // Partial Area Column Set +#define CO5300_C_TEAROFF 0x34 // Tearing effect off +#define CO5300_WC_TEARON 0x35 // Tearing effect on +#define CO5300_W_MADCTL 0x36 // Memory data access control +#define CO5300_C_IDLEOFF 0x38 // Idle Mode Off +#define CO5300_C_IDLEON 0x39 // Idle Mode On +#define CO5300_W_PIXFMT 0x3A // Write Display Pixel Format +#define CO5300_W_WRMC 0x3C // Memory Write Continue + +#define CO5300_W_SETTSL 0x44 // Write Tearing Effect Scan Line +#define CO5300_R_GETSL 0x45 // Read Scan Line Number +#define CO5300_C_SPIROFF 0x46 // SPI read Off +#define CO5300_C_SPIRON 0x47 // SPI read On +#define CO5300_C_AODMOFF 0x48 // AOD Mode Off +#define CO5300_C_AODMON 0x49 // AOD Mode On +#define CO5300_W_WDBRIGHTNESSVALAOD 0x4A // Write Display Brightness Value in AOD Mode +#define CO5300_R_RDBRIGHTNESSVALAOD 0x4B // Read Display Brightness Value in AOD Mode +#define CO5300_W_DEEPSTMODE 0x4F // Deep Standby Mode On + +#define CO5300_W_WDBRIGHTNESSVALNOR 0x51 // Write Display Brightness Value in Normal Mode +#define CO5300_R_RDBRIGHTNESSVALNOR 0x52 // Read display brightness value in Normal Mode +#define CO5300_W_WCTRLD1 0x53 // Write CTRL Display1 +#define CO5300_R_RCTRLD1 0x54 // Read CTRL Display1 +#define CO5300_W_WCTRLD2 0x55 // Write CTRL Display2 +#define CO5300_R_RCTRLD2 0x56 // Read CTRL Display2 +#define CO5300_W_WCE 0x58 // Write CE +#define CO5300_R_RCE 0x59 // Read CE + +#define CO5300_W_WDBRIGHTNESSVALHBM 0x63 // Write Display Brightness Value in HBM Mode +#define CO5300_R_WDBRIGHTNESSVALHBM 0x64 // Read Display Brightness Value in HBM Mode +#define CO5300_W_WHBMCTL 0x66 // Write HBM Control + +#define CO5300_W_COLORSET0 0x70 // Color Set 0 +#define CO5300_W_COLORSET1 0x71 // Color Set 1 +#define CO5300_W_COLORSET2 0x72 // Color Set 2 +#define CO5300_W_COLORSET3 0x73 // Color Set 3 +#define CO5300_W_COLORSET4 0x74 // Color Set 4 +#define CO5300_W_COLORSET5 0x75 // Color Set 5 +#define CO5300_W_COLORSET6 0x76 // Color Set 6 +#define CO5300_W_COLORSET7 0x77 // Color Set 7 +#define CO5300_W_COLORSET8 0x78 // Color Set 8 +#define CO5300_W_COLORSET9 0x79 // Color Set 9 +#define CO5300_W_COLORSET10 0x7A // Color Set 10 +#define CO5300_W_COLORSET11 0x7B // Color Set 11 +#define CO5300_W_COLORSET12 0x7C // Color Set 12 +#define CO5300_W_COLORSET13 0x7D // Color Set 13 +#define CO5300_W_COLORSET14 0x7E // Color Set 14 +#define CO5300_W_COLORSET15 0x7F // Color Set 15 + +#define CO5300_W_COLOROPTION 0x80 // Color Option + +#define CO5300_R_RDDBSTART 0xA1 // Read DDB start +#define CO5300_R_DDBCONTINUE 0xA8 // Read DDB Continue +#define CO5300_R_RFIRCHECKSUN 0xAA // Read First Checksum +#define CO5300_R_RCONTINUECHECKSUN 0xAF // Read Continue Checksum + +#define CO5300_W_SPIMODECTL 0xC4 // SPI mode control + +#define CO5300_R_RDID1 0xDA // Read ID1 +#define CO5300_R_RDID2 0xDB // Read ID2 +#define CO5300_R_RDID3 0xDC // Read ID3 + +// Flip +#define CO5300_MADCTL_X_AXIS_FLIP 0x02 // Flip Horizontal +#define CO5300_MADCTL_Y_AXIS_FLIP 0x05 // Flip Vertical + +// Color Order +#define CO5300_MADCTL_RGB 0x00 // Red-Green-Blue pixel order +#define CO5300_MADCTL_BGR 0x08 // Blue-Green-Red pixel order +#define CO5300_MADCTL_COLOR_ORDER CO5300_MADCTL_RGB // RGB + +enum +{ + CO5300_ContrastOff = 0, + CO5300_LowContrast, + CO5300_MediumContrast, + CO5300_HighContrast +}; + +static const uint8_t co5300_init_operations[] = { + BEGIN_WRITE, + WRITE_COMMAND_8, CO5300_C_SLPOUT, // Sleep Out + END_WRITE, + + DELAY, CO5300_SLPOUT_DELAY, + + BEGIN_WRITE, + // WRITE_C8_D8, CO5300_WC_TEARON, 0x00, + WRITE_C8_D8, 0xFE, 0x00, + WRITE_C8_D8, CO5300_W_SPIMODECTL, 0x80, + // WRITE_C8_D8, CO5300_W_MADCTL, CO5300_MADCTL_COLOR_ORDER, // RGB/BGR + WRITE_C8_D8, CO5300_W_PIXFMT, 0x55, // Interface Pixel Format 16bit/pixel + // WRITE_C8_D8, CO5300_W_PIXFMT, 0x66, // Interface Pixel Format 18bit/pixel + // WRITE_C8_D8, CO5300_W_PIXFMT, 0x77, // Interface Pixel Format 24bit/pixel + WRITE_C8_D8, CO5300_W_WCTRLD1, 0x20, + WRITE_C8_D8, CO5300_W_WDBRIGHTNESSVALHBM, 0xFF, + WRITE_COMMAND_8, CO5300_C_DISPON, // Display ON + WRITE_C8_D8, CO5300_W_WDBRIGHTNESSVALNOR, 0xD0, // Brightness adjustment + + // High contrast mode (Sunlight Readability Enhancement) + WRITE_C8_D8, CO5300_W_WCE, 0x00, // Off + // WRITE_C8_D8, CO5300_W_WCE, 0x05, // On Low + // WRITE_C8_D8, CO5300_W_WCE, 0x06, // On Medium + // WRITE_C8_D8, CO5300_W_WCE, 0x07, // On High + + END_WRITE, + + DELAY, 10}; + +class Arduino_CO5300 : public Arduino_TFT +{ +public: + Arduino_CO5300( + Arduino_DataBus *bus, int8_t rst = GFX_NOT_DEFINED, uint8_t r = 0, + bool ips = false, int16_t w = CO5300_MAXWIDTH, int16_t h = CO5300_MAXHEIGHT, + uint8_t col_offset1 = 0, uint8_t row_offset1 = 0, uint8_t col_offset2 = 0, uint8_t row_offset2 = 0); + + bool begin(int32_t speed = GFX_NOT_DEFINED) override; + + void setRotation(uint8_t r) override; + + void writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) override; + + void invertDisplay(bool) override; + void displayOn() override; + void displayOff() override; + + void setBrightness(uint8_t brightness); + void setContrast(uint8_t Contrast); + +protected: + void tftInit() override; + +private: +};