mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 20:56:35 +00:00
Change to latest GFX/ILI9341 libs
Change to latest Adafruit GFX and ILI9341 libraries (saves 300 bytes ;-)
This commit is contained in:
parent
8ac213e99d
commit
510321f2e1
6
lib/Adafruit-GFX-Library-1.2.9/.gitignore
vendored
Normal file
6
lib/Adafruit-GFX-Library-1.2.9/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
default.vim
|
||||||
|
fontconvert/fontconvert
|
||||||
|
# Our handy .gitignore for automation ease
|
||||||
|
Doxyfile*
|
||||||
|
doxygen_sqlite3.db
|
||||||
|
html
|
27
lib/Adafruit-GFX-Library-1.2.9/.travis.yml
Normal file
27
lib/Adafruit-GFX-Library-1.2.9/.travis.yml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
language: c
|
||||||
|
sudo: false
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- ~/arduino_ide
|
||||||
|
- ~/.arduino15/packages/
|
||||||
|
git:
|
||||||
|
depth: false
|
||||||
|
quiet: true
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- ARDUINO_IDE_VERSION="1.8.5"
|
||||||
|
- PRETTYNAME="Adafruit GFX Library"
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
|
||||||
|
|
||||||
|
install:
|
||||||
|
- arduino --install-library "Adafruit ILI9341"
|
||||||
|
|
||||||
|
script:
|
||||||
|
- build_main_platforms
|
||||||
|
|
||||||
|
# Generate and deploy documentation
|
||||||
|
after_success:
|
||||||
|
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/library_check.sh)
|
||||||
|
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh)
|
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "gfxfont.h"
|
#include "gfxfont.h"
|
||||||
|
|
||||||
|
/// A generic graphics superclass that can handle all sorts of drawing. At a minimum you can subclass and provide drawPixel(). At a maximum you can do a ton of overriding to optimize. Used for any/all Adafruit displays!
|
||||||
class Adafruit_GFX : public Print {
|
class Adafruit_GFX : public Print {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -16,7 +17,7 @@ class Adafruit_GFX : public Print {
|
|||||||
Adafruit_GFX(int16_t w, int16_t h); // Constructor
|
Adafruit_GFX(int16_t w, int16_t h); // Constructor
|
||||||
|
|
||||||
// This MUST be defined by the subclass:
|
// This MUST be defined by the subclass:
|
||||||
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
|
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; ///< Virtual drawPixel() function to draw to the screen/framebuffer/etc, must be overridden in subclass. @param x X coordinate. @param y Y coordinate. @param color 16-bit pixel color.
|
||||||
|
|
||||||
// TRANSACTION API / CORE DRAW API
|
// TRANSACTION API / CORE DRAW API
|
||||||
// These MAY be overridden by the subclass to provide device-specific
|
// These MAY be overridden by the subclass to provide device-specific
|
||||||
@ -101,11 +102,14 @@ class Adafruit_GFX : public Print {
|
|||||||
setTextWrap(boolean w),
|
setTextWrap(boolean w),
|
||||||
cp437(boolean x=true),
|
cp437(boolean x=true),
|
||||||
setFont(const GFXfont *f = NULL),
|
setFont(const GFXfont *f = NULL),
|
||||||
getTextBounds(char *string, int16_t x, int16_t y,
|
getTextBounds(const char *string, int16_t x, int16_t y,
|
||||||
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
|
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
|
||||||
getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
|
getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
|
||||||
|
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
|
||||||
|
getTextBounds(const String &str, int16_t x, int16_t y,
|
||||||
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
|
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
|
||||||
|
|
||||||
|
|
||||||
#if ARDUINO >= 100
|
#if ARDUINO >= 100
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
#else
|
#else
|
||||||
@ -126,22 +130,28 @@ class Adafruit_GFX : public Print {
|
|||||||
charBounds(char c, int16_t *x, int16_t *y,
|
charBounds(char c, int16_t *x, int16_t *y,
|
||||||
int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy);
|
int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy);
|
||||||
const int16_t
|
const int16_t
|
||||||
WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
|
WIDTH, ///< This is the 'raw' display width - never changes
|
||||||
|
HEIGHT; ///< This is the 'raw' display height - never changes
|
||||||
int16_t
|
int16_t
|
||||||
_width, _height, // Display w/h as modified by current rotation
|
_width, ///< Display width as modified by current rotation
|
||||||
cursor_x, cursor_y;
|
_height, ///< Display height as modified by current rotation
|
||||||
|
cursor_x, ///< x location to start print()ing text
|
||||||
|
cursor_y; ///< y location to start print()ing text
|
||||||
uint16_t
|
uint16_t
|
||||||
textcolor, textbgcolor;
|
textcolor, ///< 16-bit background color for print()
|
||||||
|
textbgcolor; ///< 16-bit text color for print()
|
||||||
uint8_t
|
uint8_t
|
||||||
textsize,
|
textsize, ///< Desired magnification of text to print()
|
||||||
rotation;
|
rotation; ///< Display rotation (0 thru 3)
|
||||||
boolean
|
boolean
|
||||||
wrap, // If set, 'wrap' text at right edge of display
|
wrap, ///< If set, 'wrap' text at right edge of display
|
||||||
_cp437; // If set, use correct CP437 charset (default is off)
|
_cp437; ///< If set, use correct CP437 charset (default is off)
|
||||||
GFXfont
|
GFXfont
|
||||||
*gfxFont;
|
*gfxFont; ///< Pointer to special font
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// A simple drawn button UI element
|
||||||
class Adafruit_GFX_Button {
|
class Adafruit_GFX_Button {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -173,6 +183,8 @@ class Adafruit_GFX_Button {
|
|||||||
boolean currstate, laststate;
|
boolean currstate, laststate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// A GFX 1-bit canvas context for graphics
|
||||||
class GFXcanvas1 : public Adafruit_GFX {
|
class GFXcanvas1 : public Adafruit_GFX {
|
||||||
public:
|
public:
|
||||||
GFXcanvas1(uint16_t w, uint16_t h);
|
GFXcanvas1(uint16_t w, uint16_t h);
|
||||||
@ -184,6 +196,8 @@ class GFXcanvas1 : public Adafruit_GFX {
|
|||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// A GFX 8-bit canvas context for graphics
|
||||||
class GFXcanvas8 : public Adafruit_GFX {
|
class GFXcanvas8 : public Adafruit_GFX {
|
||||||
public:
|
public:
|
||||||
GFXcanvas8(uint16_t w, uint16_t h);
|
GFXcanvas8(uint16_t w, uint16_t h);
|
||||||
@ -197,6 +211,8 @@ class GFXcanvas8 : public Adafruit_GFX {
|
|||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// A GFX 16-bit canvas context for graphics
|
||||||
class GFXcanvas16 : public Adafruit_GFX {
|
class GFXcanvas16 : public Adafruit_GFX {
|
||||||
public:
|
public:
|
||||||
GFXcanvas16(uint16_t w, uint16_t h);
|
GFXcanvas16(uint16_t w, uint16_t h);
|
555
lib/Adafruit-GFX-Library-1.2.9/Adafruit_SPITFT.cpp
Normal file
555
lib/Adafruit-GFX-Library-1.2.9/Adafruit_SPITFT.cpp
Normal file
@ -0,0 +1,555 @@
|
|||||||
|
/*!
|
||||||
|
* @file Adafruit_SPITFT.cpp
|
||||||
|
*
|
||||||
|
* @mainpage Adafruit SPI TFT Displays
|
||||||
|
*
|
||||||
|
* @section intro_sec Introduction
|
||||||
|
This is our library for generic SPI TFT Displays with
|
||||||
|
address windows and 16 bit color (e.g. ILI9341, HX8357D, ST7735...)
|
||||||
|
|
||||||
|
Check out the links above for our tutorials and wiring diagrams
|
||||||
|
These displays use SPI to communicate, 4 or 5 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
|
||||||
|
* @section dependencies Dependencies
|
||||||
|
*
|
||||||
|
* This library depends on <a href="https://github.com/adafruit/Adafruit_GFX">
|
||||||
|
* Adafruit_GFX</a> being present on your system. Please make sure you have
|
||||||
|
* installed the latest version before using this library.
|
||||||
|
*
|
||||||
|
* @section author Author
|
||||||
|
*
|
||||||
|
* Written by Limor "ladyada" Fried for Adafruit Industries.
|
||||||
|
*
|
||||||
|
* @section license License
|
||||||
|
*
|
||||||
|
* BSD license, all text here must be included in any redistribution.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __AVR_ATtiny85__ // NOT A CHANCE of this stuff working on ATtiny!
|
||||||
|
|
||||||
|
#include "Adafruit_SPITFT.h"
|
||||||
|
#ifndef ARDUINO_STM32_FEATHER
|
||||||
|
#include "pins_arduino.h"
|
||||||
|
#ifndef RASPI
|
||||||
|
#include "wiring_private.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include "Adafruit_SPITFT_Macros.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Pass 8-bit (each) R,G,B, get back 16-bit packed color
|
||||||
|
This function converts 8-8-8 RGB data to 16-bit 5-6-5
|
||||||
|
@param red Red 8 bit color
|
||||||
|
@param green Green 8 bit color
|
||||||
|
@param blue Blue 8 bit color
|
||||||
|
@return Unsigned 16-bit down-sampled color in 5-6-5 format
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
uint16_t Adafruit_SPITFT::color565(uint8_t red, uint8_t green, uint8_t blue) {
|
||||||
|
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ((blue & 0xF8) >> 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Instantiate Adafruit SPI display driver with software SPI
|
||||||
|
@param w Display width in pixels
|
||||||
|
@param h Display height in pixels
|
||||||
|
@param cs Chip select pin #
|
||||||
|
@param dc Data/Command pin #
|
||||||
|
@param mosi SPI MOSI pin #
|
||||||
|
@param sclk SPI Clock pin #
|
||||||
|
@param rst Reset pin # (optional, pass -1 if unused)
|
||||||
|
@param miso SPI MISO pin # (optional, pass -1 if unused)
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
|
||||||
|
int8_t cs, int8_t dc, int8_t mosi,
|
||||||
|
int8_t sclk, int8_t rst, int8_t miso)
|
||||||
|
: Adafruit_GFX(w, h) {
|
||||||
|
_cs = cs;
|
||||||
|
_dc = dc;
|
||||||
|
_rst = rst;
|
||||||
|
_sclk = sclk;
|
||||||
|
_mosi = mosi;
|
||||||
|
_miso = miso;
|
||||||
|
_freq = 0;
|
||||||
|
#ifdef USE_FAST_PINIO
|
||||||
|
dcport = (RwReg *)portOutputRegister(digitalPinToPort(dc));
|
||||||
|
dcpinmask = digitalPinToBitMask(dc);
|
||||||
|
clkport = (RwReg *)portOutputRegister(digitalPinToPort(sclk));
|
||||||
|
clkpinmask = digitalPinToBitMask(sclk);
|
||||||
|
mosiport = (RwReg *)portOutputRegister(digitalPinToPort(mosi));
|
||||||
|
mosipinmask = digitalPinToBitMask(mosi);
|
||||||
|
if(miso >= 0){
|
||||||
|
misoport = (RwReg *)portInputRegister(digitalPinToPort(miso));
|
||||||
|
misopinmask = digitalPinToBitMask(miso);
|
||||||
|
} else {
|
||||||
|
misoport = 0;
|
||||||
|
misopinmask = 0;
|
||||||
|
}
|
||||||
|
if(cs >= 0) {
|
||||||
|
csport = (RwReg *)portOutputRegister(digitalPinToPort(cs));
|
||||||
|
cspinmask = digitalPinToBitMask(cs);
|
||||||
|
} else {
|
||||||
|
// No chip-select line defined; might be permanently tied to GND.
|
||||||
|
// Assign a valid GPIO register (though not used for CS), and an
|
||||||
|
// empty pin bitmask...the nonsense bit-twiddling might be faster
|
||||||
|
// than checking _cs and possibly branching.
|
||||||
|
csport = dcport;
|
||||||
|
cspinmask = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Instantiate Adafruit SPI display driver with hardware SPI
|
||||||
|
@param w Display width in pixels
|
||||||
|
@param h Display height in pixels
|
||||||
|
@param cs Chip select pin #
|
||||||
|
@param dc Data/Command pin #
|
||||||
|
@param rst Reset pin # (optional, pass -1 if unused)
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
|
||||||
|
int8_t cs, int8_t dc, int8_t rst)
|
||||||
|
: Adafruit_GFX(w, h) {
|
||||||
|
_cs = cs;
|
||||||
|
_dc = dc;
|
||||||
|
_rst = rst;
|
||||||
|
_sclk = -1;
|
||||||
|
_mosi = -1;
|
||||||
|
_miso = -1;
|
||||||
|
_freq = 0;
|
||||||
|
#ifdef USE_FAST_PINIO
|
||||||
|
clkport = 0;
|
||||||
|
clkpinmask = 0;
|
||||||
|
mosiport = 0;
|
||||||
|
mosipinmask = 0;
|
||||||
|
misoport = 0;
|
||||||
|
misopinmask = 0;
|
||||||
|
dcport = (RwReg *)portOutputRegister(digitalPinToPort(dc));
|
||||||
|
dcpinmask = digitalPinToBitMask(dc);
|
||||||
|
if(cs >= 0) {
|
||||||
|
csport = (RwReg *)portOutputRegister(digitalPinToPort(cs));
|
||||||
|
cspinmask = digitalPinToBitMask(cs);
|
||||||
|
} else {
|
||||||
|
// See notes in prior constructor.
|
||||||
|
csport = dcport;
|
||||||
|
cspinmask = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Initialiaze the SPI interface (hardware or software)
|
||||||
|
@param freq The desired maximum SPI hardware clock frequency
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::initSPI(uint32_t freq) {
|
||||||
|
_freq = freq;
|
||||||
|
|
||||||
|
// Control Pins
|
||||||
|
if(_cs >= 0) {
|
||||||
|
pinMode(_cs, OUTPUT);
|
||||||
|
digitalWrite(_cs, HIGH); // Deselect
|
||||||
|
}
|
||||||
|
pinMode(_dc, OUTPUT);
|
||||||
|
digitalWrite(_dc, LOW);
|
||||||
|
|
||||||
|
// Software SPI
|
||||||
|
if(_sclk >= 0){
|
||||||
|
pinMode(_mosi, OUTPUT);
|
||||||
|
digitalWrite(_mosi, LOW);
|
||||||
|
pinMode(_sclk, OUTPUT);
|
||||||
|
digitalWrite(_sclk, HIGH);
|
||||||
|
if(_miso >= 0){
|
||||||
|
pinMode(_miso, INPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hardware SPI
|
||||||
|
SPI_BEGIN();
|
||||||
|
|
||||||
|
// toggle RST low to reset
|
||||||
|
if (_rst >= 0) {
|
||||||
|
pinMode(_rst, OUTPUT);
|
||||||
|
digitalWrite(_rst, HIGH);
|
||||||
|
delay(100);
|
||||||
|
digitalWrite(_rst, LOW);
|
||||||
|
delay(100);
|
||||||
|
digitalWrite(_rst, HIGH);
|
||||||
|
delay(200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Read one byte from SPI interface (hardware or software
|
||||||
|
@returns One byte, MSB order
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
uint8_t Adafruit_SPITFT::spiRead() {
|
||||||
|
if(_sclk < 0){
|
||||||
|
return HSPI_READ();
|
||||||
|
}
|
||||||
|
if(_miso < 0){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
uint8_t r = 0;
|
||||||
|
for (uint8_t i=0; i<8; i++) {
|
||||||
|
SSPI_SCK_LOW();
|
||||||
|
SSPI_SCK_HIGH();
|
||||||
|
r <<= 1;
|
||||||
|
if (SSPI_MISO_READ()){
|
||||||
|
r |= 0x1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Write one byte to SPI interface (hardware or software
|
||||||
|
@param b One byte to send, MSB order
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::spiWrite(uint8_t b) {
|
||||||
|
if(_sclk < 0){
|
||||||
|
HSPI_WRITE(b);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(uint8_t bit = 0x80; bit; bit >>= 1){
|
||||||
|
if((b) & bit){
|
||||||
|
SSPI_MOSI_HIGH();
|
||||||
|
} else {
|
||||||
|
SSPI_MOSI_LOW();
|
||||||
|
}
|
||||||
|
SSPI_SCK_LOW();
|
||||||
|
SSPI_SCK_HIGH();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Transaction API
|
||||||
|
* */
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Begin an SPI transaction & set CS low.
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void inline Adafruit_SPITFT::startWrite(void){
|
||||||
|
SPI_BEGIN_TRANSACTION();
|
||||||
|
SPI_CS_LOW();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Begin an SPI transaction & set CS high.
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void inline Adafruit_SPITFT::endWrite(void){
|
||||||
|
SPI_CS_HIGH();
|
||||||
|
SPI_END_TRANSACTION();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Write a command byte (must have a transaction in progress)
|
||||||
|
@param cmd The 8-bit command to send
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::writeCommand(uint8_t cmd){
|
||||||
|
SPI_DC_LOW();
|
||||||
|
spiWrite(cmd);
|
||||||
|
SPI_DC_HIGH();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Push a 2-byte color to the framebuffer RAM, will start transaction
|
||||||
|
@param color 16-bit 5-6-5 Color to draw
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::pushColor(uint16_t color) {
|
||||||
|
startWrite();
|
||||||
|
SPI_WRITE16(color);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Blit multiple 2-byte colors (must have a transaction in progress)
|
||||||
|
@param colors Array of 16-bit 5-6-5 Colors to draw
|
||||||
|
@param len How many pixels to draw - 2 bytes per pixel!
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::writePixels(uint16_t * colors, uint32_t len){
|
||||||
|
SPI_WRITE_PIXELS((uint8_t*)colors , len * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Blit a 2-byte color many times (must have a transaction in progress)
|
||||||
|
@param color The 16-bit 5-6-5 Color to draw
|
||||||
|
@param len How many pixels to draw
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len){
|
||||||
|
#ifdef SPI_HAS_WRITE_PIXELS
|
||||||
|
if(_sclk >= 0){
|
||||||
|
for (uint32_t t=0; t<len; t++){
|
||||||
|
writePixel(color);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
static uint16_t temp[SPI_MAX_PIXELS_AT_ONCE];
|
||||||
|
size_t blen = (len > SPI_MAX_PIXELS_AT_ONCE)?SPI_MAX_PIXELS_AT_ONCE:len;
|
||||||
|
uint16_t tlen = 0;
|
||||||
|
|
||||||
|
for (uint32_t t=0; t<blen; t++){
|
||||||
|
temp[t] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(len){
|
||||||
|
tlen = (len>blen)?blen:len;
|
||||||
|
writePixels(temp, tlen);
|
||||||
|
len -= tlen;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
uint8_t hi = color >> 8, lo = color;
|
||||||
|
if(_sclk < 0){ //AVR Optimization
|
||||||
|
for (uint32_t t=len; t; t--){
|
||||||
|
HSPI_WRITE(hi);
|
||||||
|
HSPI_WRITE(lo);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (uint32_t t=len; t; t--){
|
||||||
|
spiWrite(hi);
|
||||||
|
spiWrite(lo);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Write a pixel (must have a transaction in progress)
|
||||||
|
@param x x coordinate
|
||||||
|
@param y y coordinate
|
||||||
|
@param color 16-bit 5-6-5 Color to draw with
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::writePixel(int16_t x, int16_t y, uint16_t color) {
|
||||||
|
if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;
|
||||||
|
setAddrWindow(x,y,1,1);
|
||||||
|
writePixel(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Write a filled rectangle (must have a transaction in progress)
|
||||||
|
@param x Top left corner x coordinate
|
||||||
|
@param y Top left corner y coordinate
|
||||||
|
@param w Width in pixels
|
||||||
|
@param h Height in pixels
|
||||||
|
@param color 16-bit 5-6-5 Color to fill with
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color){
|
||||||
|
if((x >= _width) || (y >= _height)) return;
|
||||||
|
int16_t x2 = x + w - 1, y2 = y + h - 1;
|
||||||
|
if((x2 < 0) || (y2 < 0)) return;
|
||||||
|
|
||||||
|
// Clip left/top
|
||||||
|
if(x < 0) {
|
||||||
|
x = 0;
|
||||||
|
w = x2 + 1;
|
||||||
|
}
|
||||||
|
if(y < 0) {
|
||||||
|
y = 0;
|
||||||
|
h = y2 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clip right/bottom
|
||||||
|
if(x2 >= _width) w = _width - x;
|
||||||
|
if(y2 >= _height) h = _height - y;
|
||||||
|
|
||||||
|
int32_t len = (int32_t)w * h;
|
||||||
|
setAddrWindow(x, y, w, h);
|
||||||
|
writeColor(color, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Write a perfectly vertical line (must have a transaction in progress)
|
||||||
|
@param x Top-most x coordinate
|
||||||
|
@param y Top-most y coordinate
|
||||||
|
@param h Height in pixels
|
||||||
|
@param color 16-bit 5-6-5 Color to fill with
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void inline Adafruit_SPITFT::writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color){
|
||||||
|
writeFillRect(x, y, 1, h, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Write a perfectly horizontal line (must have a transaction in progress)
|
||||||
|
@param x Left-most x coordinate
|
||||||
|
@param y Left-most y coordinate
|
||||||
|
@param w Width in pixels
|
||||||
|
@param color 16-bit 5-6-5 Color to fill with
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void inline Adafruit_SPITFT::writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color){
|
||||||
|
writeFillRect(x, y, w, 1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Draw a pixel - sets up transaction
|
||||||
|
@param x x coordinate
|
||||||
|
@param y y coordinate
|
||||||
|
@param color 16-bit 5-6-5 Color to draw with
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::drawPixel(int16_t x, int16_t y, uint16_t color){
|
||||||
|
startWrite();
|
||||||
|
writePixel(x, y, color);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Write a perfectly vertical line - sets up transaction
|
||||||
|
@param x Top-most x coordinate
|
||||||
|
@param y Top-most y coordinate
|
||||||
|
@param h Height in pixels
|
||||||
|
@param color 16-bit 5-6-5 Color to fill with
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::drawFastVLine(int16_t x, int16_t y,
|
||||||
|
int16_t h, uint16_t color) {
|
||||||
|
startWrite();
|
||||||
|
writeFastVLine(x, y, h, color);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Write a perfectly horizontal line - sets up transaction
|
||||||
|
@param x Left-most x coordinate
|
||||||
|
@param y Left-most y coordinate
|
||||||
|
@param w Width in pixels
|
||||||
|
@param color 16-bit 5-6-5 Color to fill with
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::drawFastHLine(int16_t x, int16_t y,
|
||||||
|
int16_t w, uint16_t color) {
|
||||||
|
startWrite();
|
||||||
|
writeFastHLine(x, y, w, color);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Fill a rectangle completely with one color.
|
||||||
|
@param x Top left corner x coordinate
|
||||||
|
@param y Top left corner y coordinate
|
||||||
|
@param w Width in pixels
|
||||||
|
@param h Height in pixels
|
||||||
|
@param color 16-bit 5-6-5 Color to fill with
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
||||||
|
uint16_t color) {
|
||||||
|
startWrite();
|
||||||
|
writeFillRect(x,y,w,h,color);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Invert the display using built-in hardware command
|
||||||
|
@param i True if you want to invert, false to make 'normal'
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::invertDisplay(boolean i) {
|
||||||
|
startWrite();
|
||||||
|
writeCommand(i ? invertOnCommand : invertOffCommand);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Draw a 16-bit image (RGB 5/6/5) at the specified (x,y) position.
|
||||||
|
For 16-bit display devices; no color reduction performed.
|
||||||
|
Adapted from https://github.com/PaulStoffregen/ILI9341_t3
|
||||||
|
by Marc MERLIN. See examples/pictureEmbed to use this.
|
||||||
|
5/6/2017: function name and arguments have changed for compatibility
|
||||||
|
with current GFX library and to avoid naming problems in prior
|
||||||
|
implementation. Formerly drawBitmap() with arguments in different order.
|
||||||
|
|
||||||
|
@param x Top left corner x coordinate
|
||||||
|
@param y Top left corner y coordinate
|
||||||
|
@param pcolors 16-bit array with 16-bit color bitmap
|
||||||
|
@param w Width of bitmap in pixels
|
||||||
|
@param h Height of bitmap in pixels
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_SPITFT::drawRGBBitmap(int16_t x, int16_t y,
|
||||||
|
uint16_t *pcolors, int16_t w, int16_t h) {
|
||||||
|
|
||||||
|
int16_t x2, y2; // Lower-right coord
|
||||||
|
if(( x >= _width ) || // Off-edge right
|
||||||
|
( y >= _height) || // " top
|
||||||
|
((x2 = (x+w-1)) < 0 ) || // " left
|
||||||
|
((y2 = (y+h-1)) < 0) ) return; // " bottom
|
||||||
|
|
||||||
|
int16_t bx1=0, by1=0, // Clipped top-left within bitmap
|
||||||
|
saveW=w; // Save original bitmap width value
|
||||||
|
if(x < 0) { // Clip left
|
||||||
|
w += x;
|
||||||
|
bx1 = -x;
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
if(y < 0) { // Clip top
|
||||||
|
h += y;
|
||||||
|
by1 = -y;
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
if(x2 >= _width ) w = _width - x; // Clip right
|
||||||
|
if(y2 >= _height) h = _height - y; // Clip bottom
|
||||||
|
|
||||||
|
pcolors += by1 * saveW + bx1; // Offset bitmap ptr to clipped top-left
|
||||||
|
startWrite();
|
||||||
|
setAddrWindow(x, y, w, h); // Clipped area
|
||||||
|
while(h--) { // For each (clipped) scanline...
|
||||||
|
writePixels(pcolors, w); // Push one (clipped) row
|
||||||
|
pcolors += saveW; // Advance pointer by one full (unclipped) line
|
||||||
|
}
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !__AVR_ATtiny85__
|
125
lib/Adafruit-GFX-Library-1.2.9/Adafruit_SPITFT.h
Normal file
125
lib/Adafruit-GFX-Library-1.2.9/Adafruit_SPITFT.h
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
#ifndef _ADAFRUIT_SPITFT_
|
||||||
|
#define _ADAFRUIT_SPITFT_
|
||||||
|
|
||||||
|
#if ARDUINO >= 100
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Print.h"
|
||||||
|
#else
|
||||||
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
#include <SPI.h>
|
||||||
|
#include "Adafruit_GFX.h"
|
||||||
|
|
||||||
|
#define USE_FAST_PINIO
|
||||||
|
|
||||||
|
#if defined(__AVR__)
|
||||||
|
typedef volatile uint8_t RwReg;
|
||||||
|
#elif defined(ARDUINO_STM32_FEATHER)
|
||||||
|
typedef volatile uint32 RwReg;
|
||||||
|
#undef USE_FAST_PINIO
|
||||||
|
#elif defined(__OPENCR__) || defined (__OPENCM904__)
|
||||||
|
#undef USE_FAST_PINIO
|
||||||
|
#elif defined(ARDUINO_FEATHER52) || defined(__arm__)
|
||||||
|
typedef volatile uint32_t RwReg;
|
||||||
|
#elif defined(ESP32) || defined(ESP8266)
|
||||||
|
typedef volatile uint32_t RwReg;
|
||||||
|
#undef USE_FAST_PINIO
|
||||||
|
#else
|
||||||
|
#undef USE_FAST_PINIO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Adafruit_SPITFT_Macros.h"
|
||||||
|
|
||||||
|
/// A heavily optimized SPI display subclass of GFX. Manages SPI bitbanging, transactions, DMA, etc! Despite being called SPITFT, the classic SPI data/command interface is also used by OLEDs.
|
||||||
|
class Adafruit_SPITFT : public Adafruit_GFX {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST = -1, int8_t _MISO = -1);
|
||||||
|
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _RST = -1);
|
||||||
|
|
||||||
|
virtual void begin(uint32_t freq) = 0; ///< Virtual begin() function to set SPI frequency, must be overridden in subclass. @param freq Maximum SPI hardware clock speed
|
||||||
|
|
||||||
|
void initSPI(uint32_t freq);
|
||||||
|
|
||||||
|
// Required Non-Transaction
|
||||||
|
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||||
|
|
||||||
|
// Transaction API
|
||||||
|
void startWrite(void);
|
||||||
|
void endWrite(void);
|
||||||
|
|
||||||
|
void writePixel(int16_t x, int16_t y, uint16_t color);
|
||||||
|
void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||||
|
void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||||
|
void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||||
|
|
||||||
|
// Transaction API not used by GFX
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief SPI displays set an address window rectangle for blitting pixels
|
||||||
|
@param x Top left corner x coordinate
|
||||||
|
@param y Top left corner x coordinate
|
||||||
|
@param w Width of window
|
||||||
|
@param h Height of window
|
||||||
|
*/
|
||||||
|
virtual void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) = 0;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief Write a 2-byte color (must have a transaction in progress)
|
||||||
|
@param color 16-bit 5-6-5 Color to draw
|
||||||
|
*/
|
||||||
|
void inline writePixel(uint16_t color) { SPI_WRITE16(color); }
|
||||||
|
void writePixels(uint16_t * colors, uint32_t len);
|
||||||
|
void writeColor(uint16_t color, uint32_t len);
|
||||||
|
void pushColor(uint16_t color);
|
||||||
|
|
||||||
|
// Recommended Non-Transaction
|
||||||
|
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||||
|
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||||
|
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||||
|
|
||||||
|
using Adafruit_GFX::drawRGBBitmap; // Check base class first
|
||||||
|
void drawRGBBitmap(int16_t x, int16_t y,
|
||||||
|
uint16_t *pcolors, int16_t w, int16_t h);
|
||||||
|
void invertDisplay(boolean i);
|
||||||
|
|
||||||
|
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint32_t _freq; ///< SPI clock frequency (for hardware SPI)
|
||||||
|
#if defined (__AVR__) || defined(TEENSYDUINO) || defined (ESP8266) || defined (ESP32)
|
||||||
|
int8_t _cs, _dc, _rst, _sclk, _mosi, _miso;
|
||||||
|
#else
|
||||||
|
int32_t _cs, ///< Arduino pin # for chip-select pin
|
||||||
|
_dc, ///< Arduino pin # for data-command pin
|
||||||
|
_rst, ///< Arduino pin # for reset pin
|
||||||
|
_sclk, ///< Arduino pin # for SPI clock pin
|
||||||
|
_mosi, ///< Arduino pin # for SPI MOSI pin
|
||||||
|
_miso; ///< Arduino pin # for SPI MISO pin
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_FAST_PINIO
|
||||||
|
volatile RwReg *mosiport, ///< Direct chip register for toggling MOSI with fast bitbang IO
|
||||||
|
*misoport, ///< Direct chip register for toggling MISO with fast bitbang IO
|
||||||
|
*clkport, ///< Direct chip register for toggling CLK with fast bitbang IO
|
||||||
|
*dcport, ///< Direct chip register for toggling DC with fast bitbang IO
|
||||||
|
*csport; ///< Direct chip register for toggling CS with fast bitbang IO
|
||||||
|
RwReg mosipinmask, ///< bitmask for turning on/off MOSI with fast register bitbang IO
|
||||||
|
misopinmask, ///< bitmask for turning on/off MISO with fast register bitbang IO
|
||||||
|
clkpinmask, ///< bitmask for turning on/off CLK with fast register bitbang IO
|
||||||
|
cspinmask, ///< bitmask for turning on/off CS with fast register bitbang IO
|
||||||
|
dcpinmask; ///< bitmask for turning on/off DC with fast register bitbang IO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void writeCommand(uint8_t cmd);
|
||||||
|
void spiWrite(uint8_t v);
|
||||||
|
uint8_t spiRead(void);
|
||||||
|
|
||||||
|
uint8_t invertOnCommand = 0, ///< SPI command byte to turn on invert
|
||||||
|
invertOffCommand = 0; ///< SPI command byte to turn off invert
|
||||||
|
int16_t _xstart = 0; ///< Many displays don't have pixels starting at (0,0) of the internal framebuffer, this is the x offset from 0 to align
|
||||||
|
int16_t _ystart = 0; ///< Many displays don't have pixels starting at (0,0) of the internal framebuffer, this is the y offset from 0 to align
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -1,3 +1,5 @@
|
|||||||
|
#ifndef _ADAFRUIT_SPITFT_MACROS
|
||||||
|
#define _ADAFRUIT_SPITFT_MACROS
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Control Pins
|
* Control Pins
|
||||||
@ -11,8 +13,8 @@
|
|||||||
#else
|
#else
|
||||||
#define SPI_DC_HIGH() digitalWrite(_dc, HIGH)
|
#define SPI_DC_HIGH() digitalWrite(_dc, HIGH)
|
||||||
#define SPI_DC_LOW() digitalWrite(_dc, LOW)
|
#define SPI_DC_LOW() digitalWrite(_dc, LOW)
|
||||||
#define SPI_CS_HIGH() digitalWrite(_cs, HIGH)
|
#define SPI_CS_HIGH() { if(_cs >= 0) digitalWrite(_cs, HIGH); }
|
||||||
#define SPI_CS_LOW() digitalWrite(_cs, LOW)
|
#define SPI_CS_LOW() { if(_cs >= 0) digitalWrite(_cs, LOW); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -112,3 +114,5 @@ static inline uint8_t _avr_spi_read(void) {
|
|||||||
#define SPI_WRITE16(s) if(_sclk < 0){HSPI_WRITE16(s);}else{SSPI_WRITE16(s);}
|
#define SPI_WRITE16(s) if(_sclk < 0){HSPI_WRITE16(s);}else{SSPI_WRITE16(s);}
|
||||||
#define SPI_WRITE32(l) if(_sclk < 0){HSPI_WRITE32(l);}else{SSPI_WRITE32(l);}
|
#define SPI_WRITE32(l) if(_sclk < 0){HSPI_WRITE32(l);}else{SSPI_WRITE32(l);}
|
||||||
#define SPI_WRITE_PIXELS(c,l) if(_sclk < 0){HSPI_WRITE_PIXELS(c,l);}else{SSPI_WRITE_PIXELS(c,l);}
|
#define SPI_WRITE_PIXELS(c,l) if(_sclk < 0){HSPI_WRITE_PIXELS(c,l);}else{SSPI_WRITE_PIXELS(c,l);}
|
||||||
|
|
||||||
|
#endif // _ADAFRUIT_SPITFT_MACROS
|
@ -1,4 +1,4 @@
|
|||||||
# Adafruit GFX Library
|
# Adafruit GFX Library # [](https://travis-ci.org/adafruit/Adafruit_GFX)
|
||||||
|
|
||||||
This is the core graphics library for all our displays, providing a common set of graphics primitives (points, lines, circles, etc.). It needs to be paired with a hardware-specific library for each display device we carry (to handle the lower-level functions).
|
This is the core graphics library for all our displays, providing a common set of graphics primitives (points, lines, circles, etc.). It needs to be paired with a hardware-specific library for each display device we carry (to handle the lower-level functions).
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ Written by Limor Fried/Ladyada for Adafruit Industries.
|
|||||||
BSD license, check license.txt for more information.
|
BSD license, check license.txt for more information.
|
||||||
All text above must be included in any redistribution.
|
All text above must be included in any redistribution.
|
||||||
|
|
||||||
Recent Arduino IDE releases include the Library Manager for easy installation. Otherwise, to download, click the DOWNLOAD ZIP button, uncompress and rename the uncompressed folder Adafruit_GFX. Confirm that the Adafruit_GFX folder contains Adafruit_GFX.cpp and Adafruit_GFX.h. Place the Adafruit_GFX library folder your <arduinosketchfolder>/Libraries/ folder. You may need to create the Libraries subfolder if its your first library. Restart the IDE.
|
Recent Arduino IDE releases include the Library Manager for easy installation. Otherwise, to download, click the DOWNLOAD ZIP button, uncompress and rename the uncompressed folder Adafruit_GFX. Confirm that the Adafruit_GFX folder contains Adafruit_GFX.cpp and Adafruit_GFX.h. Place the Adafruit_GFX library folder your ArduinoSketchFolder/Libraries/ folder. You may need to create the Libraries subfolder if its your first library. Restart the IDE.
|
||||||
|
|
||||||
# Useful Resources
|
# Useful Resources
|
||||||
|
|
||||||
@ -16,9 +16,9 @@ Recent Arduino IDE releases include the Library Manager for easy installation. O
|
|||||||
|
|
||||||
- drawXBitmap function: You can use the GIMP photo editor to save a .xbm file and use the array saved in the file to draw a bitmap with the drawXBitmap function. See the pull request here for more details: https://github.com/adafruit/Adafruit-GFX-Library/pull/31
|
- drawXBitmap function: You can use the GIMP photo editor to save a .xbm file and use the array saved in the file to draw a bitmap with the drawXBitmap function. See the pull request here for more details: https://github.com/adafruit/Adafruit-GFX-Library/pull/31
|
||||||
|
|
||||||
- 'Fonts' folder contains bitmap fonts for use with recent (1.1 and later) Adafruit_GFX. To use a font in your Arduino sketch, #include the corresponding .h file and pass address of GFXfont struct to setFont(). Pass NULL to revert to 'classic' fixed-space bitmap font.
|
- 'Fonts' folder contains bitmap fonts for use with recent (1.1 and later) Adafruit_GFX. To use a font in your Arduino sketch, \#include the corresponding .h file and pass address of GFXfont struct to setFont(). Pass NULL to revert to 'classic' fixed-space bitmap font.
|
||||||
|
|
||||||
- 'fontconvert' folder contains a command-line tool for converting TTF fonts to Adafruit_GFX .h format.
|
- 'fontconvert' folder contains a command-line tool for converting TTF fonts to Adafruit_GFX header format.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
29
lib/Adafruit-GFX-Library-1.2.9/gfxfont.h
Normal file
29
lib/Adafruit-GFX-Library-1.2.9/gfxfont.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Font structures for newer Adafruit_GFX (1.1 and later).
|
||||||
|
// Example fonts are included in 'Fonts' directory.
|
||||||
|
// To use a font in your Arduino sketch, #include the corresponding .h
|
||||||
|
// file and pass address of GFXfont struct to setFont(). Pass NULL to
|
||||||
|
// revert to 'classic' fixed-space bitmap font.
|
||||||
|
|
||||||
|
#ifndef _GFXFONT_H_
|
||||||
|
#define _GFXFONT_H_
|
||||||
|
|
||||||
|
/// Font data stored PER GLYPH
|
||||||
|
typedef struct {
|
||||||
|
uint16_t bitmapOffset; ///< Pointer into GFXfont->bitmap
|
||||||
|
uint8_t width; ///< Bitmap dimensions in pixels
|
||||||
|
uint8_t height; ///< Bitmap dimensions in pixels
|
||||||
|
uint8_t xAdvance; ///< Distance to advance cursor (x axis)
|
||||||
|
int8_t xOffset; ///< X dist from cursor pos to UL corner
|
||||||
|
int8_t yOffset; ///< Y dist from cursor pos to UL corner
|
||||||
|
} GFXglyph;
|
||||||
|
|
||||||
|
/// Data stored for FONT AS A WHOLE
|
||||||
|
typedef struct {
|
||||||
|
uint8_t *bitmap; ///< Glyph bitmaps, concatenated
|
||||||
|
GFXglyph *glyph; ///< Glyph array
|
||||||
|
uint8_t first; ///< ASCII extents (first char)
|
||||||
|
uint8_t last; ///< ASCII extents (last char)
|
||||||
|
uint8_t yAdvance; ///< Newline distance (y axis)
|
||||||
|
} GFXfont;
|
||||||
|
|
||||||
|
#endif // _GFXFONT_H_
|
@ -1,5 +1,5 @@
|
|||||||
name=Adafruit GFX Library
|
name=Adafruit GFX Library
|
||||||
version=1.2.2
|
version=1.2.9
|
||||||
author=Adafruit
|
author=Adafruit
|
||||||
maintainer=Adafruit <info@adafruit.com>
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.
|
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.
|
2
lib/Adafruit_GFX-1.2.2.07/.gitignore
vendored
2
lib/Adafruit_GFX-1.2.2.07/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
default.vim
|
|
||||||
fontconvert/fontconvert
|
|
@ -1,336 +0,0 @@
|
|||||||
/***************************************************
|
|
||||||
This is our library for generic SPI TFT Displays with
|
|
||||||
address windows and 16 bit color (e.g. ILI9341, HX8357D, ST7735...)
|
|
||||||
|
|
||||||
Check out the links above for our tutorials and wiring diagrams
|
|
||||||
These displays use SPI to communicate, 4 or 5 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
|
|
||||||
****************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
#include "Adafruit_SPITFT.h"
|
|
||||||
#ifndef ARDUINO_STM32_FEATHER
|
|
||||||
#include "pins_arduino.h"
|
|
||||||
#ifndef RASPI
|
|
||||||
#include "wiring_private.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
#include "Adafruit_SPITFT_Macros.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Pass 8-bit (each) R,G,B, get back 16-bit packed color
|
|
||||||
uint16_t Adafruit_SPITFT::color565(uint8_t r, uint8_t g, uint8_t b) {
|
|
||||||
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
|
|
||||||
int8_t cs, int8_t dc, int8_t mosi,
|
|
||||||
int8_t sclk, int8_t rst, int8_t miso)
|
|
||||||
: Adafruit_GFX(w, h) {
|
|
||||||
_cs = cs;
|
|
||||||
_dc = dc;
|
|
||||||
_rst = rst;
|
|
||||||
_sclk = sclk;
|
|
||||||
_mosi = mosi;
|
|
||||||
_miso = miso;
|
|
||||||
_freq = 0;
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
csport = portOutputRegister(digitalPinToPort(_cs));
|
|
||||||
cspinmask = digitalPinToBitMask(_cs);
|
|
||||||
dcport = portOutputRegister(digitalPinToPort(_dc));
|
|
||||||
dcpinmask = digitalPinToBitMask(_dc);
|
|
||||||
clkport = portOutputRegister(digitalPinToPort(_sclk));
|
|
||||||
clkpinmask = digitalPinToBitMask(_sclk);
|
|
||||||
mosiport = portOutputRegister(digitalPinToPort(_mosi));
|
|
||||||
mosipinmask = digitalPinToBitMask(_mosi);
|
|
||||||
if(miso >= 0){
|
|
||||||
misoport = portInputRegister(digitalPinToPort(_miso));
|
|
||||||
misopinmask = digitalPinToBitMask(_miso);
|
|
||||||
} else {
|
|
||||||
misoport = 0;
|
|
||||||
misopinmask = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
|
|
||||||
int8_t cs, int8_t dc, int8_t rst)
|
|
||||||
: Adafruit_GFX(w, h) {
|
|
||||||
_cs = cs;
|
|
||||||
_dc = dc;
|
|
||||||
_rst = rst;
|
|
||||||
_sclk = -1;
|
|
||||||
_mosi = -1;
|
|
||||||
_miso = -1;
|
|
||||||
_freq = 0;
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
csport = portOutputRegister(digitalPinToPort(_cs));
|
|
||||||
cspinmask = digitalPinToBitMask(_cs);
|
|
||||||
dcport = portOutputRegister(digitalPinToPort(_dc));
|
|
||||||
dcpinmask = digitalPinToBitMask(_dc);
|
|
||||||
clkport = 0;
|
|
||||||
clkpinmask = 0;
|
|
||||||
mosiport = 0;
|
|
||||||
mosipinmask = 0;
|
|
||||||
misoport = 0;
|
|
||||||
misopinmask = 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::initSPI(uint32_t freq)
|
|
||||||
{
|
|
||||||
_freq = freq;
|
|
||||||
|
|
||||||
// Control Pins
|
|
||||||
pinMode(_dc, OUTPUT);
|
|
||||||
digitalWrite(_dc, LOW);
|
|
||||||
pinMode(_cs, OUTPUT);
|
|
||||||
digitalWrite(_cs, HIGH);
|
|
||||||
|
|
||||||
// Software SPI
|
|
||||||
if(_sclk >= 0){
|
|
||||||
pinMode(_mosi, OUTPUT);
|
|
||||||
digitalWrite(_mosi, LOW);
|
|
||||||
pinMode(_sclk, OUTPUT);
|
|
||||||
digitalWrite(_sclk, HIGH);
|
|
||||||
if(_miso >= 0){
|
|
||||||
pinMode(_miso, INPUT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hardware SPI
|
|
||||||
SPI_BEGIN();
|
|
||||||
|
|
||||||
// toggle RST low to reset
|
|
||||||
if (_rst >= 0) {
|
|
||||||
pinMode(_rst, OUTPUT);
|
|
||||||
digitalWrite(_rst, HIGH);
|
|
||||||
delay(100);
|
|
||||||
digitalWrite(_rst, LOW);
|
|
||||||
delay(100);
|
|
||||||
digitalWrite(_rst, HIGH);
|
|
||||||
delay(200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Adafruit_SPITFT::spiRead() {
|
|
||||||
if(_sclk < 0){
|
|
||||||
return HSPI_READ();
|
|
||||||
}
|
|
||||||
if(_miso < 0){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint8_t r = 0;
|
|
||||||
for (uint8_t i=0; i<8; i++) {
|
|
||||||
SSPI_SCK_LOW();
|
|
||||||
SSPI_SCK_HIGH();
|
|
||||||
r <<= 1;
|
|
||||||
if (SSPI_MISO_READ()){
|
|
||||||
r |= 0x1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::spiWrite(uint8_t b) {
|
|
||||||
if(_sclk < 0){
|
|
||||||
HSPI_WRITE(b);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for(uint8_t bit = 0x80; bit; bit >>= 1){
|
|
||||||
if((b) & bit){
|
|
||||||
SSPI_MOSI_HIGH();
|
|
||||||
} else {
|
|
||||||
SSPI_MOSI_LOW();
|
|
||||||
}
|
|
||||||
SSPI_SCK_LOW();
|
|
||||||
SSPI_SCK_HIGH();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Transaction API
|
|
||||||
* */
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::startWrite(void){
|
|
||||||
SPI_BEGIN_TRANSACTION();
|
|
||||||
SPI_CS_LOW();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::endWrite(void){
|
|
||||||
SPI_CS_HIGH();
|
|
||||||
SPI_END_TRANSACTION();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::writeCommand(uint8_t cmd){
|
|
||||||
SPI_DC_LOW();
|
|
||||||
spiWrite(cmd);
|
|
||||||
SPI_DC_HIGH();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::pushColor(uint16_t color) {
|
|
||||||
startWrite();
|
|
||||||
SPI_WRITE16(color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::writePixel(uint16_t color){
|
|
||||||
SPI_WRITE16(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::writePixels(uint16_t * colors, uint32_t len){
|
|
||||||
SPI_WRITE_PIXELS((uint8_t*)colors , len * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len){
|
|
||||||
#ifdef SPI_HAS_WRITE_PIXELS
|
|
||||||
if(_sclk >= 0){
|
|
||||||
for (uint32_t t=0; t<len; t++){
|
|
||||||
writePixel(color);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static uint16_t temp[SPI_MAX_PIXELS_AT_ONCE];
|
|
||||||
size_t blen = (len > SPI_MAX_PIXELS_AT_ONCE)?SPI_MAX_PIXELS_AT_ONCE:len;
|
|
||||||
uint16_t tlen = 0;
|
|
||||||
|
|
||||||
for (uint32_t t=0; t<blen; t++){
|
|
||||||
temp[t] = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(len){
|
|
||||||
tlen = (len>blen)?blen:len;
|
|
||||||
writePixels(temp, tlen);
|
|
||||||
len -= tlen;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
uint8_t hi = color >> 8, lo = color;
|
|
||||||
if(_sclk < 0){ //AVR Optimization
|
|
||||||
for (uint32_t t=len; t; t--){
|
|
||||||
HSPI_WRITE(hi);
|
|
||||||
HSPI_WRITE(lo);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (uint32_t t=len; t; t--){
|
|
||||||
spiWrite(hi);
|
|
||||||
spiWrite(lo);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::writePixel(int16_t x, int16_t y, uint16_t color) {
|
|
||||||
if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;
|
|
||||||
setAddrWindow(x,y,1,1);
|
|
||||||
writePixel(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color){
|
|
||||||
if((x >= _width) || (y >= _height)) return;
|
|
||||||
int16_t x2 = x + w - 1, y2 = y + h - 1;
|
|
||||||
if((x2 < 0) || (y2 < 0)) return;
|
|
||||||
|
|
||||||
// Clip left/top
|
|
||||||
if(x < 0) {
|
|
||||||
x = 0;
|
|
||||||
w = x2 + 1;
|
|
||||||
}
|
|
||||||
if(y < 0) {
|
|
||||||
y = 0;
|
|
||||||
h = y2 + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clip right/bottom
|
|
||||||
if(x2 >= _width) w = _width - x;
|
|
||||||
if(y2 >= _height) h = _height - y;
|
|
||||||
|
|
||||||
int32_t len = (int32_t)w * h;
|
|
||||||
setAddrWindow(x, y, w, h);
|
|
||||||
writeColor(color, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color){
|
|
||||||
writeFillRect(x, y, 1, h, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color){
|
|
||||||
writeFillRect(x, y, w, 1, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::drawPixel(int16_t x, int16_t y, uint16_t color){
|
|
||||||
startWrite();
|
|
||||||
writePixel(x, y, color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::drawFastVLine(int16_t x, int16_t y,
|
|
||||||
int16_t h, uint16_t color) {
|
|
||||||
startWrite();
|
|
||||||
writeFastVLine(x, y, h, color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::drawFastHLine(int16_t x, int16_t y,
|
|
||||||
int16_t w, uint16_t color) {
|
|
||||||
startWrite();
|
|
||||||
writeFastHLine(x, y, w, color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_SPITFT::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
|
||||||
uint16_t color) {
|
|
||||||
startWrite();
|
|
||||||
writeFillRect(x,y,w,h,color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adapted from https://github.com/PaulStoffregen/ILI9341_t3
|
|
||||||
// by Marc MERLIN. See examples/pictureEmbed to use this.
|
|
||||||
// 5/6/2017: function name and arguments have changed for compatibility
|
|
||||||
// with current GFX library and to avoid naming problems in prior
|
|
||||||
// implementation. Formerly drawBitmap() with arguments in different order.
|
|
||||||
void Adafruit_SPITFT::drawRGBBitmap(int16_t x, int16_t y,
|
|
||||||
uint16_t *pcolors, int16_t w, int16_t h) {
|
|
||||||
|
|
||||||
int16_t x2, y2; // Lower-right coord
|
|
||||||
if(( x >= _width ) || // Off-edge right
|
|
||||||
( y >= _height) || // " top
|
|
||||||
((x2 = (x+w-1)) < 0 ) || // " left
|
|
||||||
((y2 = (y+h-1)) < 0) ) return; // " bottom
|
|
||||||
|
|
||||||
int16_t bx1=0, by1=0, // Clipped top-left within bitmap
|
|
||||||
saveW=w; // Save original bitmap width value
|
|
||||||
if(x < 0) { // Clip left
|
|
||||||
w += x;
|
|
||||||
bx1 = -x;
|
|
||||||
x = 0;
|
|
||||||
}
|
|
||||||
if(y < 0) { // Clip top
|
|
||||||
h += y;
|
|
||||||
by1 = -y;
|
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
if(x2 >= _width ) w = _width - x; // Clip right
|
|
||||||
if(y2 >= _height) h = _height - y; // Clip bottom
|
|
||||||
|
|
||||||
pcolors += by1 * saveW + bx1; // Offset bitmap ptr to clipped top-left
|
|
||||||
startWrite();
|
|
||||||
setAddrWindow(x, y, w, h); // Clipped area
|
|
||||||
while(h--) { // For each (clipped) scanline...
|
|
||||||
writePixels(pcolors, w); // Push one (clipped) row
|
|
||||||
pcolors += saveW; // Advance pointer by one full (unclipped) line
|
|
||||||
}
|
|
||||||
endWrite();
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
|
|
||||||
#ifndef _ADAFRUIT_SPITFT_
|
|
||||||
#define _ADAFRUIT_SPITFT_
|
|
||||||
|
|
||||||
|
|
||||||
#if ARDUINO >= 100
|
|
||||||
#include "Arduino.h"
|
|
||||||
#include "Print.h"
|
|
||||||
#else
|
|
||||||
#include "WProgram.h"
|
|
||||||
#endif
|
|
||||||
#include <SPI.h>
|
|
||||||
#include "Adafruit_GFX.h"
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(ARDUINO_STM32_FEATHER)
|
|
||||||
typedef volatile uint32 RwReg;
|
|
||||||
#endif
|
|
||||||
#if defined(ARDUINO_FEATHER52)
|
|
||||||
typedef volatile uint32_t RwReg;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Adafruit_SPITFT : public Adafruit_GFX {
|
|
||||||
protected:
|
|
||||||
|
|
||||||
public:
|
|
||||||
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST = -1, int8_t _MISO = -1);
|
|
||||||
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _RST = -1);
|
|
||||||
|
|
||||||
virtual void begin(uint32_t freq) = 0;
|
|
||||||
void initSPI(uint32_t freq);
|
|
||||||
|
|
||||||
// Required Non-Transaction
|
|
||||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
|
||||||
|
|
||||||
// Transaction API
|
|
||||||
void startWrite(void);
|
|
||||||
void endWrite(void);
|
|
||||||
void writePixel(int16_t x, int16_t y, uint16_t color);
|
|
||||||
void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
|
||||||
void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
|
||||||
void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
|
||||||
|
|
||||||
// Transaction API not used by GFX
|
|
||||||
virtual void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) = 0;
|
|
||||||
void writePixel(uint16_t color);
|
|
||||||
void writePixels(uint16_t * colors, uint32_t len);
|
|
||||||
void writeColor(uint16_t color, uint32_t len);
|
|
||||||
void pushColor(uint16_t color);
|
|
||||||
|
|
||||||
// Recommended Non-Transaction
|
|
||||||
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
|
||||||
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
|
||||||
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
|
||||||
|
|
||||||
using Adafruit_GFX::drawRGBBitmap; // Check base class first
|
|
||||||
void drawRGBBitmap(int16_t x, int16_t y,
|
|
||||||
uint16_t *pcolors, int16_t w, int16_t h);
|
|
||||||
|
|
||||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
uint32_t _freq;
|
|
||||||
#if defined (__AVR__) || defined(TEENSYDUINO) || defined (ESP8266) || defined (ESP32)
|
|
||||||
int8_t _cs, _dc, _rst, _sclk, _mosi, _miso;
|
|
||||||
#else
|
|
||||||
int32_t _cs, _dc, _rst, _sclk, _mosi, _miso;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
volatile RwReg *mosiport, *misoport, *clkport, *dcport, *csport;
|
|
||||||
RwReg mosipinmask, misopinmask, clkpinmask, cspinmask, dcpinmask;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void writeCommand(uint8_t cmd);
|
|
||||||
void spiWrite(uint8_t v);
|
|
||||||
uint8_t spiRead(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,24 +0,0 @@
|
|||||||
// Font structures for newer Adafruit_GFX (1.1 and later).
|
|
||||||
// Example fonts are included in 'Fonts' directory.
|
|
||||||
// To use a font in your Arduino sketch, #include the corresponding .h
|
|
||||||
// file and pass address of GFXfont struct to setFont(). Pass NULL to
|
|
||||||
// revert to 'classic' fixed-space bitmap font.
|
|
||||||
|
|
||||||
#ifndef _GFXFONT_H_
|
|
||||||
#define _GFXFONT_H_
|
|
||||||
|
|
||||||
typedef struct { // Data stored PER GLYPH
|
|
||||||
uint16_t bitmapOffset; // Pointer into GFXfont->bitmap
|
|
||||||
uint8_t width, height; // Bitmap dimensions in pixels
|
|
||||||
uint8_t xAdvance; // Distance to advance cursor (x axis)
|
|
||||||
int8_t xOffset, yOffset; // Dist from cursor pos to UL corner
|
|
||||||
} GFXglyph;
|
|
||||||
|
|
||||||
typedef struct { // Data stored for FONT AS A WHOLE:
|
|
||||||
uint8_t *bitmap; // Glyph bitmaps, concatenated
|
|
||||||
GFXglyph *glyph; // Glyph array
|
|
||||||
uint8_t first, last; // ASCII extents
|
|
||||||
uint8_t yAdvance; // Newline distance (y axis)
|
|
||||||
} GFXfont;
|
|
||||||
|
|
||||||
#endif // _GFXFONT_H_
|
|
@ -1,683 +0,0 @@
|
|||||||
/***************************************************
|
|
||||||
This is our library for the Adafruit ILI9341 Breakout and Shield
|
|
||||||
----> http://www.adafruit.com/products/1651
|
|
||||||
|
|
||||||
Check out the links above for our tutorials and wiring diagrams
|
|
||||||
These displays use SPI to communicate, 4 or 5 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
|
|
||||||
****************************************************/
|
|
||||||
|
|
||||||
#include "Adafruit_ILI9341.h"
|
|
||||||
#ifndef ARDUINO_STM32_FEATHER
|
|
||||||
#include "pins_arduino.h"
|
|
||||||
#ifndef RASPI
|
|
||||||
#include "wiring_private.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Control Pins
|
|
||||||
* */
|
|
||||||
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
#define SPI_DC_HIGH() *dcport |= dcpinmask
|
|
||||||
#define SPI_DC_LOW() *dcport &= ~dcpinmask
|
|
||||||
#define SPI_CS_HIGH() *csport |= cspinmask
|
|
||||||
#define SPI_CS_LOW() *csport &= ~cspinmask
|
|
||||||
#else
|
|
||||||
#define SPI_DC_HIGH() digitalWrite(_dc, HIGH)
|
|
||||||
#define SPI_DC_LOW() digitalWrite(_dc, LOW)
|
|
||||||
#define SPI_CS_HIGH() digitalWrite(_cs, HIGH)
|
|
||||||
#define SPI_CS_LOW() digitalWrite(_cs, LOW)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Software SPI Macros
|
|
||||||
* */
|
|
||||||
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
#define SSPI_MOSI_HIGH() *mosiport |= mosipinmask
|
|
||||||
#define SSPI_MOSI_LOW() *mosiport &= ~mosipinmask
|
|
||||||
#define SSPI_SCK_HIGH() *clkport |= clkpinmask
|
|
||||||
#define SSPI_SCK_LOW() *clkport &= ~clkpinmask
|
|
||||||
#define SSPI_MISO_READ() ((*misoport & misopinmask) != 0)
|
|
||||||
#else
|
|
||||||
#define SSPI_MOSI_HIGH() digitalWrite(_mosi, HIGH)
|
|
||||||
#define SSPI_MOSI_LOW() digitalWrite(_mosi, LOW)
|
|
||||||
#define SSPI_SCK_HIGH() digitalWrite(_sclk, HIGH)
|
|
||||||
#define SSPI_SCK_LOW() digitalWrite(_sclk, LOW)
|
|
||||||
#define SSPI_MISO_READ() digitalRead(_miso)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SSPI_BEGIN_TRANSACTION()
|
|
||||||
#define SSPI_END_TRANSACTION()
|
|
||||||
#define SSPI_WRITE(v) spiWrite(v)
|
|
||||||
#define SSPI_WRITE16(s) SSPI_WRITE((s) >> 8); SSPI_WRITE(s)
|
|
||||||
#define SSPI_WRITE32(l) SSPI_WRITE((l) >> 24); SSPI_WRITE((l) >> 16); SSPI_WRITE((l) >> 8); SSPI_WRITE(l)
|
|
||||||
#define SSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<(l); i+=2){ SSPI_WRITE(((uint8_t*)(c))[i+1]); SSPI_WRITE(((uint8_t*)(c))[i]); }
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hardware SPI Macros
|
|
||||||
* */
|
|
||||||
|
|
||||||
#ifndef ESP32
|
|
||||||
#define SPI_OBJECT SPI
|
|
||||||
#else
|
|
||||||
#define SPI_OBJECT _spi
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined (__AVR__) || defined(TEENSYDUINO) || defined(ARDUINO_ARCH_STM32F1)
|
|
||||||
#define HSPI_SET_CLOCK() SPI_OBJECT.setClockDivider(SPI_CLOCK_DIV2);
|
|
||||||
#elif defined (__arm__)
|
|
||||||
#define HSPI_SET_CLOCK() SPI_OBJECT.setClockDivider(11);
|
|
||||||
#elif defined(ESP8266) || defined(ESP32)
|
|
||||||
#define HSPI_SET_CLOCK() SPI_OBJECT.setFrequency(_freq);
|
|
||||||
#elif defined(RASPI)
|
|
||||||
#define HSPI_SET_CLOCK() SPI_OBJECT.setClock(_freq);
|
|
||||||
#elif defined(ARDUINO_ARCH_STM32F1)
|
|
||||||
#define HSPI_SET_CLOCK() SPI_OBJECT.setClock(_freq);
|
|
||||||
#else
|
|
||||||
#define HSPI_SET_CLOCK()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SPI_HAS_TRANSACTION
|
|
||||||
#define HSPI_BEGIN_TRANSACTION() SPI_OBJECT.beginTransaction(SPISettings(_freq, MSBFIRST, SPI_MODE0))
|
|
||||||
#define HSPI_END_TRANSACTION() SPI_OBJECT.endTransaction()
|
|
||||||
#else
|
|
||||||
#define HSPI_BEGIN_TRANSACTION() HSPI_SET_CLOCK(); SPI_OBJECT.setBitOrder(MSBFIRST); SPI_OBJECT.setDataMode(SPI_MODE0)
|
|
||||||
#define HSPI_END_TRANSACTION()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#define SPI_HAS_WRITE_PIXELS
|
|
||||||
#endif
|
|
||||||
#if defined(ESP8266) || defined(ESP32)
|
|
||||||
// Optimized SPI (ESP8266 and ESP32)
|
|
||||||
#define HSPI_READ() SPI_OBJECT.transfer(0)
|
|
||||||
#define HSPI_WRITE(b) SPI_OBJECT.write(b)
|
|
||||||
#define HSPI_WRITE16(s) SPI_OBJECT.write16(s)
|
|
||||||
#define HSPI_WRITE32(l) SPI_OBJECT.write32(l)
|
|
||||||
#ifdef SPI_HAS_WRITE_PIXELS
|
|
||||||
#define SPI_MAX_PIXELS_AT_ONCE 32
|
|
||||||
#define HSPI_WRITE_PIXELS(c,l) SPI_OBJECT.writePixels(c,l)
|
|
||||||
#else
|
|
||||||
#define HSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<((l)/2); i++){ SPI_WRITE16(((uint16_t*)(c))[i]); }
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
// Standard Byte-by-Byte SPI
|
|
||||||
|
|
||||||
#if defined (__AVR__) || defined(TEENSYDUINO)
|
|
||||||
static inline uint8_t _avr_spi_read(void) __attribute__((always_inline));
|
|
||||||
static inline uint8_t _avr_spi_read(void) {
|
|
||||||
uint8_t r = 0;
|
|
||||||
SPDR = r;
|
|
||||||
while(!(SPSR & _BV(SPIF)));
|
|
||||||
r = SPDR;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
#define HSPI_WRITE(b) {SPDR = (b); while(!(SPSR & _BV(SPIF)));}
|
|
||||||
#define HSPI_READ() _avr_spi_read()
|
|
||||||
#else
|
|
||||||
#define HSPI_WRITE(b) SPI_OBJECT.transfer((uint8_t)(b))
|
|
||||||
#define HSPI_READ() HSPI_WRITE(0)
|
|
||||||
#endif
|
|
||||||
#define HSPI_WRITE16(s) HSPI_WRITE((s) >> 8); HSPI_WRITE(s)
|
|
||||||
#define HSPI_WRITE32(l) HSPI_WRITE((l) >> 24); HSPI_WRITE((l) >> 16); HSPI_WRITE((l) >> 8); HSPI_WRITE(l)
|
|
||||||
#define HSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<(l); i+=2){ HSPI_WRITE(((uint8_t*)(c))[i+1]); HSPI_WRITE(((uint8_t*)(c))[i]); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Final SPI Macros
|
|
||||||
* */
|
|
||||||
#if defined (ARDUINO_ARCH_ARC32)
|
|
||||||
#define SPI_DEFAULT_FREQ 16000000
|
|
||||||
#elif defined (__AVR__) || defined(TEENSYDUINO)
|
|
||||||
#define SPI_DEFAULT_FREQ 8000000
|
|
||||||
#elif defined(ESP8266) || defined(ESP32)
|
|
||||||
#define SPI_DEFAULT_FREQ 40000000
|
|
||||||
#elif defined(RASPI)
|
|
||||||
#define SPI_DEFAULT_FREQ 80000000
|
|
||||||
#elif defined(ARDUINO_ARCH_STM32F1)
|
|
||||||
#define SPI_DEFAULT_FREQ 36000000
|
|
||||||
#else
|
|
||||||
#define SPI_DEFAULT_FREQ 24000000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SPI_BEGIN() if(_sclk < 0){SPI_OBJECT.begin();}
|
|
||||||
#define SPI_BEGIN_TRANSACTION() if(_sclk < 0){HSPI_BEGIN_TRANSACTION();}
|
|
||||||
#define SPI_END_TRANSACTION() if(_sclk < 0){HSPI_END_TRANSACTION();}
|
|
||||||
#define SPI_WRITE16(s) if(_sclk < 0){HSPI_WRITE16(s);}else{SSPI_WRITE16(s);}
|
|
||||||
#define SPI_WRITE32(l) if(_sclk < 0){HSPI_WRITE32(l);}else{SSPI_WRITE32(l);}
|
|
||||||
#define SPI_WRITE_PIXELS(c,l) if(_sclk < 0){HSPI_WRITE_PIXELS(c,l);}else{SSPI_WRITE_PIXELS(c,l);}
|
|
||||||
|
|
||||||
// Pass 8-bit (each) R,G,B, get back 16-bit packed color
|
|
||||||
uint16_t Adafruit_ILI9341::color565(uint8_t r, uint8_t g, uint8_t b) {
|
|
||||||
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t mosi,
|
|
||||||
int8_t sclk, int8_t rst, int8_t miso) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
|
|
||||||
_cs = cs;
|
|
||||||
_dc = dc;
|
|
||||||
_rst = rst;
|
|
||||||
_sclk = sclk;
|
|
||||||
_mosi = mosi;
|
|
||||||
_miso = miso;
|
|
||||||
_freq = 0;
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
csport = portOutputRegister(digitalPinToPort(_cs));
|
|
||||||
cspinmask = digitalPinToBitMask(_cs);
|
|
||||||
dcport = portOutputRegister(digitalPinToPort(_dc));
|
|
||||||
dcpinmask = digitalPinToBitMask(_dc);
|
|
||||||
clkport = portOutputRegister(digitalPinToPort(_sclk));
|
|
||||||
clkpinmask = digitalPinToBitMask(_sclk);
|
|
||||||
mosiport = portOutputRegister(digitalPinToPort(_mosi));
|
|
||||||
mosipinmask = digitalPinToBitMask(_mosi);
|
|
||||||
if(miso >= 0){
|
|
||||||
misoport = portInputRegister(digitalPinToPort(_miso));
|
|
||||||
misopinmask = digitalPinToBitMask(_miso);
|
|
||||||
} else {
|
|
||||||
misoport = 0;
|
|
||||||
misopinmask = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
|
|
||||||
_cs = cs;
|
|
||||||
_dc = dc;
|
|
||||||
_rst = rst;
|
|
||||||
_sclk = -1;
|
|
||||||
_mosi = -1;
|
|
||||||
_miso = -1;
|
|
||||||
_freq = 0;
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
csport = portOutputRegister(digitalPinToPort(_cs));
|
|
||||||
cspinmask = digitalPinToBitMask(_cs);
|
|
||||||
dcport = portOutputRegister(digitalPinToPort(_dc));
|
|
||||||
dcpinmask = digitalPinToBitMask(_dc);
|
|
||||||
clkport = 0;
|
|
||||||
clkpinmask = 0;
|
|
||||||
mosiport = 0;
|
|
||||||
mosipinmask = 0;
|
|
||||||
misoport = 0;
|
|
||||||
misopinmask = 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
void Adafruit_ILI9341::begin(uint32_t freq, SPIClass &spi)
|
|
||||||
#else
|
|
||||||
void Adafruit_ILI9341::begin(uint32_t freq)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#ifdef ESP32
|
|
||||||
_spi = spi;
|
|
||||||
#endif
|
|
||||||
if(!freq){
|
|
||||||
freq = SPI_DEFAULT_FREQ;
|
|
||||||
}
|
|
||||||
_freq = freq;
|
|
||||||
|
|
||||||
// Control Pins
|
|
||||||
pinMode(_dc, OUTPUT);
|
|
||||||
digitalWrite(_dc, LOW);
|
|
||||||
pinMode(_cs, OUTPUT);
|
|
||||||
digitalWrite(_cs, HIGH);
|
|
||||||
|
|
||||||
// Software SPI
|
|
||||||
if(_sclk >= 0){
|
|
||||||
pinMode(_mosi, OUTPUT);
|
|
||||||
digitalWrite(_mosi, LOW);
|
|
||||||
pinMode(_sclk, OUTPUT);
|
|
||||||
digitalWrite(_sclk, HIGH);
|
|
||||||
if(_miso >= 0){
|
|
||||||
pinMode(_miso, INPUT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hardware SPI
|
|
||||||
SPI_BEGIN();
|
|
||||||
|
|
||||||
// toggle RST low to reset
|
|
||||||
if (_rst >= 0) {
|
|
||||||
pinMode(_rst, OUTPUT);
|
|
||||||
digitalWrite(_rst, HIGH);
|
|
||||||
delay(100);
|
|
||||||
digitalWrite(_rst, LOW);
|
|
||||||
delay(100);
|
|
||||||
digitalWrite(_rst, HIGH);
|
|
||||||
delay(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
startWrite();
|
|
||||||
|
|
||||||
writeCommand(0xEF);
|
|
||||||
spiWrite(0x03);
|
|
||||||
spiWrite(0x80);
|
|
||||||
spiWrite(0x02);
|
|
||||||
|
|
||||||
writeCommand(0xCF);
|
|
||||||
spiWrite(0x00);
|
|
||||||
spiWrite(0XC1);
|
|
||||||
spiWrite(0X30);
|
|
||||||
|
|
||||||
writeCommand(0xED);
|
|
||||||
spiWrite(0x64);
|
|
||||||
spiWrite(0x03);
|
|
||||||
spiWrite(0X12);
|
|
||||||
spiWrite(0X81);
|
|
||||||
|
|
||||||
writeCommand(0xE8);
|
|
||||||
spiWrite(0x85);
|
|
||||||
spiWrite(0x00);
|
|
||||||
spiWrite(0x78);
|
|
||||||
|
|
||||||
writeCommand(0xCB);
|
|
||||||
spiWrite(0x39);
|
|
||||||
spiWrite(0x2C);
|
|
||||||
spiWrite(0x00);
|
|
||||||
spiWrite(0x34);
|
|
||||||
spiWrite(0x02);
|
|
||||||
|
|
||||||
writeCommand(0xF7);
|
|
||||||
spiWrite(0x20);
|
|
||||||
|
|
||||||
writeCommand(0xEA);
|
|
||||||
spiWrite(0x00);
|
|
||||||
spiWrite(0x00);
|
|
||||||
|
|
||||||
writeCommand(ILI9341_PWCTR1); //Power control
|
|
||||||
spiWrite(0x23); //VRH[5:0]
|
|
||||||
|
|
||||||
writeCommand(ILI9341_PWCTR2); //Power control
|
|
||||||
spiWrite(0x10); //SAP[2:0];BT[3:0]
|
|
||||||
|
|
||||||
writeCommand(ILI9341_VMCTR1); //VCM control
|
|
||||||
spiWrite(0x3e);
|
|
||||||
spiWrite(0x28);
|
|
||||||
|
|
||||||
writeCommand(ILI9341_VMCTR2); //VCM control2
|
|
||||||
spiWrite(0x86); //--
|
|
||||||
|
|
||||||
writeCommand(ILI9341_MADCTL); // Memory Access Control
|
|
||||||
spiWrite(0x48);
|
|
||||||
|
|
||||||
writeCommand(ILI9341_VSCRSADD); // Vertical scroll
|
|
||||||
SPI_WRITE16(0); // Zero
|
|
||||||
|
|
||||||
writeCommand(ILI9341_PIXFMT);
|
|
||||||
spiWrite(0x55);
|
|
||||||
|
|
||||||
writeCommand(ILI9341_FRMCTR1);
|
|
||||||
spiWrite(0x00);
|
|
||||||
spiWrite(0x18);
|
|
||||||
|
|
||||||
writeCommand(ILI9341_DFUNCTR); // Display Function Control
|
|
||||||
spiWrite(0x08);
|
|
||||||
spiWrite(0x82);
|
|
||||||
spiWrite(0x27);
|
|
||||||
|
|
||||||
writeCommand(0xF2); // 3Gamma Function Disable
|
|
||||||
spiWrite(0x00);
|
|
||||||
|
|
||||||
writeCommand(ILI9341_GAMMASET); //Gamma curve selected
|
|
||||||
spiWrite(0x01);
|
|
||||||
|
|
||||||
writeCommand(ILI9341_GMCTRP1); //Set Gamma
|
|
||||||
spiWrite(0x0F);
|
|
||||||
spiWrite(0x31);
|
|
||||||
spiWrite(0x2B);
|
|
||||||
spiWrite(0x0C);
|
|
||||||
spiWrite(0x0E);
|
|
||||||
spiWrite(0x08);
|
|
||||||
spiWrite(0x4E);
|
|
||||||
spiWrite(0xF1);
|
|
||||||
spiWrite(0x37);
|
|
||||||
spiWrite(0x07);
|
|
||||||
spiWrite(0x10);
|
|
||||||
spiWrite(0x03);
|
|
||||||
spiWrite(0x0E);
|
|
||||||
spiWrite(0x09);
|
|
||||||
spiWrite(0x00);
|
|
||||||
|
|
||||||
writeCommand(ILI9341_GMCTRN1); //Set Gamma
|
|
||||||
spiWrite(0x00);
|
|
||||||
spiWrite(0x0E);
|
|
||||||
spiWrite(0x14);
|
|
||||||
spiWrite(0x03);
|
|
||||||
spiWrite(0x11);
|
|
||||||
spiWrite(0x07);
|
|
||||||
spiWrite(0x31);
|
|
||||||
spiWrite(0xC1);
|
|
||||||
spiWrite(0x48);
|
|
||||||
spiWrite(0x08);
|
|
||||||
spiWrite(0x0F);
|
|
||||||
spiWrite(0x0C);
|
|
||||||
spiWrite(0x31);
|
|
||||||
spiWrite(0x36);
|
|
||||||
spiWrite(0x0F);
|
|
||||||
|
|
||||||
writeCommand(ILI9341_SLPOUT); //Exit Sleep
|
|
||||||
delay(120);
|
|
||||||
writeCommand(ILI9341_DISPON); //Display on
|
|
||||||
delay(120);
|
|
||||||
endWrite();
|
|
||||||
|
|
||||||
_width = ILI9341_TFTWIDTH;
|
|
||||||
_height = ILI9341_TFTHEIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*********************************************************************************************/
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::setScrollMargins(uint16_t top, uint16_t bottom)
|
|
||||||
{
|
|
||||||
uint16_t height = _height - (top + bottom);
|
|
||||||
|
|
||||||
startWrite();
|
|
||||||
writeCommand(0x33);
|
|
||||||
SPI_WRITE16(top);
|
|
||||||
SPI_WRITE16(height);
|
|
||||||
SPI_WRITE16(bottom);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*********************************************************************************************/
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::setRotation(uint8_t m) {
|
|
||||||
rotation = m % 4; // can't be higher than 3
|
|
||||||
switch (rotation) {
|
|
||||||
case 0:
|
|
||||||
m = (MADCTL_MX | MADCTL_BGR);
|
|
||||||
_width = ILI9341_TFTWIDTH;
|
|
||||||
_height = ILI9341_TFTHEIGHT;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
m = (MADCTL_MV | MADCTL_BGR);
|
|
||||||
_width = ILI9341_TFTHEIGHT;
|
|
||||||
_height = ILI9341_TFTWIDTH;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
m = (MADCTL_MY | MADCTL_BGR);
|
|
||||||
_width = ILI9341_TFTWIDTH;
|
|
||||||
_height = ILI9341_TFTHEIGHT;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
m = (MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR);
|
|
||||||
_width = ILI9341_TFTHEIGHT;
|
|
||||||
_height = ILI9341_TFTWIDTH;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
startWrite();
|
|
||||||
writeCommand(ILI9341_MADCTL);
|
|
||||||
spiWrite(m);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::invertDisplay(boolean i) {
|
|
||||||
startWrite();
|
|
||||||
writeCommand(i ? ILI9341_INVON : ILI9341_INVOFF);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::scrollTo(uint16_t y) {
|
|
||||||
startWrite();
|
|
||||||
writeCommand(ILI9341_VSCRSADD);
|
|
||||||
SPI_WRITE16(y);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Adafruit_ILI9341::spiRead() {
|
|
||||||
if(_sclk < 0){
|
|
||||||
return HSPI_READ();
|
|
||||||
}
|
|
||||||
if(_miso < 0){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint8_t r = 0;
|
|
||||||
for (uint8_t i=0; i<8; i++) {
|
|
||||||
SSPI_SCK_LOW();
|
|
||||||
SSPI_SCK_HIGH();
|
|
||||||
r <<= 1;
|
|
||||||
if (SSPI_MISO_READ()){
|
|
||||||
r |= 0x1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::spiWrite(uint8_t b) {
|
|
||||||
if(_sclk < 0){
|
|
||||||
HSPI_WRITE(b);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for(uint8_t bit = 0x80; bit; bit >>= 1){
|
|
||||||
if((b) & bit){
|
|
||||||
SSPI_MOSI_HIGH();
|
|
||||||
} else {
|
|
||||||
SSPI_MOSI_LOW();
|
|
||||||
}
|
|
||||||
SSPI_SCK_LOW();
|
|
||||||
SSPI_SCK_HIGH();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Transaction API
|
|
||||||
* */
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::startWrite(void){
|
|
||||||
SPI_BEGIN_TRANSACTION();
|
|
||||||
SPI_CS_LOW();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::endWrite(void){
|
|
||||||
SPI_CS_HIGH();
|
|
||||||
SPI_END_TRANSACTION();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::writeCommand(uint8_t cmd){
|
|
||||||
SPI_DC_LOW();
|
|
||||||
spiWrite(cmd);
|
|
||||||
SPI_DC_HIGH();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
|
||||||
uint32_t xa = ((uint32_t)x << 16) | (x+w-1);
|
|
||||||
uint32_t ya = ((uint32_t)y << 16) | (y+h-1);
|
|
||||||
writeCommand(ILI9341_CASET); // Column addr set
|
|
||||||
SPI_WRITE32(xa);
|
|
||||||
writeCommand(ILI9341_PASET); // Row addr set
|
|
||||||
SPI_WRITE32(ya);
|
|
||||||
writeCommand(ILI9341_RAMWR); // write to RAM
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::pushColor(uint16_t color) {
|
|
||||||
startWrite();
|
|
||||||
SPI_WRITE16(color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::writePixel(uint16_t color){
|
|
||||||
SPI_WRITE16(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::writePixels(uint16_t * colors, uint32_t len){
|
|
||||||
SPI_WRITE_PIXELS((uint8_t*)colors , len * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::writeColor(uint16_t color, uint32_t len){
|
|
||||||
#ifdef SPI_HAS_WRITE_PIXELS
|
|
||||||
if(_sclk >= 0){
|
|
||||||
for (uint32_t t=0; t<len; t++){
|
|
||||||
writePixel(color);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static uint16_t temp[SPI_MAX_PIXELS_AT_ONCE];
|
|
||||||
size_t blen = (len > SPI_MAX_PIXELS_AT_ONCE)?SPI_MAX_PIXELS_AT_ONCE:len;
|
|
||||||
uint16_t tlen = 0;
|
|
||||||
|
|
||||||
for (uint32_t t=0; t<blen; t++){
|
|
||||||
temp[t] = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(len){
|
|
||||||
tlen = (len>blen)?blen:len;
|
|
||||||
writePixels(temp, tlen);
|
|
||||||
len -= tlen;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
uint8_t hi = color >> 8, lo = color;
|
|
||||||
if(_sclk < 0){ //AVR Optimization
|
|
||||||
for (uint32_t t=len; t; t--){
|
|
||||||
HSPI_WRITE(hi);
|
|
||||||
HSPI_WRITE(lo);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (uint32_t t=len; t; t--){
|
|
||||||
spiWrite(hi);
|
|
||||||
spiWrite(lo);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::writePixel(int16_t x, int16_t y, uint16_t color) {
|
|
||||||
if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;
|
|
||||||
setAddrWindow(x,y,1,1);
|
|
||||||
writePixel(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color){
|
|
||||||
if((x >= _width) || (y >= _height)) return;
|
|
||||||
int16_t x2 = x + w - 1, y2 = y + h - 1;
|
|
||||||
if((x2 < 0) || (y2 < 0)) return;
|
|
||||||
|
|
||||||
// Clip left/top
|
|
||||||
if(x < 0) {
|
|
||||||
x = 0;
|
|
||||||
w = x2 + 1;
|
|
||||||
}
|
|
||||||
if(y < 0) {
|
|
||||||
y = 0;
|
|
||||||
h = y2 + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clip right/bottom
|
|
||||||
if(x2 >= _width) w = _width - x;
|
|
||||||
if(y2 >= _height) h = _height - y;
|
|
||||||
|
|
||||||
int32_t len = (int32_t)w * h;
|
|
||||||
setAddrWindow(x, y, w, h);
|
|
||||||
writeColor(color, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color){
|
|
||||||
writeFillRect(x, y, 1, h, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color){
|
|
||||||
writeFillRect(x, y, w, 1, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Adafruit_ILI9341::readcommand8(uint8_t c, uint8_t index) {
|
|
||||||
uint32_t freq = _freq;
|
|
||||||
if(_freq > 24000000){
|
|
||||||
_freq = 24000000;
|
|
||||||
}
|
|
||||||
startWrite();
|
|
||||||
writeCommand(0xD9); // woo sekret command?
|
|
||||||
spiWrite(0x10 + index);
|
|
||||||
writeCommand(c);
|
|
||||||
uint8_t r = spiRead();
|
|
||||||
endWrite();
|
|
||||||
_freq = freq;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::drawPixel(int16_t x, int16_t y, uint16_t color){
|
|
||||||
startWrite();
|
|
||||||
writePixel(x, y, color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::drawFastVLine(int16_t x, int16_t y,
|
|
||||||
int16_t h, uint16_t color) {
|
|
||||||
startWrite();
|
|
||||||
writeFastVLine(x, y, h, color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::drawFastHLine(int16_t x, int16_t y,
|
|
||||||
int16_t w, uint16_t color) {
|
|
||||||
startWrite();
|
|
||||||
writeFastHLine(x, y, w, color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
|
||||||
uint16_t color) {
|
|
||||||
startWrite();
|
|
||||||
writeFillRect(x,y,w,h,color);
|
|
||||||
endWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adapted from https://github.com/PaulStoffregen/ILI9341_t3
|
|
||||||
// by Marc MERLIN. See examples/pictureEmbed to use this.
|
|
||||||
// 5/6/2017: function name and arguments have changed for compatibility
|
|
||||||
// with current GFX library and to avoid naming problems in prior
|
|
||||||
// implementation. Formerly drawBitmap() with arguments in different order.
|
|
||||||
void Adafruit_ILI9341::drawRGBBitmap(int16_t x, int16_t y,
|
|
||||||
uint16_t *pcolors, int16_t w, int16_t h) {
|
|
||||||
|
|
||||||
int16_t x2, y2; // Lower-right coord
|
|
||||||
if(( x >= _width ) || // Off-edge right
|
|
||||||
( y >= _height) || // " top
|
|
||||||
((x2 = (x+w-1)) < 0 ) || // " left
|
|
||||||
((y2 = (y+h-1)) < 0) ) return; // " bottom
|
|
||||||
|
|
||||||
int16_t bx1=0, by1=0, // Clipped top-left within bitmap
|
|
||||||
saveW=w; // Save original bitmap width value
|
|
||||||
if(x < 0) { // Clip left
|
|
||||||
w += x;
|
|
||||||
bx1 = -x;
|
|
||||||
x = 0;
|
|
||||||
}
|
|
||||||
if(y < 0) { // Clip top
|
|
||||||
h += y;
|
|
||||||
by1 = -y;
|
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
if(x2 >= _width ) w = _width - x; // Clip right
|
|
||||||
if(y2 >= _height) h = _height - y; // Clip bottom
|
|
||||||
|
|
||||||
pcolors += by1 * saveW + bx1; // Offset bitmap ptr to clipped top-left
|
|
||||||
startWrite();
|
|
||||||
setAddrWindow(x, y, w, h); // Clipped area
|
|
||||||
while(h--) { // For each (clipped) scanline...
|
|
||||||
writePixels(pcolors, w); // Push one (clipped) row
|
|
||||||
pcolors += saveW; // Advance pointer by one full (unclipped) line
|
|
||||||
}
|
|
||||||
endWrite();
|
|
||||||
}
|
|
@ -1,205 +0,0 @@
|
|||||||
/******************************************************************
|
|
||||||
This is our library for the Adafruit ILI9341 Breakout and Shield
|
|
||||||
----> http://www.adafruit.com/products/1651
|
|
||||||
|
|
||||||
Check out the links above for our tutorials and wiring diagrams
|
|
||||||
These displays use SPI to communicate, 4 or 5 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
|
|
||||||
*******************************************************************/
|
|
||||||
|
|
||||||
#ifndef _ADAFRUIT_ILI9341H_
|
|
||||||
#define _ADAFRUIT_ILI9341H_
|
|
||||||
|
|
||||||
#if ARDUINO >= 100
|
|
||||||
#include "Arduino.h"
|
|
||||||
#include "Print.h"
|
|
||||||
#else
|
|
||||||
#include "WProgram.h"
|
|
||||||
#endif
|
|
||||||
#include <SPI.h>
|
|
||||||
#include "Adafruit_GFX.h"
|
|
||||||
|
|
||||||
#if defined(ARDUINO_STM32_FEATHER)
|
|
||||||
typedef volatile uint32 RwReg;
|
|
||||||
#endif
|
|
||||||
#if defined(ARDUINO_FEATHER52)
|
|
||||||
typedef volatile uint32_t RwReg;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#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 0x0D
|
|
||||||
#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_VSCRSADD 0x37
|
|
||||||
#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
|
|
||||||
|
|
||||||
#if defined (ARDUINO_STM32_FEATHER) // doesnt work on wiced feather
|
|
||||||
#undef USE_FAST_PINIO
|
|
||||||
#elif defined (__AVR__) || defined(TEENSYDUINO) || defined(ESP8266) || defined (ESP32) || defined(__arm__)
|
|
||||||
#define USE_FAST_PINIO
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Adafruit_ILI9341 : public Adafruit_GFX {
|
|
||||||
protected:
|
|
||||||
|
|
||||||
public:
|
|
||||||
Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST = -1, int8_t _MISO = -1);
|
|
||||||
Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);
|
|
||||||
|
|
||||||
#ifndef ESP32
|
|
||||||
void begin(uint32_t freq = 0);
|
|
||||||
#else
|
|
||||||
void begin(uint32_t freq = 0, SPIClass &spi=SPI);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void setScrollMargins(uint16_t top, uint16_t bottom);
|
|
||||||
|
|
||||||
void setRotation(uint8_t r);
|
|
||||||
void invertDisplay(boolean i);
|
|
||||||
void scrollTo(uint16_t y);
|
|
||||||
|
|
||||||
// Required Non-Transaction
|
|
||||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
|
||||||
|
|
||||||
// Transaction API
|
|
||||||
void startWrite(void);
|
|
||||||
void endWrite(void);
|
|
||||||
void writePixel(int16_t x, int16_t y, uint16_t color);
|
|
||||||
void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
|
||||||
void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
|
||||||
void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
|
||||||
|
|
||||||
// Transaction API not used by GFX
|
|
||||||
void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
|
||||||
void writePixel(uint16_t color);
|
|
||||||
void writePixels(uint16_t * colors, uint32_t len);
|
|
||||||
void writeColor(uint16_t color, uint32_t len);
|
|
||||||
void pushColor(uint16_t color);
|
|
||||||
|
|
||||||
// Recommended Non-Transaction
|
|
||||||
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
|
||||||
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
|
||||||
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
|
||||||
|
|
||||||
using Adafruit_GFX::drawRGBBitmap; // Check base class first
|
|
||||||
void drawRGBBitmap(int16_t x, int16_t y,
|
|
||||||
uint16_t *pcolors, int16_t w, int16_t h);
|
|
||||||
|
|
||||||
uint8_t readcommand8(uint8_t reg, uint8_t index = 0);
|
|
||||||
|
|
||||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
|
|
||||||
|
|
||||||
private:
|
|
||||||
#ifdef ESP32
|
|
||||||
SPIClass _spi;
|
|
||||||
#endif
|
|
||||||
uint32_t _freq;
|
|
||||||
#if defined (__AVR__) || defined(TEENSYDUINO)
|
|
||||||
int8_t _cs, _dc, _rst, _sclk, _mosi, _miso;
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
volatile uint8_t *mosiport, *misoport, *clkport, *dcport, *csport;
|
|
||||||
uint8_t mosipinmask, misopinmask, clkpinmask, cspinmask, dcpinmask;
|
|
||||||
#endif
|
|
||||||
#elif defined (__arm__)
|
|
||||||
int32_t _cs, _dc, _rst, _sclk, _mosi, _miso;
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
volatile RwReg *mosiport, *misoport, *clkport, *dcport, *csport;
|
|
||||||
uint32_t mosipinmask, misopinmask, clkpinmask, cspinmask, dcpinmask;
|
|
||||||
#endif
|
|
||||||
#elif defined (ESP8266) || defined (ESP32)
|
|
||||||
int8_t _cs, _dc, _rst, _sclk, _mosi, _miso;
|
|
||||||
#ifdef USE_FAST_PINIO
|
|
||||||
volatile uint32_t *mosiport, *misoport, *clkport, *dcport, *csport;
|
|
||||||
uint32_t mosipinmask, misopinmask, clkpinmask, cspinmask, dcpinmask;
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
int8_t _cs, _dc, _rst, _sclk, _mosi, _miso;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void writeCommand(uint8_t cmd);
|
|
||||||
void spiWrite(uint8_t v);
|
|
||||||
uint8_t spiRead(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
4
lib/Adafruit_ILI9341-1.2.0-Tasmota-1.0/.gitignore
vendored
Normal file
4
lib/Adafruit_ILI9341-1.2.0-Tasmota-1.0/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Our handy .gitignore for automation ease
|
||||||
|
Doxyfile*
|
||||||
|
doxygen_sqlite3.db
|
||||||
|
html
|
38
lib/Adafruit_ILI9341-1.2.0-Tasmota-1.0/.travis.yml
Normal file
38
lib/Adafruit_ILI9341-1.2.0-Tasmota-1.0/.travis.yml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
language: c
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- ~/arduino_ide
|
||||||
|
# Caches Arduino IDE + ESP32 platform
|
||||||
|
- ~/.arduino15/packages/
|
||||||
|
# Caches Arduino platforms
|
||||||
|
git:
|
||||||
|
depth: false
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
# Blacklist
|
||||||
|
branches:
|
||||||
|
except:
|
||||||
|
- gh-pages
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- PRETTYNAME="Adafruit ILI9341 Arduino Library"
|
||||||
|
# Optional, will default to "$TRAVIS_BUILD_DIR/Doxyfile"
|
||||||
|
# - DOXYFILE: $TRAVIS_BUILD_DIR/Doxyfile
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
|
||||||
|
|
||||||
|
install:
|
||||||
|
- arduino --install-library "Adafruit GFX Library","Adafruit STMPE610","Adafruit TouchScreen"
|
||||||
|
|
||||||
|
script:
|
||||||
|
- build_main_platforms
|
||||||
|
|
||||||
|
# Generate and deploy documentation
|
||||||
|
after_success:
|
||||||
|
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/library_check.sh)
|
||||||
|
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh)
|
||||||
|
|
282
lib/Adafruit_ILI9341-1.2.0-Tasmota-1.0/Adafruit_ILI9341.cpp
Normal file
282
lib/Adafruit_ILI9341-1.2.0-Tasmota-1.0/Adafruit_ILI9341.cpp
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
/*!
|
||||||
|
* @file Adafruit_ILI9341.cpp
|
||||||
|
*
|
||||||
|
* @mainpage Adafruit ILI9341 TFT Displays
|
||||||
|
*
|
||||||
|
* @section intro_sec Introduction
|
||||||
|
*
|
||||||
|
* This is the documentation for Adafruit's ILI9341 driver for the
|
||||||
|
* Arduino platform.
|
||||||
|
*
|
||||||
|
* This library works with the Adafruit 2.8" Touch Shield V2 (SPI)
|
||||||
|
* http://www.adafruit.com/products/1651
|
||||||
|
*
|
||||||
|
* Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket - ILI9341
|
||||||
|
* https://www.adafruit.com/product/2478
|
||||||
|
*
|
||||||
|
* 2.8" TFT LCD with Touchscreen Breakout Board w/MicroSD Socket - ILI9341
|
||||||
|
* https://www.adafruit.com/product/1770
|
||||||
|
*
|
||||||
|
* 2.2" 18-bit color TFT LCD display with microSD card breakout - ILI9340
|
||||||
|
* https://www.adafruit.com/product/1770
|
||||||
|
*
|
||||||
|
* TFT FeatherWing - 2.4" 320x240 Touchscreen For All Feathers
|
||||||
|
* https://www.adafruit.com/product/3315
|
||||||
|
*
|
||||||
|
* These displays use SPI to communicate, 4 or 5 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!
|
||||||
|
*
|
||||||
|
* @section dependencies Dependencies
|
||||||
|
*
|
||||||
|
* This library depends on <a href="https://github.com/adafruit/Adafruit_GFX">
|
||||||
|
* Adafruit_GFX</a> being present on your system. Please make sure you have
|
||||||
|
* installed the latest version before using this library.
|
||||||
|
*
|
||||||
|
* @section author Author
|
||||||
|
*
|
||||||
|
* Written by Limor "ladyada" Fried for Adafruit Industries.
|
||||||
|
*
|
||||||
|
* @section license License
|
||||||
|
*
|
||||||
|
* BSD license, all text here must be included in any redistribution.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Adafruit_ILI9341.h"
|
||||||
|
#ifndef ARDUINO_STM32_FEATHER
|
||||||
|
#include "pins_arduino.h"
|
||||||
|
#ifndef RASPI
|
||||||
|
#include "wiring_private.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#if defined (ARDUINO_ARCH_ARC32) || defined (ARDUINO_MAXIM)
|
||||||
|
#define SPI_DEFAULT_FREQ 16000000
|
||||||
|
#elif defined (__AVR__) || defined(TEENSYDUINO)
|
||||||
|
#define SPI_DEFAULT_FREQ 8000000
|
||||||
|
#elif defined(ESP8266) || defined(ESP32)
|
||||||
|
#define SPI_DEFAULT_FREQ 40000000
|
||||||
|
#elif defined(RASPI)
|
||||||
|
#define SPI_DEFAULT_FREQ 80000000
|
||||||
|
#elif defined(ARDUINO_ARCH_STM32F1)
|
||||||
|
#define SPI_DEFAULT_FREQ 36000000
|
||||||
|
#else
|
||||||
|
#define SPI_DEFAULT_FREQ 24000000 ///< Default SPI data clock frequency
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MADCTL_MY 0x80 ///< Bottom to top
|
||||||
|
#define MADCTL_MX 0x40 ///< Right to left
|
||||||
|
#define MADCTL_MV 0x20 ///< Reverse Mode
|
||||||
|
#define MADCTL_ML 0x10 ///< LCD refresh Bottom to top
|
||||||
|
#define MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order
|
||||||
|
#define MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order
|
||||||
|
#define MADCTL_MH 0x04 ///< LCD refresh right to left
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Instantiate Adafruit ILI9341 driver with software SPI
|
||||||
|
@param cs Chip select pin #
|
||||||
|
@param dc Data/Command pin #
|
||||||
|
@param mosi SPI MOSI pin #
|
||||||
|
@param sclk SPI Clock pin #
|
||||||
|
@param rst Reset pin # (optional, pass -1 if unused)
|
||||||
|
@param miso SPI MISO pin # (optional, pass -1 if unused)
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t mosi,
|
||||||
|
int8_t sclk, int8_t rst, int8_t miso) : Adafruit_SPITFT(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT, cs, dc, mosi, sclk, rst, miso) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Instantiate Adafruit ILI9341 driver with hardware SPI
|
||||||
|
@param cs Chip select pin #
|
||||||
|
@param dc Data/Command pin #
|
||||||
|
@param rst Reset pin # (optional, pass -1 if unused)
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst) : Adafruit_SPITFT(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT, cs, dc, rst) {
|
||||||
|
}
|
||||||
|
|
||||||
|
static const uint8_t PROGMEM initcmd[] = {
|
||||||
|
0xEF, 3, 0x03, 0x80, 0x02,
|
||||||
|
0xCF, 3, 0x00, 0xC1, 0x30,
|
||||||
|
0xED, 4, 0x64, 0x03, 0x12, 0x81,
|
||||||
|
0xE8, 3, 0x85, 0x00, 0x78,
|
||||||
|
0xCB, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
|
||||||
|
0xF7, 1, 0x20,
|
||||||
|
0xEA, 2, 0x00, 0x00,
|
||||||
|
ILI9341_PWCTR1 , 1, 0x23, // Power control VRH[5:0]
|
||||||
|
ILI9341_PWCTR2 , 1, 0x10, // Power control SAP[2:0];BT[3:0]
|
||||||
|
ILI9341_VMCTR1 , 2, 0x3e, 0x28, // VCM control
|
||||||
|
ILI9341_VMCTR2 , 1, 0x86, // VCM control2
|
||||||
|
ILI9341_MADCTL , 1, 0x48, // Memory Access Control
|
||||||
|
ILI9341_VSCRSADD, 1, 0x00, // Vertical scroll zero
|
||||||
|
ILI9341_PIXFMT , 1, 0x55,
|
||||||
|
ILI9341_FRMCTR1 , 2, 0x00, 0x18,
|
||||||
|
ILI9341_DFUNCTR , 3, 0x08, 0x82, 0x27, // Display Function Control
|
||||||
|
0xF2, 1, 0x00, // 3Gamma Function Disable
|
||||||
|
ILI9341_GAMMASET , 1, 0x01, // Gamma curve selected
|
||||||
|
ILI9341_GMCTRP1 , 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, // Set Gamma
|
||||||
|
0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
|
||||||
|
ILI9341_GMCTRN1 , 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, // Set Gamma
|
||||||
|
0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
|
||||||
|
ILI9341_SLPOUT , 0x80, // Exit Sleep
|
||||||
|
ILI9341_DISPON , 0x80, // Display on
|
||||||
|
0x00 // End of list
|
||||||
|
};
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Initialize ILI9341 chip
|
||||||
|
Connects to the ILI9341 over SPI and sends initialization procedure commands
|
||||||
|
@param freq Desired SPI clock frequency
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_ILI9341::begin(uint32_t freq) {
|
||||||
|
if(!freq) freq = SPI_DEFAULT_FREQ;
|
||||||
|
_freq = freq;
|
||||||
|
|
||||||
|
initSPI(freq);
|
||||||
|
|
||||||
|
startWrite();
|
||||||
|
|
||||||
|
uint8_t cmd, x, numArgs;
|
||||||
|
const uint8_t *addr = initcmd;
|
||||||
|
while((cmd = pgm_read_byte(addr++)) > 0) {
|
||||||
|
writeCommand(cmd);
|
||||||
|
x = pgm_read_byte(addr++);
|
||||||
|
numArgs = x & 0x7F;
|
||||||
|
while(numArgs--) spiWrite(pgm_read_byte(addr++));
|
||||||
|
if(x & 0x80) delay(120);
|
||||||
|
}
|
||||||
|
|
||||||
|
endWrite();
|
||||||
|
|
||||||
|
_width = ILI9341_TFTWIDTH;
|
||||||
|
_height = ILI9341_TFTHEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Set origin of (0,0) and orientation of TFT display
|
||||||
|
@param m The index for rotation, from 0-3 inclusive
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_ILI9341::setRotation(uint8_t m) {
|
||||||
|
rotation = m % 4; // can't be higher than 3
|
||||||
|
switch (rotation) {
|
||||||
|
case 0:
|
||||||
|
m = (MADCTL_MX | MADCTL_BGR);
|
||||||
|
_width = ILI9341_TFTWIDTH;
|
||||||
|
_height = ILI9341_TFTHEIGHT;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
m = (MADCTL_MV | MADCTL_BGR);
|
||||||
|
_width = ILI9341_TFTHEIGHT;
|
||||||
|
_height = ILI9341_TFTWIDTH;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
m = (MADCTL_MY | MADCTL_BGR);
|
||||||
|
_width = ILI9341_TFTWIDTH;
|
||||||
|
_height = ILI9341_TFTHEIGHT;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
m = (MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR);
|
||||||
|
_width = ILI9341_TFTHEIGHT;
|
||||||
|
_height = ILI9341_TFTWIDTH;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
startWrite();
|
||||||
|
writeCommand(ILI9341_MADCTL);
|
||||||
|
spiWrite(m);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Enable/Disable display color inversion
|
||||||
|
@param invert True to invert, False to have normal color
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_ILI9341::invertDisplay(boolean invert) {
|
||||||
|
startWrite();
|
||||||
|
writeCommand(invert ? ILI9341_INVON : ILI9341_INVOFF);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Scroll display memory
|
||||||
|
@param y How many pixels to scroll display by
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_ILI9341::scrollTo(uint16_t y) {
|
||||||
|
startWrite();
|
||||||
|
writeCommand(ILI9341_VSCRSADD);
|
||||||
|
SPI_WRITE16(y);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
void Adafruit_ILI9341::setScrollMargins(uint16_t top, uint16_t bottom)
|
||||||
|
{
|
||||||
|
uint16_t height = _height - (top + bottom);
|
||||||
|
|
||||||
|
startWrite();
|
||||||
|
writeCommand(0x33);
|
||||||
|
SPI_WRITE16(top);
|
||||||
|
SPI_WRITE16(height);
|
||||||
|
SPI_WRITE16(bottom);
|
||||||
|
endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Set the "address window" - the rectangle we will write to RAM with the next chunk of SPI data writes. The ILI9341 will automatically wrap the data as each row is filled
|
||||||
|
@param x TFT memory 'x' origin
|
||||||
|
@param y TFT memory 'y' origin
|
||||||
|
@param w Width of rectangle
|
||||||
|
@param h Height of rectangle
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_ILI9341::setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||||
|
uint32_t xa = ((uint32_t)x << 16) | (x+w-1);
|
||||||
|
uint32_t ya = ((uint32_t)y << 16) | (y+h-1);
|
||||||
|
writeCommand(ILI9341_CASET); // Column addr set
|
||||||
|
SPI_WRITE32(xa);
|
||||||
|
writeCommand(ILI9341_PASET); // Row addr set
|
||||||
|
SPI_WRITE32(ya);
|
||||||
|
writeCommand(ILI9341_RAMWR); // write to RAM
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Read 8 bits of data from ILI9341 configuration memory. NOT from RAM!
|
||||||
|
This is highly undocumented/supported, it's really a hack but kinda works?
|
||||||
|
@param command The command register to read data from
|
||||||
|
@param index The byte index into the command to read from
|
||||||
|
@return Unsigned 8-bit data read from ILI9341 register
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
uint8_t Adafruit_ILI9341::readcommand8(uint8_t command, uint8_t index) {
|
||||||
|
uint32_t freq = _freq;
|
||||||
|
if(_freq > 24000000) _freq = 24000000;
|
||||||
|
startWrite();
|
||||||
|
writeCommand(0xD9); // woo sekret command?
|
||||||
|
spiWrite(0x10 + index);
|
||||||
|
writeCommand(command);
|
||||||
|
uint8_t r = spiRead();
|
||||||
|
endWrite();
|
||||||
|
_freq = freq;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
144
lib/Adafruit_ILI9341-1.2.0-Tasmota-1.0/Adafruit_ILI9341.h
Normal file
144
lib/Adafruit_ILI9341-1.2.0-Tasmota-1.0/Adafruit_ILI9341.h
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/*!
|
||||||
|
* @file Adafruit_ILI9341.h
|
||||||
|
*
|
||||||
|
* This is the documentation for Adafruit's ILI9341 driver for the
|
||||||
|
* Arduino platform.
|
||||||
|
*
|
||||||
|
* This library works with the Adafruit 2.8" Touch Shield V2 (SPI)
|
||||||
|
* http://www.adafruit.com/products/1651
|
||||||
|
* Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket - ILI9341
|
||||||
|
* https://www.adafruit.com/product/2478
|
||||||
|
* 2.8" TFT LCD with Touchscreen Breakout Board w/MicroSD Socket - ILI9341
|
||||||
|
* https://www.adafruit.com/product/1770
|
||||||
|
* 2.2" 18-bit color TFT LCD display with microSD card breakout - ILI9340
|
||||||
|
* https://www.adafruit.com/product/1770
|
||||||
|
* TFT FeatherWing - 2.4" 320x240 Touchscreen For All Feathers
|
||||||
|
* https://www.adafruit.com/product/3315
|
||||||
|
*
|
||||||
|
* These displays use SPI to communicate, 4 or 5 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!
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* This library depends on <a href="https://github.com/adafruit/Adafruit_GFX">
|
||||||
|
* Adafruit_GFX</a> being present on your system. Please make sure you have
|
||||||
|
* installed the latest version before using this library.
|
||||||
|
*
|
||||||
|
* Written by Limor "ladyada" Fried for Adafruit Industries.
|
||||||
|
*
|
||||||
|
* BSD license, all text here must be included in any redistribution.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ADAFRUIT_ILI9341H_
|
||||||
|
#define _ADAFRUIT_ILI9341H_
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Print.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
#include "Adafruit_GFX.h"
|
||||||
|
#include <Adafruit_SPITFT.h>
|
||||||
|
#include <Adafruit_SPITFT_Macros.h>
|
||||||
|
|
||||||
|
#define ILI9341_TFTWIDTH 240 ///< ILI9341 max TFT width
|
||||||
|
#define ILI9341_TFTHEIGHT 320 ///< ILI9341 max TFT height
|
||||||
|
|
||||||
|
#define ILI9341_NOP 0x00 ///< No-op register
|
||||||
|
#define ILI9341_SWRESET 0x01 ///< Software reset register
|
||||||
|
#define ILI9341_RDDID 0x04 ///< Read display identification information
|
||||||
|
#define ILI9341_RDDST 0x09 ///< Read Display Status
|
||||||
|
|
||||||
|
#define ILI9341_SLPIN 0x10 ///< Enter Sleep Mode
|
||||||
|
#define ILI9341_SLPOUT 0x11 ///< Sleep Out
|
||||||
|
#define ILI9341_PTLON 0x12 ///< Partial Mode ON
|
||||||
|
#define ILI9341_NORON 0x13 ///< Normal Display Mode ON
|
||||||
|
|
||||||
|
#define ILI9341_RDMODE 0x0A ///< Read Display Power Mode
|
||||||
|
#define ILI9341_RDMADCTL 0x0B ///< Read Display MADCTL
|
||||||
|
#define ILI9341_RDPIXFMT 0x0C ///< Read Display Pixel Format
|
||||||
|
#define ILI9341_RDIMGFMT 0x0D ///< Read Display Image Format
|
||||||
|
#define ILI9341_RDSELFDIAG 0x0F ///< Read Display Self-Diagnostic Result
|
||||||
|
|
||||||
|
#define ILI9341_INVOFF 0x20 ///< Display Inversion OFF
|
||||||
|
#define ILI9341_INVON 0x21 ///< Display Inversion ON
|
||||||
|
#define ILI9341_GAMMASET 0x26 ///< Gamma Set
|
||||||
|
#define ILI9341_DISPOFF 0x28 ///< Display OFF
|
||||||
|
#define ILI9341_DISPON 0x29 ///< Display ON
|
||||||
|
|
||||||
|
#define ILI9341_CASET 0x2A ///< Column Address Set
|
||||||
|
#define ILI9341_PASET 0x2B ///< Page Address Set
|
||||||
|
#define ILI9341_RAMWR 0x2C ///< Memory Write
|
||||||
|
#define ILI9341_RAMRD 0x2E ///< Memory Read
|
||||||
|
|
||||||
|
#define ILI9341_PTLAR 0x30 ///< Partial Area
|
||||||
|
#define ILI9341_MADCTL 0x36 ///< Memory Access Control
|
||||||
|
#define ILI9341_VSCRSADD 0x37 ///< Vertical Scrolling Start Address
|
||||||
|
#define ILI9341_PIXFMT 0x3A ///< COLMOD: Pixel Format Set
|
||||||
|
|
||||||
|
#define ILI9341_FRMCTR1 0xB1 ///< Frame Rate Control (In Normal Mode/Full Colors)
|
||||||
|
#define ILI9341_FRMCTR2 0xB2 ///< Frame Rate Control (In Idle Mode/8 colors)
|
||||||
|
#define ILI9341_FRMCTR3 0xB3 ///< Frame Rate control (In Partial Mode/Full Colors)
|
||||||
|
#define ILI9341_INVCTR 0xB4 ///< Display Inversion Control
|
||||||
|
#define ILI9341_DFUNCTR 0xB6 ///< Display Function Control
|
||||||
|
|
||||||
|
#define ILI9341_PWCTR1 0xC0 ///< Power Control 1
|
||||||
|
#define ILI9341_PWCTR2 0xC1 ///< Power Control 2
|
||||||
|
#define ILI9341_PWCTR3 0xC2 ///< Power Control 3
|
||||||
|
#define ILI9341_PWCTR4 0xC3 ///< Power Control 4
|
||||||
|
#define ILI9341_PWCTR5 0xC4 ///< Power Control 5
|
||||||
|
#define ILI9341_VMCTR1 0xC5 ///< VCOM Control 1
|
||||||
|
#define ILI9341_VMCTR2 0xC7 ///< VCOM Control 2
|
||||||
|
|
||||||
|
#define ILI9341_RDID1 0xDA ///< Read ID 1
|
||||||
|
#define ILI9341_RDID2 0xDB ///< Read ID 2
|
||||||
|
#define ILI9341_RDID3 0xDC ///< Read ID 3
|
||||||
|
#define ILI9341_RDID4 0xDD ///< Read ID 4
|
||||||
|
|
||||||
|
#define ILI9341_GMCTRP1 0xE0 ///< Positive Gamma Correction
|
||||||
|
#define ILI9341_GMCTRN1 0xE1 ///< Negative Gamma Correction
|
||||||
|
//#define ILI9341_PWCTR6 0xFC
|
||||||
|
|
||||||
|
// Color definitions
|
||||||
|
#define ILI9341_BLACK 0x0000 ///< 0, 0, 0
|
||||||
|
#define ILI9341_NAVY 0x000F ///< 0, 0, 123
|
||||||
|
#define ILI9341_DARKGREEN 0x03E0 ///< 0, 125, 0
|
||||||
|
#define ILI9341_DARKCYAN 0x03EF ///< 0, 125, 123
|
||||||
|
#define ILI9341_MAROON 0x7800 ///< 123, 0, 0
|
||||||
|
#define ILI9341_PURPLE 0x780F ///< 123, 0, 123
|
||||||
|
#define ILI9341_OLIVE 0x7BE0 ///< 123, 125, 0
|
||||||
|
#define ILI9341_LIGHTGREY 0xC618 ///< 198, 195, 198
|
||||||
|
#define ILI9341_DARKGREY 0x7BEF ///< 123, 125, 123
|
||||||
|
#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, 41
|
||||||
|
#define ILI9341_PINK 0xFC18 ///< 255, 130, 198
|
||||||
|
|
||||||
|
///< Class to manage hardware interface with ILI9341 chipset (also seems to work with ILI9340)
|
||||||
|
class Adafruit_ILI9341 : public Adafruit_SPITFT {
|
||||||
|
public:
|
||||||
|
Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST = -1, int8_t _MISO = -1);
|
||||||
|
Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);
|
||||||
|
|
||||||
|
void begin(uint32_t freq=0);
|
||||||
|
void setRotation(uint8_t r);
|
||||||
|
void invertDisplay(boolean i);
|
||||||
|
void scrollTo(uint16_t y);
|
||||||
|
|
||||||
|
void setScrollMargins(uint16_t top, uint16_t bottom);
|
||||||
|
|
||||||
|
// Transaction API not used by GFX
|
||||||
|
void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||||
|
|
||||||
|
uint8_t readcommand8(uint8_t reg, uint8_t index=0);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _ADAFRUIT_ILI9341H_
|
@ -1,7 +1,21 @@
|
|||||||
|
# Adafruit ILI9341 Arduino Library [](https://travis-ci.org/adafruit/Adafruit_ILI9341)
|
||||||
|
|
||||||
This is a library for the Adafruit ILI9341 display products
|
This is a library for the Adafruit ILI9341 display products
|
||||||
|
|
||||||
This library works with the Adafruit 2.8" Touch Shield V2 (SPI)
|
This library works with the Adafruit 2.8" Touch Shield V2 (SPI)
|
||||||
----> http://www.adafruit.com/products/1651
|
* http://www.adafruit.com/products/1651
|
||||||
|
|
||||||
|
Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket - ILI9341
|
||||||
|
* https://www.adafruit.com/product/2478
|
||||||
|
|
||||||
|
2.8" TFT LCD with Touchscreen Breakout Board w/MicroSD Socket - ILI9341
|
||||||
|
* https://www.adafruit.com/product/1770
|
||||||
|
|
||||||
|
2.2" 18-bit color TFT LCD display with microSD card breakout - ILI9340
|
||||||
|
* https://www.adafruit.com/product/1480
|
||||||
|
|
||||||
|
TFT FeatherWing - 2.4" 320x240 Touchscreen For All Feathers
|
||||||
|
* https://www.adafruit.com/product/3315
|
||||||
|
|
||||||
Check out the links above for our tutorials and wiring diagrams.
|
Check out the links above for our tutorials and wiring diagrams.
|
||||||
These displays use SPI to communicate, 4 or 5 pins are required
|
These displays use SPI to communicate, 4 or 5 pins are required
|
@ -32,12 +32,6 @@
|
|||||||
#define TFT_DC 33
|
#define TFT_DC 33
|
||||||
#define SD_CS 14
|
#define SD_CS 14
|
||||||
#endif
|
#endif
|
||||||
#if defined (__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_FEATHER_M0) || defined (__AVR_ATmega328P__)
|
|
||||||
#define STMPE_CS 6
|
|
||||||
#define TFT_CS 9
|
|
||||||
#define TFT_DC 10
|
|
||||||
#define SD_CS 5
|
|
||||||
#endif
|
|
||||||
#ifdef TEENSYDUINO
|
#ifdef TEENSYDUINO
|
||||||
#define TFT_DC 10
|
#define TFT_DC 10
|
||||||
#define TFT_CS 4
|
#define TFT_CS 4
|
||||||
@ -56,6 +50,20 @@
|
|||||||
#define STMPE_CS 30
|
#define STMPE_CS 30
|
||||||
#define SD_CS 27
|
#define SD_CS 27
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR)
|
||||||
|
#define TFT_DC P5_4
|
||||||
|
#define TFT_CS P5_3
|
||||||
|
#define STMPE_CS P3_3
|
||||||
|
#define SD_CS P3_2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Anything else!
|
||||||
|
#if defined (__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_FEATHER_M0) || defined (__AVR_ATmega328P__) || defined(ARDUINO_SAMD_ZERO) || defined(__SAMD51__) || defined(__SAM3X8E__)
|
||||||
|
#define STMPE_CS 6
|
||||||
|
#define TFT_CS 9
|
||||||
|
#define TFT_DC 10
|
||||||
|
#define SD_CS 5
|
||||||
|
#endif
|
||||||
|
|
||||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||||
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
|
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
|
||||||
@ -102,7 +110,6 @@ void loop() {
|
|||||||
Serial.print("\tY = "); Serial.print(p.y);
|
Serial.print("\tY = "); Serial.print(p.y);
|
||||||
Serial.print("\tPressure = "); Serial.println(p.z);
|
Serial.print("\tPressure = "); Serial.println(p.z);
|
||||||
|
|
||||||
|
|
||||||
// Scale from ~0->4000 to tft.width using the calibration #'s
|
// Scale from ~0->4000 to tft.width using the calibration #'s
|
||||||
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
|
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
|
||||||
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
|
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
|
||||||
@ -122,7 +129,7 @@ void loop() {
|
|||||||
|
|
||||||
#define BUFFPIXEL 20
|
#define BUFFPIXEL 20
|
||||||
|
|
||||||
void bmpDraw(char *filename, uint8_t x, uint16_t y) {
|
void bmpDraw(char *filename, int16_t x, int16_t y) {
|
||||||
|
|
||||||
File bmpFile;
|
File bmpFile;
|
||||||
int bmpWidth, bmpHeight; // W+H in pixels
|
int bmpWidth, bmpHeight; // W+H in pixels
|
||||||
@ -188,7 +195,8 @@ void bmpDraw(char *filename, uint8_t x, uint16_t y) {
|
|||||||
if((y+h-1) >= tft.height()) h = tft.height() - y;
|
if((y+h-1) >= tft.height()) h = tft.height() - y;
|
||||||
|
|
||||||
// Set TFT address window to clipped image bounds
|
// Set TFT address window to clipped image bounds
|
||||||
tft.setAddrWindow(x, y, x+w-1, y+h-1);
|
tft.startWrite();
|
||||||
|
tft.setAddrWindow(x, y, w, h);
|
||||||
|
|
||||||
for (row=0; row<h; row++) { // For each scanline...
|
for (row=0; row<h; row++) { // For each scanline...
|
||||||
|
|
||||||
@ -203,6 +211,7 @@ void bmpDraw(char *filename, uint8_t x, uint16_t y) {
|
|||||||
else // Bitmap is stored top-to-bottom
|
else // Bitmap is stored top-to-bottom
|
||||||
pos = bmpImageoffset + row * rowSize;
|
pos = bmpImageoffset + row * rowSize;
|
||||||
if(bmpFile.position() != pos) { // Need seek?
|
if(bmpFile.position() != pos) { // Need seek?
|
||||||
|
tft.endWrite();
|
||||||
bmpFile.seek(pos);
|
bmpFile.seek(pos);
|
||||||
buffidx = sizeof(sdbuffer); // Force buffer reload
|
buffidx = sizeof(sdbuffer); // Force buffer reload
|
||||||
}
|
}
|
||||||
@ -210,7 +219,9 @@ void bmpDraw(char *filename, uint8_t x, uint16_t y) {
|
|||||||
for (col=0; col<w; col++) { // For each pixel...
|
for (col=0; col<w; col++) { // For each pixel...
|
||||||
// Time to read more pixel data?
|
// Time to read more pixel data?
|
||||||
if (buffidx >= sizeof(sdbuffer)) { // Indeed
|
if (buffidx >= sizeof(sdbuffer)) { // Indeed
|
||||||
|
tft.endWrite();
|
||||||
bmpFile.read(sdbuffer, sizeof(sdbuffer));
|
bmpFile.read(sdbuffer, sizeof(sdbuffer));
|
||||||
|
tft.startWrite();
|
||||||
buffidx = 0; // Set index to beginning
|
buffidx = 0; // Set index to beginning
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,6 +231,7 @@ void bmpDraw(char *filename, uint8_t x, uint16_t y) {
|
|||||||
r = sdbuffer[buffidx++];
|
r = sdbuffer[buffidx++];
|
||||||
tft.pushColor(tft.color565(r,g,b));
|
tft.pushColor(tft.color565(r,g,b));
|
||||||
} // end pixel
|
} // end pixel
|
||||||
|
tft.endWrite();
|
||||||
} // end scanline
|
} // end scanline
|
||||||
Serial.print(F("Loaded in "));
|
Serial.print(F("Loaded in "));
|
||||||
Serial.print(millis() - startTime);
|
Serial.print(millis() - startTime);
|
@ -0,0 +1,365 @@
|
|||||||
|
/***************************************************
|
||||||
|
This is our GFX example for the Adafruit ILI9341 Breakout and Shield
|
||||||
|
----> http://www.adafruit.com/products/1651
|
||||||
|
|
||||||
|
Check out the links above for our tutorials and wiring diagrams
|
||||||
|
These displays use SPI to communicate, 4 or 5 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
|
||||||
|
****************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include "SPI.h"
|
||||||
|
#include "Adafruit_GFX.h"
|
||||||
|
#include "Adafruit_ILI9341.h"
|
||||||
|
|
||||||
|
// For the Adafruit shield, these are the default.
|
||||||
|
#define TFT_DC 9
|
||||||
|
#define TFT_CS 10
|
||||||
|
|
||||||
|
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
|
||||||
|
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||||
|
// If using the breakout, change pins as desired
|
||||||
|
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
Serial.println("ILI9341 Test!");
|
||||||
|
|
||||||
|
tft.begin();
|
||||||
|
|
||||||
|
// read diagnostics (optional but can help debug problems)
|
||||||
|
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
|
||||||
|
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
|
||||||
|
x = tft.readcommand8(ILI9341_RDMADCTL);
|
||||||
|
Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
|
||||||
|
x = tft.readcommand8(ILI9341_RDPIXFMT);
|
||||||
|
Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
|
||||||
|
x = tft.readcommand8(ILI9341_RDIMGFMT);
|
||||||
|
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
|
||||||
|
x = tft.readcommand8(ILI9341_RDSELFDIAG);
|
||||||
|
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
|
||||||
|
|
||||||
|
Serial.println(F("Benchmark Time (microseconds)"));
|
||||||
|
delay(10);
|
||||||
|
Serial.print(F("Screen fill "));
|
||||||
|
Serial.println(testFillScreen());
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print(F("Text "));
|
||||||
|
Serial.println(testText());
|
||||||
|
delay(3000);
|
||||||
|
|
||||||
|
Serial.print(F("Lines "));
|
||||||
|
Serial.println(testLines(ILI9341_CYAN));
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print(F("Horiz/Vert Lines "));
|
||||||
|
Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print(F("Rectangles (outline) "));
|
||||||
|
Serial.println(testRects(ILI9341_GREEN));
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print(F("Rectangles (filled) "));
|
||||||
|
Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print(F("Circles (filled) "));
|
||||||
|
Serial.println(testFilledCircles(10, ILI9341_MAGENTA));
|
||||||
|
|
||||||
|
Serial.print(F("Circles (outline) "));
|
||||||
|
Serial.println(testCircles(10, ILI9341_WHITE));
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print(F("Triangles (outline) "));
|
||||||
|
Serial.println(testTriangles());
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print(F("Triangles (filled) "));
|
||||||
|
Serial.println(testFilledTriangles());
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print(F("Rounded rects (outline) "));
|
||||||
|
Serial.println(testRoundRects());
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print(F("Rounded rects (filled) "));
|
||||||
|
Serial.println(testFilledRoundRects());
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.println(F("Done!"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop(void) {
|
||||||
|
for(uint8_t rotation=0; rotation<4; rotation++) {
|
||||||
|
tft.setRotation(rotation);
|
||||||
|
testText();
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testFillScreen() {
|
||||||
|
unsigned long start = micros();
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
yield();
|
||||||
|
tft.fillScreen(ILI9341_RED);
|
||||||
|
yield();
|
||||||
|
tft.fillScreen(ILI9341_GREEN);
|
||||||
|
yield();
|
||||||
|
tft.fillScreen(ILI9341_BLUE);
|
||||||
|
yield();
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
yield();
|
||||||
|
return micros() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testText() {
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
unsigned long start = micros();
|
||||||
|
tft.setCursor(0, 0);
|
||||||
|
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1);
|
||||||
|
tft.println("Hello World!");
|
||||||
|
tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
|
||||||
|
tft.println(1234.56);
|
||||||
|
tft.setTextColor(ILI9341_RED); tft.setTextSize(3);
|
||||||
|
tft.println(0xDEADBEEF, HEX);
|
||||||
|
tft.println();
|
||||||
|
tft.setTextColor(ILI9341_GREEN);
|
||||||
|
tft.setTextSize(5);
|
||||||
|
tft.println("Groop");
|
||||||
|
tft.setTextSize(2);
|
||||||
|
tft.println("I implore thee,");
|
||||||
|
tft.setTextSize(1);
|
||||||
|
tft.println("my foonting turlingdromes.");
|
||||||
|
tft.println("And hooptiously drangle me");
|
||||||
|
tft.println("with crinkly bindlewurdles,");
|
||||||
|
tft.println("Or I will rend thee");
|
||||||
|
tft.println("in the gobberwarts");
|
||||||
|
tft.println("with my blurglecruncheon,");
|
||||||
|
tft.println("see if I don't!");
|
||||||
|
return micros() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testLines(uint16_t color) {
|
||||||
|
unsigned long start, t;
|
||||||
|
int x1, y1, x2, y2,
|
||||||
|
w = tft.width(),
|
||||||
|
h = tft.height();
|
||||||
|
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
yield();
|
||||||
|
|
||||||
|
x1 = y1 = 0;
|
||||||
|
y2 = h - 1;
|
||||||
|
start = micros();
|
||||||
|
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||||
|
x2 = w - 1;
|
||||||
|
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||||
|
t = micros() - start; // fillScreen doesn't count against timing
|
||||||
|
|
||||||
|
yield();
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
yield();
|
||||||
|
|
||||||
|
x1 = w - 1;
|
||||||
|
y1 = 0;
|
||||||
|
y2 = h - 1;
|
||||||
|
start = micros();
|
||||||
|
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||||
|
x2 = 0;
|
||||||
|
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||||
|
t += micros() - start;
|
||||||
|
|
||||||
|
yield();
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
yield();
|
||||||
|
|
||||||
|
x1 = 0;
|
||||||
|
y1 = h - 1;
|
||||||
|
y2 = 0;
|
||||||
|
start = micros();
|
||||||
|
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||||
|
x2 = w - 1;
|
||||||
|
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||||
|
t += micros() - start;
|
||||||
|
|
||||||
|
yield();
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
yield();
|
||||||
|
|
||||||
|
x1 = w - 1;
|
||||||
|
y1 = h - 1;
|
||||||
|
y2 = 0;
|
||||||
|
start = micros();
|
||||||
|
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||||
|
x2 = 0;
|
||||||
|
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||||
|
|
||||||
|
yield();
|
||||||
|
return micros() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testFastLines(uint16_t color1, uint16_t color2) {
|
||||||
|
unsigned long start;
|
||||||
|
int x, y, w = tft.width(), h = tft.height();
|
||||||
|
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
start = micros();
|
||||||
|
for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
|
||||||
|
for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
|
||||||
|
|
||||||
|
return micros() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testRects(uint16_t color) {
|
||||||
|
unsigned long start;
|
||||||
|
int n, i, i2,
|
||||||
|
cx = tft.width() / 2,
|
||||||
|
cy = tft.height() / 2;
|
||||||
|
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
n = min(tft.width(), tft.height());
|
||||||
|
start = micros();
|
||||||
|
for(i=2; i<n; i+=6) {
|
||||||
|
i2 = i / 2;
|
||||||
|
tft.drawRect(cx-i2, cy-i2, i, i, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
return micros() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
|
||||||
|
unsigned long start, t = 0;
|
||||||
|
int n, i, i2,
|
||||||
|
cx = tft.width() / 2 - 1,
|
||||||
|
cy = tft.height() / 2 - 1;
|
||||||
|
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
n = min(tft.width(), tft.height());
|
||||||
|
for(i=n; i>0; i-=6) {
|
||||||
|
i2 = i / 2;
|
||||||
|
start = micros();
|
||||||
|
tft.fillRect(cx-i2, cy-i2, i, i, color1);
|
||||||
|
t += micros() - start;
|
||||||
|
// Outlines are not included in timing results
|
||||||
|
tft.drawRect(cx-i2, cy-i2, i, i, color2);
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
|
||||||
|
unsigned long start;
|
||||||
|
int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
|
||||||
|
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
start = micros();
|
||||||
|
for(x=radius; x<w; x+=r2) {
|
||||||
|
for(y=radius; y<h; y+=r2) {
|
||||||
|
tft.fillCircle(x, y, radius, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return micros() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testCircles(uint8_t radius, uint16_t color) {
|
||||||
|
unsigned long start;
|
||||||
|
int x, y, r2 = radius * 2,
|
||||||
|
w = tft.width() + radius,
|
||||||
|
h = tft.height() + radius;
|
||||||
|
|
||||||
|
// Screen is not cleared for this one -- this is
|
||||||
|
// intentional and does not affect the reported time.
|
||||||
|
start = micros();
|
||||||
|
for(x=0; x<w; x+=r2) {
|
||||||
|
for(y=0; y<h; y+=r2) {
|
||||||
|
tft.drawCircle(x, y, radius, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return micros() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testTriangles() {
|
||||||
|
unsigned long start;
|
||||||
|
int n, i, cx = tft.width() / 2 - 1,
|
||||||
|
cy = tft.height() / 2 - 1;
|
||||||
|
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
n = min(cx, cy);
|
||||||
|
start = micros();
|
||||||
|
for(i=0; i<n; i+=5) {
|
||||||
|
tft.drawTriangle(
|
||||||
|
cx , cy - i, // peak
|
||||||
|
cx - i, cy + i, // bottom left
|
||||||
|
cx + i, cy + i, // bottom right
|
||||||
|
tft.color565(i, i, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return micros() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testFilledTriangles() {
|
||||||
|
unsigned long start, t = 0;
|
||||||
|
int i, cx = tft.width() / 2 - 1,
|
||||||
|
cy = tft.height() / 2 - 1;
|
||||||
|
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
start = micros();
|
||||||
|
for(i=min(cx,cy); i>10; i-=5) {
|
||||||
|
start = micros();
|
||||||
|
tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||||
|
tft.color565(0, i*10, i*10));
|
||||||
|
t += micros() - start;
|
||||||
|
tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||||
|
tft.color565(i*10, i*10, 0));
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testRoundRects() {
|
||||||
|
unsigned long start;
|
||||||
|
int w, i, i2,
|
||||||
|
cx = tft.width() / 2 - 1,
|
||||||
|
cy = tft.height() / 2 - 1;
|
||||||
|
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
w = min(tft.width(), tft.height());
|
||||||
|
start = micros();
|
||||||
|
for(i=0; i<w; i+=6) {
|
||||||
|
i2 = i / 2;
|
||||||
|
tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return micros() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long testFilledRoundRects() {
|
||||||
|
unsigned long start;
|
||||||
|
int i, i2,
|
||||||
|
cx = tft.width() / 2 - 1,
|
||||||
|
cy = tft.height() / 2 - 1;
|
||||||
|
|
||||||
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
|
start = micros();
|
||||||
|
for(i=min(tft.width(), tft.height()); i>20; i-=6) {
|
||||||
|
i2 = i / 2;
|
||||||
|
tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
return micros() - start;
|
||||||
|
}
|
@ -28,12 +28,6 @@
|
|||||||
#define TFT_DC 33
|
#define TFT_DC 33
|
||||||
#define SD_CS 14
|
#define SD_CS 14
|
||||||
#endif
|
#endif
|
||||||
#if defined (__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_FEATHER_M0) || defined (__AVR_ATmega328P__)
|
|
||||||
#define STMPE_CS 6
|
|
||||||
#define TFT_CS 9
|
|
||||||
#define TFT_DC 10
|
|
||||||
#define SD_CS 5
|
|
||||||
#endif
|
|
||||||
#ifdef TEENSYDUINO
|
#ifdef TEENSYDUINO
|
||||||
#define TFT_DC 10
|
#define TFT_DC 10
|
||||||
#define TFT_CS 4
|
#define TFT_CS 4
|
||||||
@ -52,6 +46,21 @@
|
|||||||
#define STMPE_CS 30
|
#define STMPE_CS 30
|
||||||
#define SD_CS 27
|
#define SD_CS 27
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR)
|
||||||
|
#define TFT_DC P5_4
|
||||||
|
#define TFT_CS P5_3
|
||||||
|
#define STMPE_CS P3_3
|
||||||
|
#define SD_CS P3_2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Anything else!
|
||||||
|
#if defined (__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_FEATHER_M0) || defined (__AVR_ATmega328P__) || defined(ARDUINO_SAMD_ZERO) || defined(__SAMD51__) || defined(__SAM3X8E__)
|
||||||
|
#define STMPE_CS 6
|
||||||
|
#define TFT_CS 9
|
||||||
|
#define TFT_DC 10
|
||||||
|
#define SD_CS 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||||
|
|
@ -31,12 +31,6 @@
|
|||||||
#define TFT_DC 33
|
#define TFT_DC 33
|
||||||
#define SD_CS 14
|
#define SD_CS 14
|
||||||
#endif
|
#endif
|
||||||
#if defined (__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_FEATHER_M0) || defined (__AVR_ATmega328P__)
|
|
||||||
#define STMPE_CS 6
|
|
||||||
#define TFT_CS 9
|
|
||||||
#define TFT_DC 10
|
|
||||||
#define SD_CS 5
|
|
||||||
#endif
|
|
||||||
#ifdef TEENSYDUINO
|
#ifdef TEENSYDUINO
|
||||||
#define TFT_DC 10
|
#define TFT_DC 10
|
||||||
#define TFT_CS 4
|
#define TFT_CS 4
|
||||||
@ -55,6 +49,21 @@
|
|||||||
#define STMPE_CS 30
|
#define STMPE_CS 30
|
||||||
#define SD_CS 27
|
#define SD_CS 27
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR)
|
||||||
|
#define TFT_DC P5_4
|
||||||
|
#define TFT_CS P5_3
|
||||||
|
#define STMPE_CS P3_3
|
||||||
|
#define SD_CS P3_2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Anything else!
|
||||||
|
#if defined (__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_FEATHER_M0) || defined (__AVR_ATmega328P__) || defined(ARDUINO_SAMD_ZERO) || defined(__SAMD51__) || defined(__SAM3X8E__)
|
||||||
|
#define STMPE_CS 6
|
||||||
|
#define TFT_CS 9
|
||||||
|
#define TFT_DC 10
|
||||||
|
#define SD_CS 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||||
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
|
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
|
@ -1,5 +1,5 @@
|
|||||||
name=Adafruit ILI9341
|
name=Adafruit ILI9341
|
||||||
version=1.0.11
|
version=1.2.0
|
||||||
author=Adafruit
|
author=Adafruit
|
||||||
maintainer=Adafruit <info@adafruit.com>
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
sentence=Library for Adafruit ILI9341 displays
|
sentence=Library for Adafruit ILI9341 displays
|
Loading…
x
Reference in New Issue
Block a user