Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
Adafruit_ST7735.h
1 /***************************************************
2  This is a library for the Adafruit 1.8" SPI display.
3 
4 This library works with the Adafruit 1.8" TFT Breakout w/SD card
5  ----> http://www.adafruit.com/products/358
6 The 1.8" TFT shield
7  ----> https://www.adafruit.com/product/802
8 The 1.44" TFT breakout
9  ----> https://www.adafruit.com/product/2088
10 as well as Adafruit raw 1.8" TFT display
11  ----> http://www.adafruit.com/products/618
12 
13  Check out the links above for our tutorials and wiring diagrams
14  These displays use SPI to communicate, 4 or 5 pins are required to
15  interface (RST is optional)
16  Adafruit invests time and resources providing this open source code,
17  please support Adafruit and open-source hardware by purchasing
18  products from Adafruit!
19 
20  Written by Limor Fried/Ladyada for Adafruit Industries.
21  MIT license, all text above must be included in any redistribution
22  ****************************************************/
23 
24 #ifndef _ADAFRUIT_ST7735H_
25 #define _ADAFRUIT_ST7735H_
26 
27 #include "Arduino.h"
28 #include "Print.h"
29 #include <Adafruit_GFX.h>
30 
31 #if defined(__AVR__) || defined(CORE_TEENSY)
32  #include <avr/pgmspace.h>
33  #define USE_FAST_IO
34  typedef volatile uint8_t RwReg;
35 #elif defined(ARDUINO_STM32_FEATHER)
36  typedef volatile uint32 RwReg;
37  #define USE_FAST_IO
38 #elif defined(ARDUINO_FEATHER52)
39  typedef volatile uint32_t RwReg;
40  #define USE_FAST_IO
41 #elif defined(ESP8266)
42  #include <pgmspace.h>
43 #elif defined(__SAM3X8E__)
44  #undef __FlashStringHelper::F(string_literal)
45  #define F(string_literal) string_literal
46  #include <include/pio.h>
47  #define PROGMEM
48  #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
49  #define pgm_read_word(addr) (*(const unsigned short *)(addr))
50  typedef unsigned char prog_uchar;
51 #endif
52 
53 // some flags for initR() :(
54 #define INITR_GREENTAB 0x0
55 #define INITR_REDTAB 0x1
56 #define INITR_BLACKTAB 0x2
57 
58 #define INITR_18GREENTAB INITR_GREENTAB
59 #define INITR_18REDTAB INITR_REDTAB
60 #define INITR_18BLACKTAB INITR_BLACKTAB
61 #define INITR_144GREENTAB 0x1
62 #define INITR_MINI160x80 0x4
63 
64 
65 // for 1.44 and mini
66 #define ST7735_TFTWIDTH_128 128
67 // for mini
68 #define ST7735_TFTWIDTH_80 80
69 // for 1.44" display
70 #define ST7735_TFTHEIGHT_128 128
71 // for 1.8" and mini display
72 #define ST7735_TFTHEIGHT_160 160
73 
74 #define ST7735_NOP 0x00
75 #define ST7735_SWRESET 0x01
76 #define ST7735_RDDID 0x04
77 #define ST7735_RDDST 0x09
78 
79 #define ST7735_SLPIN 0x10
80 #define ST7735_SLPOUT 0x11
81 #define ST7735_PTLON 0x12
82 #define ST7735_NORON 0x13
83 
84 #define ST7735_INVOFF 0x20
85 #define ST7735_INVON 0x21
86 #define ST7735_DISPOFF 0x28
87 #define ST7735_DISPON 0x29
88 #define ST7735_CASET 0x2A
89 #define ST7735_RASET 0x2B
90 #define ST7735_RAMWR 0x2C
91 #define ST7735_RAMRD 0x2E
92 
93 #define ST7735_PTLAR 0x30
94 #define ST7735_COLMOD 0x3A
95 #define ST7735_MADCTL 0x36
96 
97 #define ST7735_FRMCTR1 0xB1
98 #define ST7735_FRMCTR2 0xB2
99 #define ST7735_FRMCTR3 0xB3
100 #define ST7735_INVCTR 0xB4
101 #define ST7735_DISSET5 0xB6
102 
103 #define ST7735_PWCTR1 0xC0
104 #define ST7735_PWCTR2 0xC1
105 #define ST7735_PWCTR3 0xC2
106 #define ST7735_PWCTR4 0xC3
107 #define ST7735_PWCTR5 0xC4
108 #define ST7735_VMCTR1 0xC5
109 
110 #define ST7735_RDID1 0xDA
111 #define ST7735_RDID2 0xDB
112 #define ST7735_RDID3 0xDC
113 #define ST7735_RDID4 0xDD
114 
115 #define ST7735_PWCTR6 0xFC
116 
117 #define ST7735_GMCTRP1 0xE0
118 #define ST7735_GMCTRN1 0xE1
119 
120 // Color definitions
121 #define ST7735_BLACK 0x0000
122 #define ST7735_BLUE 0x001F
123 #define ST7735_RED 0xF800
124 #define ST7735_GREEN 0x07E0
125 #define ST7735_CYAN 0x07FF
126 #define ST7735_MAGENTA 0xF81F
127 #define ST7735_YELLOW 0xFFE0
128 #define ST7735_WHITE 0xFFFF
129 
130 
132 
133  public:
134 
135  Adafruit_ST7735(int8_t CS, int8_t RS, int8_t SID, int8_t SCLK, int8_t RST = -1);
136  Adafruit_ST7735(int8_t CS, int8_t RS, int8_t RST = -1);
137 
138  void initB(void), // for ST7735B displays
139  initR(uint8_t options = INITR_GREENTAB), // for ST7735R
140  setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1),
141  pushColor(uint16_t color),
142  fillScreen(uint16_t color),
143  drawPixel(int16_t x, int16_t y, uint16_t color),
144  drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
145  drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
146  fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
147  uint16_t color),
148  setRotation(uint8_t r),
149  invertDisplay(boolean i);
150  uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);
151 
152  /* These are not for current use, 8-bit protocol only!
153  uint8_t readdata(void),
154  readcommand8(uint8_t);
155  uint16_t readcommand16(uint8_t);
156  uint32_t readcommand32(uint8_t);
157  void dummyclock(void);
158  */
159 
160  private:
161  uint8_t tabcolor;
162 
163  void spiwrite(uint8_t),
164  writecommand(uint8_t c),
165  writedata(uint8_t d),
166  commandList(const uint8_t *addr),
167  commonInit(const uint8_t *cmdList);
168 //uint8_t spiread(void);
169 
170 
171  inline void CS_HIGH(void);
172  inline void CS_LOW(void);
173  inline void DC_HIGH(void);
174  inline void DC_LOW(void);
175 
176  boolean hwSPI;
177 
178  int8_t _cs, _dc, _rst, _sid, _sclk;
179  uint8_t colstart, rowstart, xstart, ystart; // some displays need this changed
180 
181 #if defined(USE_FAST_IO)
182  volatile RwReg *dataport, *clkport, *csport, *dcport;
183 
184  #if defined(__AVR__) || defined(CORE_TEENSY) // 8 bit!
185  uint8_t datapinmask, clkpinmask, cspinmask, dcpinmask;
186  #else // 32 bit!
187  uint32_t datapinmask, clkpinmask, cspinmask, dcpinmask;
188  #endif
189 #endif
190 
191 };
192 
193 
194 #endif
Definition: Adafruit_GFX.h:13
Definition: Adafruit_ST7735.h:131