Merge branch 'master' of github.com:adafruit/TFTLCD-Library

Conflicts:
	Adafruit_TFTLCD.cpp
	Adafruit_TFTLCD.h
This commit is contained in:
ladyada
2014-03-17 21:23:22 -04:00
10 changed files with 630 additions and 152 deletions
+81 -43
View File
@@ -4,8 +4,14 @@
// Graphics library by ladyada/adafruit with init code from Rossum
// MIT license
#if defined(__SAM3X8E__)
#include <include/pio.h>
#define PROGMEM
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
#endif
#ifdef __AVR__
#include <avr/pgmspace.h>
#include <avr/pgmspace.h>
#endif
#include "pins_arduino.h"
#include "wiring_private.h"
@@ -32,10 +38,18 @@ Adafruit_TFTLCD::Adafruit_TFTLCD(
#ifndef USE_ADAFRUIT_SHIELD_PINOUT
// Convert pin numbers to registers and bitmasks
_reset = reset;
csPort = portOutputRegister(digitalPinToPort(cs));
cdPort = portOutputRegister(digitalPinToPort(cd));
wrPort = portOutputRegister(digitalPinToPort(wr));
rdPort = portOutputRegister(digitalPinToPort(rd));
#ifdef __AVR__
csPort = portOutputRegister(digitalPinToPort(cs));
cdPort = portOutputRegister(digitalPinToPort(cd));
wrPort = portOutputRegister(digitalPinToPort(wr));
rdPort = portOutputRegister(digitalPinToPort(rd));
#endif
#if defined(__SAM3X8E__)
csPort = digitalPinToPort(cs);
cdPort = digitalPinToPort(cd);
wrPort = digitalPinToPort(wr);
rdPort = digitalPinToPort(rd);
#endif
csPinSet = digitalPinToBitMask(cs);
cdPinSet = digitalPinToBitMask(cd);
wrPinSet = digitalPinToBitMask(wr);
@@ -44,10 +58,18 @@ Adafruit_TFTLCD::Adafruit_TFTLCD(
cdPinUnset = ~cdPinSet;
wrPinUnset = ~wrPinSet;
rdPinUnset = ~rdPinSet;
*csPort |= csPinSet; // Set all control bits to HIGH (idle)
*cdPort |= cdPinSet; // Signals are ACTIVE LOW
*wrPort |= wrPinSet;
*rdPort |= rdPinSet;
#ifdef __AVR__
*csPort |= csPinSet; // Set all control bits to HIGH (idle)
*cdPort |= cdPinSet; // Signals are ACTIVE LOW
*wrPort |= wrPinSet;
*rdPort |= rdPinSet;
#endif
#if defined(__SAM3X8E__)
csPort->PIO_SODR |= csPinSet; // Set all control bits to HIGH (idle)
cdPort->PIO_SODR |= cdPinSet; // Signals are ACTIVE LOW
wrPort->PIO_SODR |= wrPinSet;
rdPort->PIO_SODR |= rdPinSet;
#endif
pinMode(cs, OUTPUT); // Enable outputs
pinMode(cd, OUTPUT);
pinMode(wr, OUTPUT);
@@ -268,7 +290,7 @@ void Adafruit_TFTLCD::begin(uint16_t id) {
void Adafruit_TFTLCD::reset(void) {
CS_IDLE;
CD_DATA;
// CD_DATA;
WR_IDLE;
RD_IDLE;
@@ -284,12 +306,12 @@ void Adafruit_TFTLCD::reset(void) {
}
#endif
// Data transfer sync
CS_ACTIVE;
CD_DATA;
CD_COMMAND;
write8(0x00);
for(uint8_t i=0; i<7; i++) WR_STROBE;
for(uint8_t i=0; i<3; i++) WR_STROBE; // Three extra 0x00s
CS_IDLE;
delay(100);
}
// Sets the LCD address window (and address counter, on 932X).
@@ -674,19 +696,22 @@ void Adafruit_TFTLCD::setRotation(uint8_t x) {
}
}
#ifdef read8isFunctionalized
#define read8(x) x=read8fn()
#endif
// Because this function is used infrequently, it configures the ports for
// the read operation, reads the data, then restores the ports to the write
// configuration. Write operations happen a LOT, so it's advantageous to
// leave the ports in that state as a default.
uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) {
uint16_t c;
if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return 0;
CS_ACTIVE;
if(driver == ID_932X) {
uint8_t hi, lo;
int16_t t;
switch(rotation) {
case 1:
@@ -706,29 +731,46 @@ uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) {
}
writeRegister16(0x0020, x);
writeRegister16(0x0021, y);
CD_COMMAND; write8(0x00); write8(0x22); // Read data from GRAM
// Inexplicable thing: sometimes pixel read has high/low bytes
// reversed. A second read fixes this. Unsure of reason. Have
// tried adjusting timing in read8() etc. to no avail.
for(uint8_t pass=0; pass<2; pass++) {
CD_COMMAND; write8(0x00); write8(0x22); // Read data from GRAM
CD_DATA;
setReadDir(); // Set up LCD data port(s) for READ operations
read8(hi); // First 2 bytes back are a dummy read
read8(hi);
read8(hi); // Bytes 3, 4 are actual pixel value
read8(lo);
setWriteDir(); // Restore LCD data port(s) to WRITE configuration
}
CS_IDLE;
return ((uint16_t)hi << 8) | lo;
} else if(driver == ID_7575) {
uint8_t r, g, b;
writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x);
writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y);
CD_COMMAND; write8(0x22); // Read data from GRAM
}
setReadDir(); // Set up LCD data port(s) for READ operations
CD_DATA;
c = read8(); // Do not merge or otherwise simplify
c <<= 8; // these lines. It's an unfortunate
delayMicroseconds(1); // artifact of the macro substitution
c |= read8(); // shenanigans that are going on.
setWriteDir(); // Restore LCD data port(s) to WRITE configuration
CS_IDLE;
return c;
setReadDir(); // Set up LCD data port(s) for READ operations
CD_DATA;
read8(r); // First byte back is a dummy read
read8(r);
read8(g);
read8(b);
setWriteDir(); // Restore LCD data port(s) to WRITE configuration
CS_IDLE;
return (((uint16_t)r & B11111000) << 8) |
(((uint16_t)g & B11111100) << 3) |
( b >> 3);
} else return 0;
}
// Ditto with the read/write port directions, as above.
uint16_t Adafruit_TFTLCD::readID(void) {
uint16_t id;
uint8_t hi, lo;
id = readReg(0xD3);
if (id == 0x9341) {
@@ -738,19 +780,15 @@ uint16_t Adafruit_TFTLCD::readID(void) {
CS_ACTIVE;
CD_COMMAND;
write8(0x00);
write8(0x00);
WR_STROBE; // Repeat prior byte (0x00)
setReadDir(); // Set up LCD data port(s) for READ operations
CD_DATA;
delayMicroseconds(10);
id = read8(); // Do not merge or otherwise simplify
id <<= 8; // these lines. It's an unfortunate
delayMicroseconds(10); // artifact of the macro substitution
id |= read8(); // shenanigans that are going on.
CS_IDLE;
read8(hi);
read8(lo);
setWriteDir(); // Restore LCD data port(s) to WRITE configuration
CS_IDLE;
return id;
return (hi << 8) | lo;
}
uint32_t Adafruit_TFTLCD::readReg(uint8_t r) {
@@ -795,11 +833,11 @@ void Adafruit_TFTLCD::write8(uint8_t value) {
}
#endif
#ifndef read8
uint8_t Adafruit_TFTLCD::read8(void) {
// Do not merge or simplify -- macro shenanigans going on!
uint8_t d = read8inline();
return d;
#ifdef read8isFunctionalized
uint8_t Adafruit_TFTLCD::read8fn(void) {
uint8_t result;
read8inline(result);
return result;
}
#endif