Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/esp8266'
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepmistry committed Apr 10, 2015
2 parents 52ffd96 + 7b54e83 commit 9560f0b
Show file tree
Hide file tree
Showing 20 changed files with 3,574 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ instead of the one that comes with the Arduino IDE (this one).
Allows the sketch to respond to multicast DNS queries for domain names like "foo.local".
See attached example and library README file for details.

#### Other libraries
#### Other libraries (not included with the IDE)

Libraries that don't rely on low-level access to AVR registers should work well. Here are a few libraries that were verified to work:

- PubSubClient MQTT library. This library is not bundled with the IDE, you need to [download it separately](https://github.com/knolleary/pubsubclient). Use this [sample](https://gist.github.com/igrr/7f7e7973366fc01d6393) to get started.
- [aREST](https://github.com/marcoschwartz/aREST) REST API handler library.
- [PubSubClient](https://github.com/knolleary/pubsubclient) MQTT library. Use this [sample](https://gist.github.com/igrr/7f7e7973366fc01d6393) to get started.
- [DHT11](https://github.com/adafruit/DHT-sensor-library) - initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);```
- [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git)

Expand Down
1 change: 1 addition & 0 deletions esp8266com/esp8266/cores/esp8266/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define PROGMEM
#define PGM_P const char *
#define PSTR(str) (str)
#define F(str) (str)

#define vsnprintf_P(...) vsnprintf( __VA_ARGS__ )
#define snprintf_P(...) snprintf( __VA_ARGS__ )
Expand Down
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);
}
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
Loading

0 comments on commit 9560f0b

Please sign in to comment.