[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 _ARDUINO_LCDH_
|
---|
| 20 | #define _ARDUINO_LCDH_
|
---|
| 21 |
|
---|
| 22 | #if ARDUINO >= 100
|
---|
| 23 | #include "Arduino.h"
|
---|
| 24 | #include "Print.h"
|
---|
| 25 | #else
|
---|
| 26 | #include "WProgram.h"
|
---|
| 27 | #endif
|
---|
| 28 | #include "utility/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 |
|
---|
| 35 | #define ILI9163C_TFTWIDTH 128
|
---|
| 36 | #define ILI9163C_TFTHEIGHT 160
|
---|
| 37 |
|
---|
| 38 | #define ILI9163C_NOP 0x00
|
---|
| 39 | #define ILI9163C_SWRESET 0x01
|
---|
| 40 | #define ILI9163C_RDDID 0x04
|
---|
| 41 | #define ILI9163C_RDDST 0x09
|
---|
| 42 |
|
---|
| 43 | #define ILI9163C_SLPIN 0x10
|
---|
| 44 | #define ILI9163C_SLPOUT 0x11
|
---|
| 45 | #define ILI9163C_PTLON 0x12
|
---|
| 46 | #define ILI9163C_NORON 0x13
|
---|
| 47 |
|
---|
| 48 | #define ILI9163C_INVOFF 0x20
|
---|
| 49 | #define ILI9163C_INVON 0x21
|
---|
| 50 | #define ILI9163C_DISPOFF 0x28
|
---|
| 51 | #define ILI9163C_DISPON 0x29
|
---|
| 52 | #define ILI9163C_CASET 0x2A
|
---|
| 53 | #define ILI9163C_RASET 0x2B
|
---|
| 54 | #define ILI9163C_RAMWR 0x2C
|
---|
| 55 | #define ILI9163C_RAMRD 0x2E
|
---|
| 56 |
|
---|
| 57 | #define ILI9163C_PTLAR 0x30
|
---|
| 58 | #define ILI9163C_COLMOD 0x3A // this is interface pixel format, this might be the issue
|
---|
| 59 | #define ILI9163C_MADCTL 0x36
|
---|
| 60 |
|
---|
| 61 | #define ILI9163C_FRMCTR1 0xB1
|
---|
| 62 | #define ILI9163C_FRMCTR2 0xB2
|
---|
| 63 | #define ILI9163C_FRMCTR3 0xB3
|
---|
| 64 | #define ILI9163C_INVCTR 0xB4
|
---|
| 65 | #define ILI9163C_DISSET5 0xB6
|
---|
| 66 |
|
---|
| 67 | #define ILI9163C_PWCTR1 0xC0
|
---|
| 68 | #define ILI9163C_PWCTR2 0xC1
|
---|
| 69 | #define ILI9163C_PWCTR3 0xC2
|
---|
| 70 | #define ILI9163C_PWCTR4 0xC3
|
---|
| 71 | #define ILI9163C_PWCTR5 0xC4
|
---|
| 72 | #define ILI9163C_VMCTR1 0xC5
|
---|
| 73 |
|
---|
| 74 | #define ILI9163C_RDID1 0xDA
|
---|
| 75 | #define ILI9163C_RDID2 0xDB
|
---|
| 76 | #define ILI9163C_RDID3 0xDC
|
---|
| 77 | #define ILI9163C_RDID4 0xDD
|
---|
| 78 |
|
---|
| 79 | #define ILI9163C_PWCTR6 0xFC
|
---|
| 80 |
|
---|
| 81 | #define ILI9163C_GMCTRP1 0xE0
|
---|
| 82 | #define ILI9163C_GMCTRN1 0xE1
|
---|
| 83 |
|
---|
| 84 | // Color definitions
|
---|
| 85 | #define ILI9163C_BLACK 0x0000
|
---|
| 86 | #define ILI9163C_BLUE 0x001F
|
---|
| 87 | #define ILI9163C_RED 0xF800
|
---|
| 88 | #define ILI9163C_GREEN 0x07E0
|
---|
| 89 | #define ILI9163C_CYAN 0x07FF
|
---|
| 90 | #define ILI9163C_MAGENTA 0xF81F
|
---|
| 91 | #define ILI9163C_YELLOW 0xFFE0
|
---|
| 92 | #define ILI9163C_WHITE 0xFFFF
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | class Arduino_LCD : public Adafruit_GFX {
|
---|
| 96 |
|
---|
| 97 | public:
|
---|
| 98 |
|
---|
| 99 | Arduino_LCD(uint8_t CS, uint8_t RS, uint8_t SID, uint8_t SCLK, uint8_t RST);
|
---|
| 100 | Arduino_LCD(uint8_t CS, uint8_t RS, uint8_t RST);
|
---|
| 101 |
|
---|
| 102 | void initB(void), // for ST7735B displays
|
---|
| 103 | initR(uint8_t options = INITR_GREENTAB), // for ST7735R
|
---|
| 104 | setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1),
|
---|
| 105 | pushColor(uint16_t color),
|
---|
| 106 | fillScreen(uint16_t color),
|
---|
| 107 | drawPixel(int16_t x, int16_t y, uint16_t color),
|
---|
| 108 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
|
---|
| 109 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
|
---|
| 110 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
|
---|
| 111 | setRotation(uint8_t r),
|
---|
| 112 | invertDisplay(boolean i);
|
---|
| 113 | uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);
|
---|
| 114 |
|
---|
| 115 | /* These are not for current use, 8-bit protocol only!
|
---|
| 116 | uint8_t readdata(void),
|
---|
| 117 | readcommand8(uint8_t);
|
---|
| 118 | uint16_t readcommand16(uint8_t);
|
---|
| 119 | uint32_t readcommand32(uint8_t);
|
---|
| 120 | void dummyclock(void);
|
---|
| 121 | */
|
---|
| 122 |
|
---|
| 123 | private:
|
---|
| 124 |
|
---|
| 125 | void spiwrite(uint8_t),
|
---|
| 126 | writecommand(uint8_t c),
|
---|
| 127 | writedata(uint8_t d),
|
---|
| 128 | // commandList(prog_uchar *addr),
|
---|
| 129 | // commonInit(prog_uchar *cmdList);
|
---|
| 130 | commandList(uint8_t *addr),
|
---|
| 131 | commonInit(uint8_t *cmdList);
|
---|
| 132 | //uint8_t spiread(void);
|
---|
| 133 |
|
---|
| 134 | boolean hwSPI;
|
---|
| 135 | volatile uint8_t *dataport, *clkport, *csport, *rsport;
|
---|
| 136 | uint8_t _cs, _rs, _rst, _sid, _sclk,
|
---|
| 137 | datapinmask, clkpinmask, cspinmask, rspinmask,
|
---|
| 138 | colstart, rowstart; // some displays need this changed
|
---|
| 139 | };
|
---|
| 140 |
|
---|
| 141 | #endif
|
---|