Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8cb704fdd | ||
|
|
c45f0df3b8 | ||
|
|
c33c9f1eae | ||
|
|
2af06829fd |
9 changed files with 209 additions and 41 deletions
|
|
@ -4,6 +4,12 @@
|
|||
// 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>
|
||||
#endif
|
||||
|
|
@ -91,10 +97,18 @@ Adafruit_TFTLCD::Adafruit_TFTLCD(
|
|||
#ifndef USE_ADAFRUIT_SHIELD_PINOUT
|
||||
// Convert pin numbers to registers and bitmasks
|
||||
_reset = reset;
|
||||
#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);
|
||||
|
|
@ -103,10 +117,18 @@ Adafruit_TFTLCD::Adafruit_TFTLCD(
|
|||
cdPinUnset = ~cdPinSet;
|
||||
wrPinUnset = ~wrPinSet;
|
||||
rdPinUnset = ~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);
|
||||
|
|
@ -301,6 +323,7 @@ void Adafruit_TFTLCD::begin(uint16_t id) {
|
|||
void Adafruit_TFTLCD::reset(void) {
|
||||
|
||||
CS_IDLE;
|
||||
// CD_DATA;
|
||||
WR_IDLE;
|
||||
RD_IDLE;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@
|
|||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
|
||||
// **** IF USING THE LCD BREAKOUT BOARD, COMMENT OUT THIS NEXT LINE. ****
|
||||
// **** IF USING THE LCD SHIELD, LEAVE THE LINE ENABLED: ****
|
||||
#define USE_ADAFRUIT_SHIELD_PINOUT
|
||||
//#define USE_ADAFRUIT_SHIELD_PINOUT
|
||||
|
||||
class Adafruit_TFTLCD : public Adafruit_GFX {
|
||||
|
||||
|
|
@ -24,19 +25,19 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
|
|||
Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t rst);
|
||||
Adafruit_TFTLCD(void);
|
||||
|
||||
void begin(uint16_t id = 0x9325),
|
||||
drawPixel(int16_t x, int16_t y, uint16_t color),
|
||||
drawFastHLine(int16_t x0, int16_t y0, int16_t w, uint16_t color),
|
||||
drawFastVLine(int16_t x0, int16_t y0, int16_t h, uint16_t color),
|
||||
fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c),
|
||||
fillScreen(uint16_t color),
|
||||
reset(void),
|
||||
setRegisters8(uint8_t *ptr, uint8_t n),
|
||||
setRegisters16(uint16_t *ptr, uint8_t n),
|
||||
setRotation(uint8_t x),
|
||||
void begin(uint16_t id = 0x9325);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
void drawFastHLine(int16_t x0, int16_t y0, int16_t w, uint16_t color);
|
||||
void drawFastVLine(int16_t x0, int16_t y0, int16_t h, uint16_t color);
|
||||
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c);
|
||||
void fillScreen(uint16_t color);
|
||||
void reset(void);
|
||||
void setRegisters8(uint8_t *ptr, uint8_t n);
|
||||
void setRegisters16(uint16_t *ptr, uint8_t n);
|
||||
void setRotation(uint8_t x);
|
||||
// These methods are public in order for BMP examples to work:
|
||||
setAddrWindow(int x1, int y1, int x2, int y2),
|
||||
pushColors(uint16_t *data, uint8_t len, boolean first);
|
||||
void setAddrWindow(int x1, int y1, int x2, int y2);
|
||||
void pushColors(uint16_t *data, uint8_t len, boolean first);
|
||||
|
||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b),
|
||||
readPixel(int16_t x, int16_t y),
|
||||
|
|
@ -68,16 +69,28 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
|
|||
setLR(void),
|
||||
flood(uint16_t color, uint32_t len);
|
||||
uint8_t driver;
|
||||
|
||||
#ifndef read8
|
||||
uint8_t read8fn(void);
|
||||
#define read8isFunctionalized
|
||||
#endif
|
||||
|
||||
#ifndef USE_ADAFRUIT_SHIELD_PINOUT
|
||||
|
||||
#ifdef __AVR__
|
||||
volatile uint8_t *csPort , *cdPort , *wrPort , *rdPort;
|
||||
uint8_t csPinSet , cdPinSet , wrPinSet , rdPinSet ,
|
||||
csPinUnset, cdPinUnset, wrPinUnset, rdPinUnset,
|
||||
_reset;
|
||||
#endif
|
||||
#if defined(__SAM3X8E__)
|
||||
Pio *csPort , *cdPort , *wrPort , *rdPort;
|
||||
uint32_t csPinSet , cdPinSet , wrPinSet , rdPinSet ,
|
||||
csPinUnset, cdPinUnset, wrPinUnset, rdPinUnset,
|
||||
_reset;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
// For compatibility with sketches written for older versions of library.
|
||||
|
|
|
|||
0
examples/graphicstest/graphicstest.pde
Normal file → Executable file
0
examples/graphicstest/graphicstest.pde
Normal file → Executable file
0
examples/rotationtest/rotationtest.pde
Normal file → Executable file
0
examples/rotationtest/rotationtest.pde
Normal file → Executable file
0
examples/tftbmp/tftbmp.pde
Normal file → Executable file
0
examples/tftbmp/tftbmp.pde
Normal file → Executable file
0
examples/tftbmp_shield/tftbmp_shield.pde
Normal file → Executable file
0
examples/tftbmp_shield/tftbmp_shield.pde
Normal file → Executable file
|
|
@ -6,6 +6,11 @@
|
|||
#include <Adafruit_TFTLCD.h> // Hardware-specific library
|
||||
#include <TouchScreen.h>
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#undef __FlashStringHelper::F(string_literal)
|
||||
#define F(string_literal) string_literal
|
||||
#endif
|
||||
|
||||
// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
|
||||
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
|
||||
// D0 connects to digital pin 8 (Notice these are
|
||||
|
|
@ -16,8 +21,28 @@
|
|||
// D5 connects to digital pin 5
|
||||
// D6 connects to digital pin 6
|
||||
// D7 connects to digital pin 7
|
||||
|
||||
// For the Arduino Mega, use digital pins 22 through 29
|
||||
// (on the 2-row header at the end of the board).
|
||||
// D0 connects to digital pin 22
|
||||
// D1 connects to digital pin 23
|
||||
// D2 connects to digital pin 24
|
||||
// D3 connects to digital pin 25
|
||||
// D4 connects to digital pin 26
|
||||
// D5 connects to digital pin 27
|
||||
// D6 connects to digital pin 28
|
||||
// D7 connects to digital pin 29
|
||||
|
||||
// For the Arduino Due, use digital pins 33 through 40
|
||||
// (on the 2-row header at the end of the board).
|
||||
// D0 connects to digital pin 33
|
||||
// D1 connects to digital pin 34
|
||||
// D2 connects to digital pin 35
|
||||
// D3 connects to digital pin 36
|
||||
// D4 connects to digital pin 37
|
||||
// D5 connects to digital pin 38
|
||||
// D6 connects to digital pin 39
|
||||
// D7 connects to digital pin 40
|
||||
|
||||
#define YP A3 // must be an analog pin, use "An" notation!
|
||||
#define XM A2 // must be an analog pin, use "An" notation!
|
||||
|
|
@ -5,6 +5,11 @@
|
|||
#include <Adafruit_TFTLCD.h> // Hardware-specific library
|
||||
#include <TouchScreen.h>
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#undef __FlashStringHelper::F(string_literal)
|
||||
#define F(string_literal) string_literal
|
||||
#endif
|
||||
|
||||
#ifndef USE_ADAFRUIT_SHIELD_PINOUT
|
||||
#error "This sketch is intended for use with the TFT LCD Shield. Make sure that USE_ADAFRUIT_SHIELD_PINOUT is #defined in the Adafruit_TFTLCD.h library file."
|
||||
#endif
|
||||
|
|
@ -15,10 +20,17 @@
|
|||
#define YM 7 // can be a digital pin
|
||||
#define XP 6 // can be a digital pin
|
||||
|
||||
#ifdef __SAM3X8E__
|
||||
#define TS_MINX 125
|
||||
#define TS_MINY 170
|
||||
#define TS_MAXX 880
|
||||
#define TS_MAXY 940
|
||||
#else
|
||||
#define TS_MINX 150
|
||||
#define TS_MINY 120
|
||||
#define TS_MAXX 920
|
||||
#define TS_MAXY 940
|
||||
#endif
|
||||
|
||||
// For better pressure precision, we need to know the resistance
|
||||
// between X+ and X- Use any multimeter to read it
|
||||
105
pin_magic.h
105
pin_magic.h
|
|
@ -37,6 +37,7 @@
|
|||
// Uno port/pin : PD7 PD6 PB5 PD4 PB3 PB2 PB1 PB0
|
||||
// Mega port/pin: PH4 PH3 PB7 PG5 PB5 PB4 PH6 PH5
|
||||
// Leo port/pin : PE6 PD7 PC7 PD4 PB7 PB6 PB5 PB4
|
||||
// Due port/pin : PC23 PC24 PB27 PC26 PD7 PC29 PC21 PC22
|
||||
// Breakout pin usage:
|
||||
// LCD Data Bit : 7 6 5 4 3 2 1 0
|
||||
// Uno dig. pin : 7 6 5 4 3 2 9 8
|
||||
|
|
@ -45,6 +46,8 @@
|
|||
// Mega port/pin: PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 (one contiguous PORT)
|
||||
// Leo dig. pin : 7 6 5 4 3 2 9 8
|
||||
// Leo port/pin : PE6 PD7 PC6 PD4 PD0 PD1 PB5 PB4
|
||||
// Due dig. pin : 40 39 38 37 36 35 34 33
|
||||
// Due port/pin : PC8 PC7 PC6 PC5 PC4 PC3 PC2 PC1 (one contiguous PORT. -ish…)
|
||||
|
||||
// Pixel read operations require a minimum 400 nS delay from RD_ACTIVE
|
||||
// to polling the input pins. At 16 MHz, one machine cycle is 62.5 nS.
|
||||
|
|
@ -67,10 +70,10 @@
|
|||
|
||||
// LCD control lines:
|
||||
// RD (read), WR (write), CD (command/data), CS (chip select)
|
||||
#define RD_PORT PORTC
|
||||
#define WR_PORT PORTC
|
||||
#define CD_PORT PORTC
|
||||
#define CS_PORT PORTC
|
||||
#define RD_PORT PORTC /*pin A0 */
|
||||
#define WR_PORT PORTC /*pin A1 */
|
||||
#define CD_PORT PORTC /*pin A2 */
|
||||
#define CS_PORT PORTC /*pin A3 */
|
||||
#define RD_MASK B00000001
|
||||
#define WR_MASK B00000010
|
||||
#define CD_MASK B00000100
|
||||
|
|
@ -252,13 +255,104 @@
|
|||
// program to compile.
|
||||
#define write8 write8inline
|
||||
|
||||
#elif defined(__SAM3X8E__)
|
||||
|
||||
// Arduino Due
|
||||
|
||||
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
|
||||
|
||||
#define RD_PORT PIOA /*pin A0 */
|
||||
#define WR_PORT PIOA /*pin A1 */
|
||||
#define CD_PORT PIOA /*pin A2 */
|
||||
#define CS_PORT PIOA /*pin A3 */
|
||||
#define RD_MASK 0x00010000
|
||||
#define WR_MASK 0x01000000
|
||||
#define CD_MASK 0x00800000
|
||||
#define CS_MASK 0x00400000
|
||||
|
||||
#define write8inline(d) { \
|
||||
PIO_Set(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_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_Clear(PIOB, (((~d) & 0x20)<<(27-5))); \
|
||||
WR_STROBE; }
|
||||
|
||||
#define read8inline(result) { \
|
||||
RD_ACTIVE; \
|
||||
delayMicroseconds(1); \
|
||||
result = (((PIOC->PIO_PDSR & (1<<23)) >> (23-7)) | ((PIOC->PIO_PDSR & (1<<24)) >> (24-6)) | \
|
||||
((PIOB->PIO_PDSR & (1<<27)) >> (27-5)) | ((PIOC->PIO_PDSR & (1<<26)) >> (26-4)) | \
|
||||
((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() { \
|
||||
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; \
|
||||
PIOB->PIO_MDDR |= 0x08000000; /*PIOB->PIO_SODR = 0x08000000;*/ PIOB->PIO_OER |= 0x08000000; PIOB->PIO_PER |= 0x08000000; }
|
||||
|
||||
#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; \
|
||||
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)
|
||||
// Command/Data: LOW = command, HIGH = data
|
||||
// These are single-instruction operations and always inline
|
||||
#define RD_ACTIVE RD_PORT->PIO_CODR |= RD_MASK
|
||||
#define RD_IDLE RD_PORT->PIO_SODR |= RD_MASK
|
||||
#define WR_ACTIVE WR_PORT->PIO_CODR |= WR_MASK
|
||||
#define WR_IDLE WR_PORT->PIO_SODR |= WR_MASK
|
||||
#define CD_COMMAND CD_PORT->PIO_CODR |= CD_MASK
|
||||
#define CD_DATA CD_PORT->PIO_SODR |= CD_MASK
|
||||
#define CS_ACTIVE CS_PORT->PIO_CODR |= CS_MASK
|
||||
#define CS_IDLE CS_PORT->PIO_SODR |= CS_MASK
|
||||
|
||||
|
||||
#else // Due w/Breakout board
|
||||
|
||||
#define write8inline(d) { \
|
||||
PIO_Set(PIOC, (((d) & 0xFF)<<1)); \
|
||||
PIO_Clear(PIOC, (((~d) & 0xFF)<<1)); \
|
||||
WR_STROBE; }
|
||||
|
||||
#define read8inline(result) { \
|
||||
RD_ACTIVE; \
|
||||
delayMicroseconds(1); \
|
||||
result = ((PIOC->PIO_PDSR & 0x1FE) >> 1); \
|
||||
RD_IDLE;}
|
||||
|
||||
#define setWriteDirInline() { \
|
||||
PIOC->PIO_MDDR |= 0x000001FE; /*PIOC->PIO_SODR |= 0x000001FE;*/ PIOC->PIO_OER |= 0x000001FE; PIOC->PIO_PER |= 0x000001FE; }
|
||||
|
||||
#define setReadDirInline() { \
|
||||
pmc_enable_periph_clk( ID_PIOC ) ; \
|
||||
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.
|
||||
#define RD_ACTIVE rdPort->PIO_CODR |= rdPinSet //PIO_Clear(rdPort, rdPinSet)
|
||||
#define RD_IDLE rdPort->PIO_SODR |= rdPinSet //PIO_Set(rdPort, rdPinSet)
|
||||
#define WR_ACTIVE wrPort->PIO_CODR |= wrPinSet //PIO_Clear(wrPort, wrPinSet)
|
||||
#define WR_IDLE wrPort->PIO_SODR |= wrPinSet //PIO_Set(wrPort, wrPinSet)
|
||||
#define CD_COMMAND cdPort->PIO_CODR |= cdPinSet //PIO_Clear(cdPort, cdPinSet)
|
||||
#define CD_DATA cdPort->PIO_SODR |= cdPinSet //PIO_Set(cdPort, cdPinSet)
|
||||
#define CS_ACTIVE csPort->PIO_CODR |= csPinSet //PIO_Clear(csPort, csPinSet)
|
||||
#define CS_IDLE csPort->PIO_SODR |= csPinSet //PIO_Set(csPort, csPinSet)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#error "Board type unsupported / not recognized"
|
||||
|
||||
#endif
|
||||
|
||||
// Stuff common to all Arduino board types:
|
||||
#if !defined(__SAM3X8E__)
|
||||
// Stuff common to all Arduino AVR board types:
|
||||
|
||||
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
|
||||
|
||||
|
|
@ -287,6 +381,7 @@
|
|||
#define CS_IDLE *csPort |= csPinSet
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Data write strobe, ~2 instructions and always inline
|
||||
#define WR_STROBE { WR_ACTIVE; WR_IDLE; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue