Skip to content

Commit

Permalink
add CO5300 display support
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed Sep 7, 2024
1 parent 7e21645 commit abb59b4
Show file tree
Hide file tree
Showing 3 changed files with 359 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Arduino_GFX_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
178 changes: 178 additions & 0 deletions src/display/Arduino_CO5300.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
180 changes: 180 additions & 0 deletions src/display/Arduino_CO5300.h
Original file line number Diff line number Diff line change
@@ -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:
};

0 comments on commit abb59b4

Please sign in to comment.