Compare commits
19 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f917ad72b | ||
|
|
aad1e5e77a | ||
|
|
ebc64f235b | ||
|
|
9b701b6d5a | ||
|
|
5eb5a21ac9 | ||
|
|
f93482daf4 | ||
|
|
22b7aaf899 | ||
|
|
5b2bead71b | ||
|
|
94d08c244f | ||
|
|
dfded750b1 | ||
|
|
4ff23d2e7b | ||
|
|
838ed8df3b | ||
|
|
7462aa6034 | ||
|
|
2006f6a454 | ||
|
|
1f6ced8df5 | ||
|
|
40db73b341 | ||
|
|
96d067bdc7 | ||
|
|
4b120b2fc4 | ||
|
|
99aba1fb73 |
12 changed files with 1172 additions and 904 deletions
|
|
@ -13,10 +13,10 @@
|
||||||
#ifdef __AVR__
|
#ifdef __AVR__
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#endif
|
#endif
|
||||||
#include "pins_arduino.h"
|
|
||||||
#include "wiring_private.h"
|
|
||||||
#include "Adafruit_TFTLCD.h"
|
#include "Adafruit_TFTLCD.h"
|
||||||
#include "pin_magic.h"
|
#include "pin_magic.h"
|
||||||
|
#include "pins_arduino.h"
|
||||||
|
#include "wiring_private.h"
|
||||||
|
|
||||||
//#define TFTWIDTH 320
|
//#define TFTWIDTH 320
|
||||||
//#define TFTHEIGHT 480
|
//#define TFTHEIGHT 480
|
||||||
|
|
@ -35,9 +35,9 @@
|
||||||
|
|
||||||
// Constructor for breakout board (configurable LCD control lines).
|
// Constructor for breakout board (configurable LCD control lines).
|
||||||
// Can still use this w/shield, but parameters are ignored.
|
// Can still use this w/shield, but parameters are ignored.
|
||||||
Adafruit_TFTLCD::Adafruit_TFTLCD(
|
Adafruit_TFTLCD::Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd,
|
||||||
uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t reset) :
|
uint8_t reset)
|
||||||
Adafruit_GFX(TFTWIDTH, TFTHEIGHT) {
|
: Adafruit_GFX(TFTWIDTH, TFTHEIGHT) {
|
||||||
|
|
||||||
#ifndef USE_ADAFRUIT_SHIELD_PINOUT
|
#ifndef USE_ADAFRUIT_SHIELD_PINOUT
|
||||||
// Convert pin numbers to registers and bitmasks
|
// Convert pin numbers to registers and bitmasks
|
||||||
|
|
@ -112,7 +112,6 @@ void Adafruit_TFTLCD::init(void) {
|
||||||
|
|
||||||
rotation = 0;
|
rotation = 0;
|
||||||
cursor_y = cursor_x = 0;
|
cursor_y = cursor_x = 0;
|
||||||
textsize = 1;
|
|
||||||
textcolor = 0xFFFF;
|
textcolor = 0xFFFF;
|
||||||
_width = TFTWIDTH;
|
_width = TFTWIDTH;
|
||||||
_height = TFTHEIGHT;
|
_height = TFTHEIGHT;
|
||||||
|
|
@ -121,131 +120,200 @@ void Adafruit_TFTLCD::init(void) {
|
||||||
// Initialization command tables for different LCD controllers
|
// Initialization command tables for different LCD controllers
|
||||||
#define TFTLCD_DELAY 0xFF
|
#define TFTLCD_DELAY 0xFF
|
||||||
static const uint8_t HX8347G_regValues[] PROGMEM = {
|
static const uint8_t HX8347G_regValues[] PROGMEM = {
|
||||||
0x2E , 0x89,
|
0x2E, 0x89, 0x29, 0x8F, 0x2B, 0x02, 0xE2, 0x00, 0xE4, 0x01, 0xE5, 0x10,
|
||||||
0x29 , 0x8F,
|
0xE6, 0x01, 0xE7, 0x10, 0xE8, 0x70, 0xF2, 0x00, 0xEA, 0x00, 0xEB, 0x20,
|
||||||
0x2B , 0x02,
|
0xEC, 0x3C, 0xED, 0xC8, 0xE9, 0x38, 0xF1, 0x01,
|
||||||
0xE2 , 0x00,
|
|
||||||
0xE4 , 0x01,
|
|
||||||
0xE5 , 0x10,
|
|
||||||
0xE6 , 0x01,
|
|
||||||
0xE7 , 0x10,
|
|
||||||
0xE8 , 0x70,
|
|
||||||
0xF2 , 0x00,
|
|
||||||
0xEA , 0x00,
|
|
||||||
0xEB , 0x20,
|
|
||||||
0xEC , 0x3C,
|
|
||||||
0xED , 0xC8,
|
|
||||||
0xE9 , 0x38,
|
|
||||||
0xF1 , 0x01,
|
|
||||||
|
|
||||||
// skip gamma, do later
|
// skip gamma, do later
|
||||||
|
|
||||||
0x1B , 0x1A,
|
0x1B, 0x1A, 0x1A, 0x02, 0x24, 0x61, 0x25, 0x5C,
|
||||||
0x1A , 0x02,
|
|
||||||
0x24 , 0x61,
|
|
||||||
0x25 , 0x5C,
|
|
||||||
|
|
||||||
0x18 , 0x36,
|
0x18, 0x36, 0x19, 0x01, 0x1F, 0x88, TFTLCD_DELAY, 5, // delay 5 ms
|
||||||
0x19 , 0x01,
|
0x1F, 0x80, TFTLCD_DELAY, 5, 0x1F, 0x90, TFTLCD_DELAY, 5, 0x1F, 0xD4,
|
||||||
0x1F , 0x88,
|
TFTLCD_DELAY, 5, 0x17, 0x05,
|
||||||
TFTLCD_DELAY , 5 , // delay 5 ms
|
|
||||||
0x1F , 0x80,
|
|
||||||
TFTLCD_DELAY , 5 ,
|
|
||||||
0x1F , 0x90,
|
|
||||||
TFTLCD_DELAY , 5 ,
|
|
||||||
0x1F , 0xD4,
|
|
||||||
TFTLCD_DELAY , 5 ,
|
|
||||||
0x17 , 0x05,
|
|
||||||
|
|
||||||
0x36 , 0x09,
|
0x36, 0x09, 0x28, 0x38, TFTLCD_DELAY, 40, 0x28, 0x3C,
|
||||||
0x28 , 0x38,
|
|
||||||
TFTLCD_DELAY , 40 ,
|
|
||||||
0x28 , 0x3C,
|
|
||||||
|
|
||||||
0x02 , 0x00,
|
0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0xEF, 0x06, 0x00, 0x07, 0x00,
|
||||||
0x03 , 0x00,
|
0x08, 0x01, 0x09, 0x3F};
|
||||||
0x04 , 0x00,
|
|
||||||
0x05 , 0xEF,
|
|
||||||
0x06 , 0x00,
|
|
||||||
0x07 , 0x00,
|
|
||||||
0x08 , 0x01,
|
|
||||||
0x09 , 0x3F
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t HX8357D_regValues[] PROGMEM = {
|
static const uint8_t HX8357D_regValues[] PROGMEM = {
|
||||||
HX8357_SWRESET, 0,
|
HX8357_SWRESET,
|
||||||
HX8357D_SETC, 3, 0xFF, 0x83, 0x57,
|
0,
|
||||||
TFTLCD_DELAY, 250,
|
HX8357D_SETC,
|
||||||
HX8357_SETRGB, 4, 0x00, 0x00, 0x06, 0x06,
|
3,
|
||||||
HX8357D_SETCOM, 1, 0x25, // -1.52V
|
0xFF,
|
||||||
HX8357_SETOSC, 1, 0x68, // Normal mode 70Hz, Idle mode 55 Hz
|
0x83,
|
||||||
HX8357_SETPANEL, 1, 0x05, // BGR, Gate direction swapped
|
0x57,
|
||||||
HX8357_SETPWR1, 6, 0x00, 0x15, 0x1C, 0x1C, 0x83, 0xAA,
|
TFTLCD_DELAY,
|
||||||
HX8357D_SETSTBA, 6, 0x50, 0x50, 0x01, 0x3C, 0x1E, 0x08,
|
250,
|
||||||
|
HX8357_SETRGB,
|
||||||
|
4,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x06,
|
||||||
|
0x06,
|
||||||
|
HX8357D_SETCOM,
|
||||||
|
1,
|
||||||
|
0x25, // -1.52V
|
||||||
|
HX8357_SETOSC,
|
||||||
|
1,
|
||||||
|
0x68, // Normal mode 70Hz, Idle mode 55 Hz
|
||||||
|
HX8357_SETPANEL,
|
||||||
|
1,
|
||||||
|
0x05, // BGR, Gate direction swapped
|
||||||
|
HX8357_SETPWR1,
|
||||||
|
6,
|
||||||
|
0x00,
|
||||||
|
0x15,
|
||||||
|
0x1C,
|
||||||
|
0x1C,
|
||||||
|
0x83,
|
||||||
|
0xAA,
|
||||||
|
HX8357D_SETSTBA,
|
||||||
|
6,
|
||||||
|
0x50,
|
||||||
|
0x50,
|
||||||
|
0x01,
|
||||||
|
0x3C,
|
||||||
|
0x1E,
|
||||||
|
0x08,
|
||||||
// MEME GAMMA HERE
|
// MEME GAMMA HERE
|
||||||
HX8357D_SETCYC, 7, 0x02, 0x40, 0x00, 0x2A, 0x2A, 0x0D, 0x78,
|
HX8357D_SETCYC,
|
||||||
HX8357_COLMOD, 1, 0x55,
|
7,
|
||||||
HX8357_MADCTL, 1, 0xC0,
|
0x02,
|
||||||
HX8357_TEON, 1, 0x00,
|
0x40,
|
||||||
HX8357_TEARLINE, 2, 0x00, 0x02,
|
0x00,
|
||||||
HX8357_SLPOUT, 0,
|
0x2A,
|
||||||
TFTLCD_DELAY, 150,
|
0x2A,
|
||||||
HX8357_DISPON, 0,
|
0x0D,
|
||||||
TFTLCD_DELAY, 50,
|
0x78,
|
||||||
|
HX8357_COLMOD,
|
||||||
|
1,
|
||||||
|
0x55,
|
||||||
|
HX8357_MADCTL,
|
||||||
|
1,
|
||||||
|
0xC0,
|
||||||
|
HX8357_TEON,
|
||||||
|
1,
|
||||||
|
0x00,
|
||||||
|
HX8357_TEARLINE,
|
||||||
|
2,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
HX8357_SLPOUT,
|
||||||
|
0,
|
||||||
|
TFTLCD_DELAY,
|
||||||
|
150,
|
||||||
|
HX8357_DISPON,
|
||||||
|
0,
|
||||||
|
TFTLCD_DELAY,
|
||||||
|
50,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t ILI932x_regValues[] PROGMEM = {
|
static const uint16_t ILI932x_regValues[] PROGMEM = {
|
||||||
ILI932X_START_OSC , 0x0001, // Start oscillator
|
ILI932X_START_OSC,
|
||||||
TFTLCD_DELAY , 50, // 50 millisecond delay
|
0x0001, // Start oscillator
|
||||||
ILI932X_DRIV_OUT_CTRL , 0x0100,
|
TFTLCD_DELAY,
|
||||||
ILI932X_DRIV_WAV_CTRL , 0x0700,
|
50, // 50 millisecond delay
|
||||||
ILI932X_ENTRY_MOD , 0x1030,
|
ILI932X_DRIV_OUT_CTRL,
|
||||||
ILI932X_RESIZE_CTRL , 0x0000,
|
0x0100,
|
||||||
ILI932X_DISP_CTRL2 , 0x0202,
|
ILI932X_DRIV_WAV_CTRL,
|
||||||
ILI932X_DISP_CTRL3 , 0x0000,
|
0x0700,
|
||||||
ILI932X_DISP_CTRL4 , 0x0000,
|
ILI932X_ENTRY_MOD,
|
||||||
ILI932X_RGB_DISP_IF_CTRL1, 0x0,
|
0x1030,
|
||||||
ILI932X_FRM_MARKER_POS , 0x0,
|
ILI932X_RESIZE_CTRL,
|
||||||
ILI932X_RGB_DISP_IF_CTRL2, 0x0,
|
0x0000,
|
||||||
ILI932X_POW_CTRL1 , 0x0000,
|
ILI932X_DISP_CTRL2,
|
||||||
ILI932X_POW_CTRL2 , 0x0007,
|
0x0202,
|
||||||
ILI932X_POW_CTRL3 , 0x0000,
|
ILI932X_DISP_CTRL3,
|
||||||
ILI932X_POW_CTRL4 , 0x0000,
|
0x0000,
|
||||||
TFTLCD_DELAY , 200,
|
ILI932X_DISP_CTRL4,
|
||||||
ILI932X_POW_CTRL1 , 0x1690,
|
0x0000,
|
||||||
ILI932X_POW_CTRL2 , 0x0227,
|
ILI932X_RGB_DISP_IF_CTRL1,
|
||||||
TFTLCD_DELAY , 50,
|
0x0,
|
||||||
ILI932X_POW_CTRL3 , 0x001A,
|
ILI932X_FRM_MARKER_POS,
|
||||||
TFTLCD_DELAY , 50,
|
0x0,
|
||||||
ILI932X_POW_CTRL4 , 0x1800,
|
ILI932X_RGB_DISP_IF_CTRL2,
|
||||||
ILI932X_POW_CTRL7 , 0x002A,
|
0x0,
|
||||||
TFTLCD_DELAY , 50,
|
ILI932X_POW_CTRL1,
|
||||||
ILI932X_GAMMA_CTRL1 , 0x0000,
|
0x0000,
|
||||||
ILI932X_GAMMA_CTRL2 , 0x0000,
|
ILI932X_POW_CTRL2,
|
||||||
ILI932X_GAMMA_CTRL3 , 0x0000,
|
0x0007,
|
||||||
ILI932X_GAMMA_CTRL4 , 0x0206,
|
ILI932X_POW_CTRL3,
|
||||||
ILI932X_GAMMA_CTRL5 , 0x0808,
|
0x0000,
|
||||||
ILI932X_GAMMA_CTRL6 , 0x0007,
|
ILI932X_POW_CTRL4,
|
||||||
ILI932X_GAMMA_CTRL7 , 0x0201,
|
0x0000,
|
||||||
ILI932X_GAMMA_CTRL8 , 0x0000,
|
TFTLCD_DELAY,
|
||||||
ILI932X_GAMMA_CTRL9 , 0x0000,
|
200,
|
||||||
ILI932X_GAMMA_CTRL10 , 0x0000,
|
ILI932X_POW_CTRL1,
|
||||||
ILI932X_GRAM_HOR_AD , 0x0000,
|
0x1690,
|
||||||
ILI932X_GRAM_VER_AD , 0x0000,
|
ILI932X_POW_CTRL2,
|
||||||
ILI932X_HOR_START_AD , 0x0000,
|
0x0227,
|
||||||
ILI932X_HOR_END_AD , 0x00EF,
|
TFTLCD_DELAY,
|
||||||
ILI932X_VER_START_AD , 0X0000,
|
50,
|
||||||
ILI932X_VER_END_AD , 0x013F,
|
ILI932X_POW_CTRL3,
|
||||||
ILI932X_GATE_SCAN_CTRL1 , 0xA700, // Driver Output Control (R60h)
|
0x001A,
|
||||||
ILI932X_GATE_SCAN_CTRL2 , 0x0003, // Driver Output Control (R61h)
|
TFTLCD_DELAY,
|
||||||
ILI932X_GATE_SCAN_CTRL3 , 0x0000, // Driver Output Control (R62h)
|
50,
|
||||||
ILI932X_PANEL_IF_CTRL1 , 0X0010, // Panel Interface Control 1 (R90h)
|
ILI932X_POW_CTRL4,
|
||||||
ILI932X_PANEL_IF_CTRL2 , 0X0000,
|
0x1800,
|
||||||
ILI932X_PANEL_IF_CTRL3 , 0X0003,
|
ILI932X_POW_CTRL7,
|
||||||
ILI932X_PANEL_IF_CTRL4 , 0X1100,
|
0x002A,
|
||||||
ILI932X_PANEL_IF_CTRL5 , 0X0000,
|
TFTLCD_DELAY,
|
||||||
ILI932X_PANEL_IF_CTRL6 , 0X0000,
|
50,
|
||||||
ILI932X_DISP_CTRL1 , 0x0133, // Main screen turn on
|
ILI932X_GAMMA_CTRL1,
|
||||||
|
0x0000,
|
||||||
|
ILI932X_GAMMA_CTRL2,
|
||||||
|
0x0000,
|
||||||
|
ILI932X_GAMMA_CTRL3,
|
||||||
|
0x0000,
|
||||||
|
ILI932X_GAMMA_CTRL4,
|
||||||
|
0x0206,
|
||||||
|
ILI932X_GAMMA_CTRL5,
|
||||||
|
0x0808,
|
||||||
|
ILI932X_GAMMA_CTRL6,
|
||||||
|
0x0007,
|
||||||
|
ILI932X_GAMMA_CTRL7,
|
||||||
|
0x0201,
|
||||||
|
ILI932X_GAMMA_CTRL8,
|
||||||
|
0x0000,
|
||||||
|
ILI932X_GAMMA_CTRL9,
|
||||||
|
0x0000,
|
||||||
|
ILI932X_GAMMA_CTRL10,
|
||||||
|
0x0000,
|
||||||
|
ILI932X_GRAM_HOR_AD,
|
||||||
|
0x0000,
|
||||||
|
ILI932X_GRAM_VER_AD,
|
||||||
|
0x0000,
|
||||||
|
ILI932X_HOR_START_AD,
|
||||||
|
0x0000,
|
||||||
|
ILI932X_HOR_END_AD,
|
||||||
|
0x00EF,
|
||||||
|
ILI932X_VER_START_AD,
|
||||||
|
0X0000,
|
||||||
|
ILI932X_VER_END_AD,
|
||||||
|
0x013F,
|
||||||
|
ILI932X_GATE_SCAN_CTRL1,
|
||||||
|
0xA700, // Driver Output Control (R60h)
|
||||||
|
ILI932X_GATE_SCAN_CTRL2,
|
||||||
|
0x0003, // Driver Output Control (R61h)
|
||||||
|
ILI932X_GATE_SCAN_CTRL3,
|
||||||
|
0x0000, // Driver Output Control (R62h)
|
||||||
|
ILI932X_PANEL_IF_CTRL1,
|
||||||
|
0X0010, // Panel Interface Control 1 (R90h)
|
||||||
|
ILI932X_PANEL_IF_CTRL2,
|
||||||
|
0X0000,
|
||||||
|
ILI932X_PANEL_IF_CTRL3,
|
||||||
|
0X0003,
|
||||||
|
ILI932X_PANEL_IF_CTRL4,
|
||||||
|
0X1100,
|
||||||
|
ILI932X_PANEL_IF_CTRL5,
|
||||||
|
0X0000,
|
||||||
|
ILI932X_PANEL_IF_CTRL6,
|
||||||
|
0X0000,
|
||||||
|
ILI932X_DISP_CTRL1,
|
||||||
|
0x0133, // Main screen turn on
|
||||||
};
|
};
|
||||||
|
|
||||||
void Adafruit_TFTLCD::begin(uint16_t id) {
|
void Adafruit_TFTLCD::begin(uint16_t id) {
|
||||||
|
|
@ -263,15 +331,16 @@ void Adafruit_TFTLCD::begin(uint16_t id) {
|
||||||
while (i < sizeof(ILI932x_regValues) / sizeof(uint16_t)) {
|
while (i < sizeof(ILI932x_regValues) / sizeof(uint16_t)) {
|
||||||
a = pgm_read_word(&ILI932x_regValues[i++]);
|
a = pgm_read_word(&ILI932x_regValues[i++]);
|
||||||
d = pgm_read_word(&ILI932x_regValues[i++]);
|
d = pgm_read_word(&ILI932x_regValues[i++]);
|
||||||
if(a == TFTLCD_DELAY) delay(d);
|
if (a == TFTLCD_DELAY)
|
||||||
else writeRegister16(a, d);
|
delay(d);
|
||||||
|
else
|
||||||
|
writeRegister16(a, d);
|
||||||
}
|
}
|
||||||
setRotation(rotation);
|
setRotation(rotation);
|
||||||
setAddrWindow(0, 0, TFTWIDTH - 1, TFTHEIGHT - 1);
|
setAddrWindow(0, 0, TFTWIDTH - 1, TFTHEIGHT - 1);
|
||||||
|
|
||||||
} else if (id == 0x9341) {
|
} else if (id == 0x9341) {
|
||||||
|
|
||||||
uint16_t a, d;
|
|
||||||
driver = ID_9341;
|
driver = ID_9341;
|
||||||
CS_ACTIVE;
|
CS_ACTIVE;
|
||||||
writeRegister8(ILI9341_SOFTRESET, 0);
|
writeRegister8(ILI9341_SOFTRESET, 0);
|
||||||
|
|
@ -318,7 +387,6 @@ void Adafruit_TFTLCD::begin(uint16_t id) {
|
||||||
write8(x);
|
write8(x);
|
||||||
}
|
}
|
||||||
CS_IDLE;
|
CS_IDLE;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
@ -331,8 +399,10 @@ void Adafruit_TFTLCD::begin(uint16_t id) {
|
||||||
while (i < sizeof(HX8347G_regValues)) {
|
while (i < sizeof(HX8347G_regValues)) {
|
||||||
a = pgm_read_byte(&HX8347G_regValues[i++]);
|
a = pgm_read_byte(&HX8347G_regValues[i++]);
|
||||||
d = pgm_read_byte(&HX8347G_regValues[i++]);
|
d = pgm_read_byte(&HX8347G_regValues[i++]);
|
||||||
if(a == TFTLCD_DELAY) delay(d);
|
if (a == TFTLCD_DELAY)
|
||||||
else writeRegister8(a, d);
|
delay(d);
|
||||||
|
else
|
||||||
|
writeRegister8(a, d);
|
||||||
}
|
}
|
||||||
setRotation(rotation);
|
setRotation(rotation);
|
||||||
setLR(); // Lower-right corner of address window
|
setLR(); // Lower-right corner of address window
|
||||||
|
|
@ -366,7 +436,8 @@ void Adafruit_TFTLCD::reset(void) {
|
||||||
CS_ACTIVE;
|
CS_ACTIVE;
|
||||||
CD_COMMAND;
|
CD_COMMAND;
|
||||||
write8(0x00);
|
write8(0x00);
|
||||||
for(uint8_t i=0; i<3; i++) WR_STROBE; // Three extra 0x00s
|
for (uint8_t i = 0; i < 3; i++)
|
||||||
|
WR_STROBE; // Three extra 0x00s
|
||||||
CS_IDLE;
|
CS_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,7 +515,6 @@ void Adafruit_TFTLCD::setAddrWindow(int x1, int y1, int x2, int y2) {
|
||||||
t <<= 16;
|
t <<= 16;
|
||||||
t |= y2;
|
t |= y2;
|
||||||
writeRegister32(ILI9341_PAGEADDRSET, t); // HX8357D uses same registers!
|
writeRegister32(ILI9341_PAGEADDRSET, t); // HX8357D uses same registers!
|
||||||
|
|
||||||
}
|
}
|
||||||
CS_IDLE;
|
CS_IDLE;
|
||||||
}
|
}
|
||||||
|
|
@ -467,8 +537,7 @@ void Adafruit_TFTLCD::setLR(void) {
|
||||||
// bounds. 'len' is inclusive, MUST be >= 1.
|
// bounds. 'len' is inclusive, MUST be >= 1.
|
||||||
void Adafruit_TFTLCD::flood(uint16_t color, uint32_t len) {
|
void Adafruit_TFTLCD::flood(uint16_t color, uint32_t len) {
|
||||||
uint16_t blocks;
|
uint16_t blocks;
|
||||||
uint8_t i, hi = color >> 8,
|
uint8_t i, hi = color >> 8, lo = color;
|
||||||
lo = color;
|
|
||||||
|
|
||||||
CS_ACTIVE;
|
CS_ACTIVE;
|
||||||
CD_COMMAND;
|
CD_COMMAND;
|
||||||
|
|
@ -496,8 +565,14 @@ void Adafruit_TFTLCD::flood(uint16_t color, uint32_t len) {
|
||||||
while (blocks--) {
|
while (blocks--) {
|
||||||
i = 16; // 64 pixels/block / 4 pixels/pass
|
i = 16; // 64 pixels/block / 4 pixels/pass
|
||||||
do {
|
do {
|
||||||
WR_STROBE; WR_STROBE; WR_STROBE; WR_STROBE; // 2 bytes/pixel
|
WR_STROBE;
|
||||||
WR_STROBE; WR_STROBE; WR_STROBE; WR_STROBE; // x 4 pixels
|
WR_STROBE;
|
||||||
|
WR_STROBE;
|
||||||
|
WR_STROBE; // 2 bytes/pixel
|
||||||
|
WR_STROBE;
|
||||||
|
WR_STROBE;
|
||||||
|
WR_STROBE;
|
||||||
|
WR_STROBE; // x 4 pixels
|
||||||
} while (--i);
|
} while (--i);
|
||||||
}
|
}
|
||||||
// Fill any remaining pixels (1 to 64)
|
// Fill any remaining pixels (1 to 64)
|
||||||
|
|
@ -509,8 +584,14 @@ void Adafruit_TFTLCD::flood(uint16_t color, uint32_t len) {
|
||||||
while (blocks--) {
|
while (blocks--) {
|
||||||
i = 16; // 64 pixels/block / 4 pixels/pass
|
i = 16; // 64 pixels/block / 4 pixels/pass
|
||||||
do {
|
do {
|
||||||
write8(hi); write8(lo); write8(hi); write8(lo);
|
write8(hi);
|
||||||
write8(hi); write8(lo); write8(hi); write8(lo);
|
write8(lo);
|
||||||
|
write8(hi);
|
||||||
|
write8(lo);
|
||||||
|
write8(hi);
|
||||||
|
write8(lo);
|
||||||
|
write8(hi);
|
||||||
|
write8(lo);
|
||||||
} while (--i);
|
} while (--i);
|
||||||
}
|
}
|
||||||
for (i = (uint8_t)len & 63; i--;) {
|
for (i = (uint8_t)len & 63; i--;) {
|
||||||
|
|
@ -522,14 +603,13 @@ void Adafruit_TFTLCD::flood(uint16_t color, uint32_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adafruit_TFTLCD::drawFastHLine(int16_t x, int16_t y, int16_t length,
|
void Adafruit_TFTLCD::drawFastHLine(int16_t x, int16_t y, int16_t length,
|
||||||
uint16_t color)
|
uint16_t color) {
|
||||||
{
|
|
||||||
int16_t x2;
|
int16_t x2;
|
||||||
|
|
||||||
// Initial off-screen clipping
|
// Initial off-screen clipping
|
||||||
if((length <= 0 ) ||
|
if ((length <= 0) || (y < 0) || (y >= _height) || (x >= _width) ||
|
||||||
(y < 0 ) || ( y >= _height) ||
|
((x2 = (x + length - 1)) < 0))
|
||||||
(x >= _width) || ((x2 = (x+length-1)) < 0 )) return;
|
return;
|
||||||
|
|
||||||
if (x < 0) { // Clip left
|
if (x < 0) { // Clip left
|
||||||
length += x;
|
length += x;
|
||||||
|
|
@ -542,19 +622,20 @@ void Adafruit_TFTLCD::drawFastHLine(int16_t x, int16_t y, int16_t length,
|
||||||
|
|
||||||
setAddrWindow(x, y, x2, y);
|
setAddrWindow(x, y, x2, y);
|
||||||
flood(color, length);
|
flood(color, length);
|
||||||
if(driver == ID_932X) setAddrWindow(0, 0, _width - 1, _height - 1);
|
if (driver == ID_932X)
|
||||||
else setLR();
|
setAddrWindow(0, 0, _width - 1, _height - 1);
|
||||||
|
else
|
||||||
|
setLR();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adafruit_TFTLCD::drawFastVLine(int16_t x, int16_t y, int16_t length,
|
void Adafruit_TFTLCD::drawFastVLine(int16_t x, int16_t y, int16_t length,
|
||||||
uint16_t color)
|
uint16_t color) {
|
||||||
{
|
|
||||||
int16_t y2;
|
int16_t y2;
|
||||||
|
|
||||||
// Initial off-screen clipping
|
// Initial off-screen clipping
|
||||||
if((length <= 0 ) ||
|
if ((length <= 0) || (x < 0) || (x >= _width) || (y >= _height) ||
|
||||||
(x < 0 ) || ( x >= _width) ||
|
((y2 = (y + length - 1)) < 0))
|
||||||
(y >= _height) || ((y2 = (y+length-1)) < 0 )) return;
|
return;
|
||||||
if (y < 0) { // Clip top
|
if (y < 0) { // Clip top
|
||||||
length += y;
|
length += y;
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|
@ -566,8 +647,10 @@ void Adafruit_TFTLCD::drawFastVLine(int16_t x, int16_t y, int16_t length,
|
||||||
|
|
||||||
setAddrWindow(x, y, x, y2);
|
setAddrWindow(x, y, x, y2);
|
||||||
flood(color, length);
|
flood(color, length);
|
||||||
if(driver == ID_932X) setAddrWindow(0, 0, _width - 1, _height - 1);
|
if (driver == ID_932X)
|
||||||
else setLR();
|
setAddrWindow(0, 0, _width - 1, _height - 1);
|
||||||
|
else
|
||||||
|
setLR();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adafruit_TFTLCD::fillRect(int16_t x1, int16_t y1, int16_t w, int16_t h,
|
void Adafruit_TFTLCD::fillRect(int16_t x1, int16_t y1, int16_t w, int16_t h,
|
||||||
|
|
@ -575,9 +658,9 @@ void Adafruit_TFTLCD::fillRect(int16_t x1, int16_t y1, int16_t w, int16_t h,
|
||||||
int16_t x2, y2;
|
int16_t x2, y2;
|
||||||
|
|
||||||
// Initial off-screen clipping
|
// Initial off-screen clipping
|
||||||
if( (w <= 0 ) || (h <= 0 ) ||
|
if ((w <= 0) || (h <= 0) || (x1 >= _width) || (y1 >= _height) ||
|
||||||
(x1 >= _width) || (y1 >= _height) ||
|
((x2 = x1 + w - 1) < 0) || ((y2 = y1 + h - 1) < 0))
|
||||||
((x2 = x1+w-1) < 0 ) || ((y2 = y1+h-1) < 0 )) return;
|
return;
|
||||||
if (x1 < 0) { // Clip left
|
if (x1 < 0) { // Clip left
|
||||||
w += x1;
|
w += x1;
|
||||||
x1 = 0;
|
x1 = 0;
|
||||||
|
|
@ -597,8 +680,10 @@ void Adafruit_TFTLCD::fillRect(int16_t x1, int16_t y1, int16_t w, int16_t h,
|
||||||
|
|
||||||
setAddrWindow(x1, y1, x2, y2);
|
setAddrWindow(x1, y1, x2, y2);
|
||||||
flood(fillcolor, (uint32_t)w * (uint32_t)h);
|
flood(fillcolor, (uint32_t)w * (uint32_t)h);
|
||||||
if(driver == ID_932X) setAddrWindow(0, 0, _width - 1, _height - 1);
|
if (driver == ID_932X)
|
||||||
else setLR();
|
setAddrWindow(0, 0, _width - 1, _height - 1);
|
||||||
|
else
|
||||||
|
setLR();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adafruit_TFTLCD::fillScreen(uint16_t color) {
|
void Adafruit_TFTLCD::fillScreen(uint16_t color) {
|
||||||
|
|
@ -612,22 +697,34 @@ void Adafruit_TFTLCD::fillScreen(uint16_t color) {
|
||||||
// fill does not occur top-to-bottom.
|
// fill does not occur top-to-bottom.
|
||||||
uint16_t x, y;
|
uint16_t x, y;
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
default: x = 0 ; y = 0 ; break;
|
default:
|
||||||
case 1 : x = TFTWIDTH - 1; y = 0 ; break;
|
x = 0;
|
||||||
case 2 : x = TFTWIDTH - 1; y = TFTHEIGHT - 1; break;
|
y = 0;
|
||||||
case 3 : x = 0 ; y = TFTHEIGHT - 1; break;
|
break;
|
||||||
|
case 1:
|
||||||
|
x = TFTWIDTH - 1;
|
||||||
|
y = 0;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
x = TFTWIDTH - 1;
|
||||||
|
y = TFTHEIGHT - 1;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
x = 0;
|
||||||
|
y = TFTHEIGHT - 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
CS_ACTIVE;
|
CS_ACTIVE;
|
||||||
writeRegister16(0x0020, x);
|
writeRegister16(0x0020, x);
|
||||||
writeRegister16(0x0021, y);
|
writeRegister16(0x0021, y);
|
||||||
|
|
||||||
} else if ((driver == ID_9341) || (driver == ID_7575) || (driver == ID_HX8357D)) {
|
} else if ((driver == ID_9341) || (driver == ID_7575) ||
|
||||||
|
(driver == ID_HX8357D)) {
|
||||||
// For these, there is no settable address pointer, instead the
|
// For these, there is no settable address pointer, instead the
|
||||||
// address window must be set for each drawing operation. However,
|
// address window must be set for each drawing operation. However,
|
||||||
// this display takes rotation into account for the parameters, no
|
// this display takes rotation into account for the parameters, no
|
||||||
// need to do extra rotation math here.
|
// need to do extra rotation math here.
|
||||||
setAddrWindow(0, 0, _width - 1, _height - 1);
|
setAddrWindow(0, 0, _width - 1, _height - 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
flood(color, (long)TFTWIDTH * (long)TFTHEIGHT);
|
flood(color, (long)TFTWIDTH * (long)TFTHEIGHT);
|
||||||
}
|
}
|
||||||
|
|
@ -635,7 +732,8 @@ void Adafruit_TFTLCD::fillScreen(uint16_t color) {
|
||||||
void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||||
|
|
||||||
// Clip
|
// Clip
|
||||||
if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return;
|
if ((x < 0) || (y < 0) || (x >= _width) || (y >= _height))
|
||||||
|
return;
|
||||||
|
|
||||||
CS_ACTIVE;
|
CS_ACTIVE;
|
||||||
if (driver == ID_932X) {
|
if (driver == ID_932X) {
|
||||||
|
|
@ -664,17 +762,30 @@ void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||||
|
|
||||||
uint8_t hi, lo;
|
uint8_t hi, lo;
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
default: lo = 0 ; break;
|
default:
|
||||||
case 1 : lo = 0x60; break;
|
lo = 0;
|
||||||
case 2 : lo = 0xc0; break;
|
break;
|
||||||
case 3 : lo = 0xa0; break;
|
case 1:
|
||||||
|
lo = 0x60;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
lo = 0xc0;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
lo = 0xa0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
writeRegister8(HX8347G_MEMACCESS, lo);
|
writeRegister8(HX8347G_MEMACCESS, lo);
|
||||||
// Only upper-left is set -- bottom-right is full screen default
|
// Only upper-left is set -- bottom-right is full screen default
|
||||||
writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x);
|
writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x);
|
||||||
writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y);
|
writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y);
|
||||||
hi = color >> 8; lo = color;
|
hi = color >> 8;
|
||||||
CD_COMMAND; write8(0x22); CD_DATA; write8(hi); write8(lo);
|
lo = color;
|
||||||
|
CD_COMMAND;
|
||||||
|
write8(0x22);
|
||||||
|
CD_DATA;
|
||||||
|
write8(hi);
|
||||||
|
write8(lo);
|
||||||
|
|
||||||
} else if ((driver == ID_9341) || (driver == ID_HX8357D)) {
|
} else if ((driver == ID_9341) || (driver == ID_HX8357D)) {
|
||||||
setAddrWindow(x, y, _width - 1, _height - 1);
|
setAddrWindow(x, y, _width - 1, _height - 1);
|
||||||
|
|
@ -682,7 +793,8 @@ void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||||
CD_COMMAND;
|
CD_COMMAND;
|
||||||
write8(0x2C);
|
write8(0x2C);
|
||||||
CD_DATA;
|
CD_DATA;
|
||||||
write8(color >> 8); write8(color);
|
write8(color >> 8);
|
||||||
|
write8(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
CS_IDLE;
|
CS_IDLE;
|
||||||
|
|
@ -698,7 +810,8 @@ void Adafruit_TFTLCD::pushColors(uint16_t *data, uint8_t len, boolean first) {
|
||||||
CS_ACTIVE;
|
CS_ACTIVE;
|
||||||
if (first == true) { // Issue GRAM write command only on first call
|
if (first == true) { // Issue GRAM write command only on first call
|
||||||
CD_COMMAND;
|
CD_COMMAND;
|
||||||
if(driver == ID_932X) write8(0x00);
|
if (driver == ID_932X)
|
||||||
|
write8(0x00);
|
||||||
if ((driver == ID_9341) || (driver == ID_HX8357D)) {
|
if ((driver == ID_9341) || (driver == ID_HX8357D)) {
|
||||||
write8(0x2C);
|
write8(0x2C);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -727,24 +840,39 @@ void Adafruit_TFTLCD::setRotation(uint8_t x) {
|
||||||
|
|
||||||
uint16_t t;
|
uint16_t t;
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
default: t = 0x1030; break;
|
default:
|
||||||
case 1 : t = 0x1028; break;
|
t = 0x1030;
|
||||||
case 2 : t = 0x1000; break;
|
break;
|
||||||
case 3 : t = 0x1018; break;
|
case 1:
|
||||||
|
t = 0x1028;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
t = 0x1000;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
t = 0x1018;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
writeRegister16(0x0003, t); // MADCTL
|
writeRegister16(0x0003, t); // MADCTL
|
||||||
// For 932X, init default full-screen address window:
|
// For 932X, init default full-screen address window:
|
||||||
setAddrWindow(0, 0, _width - 1, _height - 1); // CS_IDLE happens here
|
setAddrWindow(0, 0, _width - 1, _height - 1); // CS_IDLE happens here
|
||||||
|
|
||||||
}
|
}
|
||||||
if (driver == ID_7575) {
|
if (driver == ID_7575) {
|
||||||
|
|
||||||
uint8_t t;
|
uint8_t t;
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
default: t = 0 ; break;
|
default:
|
||||||
case 1 : t = 0x60; break;
|
t = 0;
|
||||||
case 2 : t = 0xc0; break;
|
break;
|
||||||
case 3 : t = 0xa0; break;
|
case 1:
|
||||||
|
t = 0x60;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
t = 0xc0;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
t = 0xa0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
writeRegister8(HX8347G_MEMACCESS, t);
|
writeRegister8(HX8347G_MEMACCESS, t);
|
||||||
// 7575 has to set the address window on most drawing operations.
|
// 7575 has to set the address window on most drawing operations.
|
||||||
|
|
@ -755,7 +883,7 @@ void Adafruit_TFTLCD::setRotation(uint8_t x) {
|
||||||
|
|
||||||
if (driver == ID_9341) {
|
if (driver == ID_9341) {
|
||||||
// MEME, HX8357D uses same registers as 9341 but different values
|
// MEME, HX8357D uses same registers as 9341 but different values
|
||||||
uint16_t t;
|
uint16_t t = 0;
|
||||||
|
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
case 2:
|
case 2:
|
||||||
|
|
@ -768,7 +896,8 @@ void Adafruit_TFTLCD::setRotation(uint8_t x) {
|
||||||
t = ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR;
|
t = ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
t = ILI9341_MADCTL_MX | ILI9341_MADCTL_MY | ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR;
|
t = ILI9341_MADCTL_MX | ILI9341_MADCTL_MY | ILI9341_MADCTL_MV |
|
||||||
|
ILI9341_MADCTL_BGR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
writeRegister8(ILI9341_MADCTL, t); // MADCTL
|
writeRegister8(ILI9341_MADCTL, t); // MADCTL
|
||||||
|
|
@ -778,7 +907,7 @@ void Adafruit_TFTLCD::setRotation(uint8_t x) {
|
||||||
|
|
||||||
if (driver == ID_HX8357D) {
|
if (driver == ID_HX8357D) {
|
||||||
// MEME, HX8357D uses same registers as 9341 but different values
|
// MEME, HX8357D uses same registers as 9341 but different values
|
||||||
uint16_t t;
|
uint16_t t = 0;
|
||||||
|
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
case 2:
|
case 2:
|
||||||
|
|
@ -797,7 +926,8 @@ void Adafruit_TFTLCD::setRotation(uint8_t x) {
|
||||||
writeRegister8(ILI9341_MADCTL, t); // MADCTL
|
writeRegister8(ILI9341_MADCTL, t); // MADCTL
|
||||||
// For 8357, init default full-screen address window:
|
// For 8357, init default full-screen address window:
|
||||||
setAddrWindow(0, 0, _width - 1, _height - 1); // CS_IDLE happens here
|
setAddrWindow(0, 0, _width - 1, _height - 1); // CS_IDLE happens here
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef read8isFunctionalized
|
#ifdef read8isFunctionalized
|
||||||
#define read8(x) x = read8fn()
|
#define read8(x) x = read8fn()
|
||||||
|
|
@ -809,7 +939,8 @@ void Adafruit_TFTLCD::setRotation(uint8_t x) {
|
||||||
// leave the ports in that state as a default.
|
// leave the ports in that state as a default.
|
||||||
uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) {
|
uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) {
|
||||||
|
|
||||||
if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return 0;
|
if ((x < 0) || (y < 0) || (x >= _width) || (y >= _height))
|
||||||
|
return 0;
|
||||||
|
|
||||||
CS_ACTIVE;
|
CS_ACTIVE;
|
||||||
if (driver == ID_932X) {
|
if (driver == ID_932X) {
|
||||||
|
|
@ -838,7 +969,9 @@ uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) {
|
||||||
// reversed. A second read fixes this. Unsure of reason. Have
|
// reversed. A second read fixes this. Unsure of reason. Have
|
||||||
// tried adjusting timing in read8() etc. to no avail.
|
// tried adjusting timing in read8() etc. to no avail.
|
||||||
for (uint8_t pass = 0; pass < 2; pass++) {
|
for (uint8_t pass = 0; pass < 2; pass++) {
|
||||||
CD_COMMAND; write8(0x00); write8(0x22); // Read data from GRAM
|
CD_COMMAND;
|
||||||
|
write8(0x00);
|
||||||
|
write8(0x22); // Read data from GRAM
|
||||||
CD_DATA;
|
CD_DATA;
|
||||||
setReadDir(); // Set up LCD data port(s) for READ operations
|
setReadDir(); // Set up LCD data port(s) for READ operations
|
||||||
read8(hi); // First 2 bytes back are a dummy read
|
read8(hi); // First 2 bytes back are a dummy read
|
||||||
|
|
@ -855,7 +988,8 @@ uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) {
|
||||||
uint8_t r, g, b;
|
uint8_t r, g, b;
|
||||||
writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x);
|
writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x);
|
||||||
writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y);
|
writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y);
|
||||||
CD_COMMAND; write8(0x22); // Read data from GRAM
|
CD_COMMAND;
|
||||||
|
write8(0x22); // Read data from GRAM
|
||||||
setReadDir(); // Set up LCD data port(s) for READ operations
|
setReadDir(); // Set up LCD data port(s) for READ operations
|
||||||
CD_DATA;
|
CD_DATA;
|
||||||
read8(r); // First byte back is a dummy read
|
read8(r); // First byte back is a dummy read
|
||||||
|
|
@ -864,10 +998,10 @@ uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) {
|
||||||
read8(b);
|
read8(b);
|
||||||
setWriteDir(); // Restore LCD data port(s) to WRITE configuration
|
setWriteDir(); // Restore LCD data port(s) to WRITE configuration
|
||||||
CS_IDLE;
|
CS_IDLE;
|
||||||
return (((uint16_t)r & B11111000) << 8) |
|
return (((uint16_t)r & B11111000) << 8) | (((uint16_t)g & B11111100) << 3) |
|
||||||
(((uint16_t)g & B11111100) << 3) |
|
|
||||||
(b >> 3);
|
(b >> 3);
|
||||||
} else return 0;
|
} else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ditto with the read/write port directions, as above.
|
// Ditto with the read/write port directions, as above.
|
||||||
|
|
@ -876,7 +1010,8 @@ uint16_t Adafruit_TFTLCD::readID(void) {
|
||||||
|
|
||||||
// retry a bunch!
|
// retry a bunch!
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
id = readReg(0xD3);
|
id = (uint16_t)readReg(0xD3);
|
||||||
|
delayMicroseconds(50);
|
||||||
if (id == 0x9341) {
|
if (id == 0x9341) {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
@ -919,7 +1054,9 @@ uint16_t Adafruit_TFTLCD::readID(void) {
|
||||||
setWriteDir(); // Restore LCD data port(s) to WRITE configuration
|
setWriteDir(); // Restore LCD data port(s) to WRITE configuration
|
||||||
CS_IDLE;
|
CS_IDLE;
|
||||||
|
|
||||||
id = hi; id <<= 8; id |= lo;
|
id = hi;
|
||||||
|
id <<= 8;
|
||||||
|
id |= lo;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -962,9 +1099,7 @@ uint16_t Adafruit_TFTLCD::color565(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
// versions that reference the inline macros just once:
|
// versions that reference the inline macros just once:
|
||||||
|
|
||||||
#ifndef write8
|
#ifndef write8
|
||||||
void Adafruit_TFTLCD::write8(uint8_t value) {
|
void Adafruit_TFTLCD::write8(uint8_t value) { write8inline(value); }
|
||||||
write8inline(value);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef read8isFunctionalized
|
#ifdef read8isFunctionalized
|
||||||
|
|
@ -976,15 +1111,11 @@ uint8_t Adafruit_TFTLCD::read8fn(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef setWriteDir
|
#ifndef setWriteDir
|
||||||
void Adafruit_TFTLCD::setWriteDir(void) {
|
void Adafruit_TFTLCD::setWriteDir(void) { setWriteDirInline(); }
|
||||||
setWriteDirInline();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef setReadDir
|
#ifndef setReadDir
|
||||||
void Adafruit_TFTLCD::setReadDir(void) {
|
void Adafruit_TFTLCD::setReadDir(void) { setReadDirInline(); }
|
||||||
setReadDirInline();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef writeRegister8
|
#ifndef writeRegister8
|
||||||
|
|
@ -1005,7 +1136,6 @@ void Adafruit_TFTLCD::writeRegisterPair(uint8_t aH, uint8_t aL, uint16_t d) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void Adafruit_TFTLCD::writeRegister24(uint8_t r, uint32_t d) {
|
void Adafruit_TFTLCD::writeRegister24(uint8_t r, uint32_t d) {
|
||||||
CS_ACTIVE;
|
CS_ACTIVE;
|
||||||
CD_COMMAND;
|
CD_COMMAND;
|
||||||
|
|
@ -1018,10 +1148,8 @@ void Adafruit_TFTLCD::writeRegister24(uint8_t r, uint32_t d) {
|
||||||
delayMicroseconds(10);
|
delayMicroseconds(10);
|
||||||
write8(d);
|
write8(d);
|
||||||
CS_IDLE;
|
CS_IDLE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Adafruit_TFTLCD::writeRegister32(uint8_t r, uint32_t d) {
|
void Adafruit_TFTLCD::writeRegister32(uint8_t r, uint32_t d) {
|
||||||
CS_ACTIVE;
|
CS_ACTIVE;
|
||||||
CD_COMMAND;
|
CD_COMMAND;
|
||||||
|
|
@ -1036,5 +1164,4 @@ void Adafruit_TFTLCD::writeRegister32(uint8_t r, uint32_t d) {
|
||||||
delayMicroseconds(10);
|
delayMicroseconds(10);
|
||||||
write8(d);
|
write8(d);
|
||||||
CS_IDLE;
|
CS_IDLE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
class Adafruit_TFTLCD : public Adafruit_GFX {
|
class Adafruit_TFTLCD : public Adafruit_GFX {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t rst);
|
Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t rst);
|
||||||
Adafruit_TFTLCD(void);
|
Adafruit_TFTLCD(void);
|
||||||
|
|
||||||
|
|
@ -41,12 +40,10 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
|
||||||
void pushColors(uint16_t *data, uint8_t len, boolean first);
|
void pushColors(uint16_t *data, uint8_t len, boolean first);
|
||||||
|
|
||||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b),
|
uint16_t color565(uint8_t r, uint8_t g, uint8_t b),
|
||||||
readPixel(int16_t x, int16_t y),
|
readPixel(int16_t x, int16_t y), readID(void);
|
||||||
readID(void);
|
|
||||||
uint32_t readReg(uint8_t r);
|
uint32_t readReg(uint8_t r);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void init(),
|
void init(),
|
||||||
// These items may have previously been defined as macros
|
// These items may have previously been defined as macros
|
||||||
// in pin_magic.h. If not, function versions are declared:
|
// in pin_magic.h. If not, function versions are declared:
|
||||||
|
|
@ -70,8 +67,7 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
|
||||||
#ifndef writeRegisterPair
|
#ifndef writeRegisterPair
|
||||||
writeRegisterPair(uint8_t aH, uint8_t aL, uint16_t d),
|
writeRegisterPair(uint8_t aH, uint8_t aL, uint16_t d),
|
||||||
#endif
|
#endif
|
||||||
setLR(void),
|
setLR(void), flood(uint16_t color, uint32_t len);
|
||||||
flood(uint16_t color, uint32_t len);
|
|
||||||
uint8_t driver;
|
uint8_t driver;
|
||||||
|
|
||||||
#ifndef read8
|
#ifndef read8
|
||||||
|
|
@ -83,15 +79,13 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
|
||||||
|
|
||||||
#ifdef __AVR__
|
#ifdef __AVR__
|
||||||
volatile uint8_t *csPort, *cdPort, *wrPort, *rdPort;
|
volatile uint8_t *csPort, *cdPort, *wrPort, *rdPort;
|
||||||
uint8_t csPinSet , cdPinSet , wrPinSet , rdPinSet ,
|
uint8_t csPinSet, cdPinSet, wrPinSet, rdPinSet, csPinUnset, cdPinUnset,
|
||||||
csPinUnset, cdPinUnset, wrPinUnset, rdPinUnset,
|
wrPinUnset, rdPinUnset, _reset;
|
||||||
_reset;
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
Pio *csPort, *cdPort, *wrPort, *rdPort;
|
Pio *csPort, *cdPort, *wrPort, *rdPort;
|
||||||
uint32_t csPinSet , cdPinSet , wrPinSet , rdPinSet ,
|
uint32_t csPinSet, cdPinSet, wrPinSet, rdPinSet, csPinUnset, cdPinUnset,
|
||||||
csPinUnset, cdPinUnset, wrPinUnset, rdPinUnset,
|
wrPinUnset, rdPinUnset, _reset;
|
||||||
_reset;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
19
README.md
Normal file
19
README.md
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Adafruit library for 8-bit TFT LCDs such as ILI9325, ILI9328, etc
|
||||||
|
|
||||||
|
This is a library for our Adafruit 16-channel PWM & Servo driver, shield or FeatherWing
|
||||||
|
|
||||||
|
<a href="https://www.adafruit.com/products/335"><img src="assets/image.jpg" height="300"/></a>
|
||||||
|
|
||||||
|
Pick one up today in the adafruit shop!
|
||||||
|
* https://www.adafruit.com/product/335
|
||||||
|
* https://www.adafruit.com/product/376
|
||||||
|
|
||||||
|
These displays use 8-bit parallel to communicate, 12 or 13 pins are required to interface (RST is optional).
|
||||||
|
|
||||||
|
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
|
||||||
|
|
||||||
|
Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more information.
|
||||||
|
|
||||||
|
All text above must be included in any redistribution
|
||||||
|
|
||||||
|
To install, use the Arduino Library Manager and search for "Adafruit 2.8" TFT display Library" and install the library.
|
||||||
21
README.txt
21
README.txt
|
|
@ -1,21 +0,0 @@
|
||||||
This is a library for the Adafruit 2.8" TFT display.
|
|
||||||
This library works with the Adafruit 2.8" TFT Breakout w/SD card
|
|
||||||
----> http://www.adafruit.com/products/335
|
|
||||||
as well as Adafruit TFT Touch Shield
|
|
||||||
----> http://www.adafruit.com/products/376
|
|
||||||
|
|
||||||
Check out the links above for our tutorials and wiring diagrams.
|
|
||||||
These displays use 8-bit parallel to communicate, 12 or 13 pins are required
|
|
||||||
to interface (RST is optional).
|
|
||||||
Adafruit invests time and resources providing this open source code,
|
|
||||||
please support Adafruit and open-source hardware by purchasing
|
|
||||||
products from Adafruit!
|
|
||||||
|
|
||||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
|
||||||
MIT license, all text above must be included in any redistribution
|
|
||||||
|
|
||||||
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_TFTLCD. Check that the Adafruit_TFTLCD folder contains Adafruit_TFTLCD.cpp and Adafruit_TFTLCD.
|
|
||||||
|
|
||||||
Place the Adafruit_TFT library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE
|
|
||||||
|
|
||||||
Also requires the Adafruit_GFX library for Arduino. https://github.com/adafruit/Adafruit-GFX-Library
|
|
||||||
BIN
assets/image.jpg
Normal file
BIN
assets/image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
10
library.properties
Normal file
10
library.properties
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
name=Adafruit TFTLCD Library
|
||||||
|
version=1.0.3
|
||||||
|
author=Adafruit
|
||||||
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
|
sentence=Adafruit 2.8" TFT display Library
|
||||||
|
paragraph=Adafruit 2.8" TFT display Library
|
||||||
|
category=Display
|
||||||
|
url=https://github.com/adafruit/TFTLCD-Library
|
||||||
|
architectures=*
|
||||||
|
depends=Adafruit GFX Library
|
||||||
324
pin_magic.h
324
pin_magic.h
|
|
@ -55,14 +55,17 @@
|
||||||
// equivalent to two NOPs each, final NOP burns the 7th cycle, and the
|
// equivalent to two NOPs each, final NOP burns the 7th cycle, and the
|
||||||
// last line is a radioactive mutant emoticon.
|
// last line is a radioactive mutant emoticon.
|
||||||
#define DELAY7 \
|
#define DELAY7 \
|
||||||
asm volatile( \
|
asm volatile("rjmp .+0" \
|
||||||
"rjmp .+0" "\n\t" \
|
"\n\t" \
|
||||||
"rjmp .+0" "\n\t" \
|
"rjmp .+0" \
|
||||||
"rjmp .+0" "\n\t" \
|
"\n\t" \
|
||||||
"nop" "\n" \
|
"rjmp .+0" \
|
||||||
::);
|
"\n\t" \
|
||||||
|
"nop" \
|
||||||
|
"\n" ::);
|
||||||
|
|
||||||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined (__AVR_ATmega328__) || defined(__AVR_ATmega8__)
|
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || \
|
||||||
|
defined(__AVR_ATmega328__) || defined(__AVR_ATmega8__)
|
||||||
|
|
||||||
// Arduino Uno, Duemilanove, etc.
|
// Arduino Uno, Duemilanove, etc.
|
||||||
|
|
||||||
|
|
@ -82,19 +85,23 @@
|
||||||
// These are macros for I/O operations...
|
// These are macros for I/O operations...
|
||||||
|
|
||||||
// Write 8-bit value to LCD data lines
|
// Write 8-bit value to LCD data lines
|
||||||
#define write8inline(d) { \
|
#define write8inline(d) \
|
||||||
|
{ \
|
||||||
PORTD = (PORTD & B00101111) | ((d)&B11010000); \
|
PORTD = (PORTD & B00101111) | ((d)&B11010000); \
|
||||||
PORTB = (PORTB & B11010000) | ((d)&B00101111); \
|
PORTB = (PORTB & B11010000) | ((d)&B00101111); \
|
||||||
WR_STROBE; } // STROBEs are defined later
|
WR_STROBE; \
|
||||||
|
} // STROBEs are defined later
|
||||||
|
|
||||||
// Read 8-bit value from LCD data lines. The signle argument
|
// Read 8-bit value from LCD data lines. The signle argument
|
||||||
// is a destination variable; this isn't a function and doesn't
|
// is a destination variable; this isn't a function and doesn't
|
||||||
// return a value in the conventional sense.
|
// return a value in the conventional sense.
|
||||||
#define read8inline(result) { \
|
#define read8inline(result) \
|
||||||
|
{ \
|
||||||
RD_ACTIVE; \
|
RD_ACTIVE; \
|
||||||
DELAY7; \
|
DELAY7; \
|
||||||
result = (PIND & B11010000) | (PINB & B00101111); \
|
result = (PIND & B11010000) | (PINB & B00101111); \
|
||||||
RD_IDLE; }
|
RD_IDLE; \
|
||||||
|
}
|
||||||
|
|
||||||
// These set the PORT directions as required before the write and read
|
// These set the PORT directions as required before the write and read
|
||||||
// operations. Because write operations are much more common than reads,
|
// operations. Because write operations are much more common than reads,
|
||||||
|
|
@ -102,22 +109,42 @@
|
||||||
// input before a read, and restore them back to the write state before
|
// input before a read, and restore them back to the write state before
|
||||||
// returning. This avoids having to set it for output inside every
|
// returning. This avoids having to set it for output inside every
|
||||||
// drawing method. The default state has them initialized for writes.
|
// drawing method. The default state has them initialized for writes.
|
||||||
#define setWriteDirInline() { DDRD |= B11010000; DDRB |= B00101111; }
|
#define setWriteDirInline() \
|
||||||
#define setReadDirInline() { DDRD &= ~B11010000; DDRB &= ~B00101111; }
|
{ \
|
||||||
|
DDRD |= B11010000; \
|
||||||
|
DDRB |= B00101111; \
|
||||||
|
}
|
||||||
|
#define setReadDirInline() \
|
||||||
|
{ \
|
||||||
|
DDRD &= ~B11010000; \
|
||||||
|
DDRB &= ~B00101111; \
|
||||||
|
}
|
||||||
|
|
||||||
#else // Uno w/Breakout board
|
#else // Uno w/Breakout board
|
||||||
|
|
||||||
#define write8inline(d) { \
|
#define write8inline(d) \
|
||||||
|
{ \
|
||||||
PORTD = (PORTD & B00000011) | ((d)&B11111100); \
|
PORTD = (PORTD & B00000011) | ((d)&B11111100); \
|
||||||
PORTB = (PORTB & B11111100) | ((d)&B00000011); \
|
PORTB = (PORTB & B11111100) | ((d)&B00000011); \
|
||||||
WR_STROBE; }
|
WR_STROBE; \
|
||||||
#define read8inline(result) { \
|
}
|
||||||
|
#define read8inline(result) \
|
||||||
|
{ \
|
||||||
RD_ACTIVE; \
|
RD_ACTIVE; \
|
||||||
DELAY7; \
|
DELAY7; \
|
||||||
result = (PIND & B11111100) | (PINB & B00000011); \
|
result = (PIND & B11111100) | (PINB & B00000011); \
|
||||||
RD_IDLE; }
|
RD_IDLE; \
|
||||||
#define setWriteDirInline() { DDRD |= B11111100; DDRB |= B00000011; }
|
}
|
||||||
#define setReadDirInline() { DDRD &= ~B11111100; DDRB &= ~B00000011; }
|
#define setWriteDirInline() \
|
||||||
|
{ \
|
||||||
|
DDRD |= B11111100; \
|
||||||
|
DDRB |= B00000011; \
|
||||||
|
}
|
||||||
|
#define setReadDirInline() \
|
||||||
|
{ \
|
||||||
|
DDRD &= ~B11111100; \
|
||||||
|
DDRB &= ~B00000011; \
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -129,7 +156,8 @@
|
||||||
// why only certain cases are inlined for each board.
|
// why only certain cases are inlined for each board.
|
||||||
#define write8 write8inline
|
#define write8 write8inline
|
||||||
|
|
||||||
#elif defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
|
#elif defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) || \
|
||||||
|
defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
|
||||||
|
|
||||||
// Arduino Mega, ADK, etc.
|
// Arduino Mega, ADK, etc.
|
||||||
|
|
||||||
|
|
@ -144,30 +172,49 @@
|
||||||
#define CD_MASK B00000100
|
#define CD_MASK B00000100
|
||||||
#define CS_MASK B00001000
|
#define CS_MASK B00001000
|
||||||
|
|
||||||
#define write8inline(d) { \
|
#define write8inline(d) \
|
||||||
PORTH = (PORTH&B10000111)|(((d)&B11000000)>>3)|(((d)&B00000011)<<5); \
|
{ \
|
||||||
|
PORTH = \
|
||||||
|
(PORTH & B10000111) | (((d)&B11000000) >> 3) | (((d)&B00000011) << 5); \
|
||||||
PORTB = (PORTB & B01001111) | (((d)&B00101100) << 2); \
|
PORTB = (PORTB & B01001111) | (((d)&B00101100) << 2); \
|
||||||
PORTG = (PORTG & B11011111) | (((d)&B00010000) << 1); \
|
PORTG = (PORTG & B11011111) | (((d)&B00010000) << 1); \
|
||||||
WR_STROBE; }
|
WR_STROBE; \
|
||||||
#define read8inline(result) { \
|
}
|
||||||
|
#define read8inline(result) \
|
||||||
|
{ \
|
||||||
RD_ACTIVE; \
|
RD_ACTIVE; \
|
||||||
DELAY7; \
|
DELAY7; \
|
||||||
result = ((PINH & B00011000) << 3) | ((PINB & B10110000) >> 2) | \
|
result = ((PINH & B00011000) << 3) | ((PINB & B10110000) >> 2) | \
|
||||||
((PING & B00100000) >> 1) | ((PINH & B01100000) >> 5); \
|
((PING & B00100000) >> 1) | ((PINH & B01100000) >> 5); \
|
||||||
RD_IDLE; }
|
RD_IDLE; \
|
||||||
#define setWriteDirInline() { \
|
}
|
||||||
DDRH |= B01111000; DDRB |= B10110000; DDRG |= B00100000; }
|
#define setWriteDirInline() \
|
||||||
#define setReadDirInline() { \
|
{ \
|
||||||
DDRH &= ~B01111000; DDRB &= ~B10110000; DDRG &= ~B00100000; }
|
DDRH |= B01111000; \
|
||||||
|
DDRB |= B10110000; \
|
||||||
|
DDRG |= B00100000; \
|
||||||
|
}
|
||||||
|
#define setReadDirInline() \
|
||||||
|
{ \
|
||||||
|
DDRH &= ~B01111000; \
|
||||||
|
DDRB &= ~B10110000; \
|
||||||
|
DDRG &= ~B00100000; \
|
||||||
|
}
|
||||||
|
|
||||||
#else // Mega w/Breakout board
|
#else // Mega w/Breakout board
|
||||||
|
|
||||||
#define write8inline(d) { PORTA = (d); WR_STROBE; }
|
#define write8inline(d) \
|
||||||
#define read8inline(result) { \
|
{ \
|
||||||
|
PORTA = (d); \
|
||||||
|
WR_STROBE; \
|
||||||
|
}
|
||||||
|
#define read8inline(result) \
|
||||||
|
{ \
|
||||||
RD_ACTIVE; \
|
RD_ACTIVE; \
|
||||||
DELAY7; \
|
DELAY7; \
|
||||||
result = PINA; \
|
result = PINA; \
|
||||||
RD_IDLE; }
|
RD_IDLE; \
|
||||||
|
}
|
||||||
#define setWriteDirInline() DDRA = 0xff
|
#define setWriteDirInline() DDRA = 0xff
|
||||||
#define setReadDirInline() DDRA = 0
|
#define setReadDirInline() DDRA = 0
|
||||||
|
|
||||||
|
|
@ -202,50 +249,74 @@
|
||||||
#define CD_MASK B00100000
|
#define CD_MASK B00100000
|
||||||
#define CS_MASK B00010000
|
#define CS_MASK B00010000
|
||||||
|
|
||||||
#define write8inline(d) { \
|
#define write8inline(d) \
|
||||||
|
{ \
|
||||||
PORTE = (PORTE & B10111111) | (((d)&B10000000) >> 1); \
|
PORTE = (PORTE & B10111111) | (((d)&B10000000) >> 1); \
|
||||||
PORTD = (PORTD & B01101111) | (((d)&B01000000) << 1) | ((d)&B00010000); \
|
PORTD = (PORTD & B01101111) | (((d)&B01000000) << 1) | ((d)&B00010000); \
|
||||||
PORTC = (PORTC & B01111111) | (((d)&B00100000) << 2); \
|
PORTC = (PORTC & B01111111) | (((d)&B00100000) << 2); \
|
||||||
PORTB = (PORTB & B00001111) | (((d)&B00001111) << 4); \
|
PORTB = (PORTB & B00001111) | (((d)&B00001111) << 4); \
|
||||||
WR_STROBE; }
|
WR_STROBE; \
|
||||||
#define read8inline(result) { \
|
}
|
||||||
|
#define read8inline(result) \
|
||||||
|
{ \
|
||||||
RD_ACTIVE; \
|
RD_ACTIVE; \
|
||||||
DELAY7; \
|
DELAY7; \
|
||||||
result = ((PINE & B01000000) << 1) | ((PIND & B10000000) >> 1) | \
|
result = ((PINE & B01000000) << 1) | ((PIND & B10000000) >> 1) | \
|
||||||
((PINC & B10000000) >> 2) | ((PINB & B11110000) >> 4) | \
|
((PINC & B10000000) >> 2) | ((PINB & B11110000) >> 4) | \
|
||||||
(PIND & B00010000); \
|
(PIND & B00010000); \
|
||||||
RD_IDLE; }
|
RD_IDLE; \
|
||||||
#define setWriteDirInline() { \
|
}
|
||||||
DDRE |= B01000000; DDRD |= B10010000; \
|
#define setWriteDirInline() \
|
||||||
DDRC |= B10000000; DDRB |= B11110000; }
|
{ \
|
||||||
#define setReadDirInline() { \
|
DDRE |= B01000000; \
|
||||||
DDRE &= ~B01000000; DDRD &= ~B10010000; \
|
DDRD |= B10010000; \
|
||||||
DDRC &= ~B10000000; DDRB &= ~B11110000; }
|
DDRC |= B10000000; \
|
||||||
|
DDRB |= B11110000; \
|
||||||
|
}
|
||||||
|
#define setReadDirInline() \
|
||||||
|
{ \
|
||||||
|
DDRE &= ~B01000000; \
|
||||||
|
DDRD &= ~B10010000; \
|
||||||
|
DDRC &= ~B10000000; \
|
||||||
|
DDRB &= ~B11110000; \
|
||||||
|
}
|
||||||
|
|
||||||
#else // Leonardo w/Breakout board
|
#else // Leonardo w/Breakout board
|
||||||
|
|
||||||
#define write8inline(d) { \
|
#define write8inline(d) \
|
||||||
|
{ \
|
||||||
uint8_t dr1 = (d) >> 1, dl1 = (d) << 1; \
|
uint8_t dr1 = (d) >> 1, dl1 = (d) << 1; \
|
||||||
PORTE = (PORTE & B10111111) | (dr1 & B01000000); \
|
PORTE = (PORTE & B10111111) | (dr1 & B01000000); \
|
||||||
PORTD = (PORTD & B01101100) | (dl1 & B10000000) | (((d)&B00001000) >> 3) | \
|
PORTD = (PORTD & B01101100) | (dl1 & B10000000) | (((d)&B00001000) >> 3) | \
|
||||||
(dr1 & B00000010) | ((d)&B00010000); \
|
(dr1 & B00000010) | ((d)&B00010000); \
|
||||||
PORTC = (PORTC & B10111111) | (dl1 & B01000000); \
|
PORTC = (PORTC & B10111111) | (dl1 & B01000000); \
|
||||||
PORTB = (PORTB & B11001111) | (((d)&B00000011) << 4); \
|
PORTB = (PORTB & B11001111) | (((d)&B00000011) << 4); \
|
||||||
WR_STROBE; }
|
WR_STROBE; \
|
||||||
#define read8inline(result) { \
|
}
|
||||||
|
#define read8inline(result) \
|
||||||
|
{ \
|
||||||
RD_ACTIVE; \
|
RD_ACTIVE; \
|
||||||
DELAY7; \
|
DELAY7; \
|
||||||
result = (((PINE & B01000000) | (PIND & B00000010)) << 1) | \
|
result = (((PINE & B01000000) | (PIND & B00000010)) << 1) | \
|
||||||
(((PINC & B01000000) | (PIND & B10000000)) >> 1) | \
|
(((PINC & B01000000) | (PIND & B10000000)) >> 1) | \
|
||||||
((PIND & B00000001) << 3) | ((PINB & B00110000) >> 4) | \
|
((PIND & B00000001) << 3) | ((PINB & B00110000) >> 4) | \
|
||||||
(PIND & B00010000); \
|
(PIND & B00010000); \
|
||||||
RD_IDLE; }
|
RD_IDLE; \
|
||||||
#define setWriteDirInline() { \
|
}
|
||||||
DDRE |= B01000000; DDRD |= B10010011; \
|
#define setWriteDirInline() \
|
||||||
DDRC |= B01000000; DDRB |= B00110000; }
|
{ \
|
||||||
#define setReadDirInline() { \
|
DDRE |= B01000000; \
|
||||||
DDRE &= ~B01000000; DDRD &= ~B10010011; \
|
DDRD |= B10010011; \
|
||||||
DDRC &= ~B01000000; DDRB &= ~B00110000; }
|
DDRC |= B01000000; \
|
||||||
|
DDRB |= B00110000; \
|
||||||
|
}
|
||||||
|
#define setReadDirInline() \
|
||||||
|
{ \
|
||||||
|
DDRE &= ~B01000000; \
|
||||||
|
DDRD &= ~B10010011; \
|
||||||
|
DDRC &= ~B01000000; \
|
||||||
|
DDRB &= ~B00110000; \
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -270,34 +341,69 @@
|
||||||
#define CD_MASK 0x00800000
|
#define CD_MASK 0x00800000
|
||||||
#define CS_MASK 0x00400000
|
#define CS_MASK 0x00400000
|
||||||
|
|
||||||
#define write8inline(d) { \
|
#define write8inline(d) \
|
||||||
|
{ \
|
||||||
PIO_Set(PIOD, (((d)&0x08) << (7 - 3))); \
|
PIO_Set(PIOD, (((d)&0x08) << (7 - 3))); \
|
||||||
PIO_Clear(PIOD, (((~d) & 0x08) << (7 - 3))); \
|
PIO_Clear(PIOD, (((~d) & 0x08) << (7 - 3))); \
|
||||||
PIO_Set(PIOC, (((d) & 0x01)<<(22-0)) | (((d) & 0x02)<<(21-1))| (((d) & 0x04)<<(29-2))| (((d) & 0x10)<<(26-4))| (((d) & 0x40)<<(24-6))| (((d) & 0x80)<<(23-7))); \
|
PIO_Set(PIOC, (((d)&0x01) << (22 - 0)) | (((d)&0x02) << (21 - 1)) | \
|
||||||
PIO_Clear(PIOC, (((~d) & 0x01)<<(22-0)) | (((~d) & 0x02)<<(21-1))| (((~d) & 0x04)<<(29-2))| (((~d) & 0x10)<<(26-4))| (((~d) & 0x40)<<(24-6))| (((~d) & 0x80)<<(23-7))); \
|
(((d)&0x04) << (29 - 2)) | (((d)&0x10) << (26 - 4)) | \
|
||||||
|
(((d)&0x40) << (24 - 6)) | (((d)&0x80) << (23 - 7))); \
|
||||||
|
PIO_Clear(PIOC, \
|
||||||
|
(((~d) & 0x01) << (22 - 0)) | (((~d) & 0x02) << (21 - 1)) | \
|
||||||
|
(((~d) & 0x04) << (29 - 2)) | (((~d) & 0x10) << (26 - 4)) | \
|
||||||
|
(((~d) & 0x40) << (24 - 6)) | (((~d) & 0x80) << (23 - 7))); \
|
||||||
PIO_Set(PIOB, (((d)&0x20) << (27 - 5))); \
|
PIO_Set(PIOB, (((d)&0x20) << (27 - 5))); \
|
||||||
PIO_Clear(PIOB, (((~d) & 0x20) << (27 - 5))); \
|
PIO_Clear(PIOB, (((~d) & 0x20) << (27 - 5))); \
|
||||||
WR_STROBE; }
|
WR_STROBE; \
|
||||||
|
}
|
||||||
|
|
||||||
#define read8inline(result) { \
|
#define read8inline(result) \
|
||||||
|
{ \
|
||||||
|
\
|
||||||
RD_ACTIVE; \
|
RD_ACTIVE; \
|
||||||
delayMicroseconds(1); \
|
delayMicroseconds(1); \
|
||||||
result = (((PIOC->PIO_PDSR & (1<<23)) >> (23-7)) | ((PIOC->PIO_PDSR & (1<<24)) >> (24-6)) | \
|
result = (((PIOC->PIO_PDSR & (1 << 23)) >> (23 - 7)) | \
|
||||||
((PIOB->PIO_PDSR & (1<<27)) >> (27-5)) | ((PIOC->PIO_PDSR & (1<<26)) >> (26-4)) | \
|
((PIOC->PIO_PDSR & (1 << 24)) >> (24 - 6)) | \
|
||||||
((PIOD->PIO_PDSR & (1<< 7)) >> ( 7-3)) | ((PIOC->PIO_PDSR & (1<<29)) >> (29-2)) | \
|
((PIOB->PIO_PDSR & (1 << 27)) >> (27 - 5)) | \
|
||||||
((PIOC->PIO_PDSR & (1<<21)) >> (21-1)) | ((PIOC->PIO_PDSR & (1<<22)) >> (22-0))); \
|
((PIOC->PIO_PDSR & (1 << 26)) >> (26 - 4)) | \
|
||||||
RD_IDLE;}
|
((PIOD->PIO_PDSR & (1 << 7)) >> (7 - 3)) | \
|
||||||
|
((PIOC->PIO_PDSR & (1 << 29)) >> (29 - 2)) | \
|
||||||
|
((PIOC->PIO_PDSR & (1 << 21)) >> (21 - 1)) | \
|
||||||
|
((PIOC->PIO_PDSR & (1 << 22)) >> (22 - 0))); \
|
||||||
|
RD_IDLE; \
|
||||||
|
}
|
||||||
|
|
||||||
#define setWriteDirInline() { \
|
#define setWriteDirInline() \
|
||||||
PIOD->PIO_MDDR |= 0x00000080; /*PIOD->PIO_SODR = 0x00000080;*/ PIOD->PIO_OER |= 0x00000080; PIOD->PIO_PER |= 0x00000080; \
|
{ \
|
||||||
PIOC->PIO_MDDR |= 0x25E00000; /*PIOC->PIO_SODR = 0x25E00000;*/ PIOC->PIO_OER |= 0x25E00000; PIOC->PIO_PER |= 0x25E00000; \
|
PIOD->PIO_MDDR |= 0x00000080; /*PIOD->PIO_SODR = 0x00000080;*/ \
|
||||||
PIOB->PIO_MDDR |= 0x08000000; /*PIOB->PIO_SODR = 0x08000000;*/ PIOB->PIO_OER |= 0x08000000; PIOB->PIO_PER |= 0x08000000; }
|
PIOD->PIO_OER |= 0x00000080; \
|
||||||
|
PIOD->PIO_PER |= 0x00000080; \
|
||||||
|
PIOC->PIO_MDDR |= 0x25E00000; /*PIOC->PIO_SODR = 0x25E00000;*/ \
|
||||||
|
PIOC->PIO_OER |= 0x25E00000; \
|
||||||
|
PIOC->PIO_PER |= 0x25E00000; \
|
||||||
|
PIOB->PIO_MDDR |= 0x08000000; /*PIOB->PIO_SODR = 0x08000000;*/ \
|
||||||
|
PIOB->PIO_OER |= 0x08000000; \
|
||||||
|
PIOB->PIO_PER |= 0x08000000; \
|
||||||
|
}
|
||||||
|
|
||||||
#define setReadDirInline() { \
|
#define setReadDirInline() \
|
||||||
pmc_enable_periph_clk( ID_PIOD ) ; pmc_enable_periph_clk( ID_PIOC ) ; pmc_enable_periph_clk( ID_PIOB ) ; \
|
{ \
|
||||||
PIOD->PIO_PUDR |= 0x00000080; PIOD->PIO_IFDR |= 0x00000080; PIOD->PIO_ODR |= 0x00000080; PIOD->PIO_PER |= 0x00000080; \
|
pmc_enable_periph_clk(ID_PIOD); \
|
||||||
PIOC->PIO_PUDR |= 0x25E00000; PIOC->PIO_IFDR |= 0x25E00000; PIOC->PIO_ODR |= 0x25E00000; PIOC->PIO_PER |= 0x25E00000; \
|
pmc_enable_periph_clk(ID_PIOC); \
|
||||||
PIOB->PIO_PUDR |= 0x08000000; PIOB->PIO_IFDR |= 0x08000000; PIOB->PIO_ODR |= 0x08000000; PIOB->PIO_PER |= 0x08000000; }
|
pmc_enable_periph_clk(ID_PIOB); \
|
||||||
|
PIOD->PIO_PUDR |= 0x00000080; \
|
||||||
|
PIOD->PIO_IFDR |= 0x00000080; \
|
||||||
|
PIOD->PIO_ODR |= 0x00000080; \
|
||||||
|
PIOD->PIO_PER |= 0x00000080; \
|
||||||
|
PIOC->PIO_PUDR |= 0x25E00000; \
|
||||||
|
PIOC->PIO_IFDR |= 0x25E00000; \
|
||||||
|
PIOC->PIO_ODR |= 0x25E00000; \
|
||||||
|
PIOC->PIO_PER |= 0x25E00000; \
|
||||||
|
PIOB->PIO_PUDR |= 0x08000000; \
|
||||||
|
PIOB->PIO_IFDR |= 0x08000000; \
|
||||||
|
PIOB->PIO_ODR |= 0x08000000; \
|
||||||
|
PIOB->PIO_PER |= 0x08000000; \
|
||||||
|
}
|
||||||
|
|
||||||
// Control signals are ACTIVE LOW (idle is HIGH)
|
// Control signals are ACTIVE LOW (idle is HIGH)
|
||||||
// Command/Data: LOW = command, HIGH = data
|
// Command/Data: LOW = command, HIGH = data
|
||||||
|
|
@ -311,26 +417,38 @@
|
||||||
#define CS_ACTIVE CS_PORT->PIO_CODR |= CS_MASK
|
#define CS_ACTIVE CS_PORT->PIO_CODR |= CS_MASK
|
||||||
#define CS_IDLE CS_PORT->PIO_SODR |= CS_MASK
|
#define CS_IDLE CS_PORT->PIO_SODR |= CS_MASK
|
||||||
|
|
||||||
|
|
||||||
#else // Due w/Breakout board
|
#else // Due w/Breakout board
|
||||||
|
|
||||||
#define write8inline(d) { \
|
#define write8inline(d) \
|
||||||
|
{ \
|
||||||
PIO_Set(PIOC, (((d)&0xFF) << 1)); \
|
PIO_Set(PIOC, (((d)&0xFF) << 1)); \
|
||||||
PIO_Clear(PIOC, (((~d) & 0xFF) << 1)); \
|
PIO_Clear(PIOC, (((~d) & 0xFF) << 1)); \
|
||||||
WR_STROBE; }
|
WR_STROBE; \
|
||||||
|
}
|
||||||
|
|
||||||
#define read8inline(result) { \
|
#define read8inline(result) \
|
||||||
|
{ \
|
||||||
RD_ACTIVE; \
|
RD_ACTIVE; \
|
||||||
delayMicroseconds(1); \
|
delayMicroseconds(1); \
|
||||||
result = ((PIOC->PIO_PDSR & 0x1FE) >> 1); \
|
result = ((PIOC->PIO_PDSR & 0x1FE) >> 1); \
|
||||||
RD_IDLE;}
|
RD_IDLE; \
|
||||||
|
}
|
||||||
|
|
||||||
#define setWriteDirInline() { \
|
#define setWriteDirInline() \
|
||||||
PIOC->PIO_MDDR |= 0x000001FE; /*PIOC->PIO_SODR |= 0x000001FE;*/ PIOC->PIO_OER |= 0x000001FE; PIOC->PIO_PER |= 0x000001FE; }
|
{ \
|
||||||
|
PIOC->PIO_MDDR |= 0x000001FE; /*PIOC->PIO_SODR |= 0x000001FE;*/ \
|
||||||
|
PIOC->PIO_OER |= 0x000001FE; \
|
||||||
|
PIOC->PIO_PER |= 0x000001FE; \
|
||||||
|
}
|
||||||
|
|
||||||
#define setReadDirInline() { \
|
#define setReadDirInline() \
|
||||||
|
{ \
|
||||||
pmc_enable_periph_clk(ID_PIOC); \
|
pmc_enable_periph_clk(ID_PIOC); \
|
||||||
PIOC->PIO_PUDR |= 0x000001FE; PIOC->PIO_IFDR |= 0x000001FE; PIOC->PIO_ODR |= 0x000001FE; PIOC->PIO_PER |= 0x000001FE; }
|
PIOC->PIO_PUDR |= 0x000001FE; \
|
||||||
|
PIOC->PIO_IFDR |= 0x000001FE; \
|
||||||
|
PIOC->PIO_ODR |= 0x000001FE; \
|
||||||
|
PIOC->PIO_PER |= 0x000001FE; \
|
||||||
|
}
|
||||||
|
|
||||||
// When using the TFT breakout board, control pins are configurable.
|
// When using the TFT breakout board, control pins are configurable.
|
||||||
#define RD_ACTIVE rdPort->PIO_CODR |= rdPinSet // PIO_Clear(rdPort, rdPinSet)
|
#define RD_ACTIVE rdPort->PIO_CODR |= rdPinSet // PIO_Clear(rdPort, rdPinSet)
|
||||||
|
|
@ -344,7 +462,6 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#error "Board type unsupported / not recognized"
|
#error "Board type unsupported / not recognized"
|
||||||
|
|
@ -384,26 +501,53 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Data write strobe, ~2 instructions and always inline
|
// Data write strobe, ~2 instructions and always inline
|
||||||
#define WR_STROBE { WR_ACTIVE; WR_IDLE; }
|
#define WR_STROBE \
|
||||||
|
{ \
|
||||||
|
WR_ACTIVE; \
|
||||||
|
WR_IDLE; \
|
||||||
|
}
|
||||||
|
|
||||||
// These higher-level operations are usually functionalized,
|
// These higher-level operations are usually functionalized,
|
||||||
// except on Mega where's there's gobs and gobs of program space.
|
// except on Mega where's there's gobs and gobs of program space.
|
||||||
|
|
||||||
// Set value of TFT register: 8-bit address, 8-bit value
|
// Set value of TFT register: 8-bit address, 8-bit value
|
||||||
#define writeRegister8inline(a, d) { \
|
#define writeRegister8inline(a, d) \
|
||||||
CD_COMMAND; write8(a); CD_DATA; write8(d); }
|
{ \
|
||||||
|
CD_COMMAND; \
|
||||||
|
write8(a); \
|
||||||
|
CD_DATA; \
|
||||||
|
write8(d); \
|
||||||
|
}
|
||||||
|
|
||||||
// Set value of TFT register: 16-bit address, 16-bit value
|
// Set value of TFT register: 16-bit address, 16-bit value
|
||||||
// See notes at top about macro expansion, hence hi & lo temp vars
|
// See notes at top about macro expansion, hence hi & lo temp vars
|
||||||
#define writeRegister16inline(a, d) { \
|
#define writeRegister16inline(a, d) \
|
||||||
|
{ \
|
||||||
uint8_t hi, lo; \
|
uint8_t hi, lo; \
|
||||||
hi = (a) >> 8; lo = (a); CD_COMMAND; write8(hi); write8(lo); \
|
hi = (a) >> 8; \
|
||||||
hi = (d) >> 8; lo = (d); CD_DATA ; write8(hi); write8(lo); }
|
lo = (a); \
|
||||||
|
CD_COMMAND; \
|
||||||
|
write8(hi); \
|
||||||
|
write8(lo); \
|
||||||
|
hi = (d) >> 8; \
|
||||||
|
lo = (d); \
|
||||||
|
CD_DATA; \
|
||||||
|
write8(hi); \
|
||||||
|
write8(lo); \
|
||||||
|
}
|
||||||
|
|
||||||
// Set value of 2 TFT registers: Two 8-bit addresses (hi & lo), 16-bit value
|
// Set value of 2 TFT registers: Two 8-bit addresses (hi & lo), 16-bit value
|
||||||
#define writeRegisterPairInline(aH, aL, d) { \
|
#define writeRegisterPairInline(aH, aL, d) \
|
||||||
|
{ \
|
||||||
uint8_t hi = (d) >> 8, lo = (d); \
|
uint8_t hi = (d) >> 8, lo = (d); \
|
||||||
CD_COMMAND; write8(aH); CD_DATA; write8(hi); \
|
CD_COMMAND; \
|
||||||
CD_COMMAND; write8(aL); CD_DATA; write8(lo); }
|
write8(aH); \
|
||||||
|
CD_DATA; \
|
||||||
|
write8(hi); \
|
||||||
|
CD_COMMAND; \
|
||||||
|
write8(aL); \
|
||||||
|
CD_DATA; \
|
||||||
|
write8(lo); \
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _pin_magic_
|
#endif // _pin_magic_
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,6 @@
|
||||||
#define HX8347G_ROWADDREND_LO 0x09
|
#define HX8347G_ROWADDREND_LO 0x09
|
||||||
#define HX8347G_MEMACCESS 0x16
|
#define HX8347G_MEMACCESS 0x16
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define ILI9341_SOFTRESET 0x01
|
#define ILI9341_SOFTRESET 0x01
|
||||||
#define ILI9341_SLEEPIN 0x10
|
#define ILI9341_SLEEPIN 0x10
|
||||||
#define ILI9341_SLEEPOUT 0x11
|
#define ILI9341_SLEEPOUT 0x11
|
||||||
|
|
@ -93,8 +91,6 @@
|
||||||
#define ILI9341_MADCTL_BGR 0x08
|
#define ILI9341_MADCTL_BGR 0x08
|
||||||
#define ILI9341_MADCTL_MH 0x04
|
#define ILI9341_MADCTL_MH 0x04
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define HX8357_NOP 0x00
|
#define HX8357_NOP 0x00
|
||||||
#define HX8357_SWRESET 0x01
|
#define HX8357_SWRESET 0x01
|
||||||
#define HX8357_RDDID 0x04
|
#define HX8357_RDDID 0x04
|
||||||
|
|
@ -148,7 +144,6 @@
|
||||||
#define HX8357B_SETCABC 0xC9
|
#define HX8357B_SETCABC 0xC9
|
||||||
#define HX8357_SETPANEL 0xCC
|
#define HX8357_SETPANEL 0xCC
|
||||||
|
|
||||||
|
|
||||||
#define HX8357B_SETPOWER 0xD0
|
#define HX8357B_SETPOWER 0xD0
|
||||||
#define HX8357B_SETVCOM 0xD1
|
#define HX8357B_SETVCOM 0xD1
|
||||||
#define HX8357B_SETPWRNORMAL 0xD2
|
#define HX8357B_SETPWRNORMAL 0xD2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue