[136] | 1 | /***************************************************
|
---|
| 2 | This is a library for the Adafruit 1.8" SPI display.
|
---|
| 3 | This library works with the Adafruit 1.8" TFT Breakout w/SD card
|
---|
| 4 | ----> http://www.adafruit.com/products/358
|
---|
| 5 | as well as Adafruit raw 1.8" TFT display
|
---|
| 6 | ----> http://www.adafruit.com/products/618
|
---|
| 7 |
|
---|
| 8 | Check out the links above for our tutorials and wiring diagrams
|
---|
| 9 | These displays use SPI to communicate, 4 or 5 pins are required to
|
---|
| 10 | interface (RST is optional)
|
---|
| 11 | Adafruit invests time and resources providing this open source code,
|
---|
| 12 | please support Adafruit and open-source hardware by purchasing
|
---|
| 13 | products from Adafruit!
|
---|
| 14 |
|
---|
| 15 | Written by Limor Fried/Ladyada for Adafruit Industries.
|
---|
| 16 | MIT license, all text above must be included in any redistribution
|
---|
| 17 | ****************************************************/
|
---|
| 18 |
|
---|
| 19 | #ifndef _ADAFRUIT_ST7735H_
|
---|
| 20 | #define _ADAFRUIT_ST7735H_
|
---|
| 21 |
|
---|
| 22 | #if ARDUINO >= 100
|
---|
| 23 | #include "Arduino.h"
|
---|
| 24 | #include "Print.h"
|
---|
| 25 | #else
|
---|
| 26 | #include "WProgram.h"
|
---|
| 27 | #endif
|
---|
| 28 | #include "Adafruit_GFX.h"
|
---|
| 29 | #include <avr/pgmspace.h>
|
---|
| 30 |
|
---|
| 31 | // some flags for initR() :(
|
---|
| 32 | #define INITR_GREENTAB 0x0
|
---|
| 33 | #define INITR_REDTAB 0x1
|
---|
| 34 | #define INITR_BLACKTAB 0x2
|
---|
| 35 |
|
---|
| 36 | #define ST7735_TFTWIDTH 128
|
---|
| 37 | #define ST7735_TFTHEIGHT 160
|
---|
| 38 |
|
---|
| 39 | #define ST7735_NOP 0x00
|
---|
| 40 | #define ST7735_SWRESET 0x01
|
---|
| 41 | #define ST7735_RDDID 0x04
|
---|
| 42 | #define ST7735_RDDST 0x09
|
---|
| 43 |
|
---|
| 44 | #define ST7735_SLPIN 0x10
|
---|
| 45 | #define ST7735_SLPOUT 0x11
|
---|
| 46 | #define ST7735_PTLON 0x12
|
---|
| 47 | #define ST7735_NORON 0x13
|
---|
| 48 |
|
---|
| 49 | #define ST7735_INVOFF 0x20
|
---|
| 50 | #define ST7735_INVON 0x21
|
---|
| 51 | #define ST7735_DISPOFF 0x28
|
---|
| 52 | #define ST7735_DISPON 0x29
|
---|
| 53 | #define ST7735_CASET 0x2A
|
---|
| 54 | #define ST7735_RASET 0x2B
|
---|
| 55 | #define ST7735_RAMWR 0x2C
|
---|
| 56 | #define ST7735_RAMRD 0x2E
|
---|
| 57 |
|
---|
| 58 | #define ST7735_PTLAR 0x30
|
---|
| 59 | #define ST7735_COLMOD 0x3A
|
---|
| 60 | #define ST7735_MADCTL 0x36
|
---|
| 61 |
|
---|
| 62 | #define ST7735_FRMCTR1 0xB1
|
---|
| 63 | #define ST7735_FRMCTR2 0xB2
|
---|
| 64 | #define ST7735_FRMCTR3 0xB3
|
---|
| 65 | #define ST7735_INVCTR 0xB4
|
---|
| 66 | #define ST7735_DISSET5 0xB6
|
---|
| 67 |
|
---|
| 68 | #define ST7735_PWCTR1 0xC0
|
---|
| 69 | #define ST7735_PWCTR2 0xC1
|
---|
| 70 | #define ST7735_PWCTR3 0xC2
|
---|
| 71 | #define ST7735_PWCTR4 0xC3
|
---|
| 72 | #define ST7735_PWCTR5 0xC4
|
---|
| 73 | #define ST7735_VMCTR1 0xC5
|
---|
| 74 |
|
---|
| 75 | #define ST7735_RDID1 0xDA
|
---|
| 76 | #define ST7735_RDID2 0xDB
|
---|
| 77 | #define ST7735_RDID3 0xDC
|
---|
| 78 | #define ST7735_RDID4 0xDD
|
---|
| 79 |
|
---|
| 80 | #define ST7735_PWCTR6 0xFC
|
---|
| 81 |
|
---|
| 82 | #define ST7735_GMCTRP1 0xE0
|
---|
| 83 | #define ST7735_GMCTRN1 0xE1
|
---|
| 84 |
|
---|
| 85 | // Color definitions
|
---|
| 86 | #define ST7735_BLACK 0x0000
|
---|
| 87 | #define ST7735_BLUE 0x001F
|
---|
| 88 | #define ST7735_RED 0xF800
|
---|
| 89 | #define ST7735_GREEN 0x07E0
|
---|
| 90 | #define ST7735_CYAN 0x07FF
|
---|
| 91 | #define ST7735_MAGENTA 0xF81F
|
---|
| 92 | #define ST7735_YELLOW 0xFFE0
|
---|
| 93 | #define ST7735_WHITE 0xFFFF
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | class Adafruit_ST7735 : public Adafruit_GFX {
|
---|
| 97 |
|
---|
| 98 | public:
|
---|
| 99 |
|
---|
| 100 | Adafruit_ST7735(uint8_t CS, uint8_t RS, uint8_t SID, uint8_t SCLK,
|
---|
| 101 | uint8_t RST);
|
---|
| 102 | Adafruit_ST7735(uint8_t CS, uint8_t RS, uint8_t RST);
|
---|
| 103 |
|
---|
| 104 | void initB(void), // for ST7735B displays
|
---|
| 105 | initG(void), // for ILI9163C displays
|
---|
| 106 | initR(uint8_t options = INITR_GREENTAB), // for ST7735R
|
---|
| 107 | setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1),
|
---|
| 108 | pushColor(uint16_t color),
|
---|
| 109 | fillScreen(uint16_t color),
|
---|
| 110 | drawPixel(int16_t x, int16_t y, uint16_t color),
|
---|
| 111 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
|
---|
| 112 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
|
---|
| 113 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
---|
| 114 | uint16_t color),
|
---|
| 115 | setRotation(uint8_t r),
|
---|
| 116 | invertDisplay(boolean i);
|
---|
| 117 | uint16_t Color565(uint8_t r, uint8_t g, uint8_t b) { return newColor(r, g, b);}
|
---|
| 118 |
|
---|
| 119 | /* These are not for current use, 8-bit protocol only!
|
---|
| 120 | uint8_t readdata(void),
|
---|
| 121 | readcommand8(uint8_t);
|
---|
| 122 | uint16_t readcommand16(uint8_t);
|
---|
| 123 | uint32_t readcommand32(uint8_t);
|
---|
| 124 | void dummyclock(void);
|
---|
| 125 | */
|
---|
| 126 |
|
---|
| 127 | private:
|
---|
| 128 | uint8_t tabcolor;
|
---|
| 129 |
|
---|
| 130 | void spiwrite(uint8_t),
|
---|
| 131 | writecommand(uint8_t c),
|
---|
| 132 | writedata(uint8_t d),
|
---|
| 133 | commandList(const uint8_t *addr),
|
---|
| 134 | commonInit(const uint8_t *cmdList);
|
---|
| 135 | //uint8_t spiread(void);
|
---|
| 136 |
|
---|
| 137 | boolean hwSPI;
|
---|
| 138 | #if defined(ARDUINO_ARCH_SAMD)
|
---|
| 139 | volatile uint32_t *dataport, *clkport, *csport, *rsport;
|
---|
| 140 | uint32_t _cs, _rs, _rst, _sid, _sclk,
|
---|
| 141 | datapinmask, clkpinmask, cspinmask, rspinmask,
|
---|
| 142 | colstart, rowstart; // some displays need this changed
|
---|
| 143 | #else
|
---|
| 144 | volatile uint8_t *dataport, *clkport, *csport, *rsport;
|
---|
| 145 | uint8_t _cs, _rs, _rst, _sid, _sclk,
|
---|
| 146 | datapinmask, clkpinmask, cspinmask, rspinmask,
|
---|
| 147 | colstart, rowstart; // some displays need this changed
|
---|
| 148 | #endif
|
---|
| 149 | };
|
---|
| 150 |
|
---|
| 151 | #endif
|
---|