forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/esp8266'
- Loading branch information
Showing
20 changed files
with
3,574 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
hardware/esp8266com/esp8266/libraries/Adafruit_ILI9341/Adafruit_ILI9341.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
#include "Adafruit_ILI9341.h" | ||
#include "Adafruit_GFX.h" | ||
|
||
extern "C"{ | ||
#include <ets_sys.h> | ||
#include <os_type.h> | ||
#include <osapi.h> | ||
#include "driver\hspi.h" | ||
} | ||
|
||
#define SWAPBYTES(i) ((i>>8) | (i<<8)) | ||
|
||
void Adafruit_ILI9341::transmitCmdData(uint8_t cmd, const uint8_t *data, uint8_t numDataByte) | ||
{ | ||
spi_wait_ready(); | ||
TFT_DC_COMMAND; | ||
spi_send_uint8(cmd); | ||
spi_wait_ready(); | ||
TFT_DC_DATA; | ||
spi_send_data(data, numDataByte); | ||
} | ||
|
||
void Adafruit_ILI9341::begin() { | ||
//Set communication using HW SPI Port | ||
config = spi_init(HSPI, 1, spi_mode_tx); | ||
TFT_DC_INIT; | ||
delay(1); | ||
|
||
uint8_t data[15] = {0}; | ||
|
||
data[0] = 0x39; | ||
data[1] = 0x2C; | ||
data[2] = 0x00; | ||
data[3] = 0x34; | ||
data[4] = 0x02; | ||
transmitCmdData(0xCB, data, 5); | ||
|
||
data[0] = 0x00; | ||
data[1] = 0XC1; | ||
data[2] = 0X30; | ||
transmitCmdData(0xCF, data, 3); | ||
|
||
data[0] = 0x85; | ||
data[1] = 0x00; | ||
data[2] = 0x78; | ||
transmitCmdData(0xE8, data, 3); | ||
|
||
data[0] = 0x00; | ||
data[1] = 0x00; | ||
transmitCmdData(0xEA, data, 2); | ||
|
||
data[0] = 0x64; | ||
data[1] = 0x03; | ||
data[2] = 0X12; | ||
data[3] = 0X81; | ||
transmitCmdData(0xED, data, 4); | ||
|
||
data[0] = 0x20; | ||
transmitCmdData(0xF7, data, 1); | ||
|
||
data[0] = 0x23; //VRH[5:0] | ||
transmitCmdData(0xC0, data, 1); //Power control | ||
|
||
data[0] = 0x10; //SAP[2:0];BT[3:0] | ||
transmitCmdData(0xC1, data, 1); //Power control | ||
|
||
data[0] = 0x3e; //Contrast | ||
data[1] = 0x28; | ||
transmitCmdData(0xC5, data, 2); //VCM control | ||
|
||
data[0] = 0x86; //-- | ||
transmitCmdData(0xC7, data, 1); //VCM control2 | ||
|
||
data[0] = 0x48; //C8 | ||
transmitCmdData(0x36, data, 1); // Memory Access Control | ||
|
||
data[0] = 0x55; | ||
transmitCmdData(0x3A, data, 1); | ||
|
||
data[0] = 0x00; | ||
data[1] = 0x18; | ||
transmitCmdData(0xB1, data, 2); | ||
|
||
data[0] = 0x08; | ||
data[1] = 0x82; | ||
data[2] = 0x27; | ||
transmitCmdData(0xB6, data, 3); // Display Function Control | ||
|
||
data[0] = 0x00; | ||
transmitCmdData(0xF2, data, 1); // 3Gamma Function Disable | ||
|
||
data[0] = 0x01; | ||
transmitCmdData(0x26, data, 1); //Gamma curve selected | ||
|
||
data[0] = 0x0F; | ||
data[1] = 0x31; | ||
data[2] = 0x2B; | ||
data[3] = 0x0C; | ||
data[4] = 0x0E; | ||
data[5] = 0x08; | ||
data[6] = 0x4E; | ||
data[7] = 0xF1; | ||
data[8] = 0x37; | ||
data[9] = 0x07; | ||
data[10] = 0x10; | ||
data[11] = 0x03; | ||
data[12] = 0x0E; | ||
data[13] = 0x09; | ||
data[14] = 0x00; | ||
transmitCmdData(0xE0, data, 15); //Set Gamma | ||
|
||
data[0] = 0x00; | ||
data[1] = 0x0E; | ||
data[2] = 0x14; | ||
data[3] = 0x03; | ||
data[4] = 0x11; | ||
data[5] = 0x07; | ||
data[6] = 0x31; | ||
data[7] = 0xC1; | ||
data[8] = 0x48; | ||
data[9] = 0x08; | ||
data[10] = 0x0F; | ||
data[11] = 0x0C; | ||
data[12] = 0x31; | ||
data[13] = 0x36; | ||
data[14] = 0x0F; | ||
transmitCmdData(0xE1, data, 15); //Set Gamma | ||
|
||
transmitCmd(0x11); //Exit Sleep | ||
delay(120); | ||
|
||
transmitCmd(0x29); //Display on | ||
transmitCmd(0x2c); | ||
spi_wait_ready(); | ||
} | ||
|
||
void Adafruit_ILI9341::drawPixel(int16_t x, int16_t y, uint16_t color) { | ||
|
||
if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return; | ||
setAddrWindow(x,y,x+1,y+1); | ||
transmitData(SWAPBYTES(color)); | ||
} | ||
|
||
|
||
void Adafruit_ILI9341::drawFastVLine(int16_t x, int16_t y, int16_t h, | ||
uint16_t color) { | ||
|
||
// Rudimentary clipping | ||
if((x >= _width) || (y >= _height)) return; | ||
|
||
if((y+h-1) >= _height) | ||
h = _height-y; | ||
|
||
setAddrWindow(x, y, x, y+h-1); | ||
transmitData(SWAPBYTES(color), h); | ||
} | ||
|
||
void Adafruit_ILI9341::drawFastHLine(int16_t x, int16_t y, int16_t w, | ||
uint16_t color) { | ||
|
||
// Rudimentary clipping | ||
if((x >= _width) || (y >= _height)) return; | ||
if((x+w-1) >= _width) w = _width-x; | ||
setAddrWindow(x, y, x+w-1, y); | ||
transmitData(SWAPBYTES(color), w); | ||
} | ||
|
||
void Adafruit_ILI9341::fillScreen(uint16_t color) { | ||
fillRect(0, 0, _width, _height, color); | ||
} | ||
|
||
// fill a rectangle | ||
void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, | ||
uint16_t color) { | ||
|
||
// rudimentary clipping (drawChar w/big text requires this) | ||
if((x >= _width) || (y >= _height)) return; | ||
if((x + w - 1) >= _width) w = _width - x; | ||
if((y + h - 1) >= _height) h = _height - y; | ||
|
||
setAddrWindow(x, y, x+w-1, y+h-1); | ||
transmitData(SWAPBYTES(color), h*w); | ||
} | ||
|
||
|
||
// 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 >> 3); | ||
} | ||
|
||
|
||
#define MADCTL_MY 0x80 | ||
#define MADCTL_MX 0x40 | ||
#define MADCTL_MV 0x20 | ||
#define MADCTL_ML 0x10 | ||
#define MADCTL_RGB 0x00 | ||
#define MADCTL_BGR 0x08 | ||
#define MADCTL_MH 0x04 | ||
|
||
void Adafruit_ILI9341::setRotation(uint8_t m) { | ||
|
||
uint8_t data; | ||
rotation = m % 4; // can't be higher than 3 | ||
switch (rotation) { | ||
case 0: | ||
data = MADCTL_MX | MADCTL_BGR; | ||
_width = ILI9341_TFTWIDTH; | ||
_height = ILI9341_TFTHEIGHT; | ||
break; | ||
case 1: | ||
data = MADCTL_MV | MADCTL_BGR; | ||
_width = ILI9341_TFTHEIGHT; | ||
_height = ILI9341_TFTWIDTH; | ||
break; | ||
case 2: | ||
data = MADCTL_MY | MADCTL_BGR; | ||
_width = ILI9341_TFTWIDTH; | ||
_height = ILI9341_TFTHEIGHT; | ||
break; | ||
case 3: | ||
data = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR; | ||
_width = ILI9341_TFTHEIGHT; | ||
_height = ILI9341_TFTWIDTH; | ||
break; | ||
} | ||
transmitCmdData(ILI9341_MADCTL, &data, 1); | ||
} | ||
|
||
|
||
void Adafruit_ILI9341::invertDisplay(boolean i) { | ||
transmitCmd(i ? ILI9341_INVON : ILI9341_INVOFF); | ||
} |
126 changes: 126 additions & 0 deletions
126
hardware/esp8266com/esp8266/libraries/Adafruit_ILI9341/Adafruit_ILI9341.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#ifndef _ADAFRUIT_ILI9341H_ | ||
#define _ADAFRUIT_ILI9341H_ | ||
|
||
#include "Adafruit_GFX.h" | ||
|
||
extern "C" | ||
{ | ||
#include <c_types.h> | ||
#include <osapi.h> | ||
#include <gpio.h> | ||
#include "driver\hspi.h" | ||
} | ||
|
||
#define ILI9341_TFTWIDTH 240 | ||
#define ILI9341_TFTHEIGHT 320 | ||
|
||
#define ILI9341_NOP 0x00 | ||
#define ILI9341_SWRESET 0x01 | ||
#define ILI9341_RDDID 0x04 | ||
#define ILI9341_RDDST 0x09 | ||
|
||
#define ILI9341_SLPIN 0x10 | ||
#define ILI9341_SLPOUT 0x11 | ||
#define ILI9341_PTLON 0x12 | ||
#define ILI9341_NORON 0x13 | ||
|
||
#define ILI9341_RDMODE 0x0A | ||
#define ILI9341_RDMADCTL 0x0B | ||
#define ILI9341_RDPIXFMT 0x0C | ||
#define ILI9341_RDIMGFMT 0x0A | ||
#define ILI9341_RDSELFDIAG 0x0F | ||
|
||
#define ILI9341_INVOFF 0x20 | ||
#define ILI9341_INVON 0x21 | ||
#define ILI9341_GAMMASET 0x26 | ||
#define ILI9341_DISPOFF 0x28 | ||
#define ILI9341_DISPON 0x29 | ||
|
||
#define ILI9341_CASET 0x2A | ||
#define ILI9341_PASET 0x2B | ||
#define ILI9341_RAMWR 0x2C | ||
#define ILI9341_RAMRD 0x2E | ||
|
||
#define ILI9341_PTLAR 0x30 | ||
#define ILI9341_MADCTL 0x36 | ||
#define ILI9341_PIXFMT 0x3A | ||
|
||
#define ILI9341_FRMCTR1 0xB1 | ||
#define ILI9341_FRMCTR2 0xB2 | ||
#define ILI9341_FRMCTR3 0xB3 | ||
#define ILI9341_INVCTR 0xB4 | ||
#define ILI9341_DFUNCTR 0xB6 | ||
|
||
#define ILI9341_PWCTR1 0xC0 | ||
#define ILI9341_PWCTR2 0xC1 | ||
#define ILI9341_PWCTR3 0xC2 | ||
#define ILI9341_PWCTR4 0xC3 | ||
#define ILI9341_PWCTR5 0xC4 | ||
#define ILI9341_VMCTR1 0xC5 | ||
#define ILI9341_VMCTR2 0xC7 | ||
|
||
#define ILI9341_RDID1 0xDA | ||
#define ILI9341_RDID2 0xDB | ||
#define ILI9341_RDID3 0xDC | ||
#define ILI9341_RDID4 0xDD | ||
|
||
#define ILI9341_GMCTRP1 0xE0 | ||
#define ILI9341_GMCTRN1 0xE1 | ||
/* | ||
#define ILI9341_PWCTR6 0xFC | ||
*/ | ||
|
||
// Color definitions | ||
#define ILI9341_BLACK 0x0000 | ||
#define ILI9341_BLUE 0x001F | ||
#define ILI9341_RED 0xF800 | ||
#define ILI9341_GREEN 0x07E0 | ||
#define ILI9341_CYAN 0x07FF | ||
#define ILI9341_MAGENTA 0xF81F | ||
#define ILI9341_YELLOW 0xFFE0 | ||
#define ILI9341_WHITE 0xFFFF | ||
|
||
#define TFT_DC_DATA GPIO_OUTPUT_SET(2, 1) | ||
#define TFT_DC_COMMAND GPIO_OUTPUT_SET(2, 0) | ||
#define TFT_DC_INIT PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); TFT_DC_DATA | ||
|
||
#define MAKEWORD(b1, b2, b3, b4) (uint32_t(b1) | ((b2) << 8) | ((b3) << 16) | ((b4) << 24)) | ||
#define SWAPBYTES(i) ((i>>8) | (i<<8)) | ||
|
||
class Adafruit_ILI9341 : public Adafruit_GFX { | ||
|
||
private: | ||
uint8_t tabcolor; | ||
spi_config config; | ||
void transmitCmdData(uint8_t cmd, const uint8_t *data, uint8_t numDataByte); | ||
inline void transmitData(uint16_t data) {spi_wait_ready(); spi_send_uint16(data);} | ||
inline void transmitCmdData(uint8_t cmd, uint32_t data) {spi_wait_ready(); TFT_DC_COMMAND; spi_send_uint8(cmd); spi_wait_ready(); TFT_DC_DATA; spi_send_uint32(data);} | ||
inline void transmitData(uint16_t data, int32_t repeats){spi_wait_ready(); spi_send_uint16_r(data, repeats);} | ||
inline void transmitCmd(uint8_t cmd){spi_wait_ready(); TFT_DC_COMMAND; spi_send_uint8(cmd);spi_wait_ready(); TFT_DC_DATA;} | ||
inline void drawPixelInternal(int16_t x, int16_t y, uint16_t color) { if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return; | ||
setAddrWindow(x,y,x+1,y+1); | ||
transmitData(SWAPBYTES(color)); | ||
} | ||
|
||
public: | ||
Adafruit_ILI9341() : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT), tabcolor(0){} | ||
|
||
void begin(), | ||
fillScreen(uint16_t color), | ||
drawPixel(int16_t x, int16_t y, uint16_t color), | ||
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), | ||
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), | ||
fillRect(int16_t x, int16_t y, int16_t w, int16_t h, | ||
uint16_t color), | ||
setRotation(uint8_t r), | ||
invertDisplay(boolean i); | ||
inline void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) | ||
{ transmitCmdData(ILI9341_CASET, MAKEWORD(x0 >> 8, x0 & 0xFF, x1 >> 8, x1 & 0xFF)); | ||
transmitCmdData(ILI9341_PASET, MAKEWORD(y0 >> 8, y0 & 0xFF, y1 >> 8, y1 & 0xFF)); | ||
transmitCmd(ILI9341_RAMWR); // write to RAM | ||
} | ||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.