Skip to content

Commit

Permalink
fix #49 and apply #46, #47
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed May 8, 2021
1 parent c1f1bdd commit c98850e
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 101 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,6 @@ This library is not putting speed at the first priority, but still paid much eff
- https://github.com/daumemo/IPS_LCD_R61529_FT6236_Arduino_eSPI_Test
- https://github.com/espressif/arduino-esp32.git
- https://github.com/gitcnd/LCDWIKI_SPI.git
- https://github.com/lcdwiki/LCDWIKI_SPI.git
- https://github.com/lovyan03/LovyanGFX.git
- https://github.com/lovyan03/M5Stack_JpgLoopAnime
2 changes: 1 addition & 1 deletion examples/PDQgraphicstest/PDQgraphicstest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void setup()
cy1 = cy - 1;
cn = min(cx1, cy1);
cn1 = cn - 1;
tsa = ((w <= 160) || (h <= 160)) ? 1 : (((w <= 240) || (h <= 240)) ? 2 : 3); // text size A
tsa = ((w <= 176) || (h <= 160)) ? 1 : (((w <= 240) || (h <= 240)) ? 2 : 3); // text size A
tsb = ((w <= 240) || (h <= 220)) ? 1 : 2; // text size B
tsc = ((w <= 220) || (h <= 220)) ? 1 : 2; // text size C
ds = (w <= 160) ? 9 : 12; // digit size
Expand Down
210 changes: 110 additions & 100 deletions src/display/Arduino_ILI9225.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* start rewrite from:
* https://github.com/adafruit/Adafruit-GFX-Library.git
* https://github.com/lcdwiki/LCDWIKI_SPI
*/
#include "Arduino_ILI9225.h"

Expand All @@ -14,49 +15,36 @@ void Arduino_ILI9225::begin(int32_t speed)
Arduino_TFT::begin(speed);
}

// Companion code to the above tables. Reads and issues
// a series of LCD commands stored in PROGMEM byte array.
void Arduino_ILI9225::tftInit()
/**************************************************************************/
/*!
@brief Set origin of (0,0) and orientation of TFT display
@param m The index for rotation, from 0-3 inclusive
*/
/**************************************************************************/
void Arduino_ILI9225::setRotation(uint8_t r)
{
if (_rst >= 0)
{
pinMode(_rst, OUTPUT);
digitalWrite(_rst, HIGH);
delay(100);
digitalWrite(_rst, LOW);
delay(ILI9225_RST_DELAY);
digitalWrite(_rst, HIGH);
delay(ILI9225_RST_DELAY);
}
else
Arduino_TFT::setRotation(r);
_bus->beginWrite();
switch (_rotation)
{
// Software Rest
case 3:
_bus->writeC8D16(ILI9225_DRIVER_OUTPUT_CTRL, 0x031C);
_bus->writeC8D16(ILI9225_ENTRY_MODE, 0x1038);
break;
case 2:
_bus->writeC8D16(ILI9225_DRIVER_OUTPUT_CTRL, 0x021C);
_bus->writeC8D16(ILI9225_ENTRY_MODE, 0x1030);
break;
case 1:
_bus->writeC8D16(ILI9225_DRIVER_OUTPUT_CTRL, 0x001C);
_bus->writeC8D16(ILI9225_ENTRY_MODE, 0x1038);
break;
default: // case 0:
_bus->writeC8D16(ILI9225_DRIVER_OUTPUT_CTRL, 0x011C);
_bus->writeC8D16(ILI9225_ENTRY_MODE, 0x1030);
break;
}

// Power-on sequence
_bus->sendCommand(ILI9225_POWER_CTRL2);
_bus->sendData16(0x0018); // Set APON,PON,AON,VCI1EN,VC
_bus->sendCommand(ILI9225_POWER_CTRL3);
_bus->sendData16(0x6121); // Set BT,DC1,DC2,DC3
_bus->sendCommand(ILI9225_POWER_CTRL4);
_bus->sendData16(0x006F); // Set GVDD /*007F 0088 */
_bus->sendCommand(ILI9225_POWER_CTRL5);
_bus->sendData16(0x495F); // Set VCOMH/VCOML voltage
_bus->sendCommand(ILI9225_POWER_CTRL1);
_bus->sendData16(0x0800); // Set SAP,DSTB,STB

delay(10);

_bus->sendCommand(ILI9225_POWER_CTRL2);
_bus->sendData16(0x103B); // Set APON,PON,AON,VCI1EN,VC

_bus->sendCommand(ILI9225_DISP_CTRL1);
_bus->sendData16(0x0012);

delay(50);

_bus->sendCommand(ILI9225_DISP_CTRL1);
_bus->sendData16(0x1017);
_bus->endWrite();
}

void Arduino_ILI9225::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
Expand All @@ -65,8 +53,9 @@ void Arduino_ILI9225::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t

if ((x != _currentX) || (w != _currentW))
{
int16_t x_start = x + _xStart, x_end = x + w - 1 + _xStart;

_currentX = x;
_currentW = w;
x += _xStart;
if (_rotation & 0x01) // Landscape
{
cmd1 = ILI9225_VERTICAL_WINDOW_ADDR2;
Expand All @@ -79,20 +68,15 @@ void Arduino_ILI9225::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t
cmd2 = ILI9225_HORIZONTAL_WINDOW_ADDR1;
cmd3 = ILI9225_RAM_ADDR_SET1;
}
_bus->writeCommand(cmd1);
_bus->write16(x_start);
_bus->writeCommand(cmd2);
_bus->write16(x_end);
_bus->writeCommand(cmd3);
_bus->write16(x_start);

_currentX = x;
_currentW = w;
_bus->writeC8D16(cmd1, x);
_bus->writeC8D16(cmd2, x + w - 1);
_bus->writeC8D16(cmd3, x);
}
if ((y != _currentY) || (h != _currentH))
{
int16_t y_start = y + _yStart, y_end = y + h - 1 + _yStart;

_currentY = y;
_currentH = h;
y += _yStart;
if (_rotation & 0x01) // Landscape
{
cmd1 = ILI9225_HORIZONTAL_WINDOW_ADDR2;
Expand All @@ -105,58 +89,14 @@ void Arduino_ILI9225::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t
cmd2 = ILI9225_VERTICAL_WINDOW_ADDR1;
cmd3 = ILI9225_RAM_ADDR_SET2;
}
_bus->writeCommand(cmd1);
_bus->write16(y_start);
_bus->writeCommand(cmd2);
_bus->write16(y_end);
_bus->writeCommand(cmd3);
_bus->write16(y_start);

_currentY = y;
_currentH = h;
_bus->writeC8D16(cmd1, y);
_bus->writeC8D16(cmd2, y + h - 1);
_bus->writeC8D16(cmd3, y);
}

_bus->writeCommand(ILI9225_GRAM_DATA_REG); // write to RAM
}

/**************************************************************************/
/*!
@brief Set origin of (0,0) and orientation of TFT display
@param m The index for rotation, from 0-3 inclusive
*/
/**************************************************************************/
void Arduino_ILI9225::setRotation(uint8_t r)
{
Arduino_TFT::setRotation(r);
switch (_rotation)
{
case 0:
_bus->sendCommand(ILI9225_DRIVER_OUTPUT_CTRL);
_bus->sendData16(0x021C);
_bus->sendCommand(ILI9225_ENTRY_MODE);
_bus->sendData16(0x1030);
break;
case 1:
_bus->sendCommand(ILI9225_DRIVER_OUTPUT_CTRL);
_bus->sendData16(0x031C);
_bus->sendCommand(ILI9225_ENTRY_MODE);
_bus->sendData16(0x1038);
break;
case 2:
_bus->sendCommand(ILI9225_DRIVER_OUTPUT_CTRL);
_bus->sendData16(0x011C);
_bus->sendCommand(ILI9225_ENTRY_MODE);
_bus->sendData16(0x1030);
break;
case 3:
_bus->sendCommand(ILI9225_DRIVER_OUTPUT_CTRL);
_bus->sendData16(0x001C);
_bus->sendCommand(ILI9225_ENTRY_MODE);
_bus->sendData16(0x1038);
break;
}
}

void Arduino_ILI9225::invertDisplay(bool i)
{
// Not Implemented
Expand All @@ -174,3 +114,73 @@ void Arduino_ILI9225::displayOff(void)
_bus->sendCommand(ILI9225_POWER_CTRL1);
_bus->sendData16(0x0801); // Set SAP,DSTB,STB
}

void Arduino_ILI9225::tftInit()
{
if (_rst >= 0)
{
pinMode(_rst, OUTPUT);
digitalWrite(_rst, HIGH);
delay(100);
digitalWrite(_rst, LOW);
delay(ILI9225_RST_DELAY);
digitalWrite(_rst, HIGH);
delay(ILI9225_RST_DELAY);
}
else
{
// Software Rest
}

uint8_t ili9225_init_operations[] = {
BEGIN_WRITE,
WRITE_C8_D16, ILI9225_LCD_AC_DRIVING_CTRL, 0x01, 0x00,
WRITE_C8_D16, ILI9225_BLANK_PERIOD_CTRL1, 0x08, 0x08, // set BP and FP
WRITE_C8_D16, ILI9225_FRAME_CYCLE_CTRL, 0x11, 0x00, // frame cycle
WRITE_C8_D16, ILI9225_INTERFACE_CTRL, 0x00, 0x00, // RGB interface setting R0Ch=0x0110 for RGB 18Bit and R0Ch=0111for RGB16Bit
WRITE_C8_D16, ILI9225_OSC_CTRL, 0x14, 0x01, // Set frame rate----0801
WRITE_C8_D16, ILI9225_VCI_RECYCLING, 0x00, 0x00, // set system interface
END_WRITE,

DELAY, 50,

//*************Power On sequence ****************//
BEGIN_WRITE,
WRITE_C8_D16, ILI9225_POWER_CTRL1, 0x08, 0x00, // Set SAP,DSTB,STB----0A00
WRITE_C8_D16, ILI9225_POWER_CTRL2, 0x1F, 0x3F, // Set APON,PON,AON,VCI1EN,VC----1038
END_WRITE,

DELAY, 50,

BEGIN_WRITE,
WRITE_C8_D16, ILI9225_POWER_CTRL3, 0x01, 0x21, // Internal reference voltage= Vci;----1121
WRITE_C8_D16, ILI9225_POWER_CTRL4, 0x00, 0x6F, // Set GVDD----0066
WRITE_C8_D16, ILI9225_POWER_CTRL5, 0x43, 0x49, // Set VCOMH/VCOML voltage----5F60
//-------------- Set GRAM area -----------------//
WRITE_C8_D16, ILI9225_GATE_SCAN_CTRL, 0x00, 0x00,
WRITE_C8_D16, ILI9225_VERTICAL_SCROLL_CTRL1, 0x00, 0xDB,
WRITE_C8_D16, ILI9225_VERTICAL_SCROLL_CTRL2, 0x00, 0x00,
WRITE_C8_D16, ILI9225_VERTICAL_SCROLL_CTRL3, 0x00, 0x00,
WRITE_C8_D16, ILI9225_PARTIAL_DRIVING_POS1, 0x00, 0xDB,
WRITE_C8_D16, ILI9225_PARTIAL_DRIVING_POS2, 0x00, 0x00,
// ----------- Adjust the Gamma Curve ----------//
WRITE_C8_D16, ILI9225_GAMMA_CTRL1, 0x00, 0x01, // 0x0400
WRITE_C8_D16, ILI9225_GAMMA_CTRL2, 0x20, 0x0B, // 0x060B
WRITE_C8_D16, ILI9225_GAMMA_CTRL3, 0x00, 0x00, // 0x0C0A
WRITE_C8_D16, ILI9225_GAMMA_CTRL4, 0x04, 0x04, // 0x0105
WRITE_C8_D16, ILI9225_GAMMA_CTRL5, 0x0C, 0x0C, // 0x0A0C
WRITE_C8_D16, ILI9225_GAMMA_CTRL6, 0x00, 0x0C, // 0x0B06
WRITE_C8_D16, ILI9225_GAMMA_CTRL7, 0x01, 0x01, // 0x0004
WRITE_C8_D16, ILI9225_GAMMA_CTRL8, 0x04, 0x00, // 0x0501
WRITE_C8_D16, ILI9225_GAMMA_CTRL9, 0x11, 0x08, // 0x0E00
WRITE_C8_D16, ILI9225_GAMMA_CTRL10, 0x05, 0x0C, // 0x000E
END_WRITE,

DELAY, 50,

BEGIN_WRITE,
WRITE_C8_D16, ILI9225_DISP_CTRL1, 0x10, 0x17,
END_WRITE};

_bus->batchOperation(ili9225_init_operations, sizeof(ili9225_init_operations));
}

0 comments on commit c98850e

Please sign in to comment.