Part of the previous commit, github didn't catch this first.

This commit is contained in:
victorpv 2015-03-18 08:59:25 -05:00
parent fcdd15e0ad
commit cbfb5d40b0
3 changed files with 0 additions and 929 deletions

View File

@ -1,652 +0,0 @@
/*
See rights and use declaration in License.h
This library has been modified for the Maple Mini
*/
#include ".\Adafruit_ILI9341_AS.h"
#include <avr/pgmspace.h>
#include <limits.h>
#include "pins_arduino.h"
#include "wiring_private.h"
#include <SPI.h> // Using library SPI in folder: D:\Documents\Arduino\hardware\STM32\STM32F1XX\libraries\SPI
// Constructor when using software SPI. All output pins are configurable.
Adafruit_ILI9341_AS::Adafruit_ILI9341_AS(int8_t cs, int8_t dc, int8_t mosi,
int8_t sclk, int8_t rst, int8_t miso) : Adafruit_GFX_AS(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
_cs = cs;
_dc = dc;
_mosi = mosi;
_miso = miso;
_sclk = sclk;
_rst = rst;
hwSPI = false;
}
// 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.)
Adafruit_ILI9341_AS::Adafruit_ILI9341_AS(int8_t cs, int8_t dc, int8_t rst) : Adafruit_GFX_AS(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
_cs = cs;
_dc = dc;
_rst = rst;
hwSPI = true;
_mosi = _sclk = 0;
}
void Adafruit_ILI9341_AS::spiwrite(uint8_t c) {
//Serial.print("0x"); Serial.print(c, HEX); Serial.print(", ");
if (hwSPI)
{
#if defined (__AVR__)
uint8_t backupSPCR = SPCR;
SPCR = mySPCR;
SPDR = c;
while(!(SPSR & _BV(SPIF)));
SPCR = backupSPCR;
#elif defined(TEENSYDUINO)
SPI.transfer(c);
#elif defined (__STM32F1__)
SPI.transfer(c);
#elif defined (__arm__)
SPI.setClockDivider(11); // 8-ish MHz (full! speed!)
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.transfer(c);
#endif
} else {
// Fast SPI bitbang swiped from LPD8806 library
for(uint8_t bit = 0x80; bit; bit >>= 1) {
if(c & bit) {
//digitalWrite(_mosi, HIGH);
*mosiport |= mosipinmask;
} else {
//digitalWrite(_mosi, LOW);
*mosiport &= ~mosipinmask;
}
//digitalWrite(_sclk, HIGH);
*clkport |= clkpinmask;
//digitalWrite(_sclk, LOW);
*clkport &= ~clkpinmask;
}
}
}
void Adafruit_ILI9341_AS::writecommand(uint8_t c) {
*dcport &= ~dcpinmask;
//digitalWrite(_dc, LOW);
//*clkport &= ~clkpinmask; // clkport is a NULL pointer when hwSPI==true
//digitalWrite(_sclk, LOW);
*csport &= ~cspinmask;
//digitalWrite(_cs, LOW);
spiwrite(c);
*csport |= cspinmask;
//digitalWrite(_cs, HIGH);
}
void Adafruit_ILI9341_AS::writedata(uint8_t c) {
*dcport |= dcpinmask;
//digitalWrite(_dc, HIGH);
//*clkport &= ~clkpinmask; // clkport is a NULL pointer when hwSPI==true
//digitalWrite(_sclk, LOW);
*csport &= ~cspinmask;
//digitalWrite(_cs, LOW);
spiwrite(c);
//digitalWrite(_cs, HIGH);
*csport |= cspinmask;
}
// If the SPI library has transaction support, these functions
// establish settings and protect from interference from other
// libraries. Otherwise, they simply do nothing.
#ifdef SPI_HAS_TRANSACTION
static inline void spi_begin(void) __attribute__((always_inline));
static inline void spi_begin(void) {
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
}
static inline void spi_end(void) __attribute__((always_inline));
static inline void spi_end(void) {
SPI.endTransaction();
}
#else
#define spi_begin()
#define spi_end()
#endif
// Rather than a bazillion writecommand() and writedata() calls, screen
// initialization commands and arguments are organized in these tables
// stored in PROGMEM. The table may look bulky, but that's mostly the
// formatting -- storage-wise this is hundreds of bytes more compact
// than the equivalent code. Companion function follows.
#define DELAY 0x80
// Companion code to the above tables. Reads and issues
// a series of LCD commands stored in PROGMEM byte array.
void Adafruit_ILI9341_AS::commandList(uint8_t *addr) {
uint8_t numCommands, numArgs;
uint16_t ms;
numCommands = pgm_read_byte(addr++); // Number of commands to follow
while(numCommands--) { // For each command...
writecommand(pgm_read_byte(addr++)); // Read, issue command
numArgs = pgm_read_byte(addr++); // Number of args to follow
ms = numArgs & DELAY; // If hibit set, delay follows args
numArgs &= ~DELAY; // Mask out delay bit
while(numArgs--) { // For each argument...
writedata(pgm_read_byte(addr++)); // Read, issue argument
}
if(ms) {
ms = pgm_read_byte(addr++); // Read post-command delay time (ms)
if(ms == 255) ms = 500; // If 255, delay for 500 ms
delay(ms);
}
}
}
void Adafruit_ILI9341_AS::begin(void) {
if (_rst > 0) {
pinMode(_rst, OUTPUT);
digitalWrite(_rst, LOW);
}
pinMode(_dc, OUTPUT);
pinMode(_cs, OUTPUT);
csport = portOutputRegister(digitalPinToPort(_cs));
cspinmask = digitalPinToBitMask(_cs);
dcport = portOutputRegister(digitalPinToPort(_dc));
dcpinmask = digitalPinToBitMask(_dc);
if(hwSPI) { // Using hardware SPI
#if defined (__AVR__)
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!)
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
mySPCR = SPCR;
#elif defined(TEENSYDUINO)
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!)
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
#elif defined (__STM32F1__)
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
#elif defined (__arm__)
SPI.begin();
SPI.setClockDivider(11); // 8-ish MHz (full! speed!)
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
#endif
} else {
pinMode(_sclk, OUTPUT);
pinMode(_mosi, OUTPUT);
pinMode(_miso, INPUT);
clkport = portOutputRegister(digitalPinToPort(_sclk));
clkpinmask = digitalPinToBitMask(_sclk);
mosiport = portOutputRegister(digitalPinToPort(_mosi));
mosipinmask = digitalPinToBitMask(_mosi);
*clkport &= ~clkpinmask;
*mosiport &= ~mosipinmask;
}
// toggle RST low to reset
if (_rst > 0) {
digitalWrite(_rst, HIGH);
delay(5);
digitalWrite(_rst, LOW);
delay(20);
digitalWrite(_rst, HIGH);
delay(150);
}
/*
uint8_t x = readcommand8(ILI9341_RDMODE);
Serial.print("\nDisplay Power Mode: 0x"); Serial.println(x, HEX);
x = readcommand8(ILI9341_RDMADCTL);
Serial.print("\nMADCTL Mode: 0x"); Serial.println(x, HEX);
x = readcommand8(ILI9341_RDPIXFMT);
Serial.print("\nPixel Format: 0x"); Serial.println(x, HEX);
x = readcommand8(ILI9341_RDIMGFMT);
Serial.print("\nImage Format: 0x"); Serial.println(x, HEX);
x = readcommand8(ILI9341_RDSELFDIAG);
Serial.print("\nSelf Diagnostic: 0x"); Serial.println(x, HEX);
*/
//if(cmdList) commandList(cmdList);
if (hwSPI) spi_begin();
writecommand(0xEF);
writedata(0x03);
writedata(0x80);
writedata(0x02);
writecommand(0xCF);
writedata(0x00);
writedata(0XC1);
writedata(0X30);
writecommand(0xED);
writedata(0x64);
writedata(0x03);
writedata(0X12);
writedata(0X81);
writecommand(0xE8);
writedata(0x85);
writedata(0x00);
writedata(0x78);
writecommand(0xCB);
writedata(0x39);
writedata(0x2C);
writedata(0x00);
writedata(0x34);
writedata(0x02);
writecommand(0xF7);
writedata(0x20);
writecommand(0xEA);
writedata(0x00);
writedata(0x00);
writecommand(ILI9341_PWCTR1); //Power control
writedata(0x23); //VRH[5:0]
writecommand(ILI9341_PWCTR2); //Power control
writedata(0x10); //SAP[2:0];BT[3:0]
writecommand(ILI9341_VMCTR1); //VCM control
writedata(0x3e); //<2F>Աȶȵ<C8B6><C8B5><EFBFBD>
writedata(0x28);
writecommand(ILI9341_VMCTR2); //VCM control2
writedata(0x86); //--
writecommand(ILI9341_MADCTL); // Memory Access Control
writedata(0x48);
writecommand(ILI9341_PIXFMT);
writedata(0x55);
writecommand(ILI9341_FRMCTR1);
writedata(0x00);
writedata(0x18);
writecommand(ILI9341_DFUNCTR); // Display Function Control
writedata(0x08);
writedata(0x82);
writedata(0x27);
writecommand(0xF2); // 3Gamma Function Disable
writedata(0x00);
writecommand(ILI9341_GAMMASET); //Gamma curve selected
writedata(0x01);
writecommand(ILI9341_GMCTRP1); //Set Gamma
writedata(0x0F);
writedata(0x31);
writedata(0x2B);
writedata(0x0C);
writedata(0x0E);
writedata(0x08);
writedata(0x4E);
writedata(0xF1);
writedata(0x37);
writedata(0x07);
writedata(0x10);
writedata(0x03);
writedata(0x0E);
writedata(0x09);
writedata(0x00);
writecommand(ILI9341_GMCTRN1); //Set Gamma
writedata(0x00);
writedata(0x0E);
writedata(0x14);
writedata(0x03);
writedata(0x11);
writedata(0x07);
writedata(0x31);
writedata(0xC1);
writedata(0x48);
writedata(0x08);
writedata(0x0F);
writedata(0x0C);
writedata(0x31);
writedata(0x36);
writedata(0x0F);
writecommand(ILI9341_SLPOUT); //Exit Sleep
if (hwSPI) spi_end();
delay(120);
if (hwSPI) spi_begin();
writecommand(ILI9341_DISPON); //Display on
if (hwSPI) spi_end();
}
void Adafruit_ILI9341_AS::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
uint16_t y1) {
writecommand(ILI9341_CASET); // Column addr set
writedata(x0 >> 8);
writedata(x0 & 0xFF); // XSTART
writedata(x1 >> 8);
writedata(x1 & 0xFF); // XEND
writecommand(ILI9341_PASET); // Row addr set
writedata(y0>>8);
writedata(y0); // YSTART
writedata(y1>>8);
writedata(y1); // YEND
writecommand(ILI9341_RAMWR); // write to RAM
}
void Adafruit_ILI9341_AS::pushColor(uint16_t color) {
if (hwSPI) spi_begin();
//digitalWrite(_dc, HIGH);
*dcport |= dcpinmask;
//digitalWrite(_cs, LOW);
*csport &= ~cspinmask;
spiwrite(color >> 8);
spiwrite(color);
*csport |= cspinmask;
//digitalWrite(_cs, HIGH);
if (hwSPI) spi_end();
}
void Adafruit_ILI9341_AS::drawPixel(int16_t x, int16_t y, uint16_t color) {
if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;
if (hwSPI) spi_begin();
setAddrWindow(x,y,x+1,y+1);
//digitalWrite(_dc, HIGH);
*dcport |= dcpinmask;
//digitalWrite(_cs, LOW);
*csport &= ~cspinmask;
spiwrite(color >> 8);
spiwrite(color);
*csport |= cspinmask;
//digitalWrite(_cs, HIGH);
if (hwSPI) spi_end();
}
void Adafruit_ILI9341_AS::drawFastVLine(int16_t x, int16_t y, int16_t h,
uint16_t color) {
// Rudimentary clipping
if((x >= _width) || (y >= _height)) return;
if((y+h-1) >= _height)
h = _height-y;
if (hwSPI) spi_begin();
setAddrWindow(x, y, x, y+h-1);
uint8_t hi = color >> 8, lo = color;
*dcport |= dcpinmask;
//digitalWrite(_dc, HIGH);
*csport &= ~cspinmask;
//digitalWrite(_cs, LOW);
while (h--) {
spiwrite(hi);
spiwrite(lo);
}
*csport |= cspinmask;
//digitalWrite(_cs, HIGH);
if (hwSPI) spi_end();
}
void Adafruit_ILI9341_AS::drawFastHLine(int16_t x, int16_t y, int16_t w,
uint16_t color) {
// Rudimentary clipping
if((x >= _width) || (y >= _height)) return;
if((x+w-1) >= _width) w = _width-x;
if (hwSPI) spi_begin();
setAddrWindow(x, y, x+w-1, y);
uint8_t hi = color >> 8, lo = color;
*dcport |= dcpinmask;
*csport &= ~cspinmask;
//digitalWrite(_dc, HIGH);
//digitalWrite(_cs, LOW);
while (w--) {
spiwrite(hi);
spiwrite(lo);
}
*csport |= cspinmask;
//digitalWrite(_cs, HIGH);
if (hwSPI) spi_end();
}
void Adafruit_ILI9341_AS::fillScreen(uint16_t color) {
fillRect(0, 0, _width, _height, color);
}
// fill a rectangle
void Adafruit_ILI9341_AS::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color) {
// rudimentary clipping (drawChar w/big text requires this)
if((x >= _width) || (y >= _height)) return;
if((x + w - 1) >= _width) w = _width - x;
if((y + h - 1) >= _height) h = _height - y;
if (hwSPI) spi_begin();
setAddrWindow(x, y, x+w-1, y+h-1);
uint8_t hi = color >> 8, lo = color;
*dcport |= dcpinmask;
//digitalWrite(_dc, HIGH);
*csport &= ~cspinmask;
//digitalWrite(_cs, LOW);
for(y=h; y>0; y--) {
for(x=w; x>0; x--) {
spiwrite(hi);
spiwrite(lo);
}
}
//digitalWrite(_cs, HIGH);
*csport |= cspinmask;
if (hwSPI) spi_end();
}
// Pass 8-bit (each) R,G,B, get back 16-bit packed color
uint16_t Adafruit_ILI9341_AS::color565(uint8_t r, uint8_t g, uint8_t b) {
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}
#define MADCTL_MY 0x80
#define MADCTL_MX 0x40
#define MADCTL_MV 0x20
#define MADCTL_ML 0x10
#define MADCTL_RGB 0x00
#define MADCTL_BGR 0x08
#define MADCTL_MH 0x04
void Adafruit_ILI9341_AS::setRotation(uint8_t m) {
if (hwSPI) spi_begin();
writecommand(ILI9341_MADCTL);
rotation = m % 4; // can't be higher than 3
switch (rotation) {
case 0:
writedata(MADCTL_MX | MADCTL_BGR);
_width = ILI9341_TFTWIDTH;
_height = ILI9341_TFTHEIGHT;
break;
case 1:
writedata(MADCTL_MV | MADCTL_BGR);
_width = ILI9341_TFTHEIGHT;
_height = ILI9341_TFTWIDTH;
break;
case 2:
writedata(MADCTL_MY | MADCTL_BGR);
_width = ILI9341_TFTWIDTH;
_height = ILI9341_TFTHEIGHT;
break;
case 3:
writedata(MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR);
_width = ILI9341_TFTHEIGHT;
_height = ILI9341_TFTWIDTH;
break;
}
if (hwSPI) spi_end();
}
void Adafruit_ILI9341_AS::invertDisplay(boolean i) {
if (hwSPI) spi_begin();
writecommand(i ? ILI9341_INVON : ILI9341_INVOFF);
if (hwSPI) spi_end();
}
////////// stuff not actively being used, but kept for posterity
uint8_t Adafruit_ILI9341_AS::spiread(void) {
uint8_t r = 0;
if (hwSPI) {
#if defined (__AVR__)
uint8_t backupSPCR = SPCR;
SPCR = mySPCR;
SPDR = 0x00;
while(!(SPSR & _BV(SPIF)));
r = SPDR;
SPCR = backupSPCR;
#elif defined(TEENSYDUINO)
r = SPI.transfer(0x00);
#elif defined (__STM32F1__)
r = SPI.transfer(0x00);
#elif defined (__arm__)
SPI.setClockDivider(11); // 8-ish MHz (full! speed!)
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
r = SPI.transfer(0x00);
#endif
} else {
for (uint8_t i=0; i<8; i++) {
digitalWrite(_sclk, LOW);
digitalWrite(_sclk, HIGH);
r <<= 1;
if (digitalRead(_miso))
r |= 0x1;
}
}
//Serial.print("read: 0x"); Serial.print(r, HEX);
return r;
}
uint8_t Adafruit_ILI9341_AS::readdata(void) {
digitalWrite(_dc, HIGH);
digitalWrite(_cs, LOW);
uint8_t r = spiread();
digitalWrite(_cs, HIGH);
return r;
}
uint8_t Adafruit_ILI9341_AS::readcommand8(uint8_t c, uint8_t index) {
if (hwSPI) spi_begin();
digitalWrite(_dc, LOW); // command
digitalWrite(_cs, LOW);
spiwrite(0xD9); // woo sekret command?
digitalWrite(_dc, HIGH); // data
spiwrite(0x10 + index);
digitalWrite(_cs, HIGH);
digitalWrite(_dc, LOW);
digitalWrite(_sclk, LOW);
digitalWrite(_cs, LOW);
spiwrite(c);
digitalWrite(_dc, HIGH);
uint8_t r = spiread();
digitalWrite(_cs, HIGH);
if (hwSPI) spi_end();
return r;
}
/*
uint16_t Adafruit_ILI9341_AS::readcommand16(uint8_t c) {
digitalWrite(_dc, LOW);
if (_cs)
digitalWrite(_cs, LOW);
spiwrite(c);
pinMode(_sid, INPUT); // input!
uint16_t r = spiread();
r <<= 8;
r |= spiread();
if (_cs)
digitalWrite(_cs, HIGH);
pinMode(_sid, OUTPUT); // back to output
return r;
}
uint32_t Adafruit_ILI9341_AS::readcommand32(uint8_t c) {
digitalWrite(_dc, LOW);
if (_cs)
digitalWrite(_cs, LOW);
spiwrite(c);
pinMode(_sid, INPUT); // input!
dummyclock();
dummyclock();
uint32_t r = spiread();
r <<= 8;
r |= spiread();
r <<= 8;
r |= spiread();
r <<= 8;
r |= spiread();
if (_cs)
digitalWrite(_cs, HIGH);
pinMode(_sid, OUTPUT); // back to output
return r;
}
*/

View File

@ -1,153 +0,0 @@
/*
See rights and use declaration in License.h
This library has been modified for the Maple Mini
*/
#ifndef _ADAFRUIT_ILI9341H_
#define _ADAFRUIT_ILI9341H_
#include "Arduino.h"
#include "Print.h"
#include ".\Adafruit_GFX_AS.h"
#include <avr/pgmspace.h>
#define ILI9341_TFTWIDTH 240
#define ILI9341_TFTHEIGHT 320
#define ILI9341_NOP 0x00
#define ILI9341_SWRESET 0x01
#define ILI9341_RDDID 0x04
#define ILI9341_RDDST 0x09
#define ILI9341_SLPIN 0x10
#define ILI9341_SLPOUT 0x11
#define ILI9341_PTLON 0x12
#define ILI9341_NORON 0x13
#define ILI9341_RDMODE 0x0A
#define ILI9341_RDMADCTL 0x0B
#define ILI9341_RDPIXFMT 0x0C
#define ILI9341_RDIMGFMT 0x0A
#define ILI9341_RDSELFDIAG 0x0F
#define ILI9341_INVOFF 0x20
#define ILI9341_INVON 0x21
#define ILI9341_GAMMASET 0x26
#define ILI9341_DISPOFF 0x28
#define ILI9341_DISPON 0x29
#define ILI9341_CASET 0x2A
#define ILI9341_PASET 0x2B
#define ILI9341_RAMWR 0x2C
#define ILI9341_RAMRD 0x2E
#define ILI9341_PTLAR 0x30
#define ILI9341_MADCTL 0x36
#define ILI9341_PIXFMT 0x3A
#define ILI9341_FRMCTR1 0xB1
#define ILI9341_FRMCTR2 0xB2
#define ILI9341_FRMCTR3 0xB3
#define ILI9341_INVCTR 0xB4
#define ILI9341_DFUNCTR 0xB6
#define ILI9341_PWCTR1 0xC0
#define ILI9341_PWCTR2 0xC1
#define ILI9341_PWCTR3 0xC2
#define ILI9341_PWCTR4 0xC3
#define ILI9341_PWCTR5 0xC4
#define ILI9341_VMCTR1 0xC5
#define ILI9341_VMCTR2 0xC7
#define ILI9341_RDID1 0xDA
#define ILI9341_RDID2 0xDB
#define ILI9341_RDID3 0xDC
#define ILI9341_RDID4 0xDD
#define ILI9341_GMCTRP1 0xE0
#define ILI9341_GMCTRN1 0xE1
/*
#define ILI9341_PWCTR6 0xFC
*/
// Color definitions
#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
#define ILI9341_NAVY 0x000F /* 0, 0, 128 */
#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
#define ILI9341_BLUE 0x001F /* 0, 0, 255 */
#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
#define ILI9341_RED 0xF800 /* 255, 0, 0 */
#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define ILI9341_PINK 0xF81F
class Adafruit_ILI9341_AS : public Adafruit_GFX_AS {
public:
Adafruit_ILI9341_AS(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,
int8_t _RST, int8_t _MISO);
Adafruit_ILI9341_AS(int8_t _CS, int8_t _DC, int8_t _RST = -1);
void begin(void),
setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
pushColor(uint16_t color),
fillScreen(uint16_t color),
drawPixel(int16_t x, int16_t y, uint16_t color),
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color),
setRotation(uint8_t r),
invertDisplay(boolean i);
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
/* These are not for current use, 8-bit protocol only! */
uint8_t readdata(void),
readcommand8(uint8_t reg, uint8_t index = 0);
/*
uint16_t readcommand16(uint8_t);
uint32_t readcommand32(uint8_t);
void dummyclock(void);
*/
void spiwrite(uint8_t),
writecommand(uint8_t c),
writedata(uint8_t d),
commandList(uint8_t *addr);
uint8_t spiread(void);
private:
uint8_t tabcolor;
boolean hwSPI;
#if defined (__AVR__) || defined(TEENSYDUINO)
uint8_t mySPCR;
volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport;
int8_t _cs, _dc, _rst, _mosi, _miso, _sclk;
uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
#elif defined (__STM32F1__)
volatile uint32 *mosiport, *clkport, *dcport, *rsport, *csport;
uint32_t _cs, _dc, _rst, _mosi, _miso, _sclk;
uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
#elif defined (__arm__)
volatile RwReg *mosiport, *clkport, *dcport, *rsport, *csport;
uint32_t _cs, _dc, _rst, _mosi, _miso, _sclk;
uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
#endif
};
#endif

View File

@ -1,124 +0,0 @@
/*
An example showing rainbow colours on a 2.2" TFT LCD screen
and to show a basic example of font use.
The existing Adafruit font is still in the library
Only new font sizes 2,4,6 and 7 are implemented in the Adafruit_GFX_AS library.
This examples uses the hardware SPI only. Non-hardware SPI
is just too slow (~8 times slower!)
Alan Senior 18/1/2015
*/
// These are the connections for the UNO
#define sclk 13 // Don't change
#define mosi 11 // Don't change
#define cs 9
#define dc 8
#define rst 7 // you can also connect this to the Arduino reset
#include <Adafruit_GFX_AS.h> // Core graphics library
#include <Adafruit_ILI9341_AS.h> // Hardware-specific library
#include <SPI.h>
Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(cs, dc, rst); // Invoke custom library
unsigned long targetTime = 0;
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11;
void setup(void) {
tft.init();
tft.setRotation(2);
tft.fillScreen(ILI9341_BLACK);
targetTime = millis() + 1000;
}
void loop() {
if (targetTime < millis()) {
targetTime = millis()+10000;
for (int i = 0; i<240; i++) {
tft.drawFastVLine(i, 0, tft.height(), colour);
switch (state) {
case 0:
green +=2;
if (green == 64) {
green=63;
state = 1;
}
break;
case 1:
red--;
if (red == 255) {
red = 0;
state = 2;
}
break;
case 2:
blue ++;
if (blue == 32) {
blue=31;
state = 3;
}
break;
case 3:
green -=2;
if (green ==255) {
green=0;
state = 4;
}
break;
case 4:
red ++;
if (red == 32) {
red = 31;
state = 5;
}
break;
case 5:
blue --;
if (blue == 255) {
blue = 0;
state = 0;
}
break;
}
colour = red<<11 | green<<5 | blue;
}
// The standard ADAFruit font still works as berfore
tft.setTextColor(ILI9341_BLACK, ILI9341_BLACK); // Note these fonts do not plot the background colour
tft.setCursor (68, 5);
tft.print("Original ADAfruit font!");
// The new larger fonts do not use the .setCursor call, coords are embedded
tft.setTextColor(ILI9341_BLACK); // Do not plot the background colour
// Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!)
tft.drawCentreString("Font size 2",120,14,2); // Draw text centre at position 120, 14 using font 2
tft.drawCentreString("Font size 4",120,30,4); // Draw text centre at position 120, 30 using font 4
tft.drawCentreString("12.34",120,54,6); // Draw text centre at position 120, 54 using font 6
tft.drawCentreString("12.34 is in font size 6",120,92,2); // Draw text centre at position 120, 92 using font 2
// Note the x position is the top of the font!
// draw a floating point number
float pi = 3.14159; // Value to print
int precision = 3; // Number of digits after decimal point
int xpos = 90; // x position
int ypos = 110; // y position
int font = 2; // font number only 2,4,6,7 valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : . a p m
xpos+=tft.drawFloat(pi,precision,xpos,ypos,font); // Draw rounded number and return new xpos delta for next print position
tft.drawString(" is pi",xpos,ypos,font); // Continue printing from new x position
}
}