Skip to content

Commit

Permalink
Merge pull request #6 from Nkawu/V1.2.3
Browse files Browse the repository at this point in the history
V.1.2.3
  • Loading branch information
Nkawu authored Oct 22, 2017
2 parents 9292150 + a4ca39d commit 291e8eb
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
TFT_22_ILI9225
==============

**Version 1.2.2, released 2017-10-20, adds backlight brightness control.** Credit: [miro1360](https://github.com/miro1360)

**Version 1.2.1, released 2017-09-18, fixed color table shift error.**

**Version 1.2.0, released 2017-01-18, speeds up Hardware SPI significantly.**

This is a library for the ILI9225 TFT display products, forked from the screen_4D_22_library library. Ability to
Expand Down
6 changes: 4 additions & 2 deletions examples/Basic_Demo/Basic_Demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#define TFT_CLK 13 // SCK
#define TFT_LED 3 // 0 if wired to +5V directly

#define TFT_BRIGHTNESS 200 // Initial brightness of TFT backlight (optional)

// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED);
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED, TFT_BRIGHTNESS);
// Use software SPI (slower)
//TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_SDI, TFT_CLK, TFT_LED);
//TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_SDI, TFT_CLK, TFT_LED, TFT_BRIGHTNESS);

// Variables and constants
uint16_t x, y;
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ begin KEYWORD2
clear KEYWORD2
invert KEYWORD2
setBacklight KEYWORD2
setBacklightBrightness KEYWORD2
setDisplay KEYWORD2
setOrientation KEYWORD2
getOrientation KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TFT_22_ILI9225
version=1.2.2
version=1.2.3
author=Nkawu
maintainer=Nkawu
sentence=ILI9225 2.2" 176x220 TFT LCD shield
Expand Down
50 changes: 44 additions & 6 deletions src/TFT_22_ILI9225.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ TFT_22_ILI9225::TFT_22_ILI9225(uint8_t rst, uint8_t rs, uint8_t cs, uint8_t sdi,
_sdi = sdi;
_clk = clk;
_led = led;
_brightness = 255; // Set to maximum brightness
hwSPI = false;
checkSPI = true;
}

// Constructor when using software SPI. All output pins are configurable. Adds backlight brightness 0-255
TFT_22_ILI9225::TFT_22_ILI9225(uint8_t rst, uint8_t rs, uint8_t cs, uint8_t sdi, uint8_t clk, uint8_t led, uint8_t brightness) {
_rst = rst;
_rs = rs;
_cs = cs;
_sdi = sdi;
_clk = clk;
_led = led;
_brightness = brightness;
hwSPI = false;
checkSPI = true;
}
Expand All @@ -40,6 +54,21 @@ TFT_22_ILI9225::TFT_22_ILI9225(uint8_t rst, uint8_t rs, uint8_t cs, uint8_t led)
_cs = cs;
_sdi = _clk = 0;
_led = led;
_brightness = 255; // Set to maximum brightness
hwSPI = true;
checkSPI = true;
}

// Constructor when using hardware SPI. Faster, but must use SPI pins
// specific to each board type (e.g. 11,13 for Uno, 51,52 for Mega, etc.)
// Adds backlight brightness 0-255
TFT_22_ILI9225::TFT_22_ILI9225(uint8_t rst, uint8_t rs, uint8_t cs, uint8_t led, uint8_t brightness) {
_rst = rst;
_rs = rs;
_cs = cs;
_sdi = _clk = 0;
_led = led;
_brightness = brightness;
hwSPI = true;
checkSPI = true;
}
Expand Down Expand Up @@ -127,12 +156,16 @@ void TFT_22_ILI9225::_setWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t

void TFT_22_ILI9225::begin() {

// Set up pins
// Set up reset pin
if (_rst > 0) {
pinMode(_rst, OUTPUT);
digitalWrite(_rst, LOW);
}
if (_led > 0) pinMode(_led, OUTPUT);
// Set up backlight pin, turn off initially
if (_led > 0) {
pinMode(_led, OUTPUT);
setBacklight(false);
}

pinMode(_rs, OUTPUT);
pinMode(_cs, OUTPUT);
Expand All @@ -156,9 +189,6 @@ void TFT_22_ILI9225::begin() {
*mosiport &= ~mosipinmask;
}

// Turn on backlight
if (_led > 0) digitalWrite(_led, HIGH);

// Initialization Code
if (_rst > 0) {
digitalWrite(_rst, HIGH); // Pull the reset pin high to release the ILI9225C from the reset status
Expand Down Expand Up @@ -239,6 +269,7 @@ void TFT_22_ILI9225::begin() {
_writeRegister(ILI9225_DISP_CTRL1, 0x1017);
if (hwSPI) spi_end();

// Turn on backlight
setBacklight(true);
setOrientation(0);

Expand Down Expand Up @@ -266,7 +297,14 @@ void TFT_22_ILI9225::invert(boolean flag) {


void TFT_22_ILI9225::setBacklight(boolean flag) {
if (_led) digitalWrite(_led, flag);
blState = flag;
if (_led) analogWrite(_led, blState ? _brightness : 0);
}


void TFT_22_ILI9225::setBacklightBrightness(uint8_t brightness) {
_brightness = brightness;
setBacklight(blState);
}


Expand Down
11 changes: 8 additions & 3 deletions src/TFT_22_ILI9225.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class TFT_22_ILI9225 {

TFT_22_ILI9225(uint8_t RST, uint8_t RS, uint8_t CS, uint8_t SDI, uint8_t CLK, uint8_t LED);
TFT_22_ILI9225(uint8_t RST, uint8_t RS, uint8_t CS, uint8_t LED);
TFT_22_ILI9225(uint8_t RST, uint8_t RS, uint8_t CS, uint8_t SDI, uint8_t CLK, uint8_t LED, uint8_t brightness);
TFT_22_ILI9225(uint8_t RST, uint8_t RS, uint8_t CS, uint8_t LED, uint8_t brightness);

/// Initialization
void begin(void);
Expand All @@ -138,6 +140,10 @@ class TFT_22_ILI9225 {
/// @param flag true=on, false=off
void setBacklight(boolean flag);

/// Set backlight brightness
/// @param brightness sets backlight brightness 0-255
void setBacklightBrightness(uint8_t brightness);

/// Switch display on or off
/// @param flag true=on, false=off
void setDisplay(boolean flag);
Expand Down Expand Up @@ -299,12 +305,11 @@ class TFT_22_ILI9225 {
uint16_t _maxX, _maxY, _bgColor;

volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport;
// int8_t _rst, _dc, _cs, _mosi, _sclk, _led,
uint8_t _rst, _rs, _cs, _sdi, _clk, _led,
_orientation;
_orientation, _brightness;
uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask;

boolean hwSPI, checkSPI;
boolean hwSPI, checkSPI, blState;

_currentFont cfont;

Expand Down

0 comments on commit 291e8eb

Please sign in to comment.