Added new display module GREENTAB2 (3.3v compact blue board, 8 pin no SD card)
Adafruit_ST7735.cpp@3:5cd5edbf5b72, 2015-11-22 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Sun Nov 22 11:26:10 2015 +0000
- Revision:
- 3:5cd5edbf5b72
- Parent:
- 2:18ecda534e06
- Child:
- 4:2123ea52a4d9
minor updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SomeRandomBloke | 0:99ee879ef5a9 | 1 | /*************************************************** |
SomeRandomBloke | 0:99ee879ef5a9 | 2 | This is a library for the Adafruit 1.8" SPI display. |
SomeRandomBloke | 0:99ee879ef5a9 | 3 | This library works with the Adafruit 1.8" TFT Breakout w/SD card |
SomeRandomBloke | 0:99ee879ef5a9 | 4 | ----> http://www.adafruit.com/products/358 |
SomeRandomBloke | 0:99ee879ef5a9 | 5 | as well as Adafruit raw 1.8" TFT display |
SomeRandomBloke | 0:99ee879ef5a9 | 6 | ----> http://www.adafruit.com/products/618 |
SomeRandomBloke | 0:99ee879ef5a9 | 7 | |
SomeRandomBloke | 0:99ee879ef5a9 | 8 | Check out the links above for our tutorials and wiring diagrams |
SomeRandomBloke | 0:99ee879ef5a9 | 9 | These displays use SPI to communicate, 4 or 5 pins are required to |
SomeRandomBloke | 0:99ee879ef5a9 | 10 | interface (RST is optional) |
SomeRandomBloke | 0:99ee879ef5a9 | 11 | Adafruit invests time and resources providing this open source code, |
SomeRandomBloke | 0:99ee879ef5a9 | 12 | please support Adafruit and open-source hardware by purchasing |
SomeRandomBloke | 0:99ee879ef5a9 | 13 | products from Adafruit! |
SomeRandomBloke | 0:99ee879ef5a9 | 14 | |
SomeRandomBloke | 0:99ee879ef5a9 | 15 | Written by Limor Fried/Ladyada for Adafruit Industries. |
SomeRandomBloke | 0:99ee879ef5a9 | 16 | MIT license, all text above must be included in any redistribution |
SomeRandomBloke | 0:99ee879ef5a9 | 17 | ****************************************************/ |
SomeRandomBloke | 0:99ee879ef5a9 | 18 | |
SomeRandomBloke | 0:99ee879ef5a9 | 19 | #include "mbed.h" |
SomeRandomBloke | 0:99ee879ef5a9 | 20 | #include "Adafruit_ST7735.h" |
SomeRandomBloke | 0:99ee879ef5a9 | 21 | |
SomeRandomBloke | 0:99ee879ef5a9 | 22 | // Constructor |
SomeRandomBloke | 0:99ee879ef5a9 | 23 | Adafruit_ST7735::Adafruit_ST7735(PinName mosi, PinName miso, PinName sck, PinName cs, PinName rs, PinName rst) |
SomeRandomBloke | 1:226fd3534967 | 24 | : lcdPort(mosi, miso, sck), _cs(cs), _rs(rs), _rst(rst), Adafruit_GFX(ST7735_TFTWIDTH, ST7735_TFTHEIGHT) |
SomeRandomBloke | 0:99ee879ef5a9 | 25 | { } |
SomeRandomBloke | 0:99ee879ef5a9 | 26 | |
SomeRandomBloke | 0:99ee879ef5a9 | 27 | |
SomeRandomBloke | 0:99ee879ef5a9 | 28 | void Adafruit_ST7735::writecommand(uint8_t c) |
SomeRandomBloke | 0:99ee879ef5a9 | 29 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 30 | _rs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 31 | _cs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 32 | lcdPort.write( c ); |
SomeRandomBloke | 0:99ee879ef5a9 | 33 | _cs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 34 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 35 | |
SomeRandomBloke | 0:99ee879ef5a9 | 36 | |
SomeRandomBloke | 0:99ee879ef5a9 | 37 | void Adafruit_ST7735::writedata(uint8_t c) |
SomeRandomBloke | 0:99ee879ef5a9 | 38 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 39 | _rs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 40 | _cs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 41 | lcdPort.write( c ); |
SomeRandomBloke | 0:99ee879ef5a9 | 42 | |
SomeRandomBloke | 0:99ee879ef5a9 | 43 | _cs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 44 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 45 | |
SomeRandomBloke | 0:99ee879ef5a9 | 46 | |
SomeRandomBloke | 0:99ee879ef5a9 | 47 | // Rather than a bazillion writecommand() and writedata() calls, screen |
SomeRandomBloke | 0:99ee879ef5a9 | 48 | // initialization commands and arguments are organized in these tables |
SomeRandomBloke | 0:99ee879ef5a9 | 49 | // stored in PROGMEM. The table may look bulky, but that's mostly the |
SomeRandomBloke | 0:99ee879ef5a9 | 50 | // formatting -- storage-wise this is hundreds of bytes more compact |
SomeRandomBloke | 0:99ee879ef5a9 | 51 | // than the equivalent code. Companion function follows. |
SomeRandomBloke | 0:99ee879ef5a9 | 52 | #define DELAY 0x80 |
SomeRandomBloke | 0:99ee879ef5a9 | 53 | static unsigned char |
SomeRandomBloke | 3:5cd5edbf5b72 | 54 | Bcmd[] = { // Initialization commands for 7735B screens |
SomeRandomBloke | 3:5cd5edbf5b72 | 55 | 18, // 18 commands in list: |
SomeRandomBloke | 3:5cd5edbf5b72 | 56 | ST7735_SWRESET, DELAY, // 1: Software reset, no args, w/delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 57 | 50, // 50 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 58 | ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 59 | 255, // 255 = 500 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 60 | ST7735_COLMOD , 1+DELAY, // 3: Set color mode, 1 arg + delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 61 | 0x05, // 16-bit color |
SomeRandomBloke | 3:5cd5edbf5b72 | 62 | 10, // 10 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 63 | ST7735_FRMCTR1, 3+DELAY, // 4: Frame rate control, 3 args + delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 64 | 0x00, // fastest refresh |
SomeRandomBloke | 3:5cd5edbf5b72 | 65 | 0x06, // 6 lines front porch |
SomeRandomBloke | 3:5cd5edbf5b72 | 66 | 0x03, // 3 lines back porch |
SomeRandomBloke | 3:5cd5edbf5b72 | 67 | 10, // 10 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 68 | ST7735_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg: |
SomeRandomBloke | 3:5cd5edbf5b72 | 69 | 0x08, // Row addr/col addr, bottom to top refresh |
SomeRandomBloke | 3:5cd5edbf5b72 | 70 | ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 71 | 0x15, // 1 clk cycle nonoverlap, 2 cycle gate |
SomeRandomBloke | 3:5cd5edbf5b72 | 72 | // rise, 3 cycle osc equalize |
SomeRandomBloke | 3:5cd5edbf5b72 | 73 | 0x02, // Fix on VTL |
SomeRandomBloke | 3:5cd5edbf5b72 | 74 | ST7735_INVCTR , 1 , // 7: Display inversion control, 1 arg: |
SomeRandomBloke | 3:5cd5edbf5b72 | 75 | 0x0, // Line inversion |
SomeRandomBloke | 3:5cd5edbf5b72 | 76 | ST7735_PWCTR1 , 2+DELAY, // 8: Power control, 2 args + delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 77 | 0x02, // GVDD = 4.7V |
SomeRandomBloke | 3:5cd5edbf5b72 | 78 | 0x70, // 1.0uA |
SomeRandomBloke | 3:5cd5edbf5b72 | 79 | 10, // 10 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 80 | ST7735_PWCTR2 , 1 , // 9: Power control, 1 arg, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 81 | 0x05, // VGH = 14.7V, VGL = -7.35V |
SomeRandomBloke | 3:5cd5edbf5b72 | 82 | ST7735_PWCTR3 , 2 , // 10: Power control, 2 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 83 | 0x01, // Opamp current small |
SomeRandomBloke | 3:5cd5edbf5b72 | 84 | 0x02, // Boost frequency |
SomeRandomBloke | 3:5cd5edbf5b72 | 85 | ST7735_VMCTR1 , 2+DELAY, // 11: Power control, 2 args + delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 86 | 0x3C, // VCOMH = 4V |
SomeRandomBloke | 3:5cd5edbf5b72 | 87 | 0x38, // VCOML = -1.1V |
SomeRandomBloke | 3:5cd5edbf5b72 | 88 | 10, // 10 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 89 | ST7735_PWCTR6 , 2 , // 12: Power control, 2 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 90 | 0x11, 0x15, |
SomeRandomBloke | 3:5cd5edbf5b72 | 91 | ST7735_GMCTRP1,16 , // 13: Magical unicorn dust, 16 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 92 | 0x09, 0x16, 0x09, 0x20, // (seriously though, not sure what |
SomeRandomBloke | 3:5cd5edbf5b72 | 93 | 0x21, 0x1B, 0x13, 0x19, // these config values represent) |
SomeRandomBloke | 3:5cd5edbf5b72 | 94 | 0x17, 0x15, 0x1E, 0x2B, |
SomeRandomBloke | 3:5cd5edbf5b72 | 95 | 0x04, 0x05, 0x02, 0x0E, |
SomeRandomBloke | 3:5cd5edbf5b72 | 96 | ST7735_GMCTRN1,16+DELAY, // 14: Sparkles and rainbows, 16 args + delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 97 | 0x0B, 0x14, 0x08, 0x1E, // (ditto) |
SomeRandomBloke | 3:5cd5edbf5b72 | 98 | 0x22, 0x1D, 0x18, 0x1E, |
SomeRandomBloke | 3:5cd5edbf5b72 | 99 | 0x1B, 0x1A, 0x24, 0x2B, |
SomeRandomBloke | 3:5cd5edbf5b72 | 100 | 0x06, 0x06, 0x02, 0x0F, |
SomeRandomBloke | 3:5cd5edbf5b72 | 101 | 10, // 10 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 102 | ST7735_CASET , 4 , // 15: Column addr set, 4 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 103 | 0x00, 0x02, // XSTART = 2 |
SomeRandomBloke | 3:5cd5edbf5b72 | 104 | 0x00, 0x81, // XEND = 129 |
SomeRandomBloke | 3:5cd5edbf5b72 | 105 | ST7735_RASET , 4 , // 16: Row addr set, 4 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 106 | 0x00, 0x02, // XSTART = 1 |
SomeRandomBloke | 3:5cd5edbf5b72 | 107 | 0x00, 0x81, // XEND = 160 |
SomeRandomBloke | 3:5cd5edbf5b72 | 108 | ST7735_NORON , DELAY, // 17: Normal display on, no args, w/delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 109 | 10, // 10 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 110 | ST7735_DISPON , DELAY, // 18: Main screen turn on, no args, w/delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 111 | 255 }, // 255 = 500 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 112 | |
SomeRandomBloke | 3:5cd5edbf5b72 | 113 | Rcmd1[] = { // Init for 7735R, part 1 (red or green tab) |
SomeRandomBloke | 3:5cd5edbf5b72 | 114 | 15, // 15 commands in list: |
SomeRandomBloke | 3:5cd5edbf5b72 | 115 | ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 116 | 150, // 150 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 117 | ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 118 | 255, // 500 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 119 | ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args: |
SomeRandomBloke | 3:5cd5edbf5b72 | 120 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) |
SomeRandomBloke | 3:5cd5edbf5b72 | 121 | ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args: |
SomeRandomBloke | 3:5cd5edbf5b72 | 122 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) |
SomeRandomBloke | 3:5cd5edbf5b72 | 123 | ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args: |
SomeRandomBloke | 3:5cd5edbf5b72 | 124 | 0x01, 0x2C, 0x2D, // Dot inversion mode |
SomeRandomBloke | 3:5cd5edbf5b72 | 125 | 0x01, 0x2C, 0x2D, // Line inversion mode |
SomeRandomBloke | 3:5cd5edbf5b72 | 126 | ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 127 | 0x07, // No inversion |
SomeRandomBloke | 3:5cd5edbf5b72 | 128 | ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 129 | 0xA2, |
SomeRandomBloke | 3:5cd5edbf5b72 | 130 | 0x02, // -4.6V |
SomeRandomBloke | 3:5cd5edbf5b72 | 131 | 0x84, // AUTO mode |
SomeRandomBloke | 3:5cd5edbf5b72 | 132 | ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 133 | 0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD |
SomeRandomBloke | 3:5cd5edbf5b72 | 134 | ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 135 | 0x0A, // Opamp current small |
SomeRandomBloke | 3:5cd5edbf5b72 | 136 | 0x00, // Boost frequency |
SomeRandomBloke | 3:5cd5edbf5b72 | 137 | ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 138 | 0x8A, // BCLK/2, Opamp current small & Medium low |
SomeRandomBloke | 3:5cd5edbf5b72 | 139 | 0x2A, |
SomeRandomBloke | 3:5cd5edbf5b72 | 140 | ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 141 | 0x8A, 0xEE, |
SomeRandomBloke | 3:5cd5edbf5b72 | 142 | ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 143 | 0x0E, |
SomeRandomBloke | 3:5cd5edbf5b72 | 144 | ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 145 | ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg: |
SomeRandomBloke | 3:5cd5edbf5b72 | 146 | 0xC8, // row addr/col addr, bottom to top refresh |
SomeRandomBloke | 3:5cd5edbf5b72 | 147 | ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 148 | 0x05 }, // 16-bit color |
SomeRandomBloke | 3:5cd5edbf5b72 | 149 | |
SomeRandomBloke | 3:5cd5edbf5b72 | 150 | Rcmd2green[] = { // Init for 7735R, part 2 (green tab only) |
SomeRandomBloke | 3:5cd5edbf5b72 | 151 | 2, // 2 commands in list: |
SomeRandomBloke | 3:5cd5edbf5b72 | 152 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 153 | 0x00, 0x02, // XSTART = 0 |
SomeRandomBloke | 3:5cd5edbf5b72 | 154 | 0x00, 0x7F+0x02, // XEND = 127 |
SomeRandomBloke | 3:5cd5edbf5b72 | 155 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 156 | 0x00, 0x01, // XSTART = 0 |
SomeRandomBloke | 3:5cd5edbf5b72 | 157 | 0x00, 0x9F+0x01 }, // XEND = 159 |
SomeRandomBloke | 3:5cd5edbf5b72 | 158 | Rcmd2red[] = { // Init for 7735R, part 2 (red tab only) |
SomeRandomBloke | 3:5cd5edbf5b72 | 159 | 2, // 2 commands in list: |
SomeRandomBloke | 3:5cd5edbf5b72 | 160 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 161 | 0x00, 0x00, // XSTART = 0 |
SomeRandomBloke | 3:5cd5edbf5b72 | 162 | 0x00, 0x7F, // XEND = 127 |
SomeRandomBloke | 3:5cd5edbf5b72 | 163 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 164 | 0x00, 0x00, // XSTART = 0 |
SomeRandomBloke | 3:5cd5edbf5b72 | 165 | 0x00, 0x9F }, // XEND = 159 |
SomeRandomBloke | 3:5cd5edbf5b72 | 166 | |
SomeRandomBloke | 3:5cd5edbf5b72 | 167 | Rcmd2green144[] = { // Init for 7735R, part 2 (green 1.44 tab) |
SomeRandomBloke | 3:5cd5edbf5b72 | 168 | 2, // 2 commands in list: |
SomeRandomBloke | 3:5cd5edbf5b72 | 169 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 170 | 0x00, 0x00, // XSTART = 0 |
SomeRandomBloke | 3:5cd5edbf5b72 | 171 | 0x00, 0x7F, // XEND = 127 |
SomeRandomBloke | 3:5cd5edbf5b72 | 172 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 173 | 0x00, 0x00, // XSTART = 0 |
SomeRandomBloke | 3:5cd5edbf5b72 | 174 | 0x00, 0x7F }, // XEND = 127 |
SomeRandomBloke | 3:5cd5edbf5b72 | 175 | |
SomeRandomBloke | 3:5cd5edbf5b72 | 176 | Rcmd3[] = { // Init for 7735R, part 3 (red or green tab) |
SomeRandomBloke | 3:5cd5edbf5b72 | 177 | 4, // 4 commands in list: |
SomeRandomBloke | 3:5cd5edbf5b72 | 178 | ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 179 | 0x02, 0x1c, 0x07, 0x12, |
SomeRandomBloke | 3:5cd5edbf5b72 | 180 | 0x37, 0x32, 0x29, 0x2d, |
SomeRandomBloke | 3:5cd5edbf5b72 | 181 | 0x29, 0x25, 0x2B, 0x39, |
SomeRandomBloke | 3:5cd5edbf5b72 | 182 | 0x00, 0x01, 0x03, 0x10, |
SomeRandomBloke | 3:5cd5edbf5b72 | 183 | ST7735_GMCTRN1, 16 , // 2: Sparkles and rainbows, 16 args, no delay: |
SomeRandomBloke | 3:5cd5edbf5b72 | 184 | 0x03, 0x1d, 0x07, 0x06, |
SomeRandomBloke | 3:5cd5edbf5b72 | 185 | 0x2E, 0x2C, 0x29, 0x2D, |
SomeRandomBloke | 3:5cd5edbf5b72 | 186 | 0x2E, 0x2E, 0x37, 0x3F, |
SomeRandomBloke | 3:5cd5edbf5b72 | 187 | 0x00, 0x00, 0x02, 0x10, |
SomeRandomBloke | 3:5cd5edbf5b72 | 188 | ST7735_NORON , DELAY, // 3: Normal display on, no args, w/delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 189 | 10, // 10 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 190 | ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 191 | 100 }; // 100 ms delay |
SomeRandomBloke | 3:5cd5edbf5b72 | 192 | |
SomeRandomBloke | 3:5cd5edbf5b72 | 193 | |
SomeRandomBloke | 3:5cd5edbf5b72 | 194 | #ifdef oldshit |
SomeRandomBloke | 3:5cd5edbf5b72 | 195 | static unsigned char |
SomeRandomBloke | 0:99ee879ef5a9 | 196 | Bcmd[] = { // Initialization commands for 7735B screens |
SomeRandomBloke | 0:99ee879ef5a9 | 197 | 18, // 18 commands in list: |
SomeRandomBloke | 0:99ee879ef5a9 | 198 | ST7735_SWRESET, DELAY, // 1: Software reset, no args, w/delay |
SomeRandomBloke | 0:99ee879ef5a9 | 199 | 50, // 50 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 200 | ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay |
SomeRandomBloke | 0:99ee879ef5a9 | 201 | 255, // 255 = 500 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 202 | ST7735_COLMOD , 1+DELAY, // 3: Set color mode, 1 arg + delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 203 | 0x05, // 16-bit color |
SomeRandomBloke | 0:99ee879ef5a9 | 204 | 10, // 10 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 205 | ST7735_FRMCTR1, 3+DELAY, // 4: Frame rate control, 3 args + delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 206 | 0x00, // fastest refresh |
SomeRandomBloke | 0:99ee879ef5a9 | 207 | 0x06, // 6 lines front porch |
SomeRandomBloke | 0:99ee879ef5a9 | 208 | 0x03, // 3 lines back porch |
SomeRandomBloke | 0:99ee879ef5a9 | 209 | 10, // 10 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 210 | ST7735_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg: |
SomeRandomBloke | 0:99ee879ef5a9 | 211 | 0x08, // Row addr/col addr, bottom to top refresh |
SomeRandomBloke | 0:99ee879ef5a9 | 212 | ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 213 | 0x15, // 1 clk cycle nonoverlap, 2 cycle gate |
SomeRandomBloke | 0:99ee879ef5a9 | 214 | // rise, 3 cycle osc equalize |
SomeRandomBloke | 0:99ee879ef5a9 | 215 | 0x02, // Fix on VTL |
SomeRandomBloke | 0:99ee879ef5a9 | 216 | ST7735_INVCTR , 1 , // 7: Display inversion control, 1 arg: |
SomeRandomBloke | 0:99ee879ef5a9 | 217 | 0x0, // Line inversion |
SomeRandomBloke | 0:99ee879ef5a9 | 218 | ST7735_PWCTR1 , 2+DELAY, // 8: Power control, 2 args + delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 219 | 0x02, // GVDD = 4.7V |
SomeRandomBloke | 0:99ee879ef5a9 | 220 | 0x70, // 1.0uA |
SomeRandomBloke | 0:99ee879ef5a9 | 221 | 10, // 10 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 222 | ST7735_PWCTR2 , 1 , // 9: Power control, 1 arg, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 223 | 0x05, // VGH = 14.7V, VGL = -7.35V |
SomeRandomBloke | 0:99ee879ef5a9 | 224 | ST7735_PWCTR3 , 2 , // 10: Power control, 2 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 225 | 0x01, // Opamp current small |
SomeRandomBloke | 0:99ee879ef5a9 | 226 | 0x02, // Boost frequency |
SomeRandomBloke | 0:99ee879ef5a9 | 227 | ST7735_VMCTR1 , 2+DELAY, // 11: Power control, 2 args + delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 228 | 0x3C, // VCOMH = 4V |
SomeRandomBloke | 0:99ee879ef5a9 | 229 | 0x38, // VCOML = -1.1V |
SomeRandomBloke | 0:99ee879ef5a9 | 230 | 10, // 10 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 231 | ST7735_PWCTR6 , 2 , // 12: Power control, 2 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 232 | 0x11, 0x15, |
SomeRandomBloke | 0:99ee879ef5a9 | 233 | ST7735_GMCTRP1,16 , // 13: Magical unicorn dust, 16 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 234 | 0x09, 0x16, 0x09, 0x20, // (seriously though, not sure what |
SomeRandomBloke | 0:99ee879ef5a9 | 235 | 0x21, 0x1B, 0x13, 0x19, // these config values represent) |
SomeRandomBloke | 0:99ee879ef5a9 | 236 | 0x17, 0x15, 0x1E, 0x2B, |
SomeRandomBloke | 0:99ee879ef5a9 | 237 | 0x04, 0x05, 0x02, 0x0E, |
SomeRandomBloke | 0:99ee879ef5a9 | 238 | ST7735_GMCTRN1,16+DELAY, // 14: Sparkles and rainbows, 16 args + delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 239 | 0x0B, 0x14, 0x08, 0x1E, // (ditto) |
SomeRandomBloke | 0:99ee879ef5a9 | 240 | 0x22, 0x1D, 0x18, 0x1E, |
SomeRandomBloke | 0:99ee879ef5a9 | 241 | 0x1B, 0x1A, 0x24, 0x2B, |
SomeRandomBloke | 0:99ee879ef5a9 | 242 | 0x06, 0x06, 0x02, 0x0F, |
SomeRandomBloke | 0:99ee879ef5a9 | 243 | 10, // 10 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 244 | ST7735_CASET , 4 , // 15: Column addr set, 4 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 245 | 0x00, 0x02, // XSTART = 2 |
SomeRandomBloke | 0:99ee879ef5a9 | 246 | 0x00, 0x81, // XEND = 129 |
SomeRandomBloke | 0:99ee879ef5a9 | 247 | ST7735_RASET , 4 , // 16: Row addr set, 4 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 248 | 0x00, 0x02, // XSTART = 1 |
SomeRandomBloke | 0:99ee879ef5a9 | 249 | 0x00, 0x81, // XEND = 160 |
SomeRandomBloke | 0:99ee879ef5a9 | 250 | ST7735_NORON , DELAY, // 17: Normal display on, no args, w/delay |
SomeRandomBloke | 0:99ee879ef5a9 | 251 | 10, // 10 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 252 | ST7735_DISPON , DELAY, // 18: Main screen turn on, no args, w/delay |
SomeRandomBloke | 0:99ee879ef5a9 | 253 | 255 |
SomeRandomBloke | 0:99ee879ef5a9 | 254 | }, // 255 = 500 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 255 | |
SomeRandomBloke | 0:99ee879ef5a9 | 256 | Rcmd1[] = { // Init for 7735R, part 1 (red or green tab) |
SomeRandomBloke | 0:99ee879ef5a9 | 257 | 15, // 15 commands in list: |
SomeRandomBloke | 0:99ee879ef5a9 | 258 | ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay |
SomeRandomBloke | 0:99ee879ef5a9 | 259 | 150, // 150 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 260 | ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay |
SomeRandomBloke | 0:99ee879ef5a9 | 261 | 255, // 500 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 262 | ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args: |
SomeRandomBloke | 0:99ee879ef5a9 | 263 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) |
SomeRandomBloke | 0:99ee879ef5a9 | 264 | ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args: |
SomeRandomBloke | 0:99ee879ef5a9 | 265 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) |
SomeRandomBloke | 0:99ee879ef5a9 | 266 | ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args: |
SomeRandomBloke | 0:99ee879ef5a9 | 267 | 0x01, 0x2C, 0x2D, // Dot inversion mode |
SomeRandomBloke | 0:99ee879ef5a9 | 268 | 0x01, 0x2C, 0x2D, // Line inversion mode |
SomeRandomBloke | 0:99ee879ef5a9 | 269 | ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 270 | 0x07, // No inversion |
SomeRandomBloke | 0:99ee879ef5a9 | 271 | ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 272 | 0xA2, |
SomeRandomBloke | 0:99ee879ef5a9 | 273 | 0x02, // -4.6V |
SomeRandomBloke | 0:99ee879ef5a9 | 274 | 0x84, // AUTO mode |
SomeRandomBloke | 0:99ee879ef5a9 | 275 | ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 276 | 0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD |
SomeRandomBloke | 0:99ee879ef5a9 | 277 | ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 278 | 0x0A, // Opamp current small |
SomeRandomBloke | 0:99ee879ef5a9 | 279 | 0x00, // Boost frequency |
SomeRandomBloke | 0:99ee879ef5a9 | 280 | ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 281 | 0x8A, // BCLK/2, Opamp current small & Medium low |
SomeRandomBloke | 0:99ee879ef5a9 | 282 | 0x2A, |
SomeRandomBloke | 0:99ee879ef5a9 | 283 | ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 284 | 0x8A, 0xEE, |
SomeRandomBloke | 0:99ee879ef5a9 | 285 | ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 286 | 0x0E, |
SomeRandomBloke | 0:99ee879ef5a9 | 287 | ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay |
SomeRandomBloke | 0:99ee879ef5a9 | 288 | ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg: |
SomeRandomBloke | 0:99ee879ef5a9 | 289 | 0xC8, // row addr/col addr, bottom to top refresh |
SomeRandomBloke | 0:99ee879ef5a9 | 290 | ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 291 | 0x05 |
SomeRandomBloke | 0:99ee879ef5a9 | 292 | }, // 16-bit color |
SomeRandomBloke | 0:99ee879ef5a9 | 293 | |
SomeRandomBloke | 0:99ee879ef5a9 | 294 | Rcmd2green[] = { // Init for 7735R, part 2 (green tab only) |
SomeRandomBloke | 0:99ee879ef5a9 | 295 | 2, // 2 commands in list: |
SomeRandomBloke | 0:99ee879ef5a9 | 296 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 297 | 0x00, 0x02, // XSTART = 0 |
SomeRandomBloke | 0:99ee879ef5a9 | 298 | 0x00, 0x7F+0x02, // XEND = 127 |
SomeRandomBloke | 0:99ee879ef5a9 | 299 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 300 | 0x00, 0x01, // XSTART = 0 |
SomeRandomBloke | 0:99ee879ef5a9 | 301 | 0x00, 0x9F+0x01 |
SomeRandomBloke | 0:99ee879ef5a9 | 302 | }, // XEND = 159 |
SomeRandomBloke | 0:99ee879ef5a9 | 303 | Rcmd2red[] = { // Init for 7735R, part 2 (red tab only) |
SomeRandomBloke | 0:99ee879ef5a9 | 304 | 2, // 2 commands in list: |
SomeRandomBloke | 0:99ee879ef5a9 | 305 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 306 | 0x00, 0x00, // XSTART = 0 |
SomeRandomBloke | 0:99ee879ef5a9 | 307 | 0x00, 0x7F, // XEND = 127 |
SomeRandomBloke | 0:99ee879ef5a9 | 308 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 309 | 0x00, 0x00, // XSTART = 0 |
SomeRandomBloke | 0:99ee879ef5a9 | 310 | 0x00, 0x9F |
SomeRandomBloke | 0:99ee879ef5a9 | 311 | }, // XEND = 159 |
SomeRandomBloke | 0:99ee879ef5a9 | 312 | |
SomeRandomBloke | 0:99ee879ef5a9 | 313 | Rcmd3[] = { // Init for 7735R, part 3 (red or green tab) |
SomeRandomBloke | 0:99ee879ef5a9 | 314 | 4, // 4 commands in list: |
SomeRandomBloke | 0:99ee879ef5a9 | 315 | ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 316 | 0x02, 0x1c, 0x07, 0x12, |
SomeRandomBloke | 0:99ee879ef5a9 | 317 | 0x37, 0x32, 0x29, 0x2d, |
SomeRandomBloke | 0:99ee879ef5a9 | 318 | 0x29, 0x25, 0x2B, 0x39, |
SomeRandomBloke | 0:99ee879ef5a9 | 319 | 0x00, 0x01, 0x03, 0x10, |
SomeRandomBloke | 0:99ee879ef5a9 | 320 | ST7735_GMCTRN1, 16 , // 2: Sparkles and rainbows, 16 args, no delay: |
SomeRandomBloke | 0:99ee879ef5a9 | 321 | 0x03, 0x1d, 0x07, 0x06, |
SomeRandomBloke | 0:99ee879ef5a9 | 322 | 0x2E, 0x2C, 0x29, 0x2D, |
SomeRandomBloke | 0:99ee879ef5a9 | 323 | 0x2E, 0x2E, 0x37, 0x3F, |
SomeRandomBloke | 0:99ee879ef5a9 | 324 | 0x00, 0x00, 0x02, 0x10, |
SomeRandomBloke | 0:99ee879ef5a9 | 325 | ST7735_NORON , DELAY, // 3: Normal display on, no args, w/delay |
SomeRandomBloke | 0:99ee879ef5a9 | 326 | 10, // 10 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 327 | ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay |
SomeRandomBloke | 0:99ee879ef5a9 | 328 | 100 |
SomeRandomBloke | 0:99ee879ef5a9 | 329 | }; // 100 ms delay |
SomeRandomBloke | 0:99ee879ef5a9 | 330 | |
SomeRandomBloke | 3:5cd5edbf5b72 | 331 | #endif |
SomeRandomBloke | 0:99ee879ef5a9 | 332 | |
SomeRandomBloke | 0:99ee879ef5a9 | 333 | // Companion code to the above tables. Reads and issues |
SomeRandomBloke | 0:99ee879ef5a9 | 334 | // a series of LCD commands stored in byte array. |
SomeRandomBloke | 0:99ee879ef5a9 | 335 | void Adafruit_ST7735::commandList(uint8_t *addr) |
SomeRandomBloke | 0:99ee879ef5a9 | 336 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 337 | |
SomeRandomBloke | 0:99ee879ef5a9 | 338 | uint8_t numCommands, numArgs; |
SomeRandomBloke | 0:99ee879ef5a9 | 339 | uint16_t ms; |
SomeRandomBloke | 0:99ee879ef5a9 | 340 | |
SomeRandomBloke | 0:99ee879ef5a9 | 341 | numCommands = *addr++; // Number of commands to follow |
SomeRandomBloke | 0:99ee879ef5a9 | 342 | while(numCommands--) { // For each command... |
SomeRandomBloke | 0:99ee879ef5a9 | 343 | writecommand(*addr++); // Read, issue command |
SomeRandomBloke | 0:99ee879ef5a9 | 344 | numArgs = *addr++; // Number of args to follow |
SomeRandomBloke | 0:99ee879ef5a9 | 345 | ms = numArgs & DELAY; // If hibit set, delay follows args |
SomeRandomBloke | 0:99ee879ef5a9 | 346 | numArgs &= ~DELAY; // Mask out delay bit |
SomeRandomBloke | 0:99ee879ef5a9 | 347 | while(numArgs--) { // For each argument... |
SomeRandomBloke | 0:99ee879ef5a9 | 348 | writedata(*addr++); // Read, issue argument |
SomeRandomBloke | 0:99ee879ef5a9 | 349 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 350 | |
SomeRandomBloke | 0:99ee879ef5a9 | 351 | if(ms) { |
SomeRandomBloke | 0:99ee879ef5a9 | 352 | ms = *addr++; // Read post-command delay time (ms) |
SomeRandomBloke | 0:99ee879ef5a9 | 353 | if(ms == 255) ms = 500; // If 255, delay for 500 ms |
SomeRandomBloke | 0:99ee879ef5a9 | 354 | wait_ms(ms); |
SomeRandomBloke | 0:99ee879ef5a9 | 355 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 356 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 357 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 358 | |
SomeRandomBloke | 0:99ee879ef5a9 | 359 | |
SomeRandomBloke | 0:99ee879ef5a9 | 360 | // Initialization code common to both 'B' and 'R' type displays |
SomeRandomBloke | 0:99ee879ef5a9 | 361 | void Adafruit_ST7735::commonInit(uint8_t *cmdList) |
SomeRandomBloke | 0:99ee879ef5a9 | 362 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 363 | |
SomeRandomBloke | 0:99ee879ef5a9 | 364 | colstart = rowstart = 0; // May be overridden in init func |
SomeRandomBloke | 0:99ee879ef5a9 | 365 | |
SomeRandomBloke | 0:99ee879ef5a9 | 366 | _rs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 367 | _cs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 368 | |
SomeRandomBloke | 0:99ee879ef5a9 | 369 | // use default SPI format |
SomeRandomBloke | 0:99ee879ef5a9 | 370 | lcdPort.format(8,0); |
SomeRandomBloke | 2:18ecda534e06 | 371 | lcdPort.frequency(4000000); // Lets try 4MHz |
SomeRandomBloke | 0:99ee879ef5a9 | 372 | |
SomeRandomBloke | 0:99ee879ef5a9 | 373 | // toggle RST low to reset; CS low so it'll listen to us |
SomeRandomBloke | 0:99ee879ef5a9 | 374 | _cs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 375 | _rst = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 376 | wait_ms(500); |
SomeRandomBloke | 0:99ee879ef5a9 | 377 | _rst = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 378 | wait_ms(500); |
SomeRandomBloke | 0:99ee879ef5a9 | 379 | _rst = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 380 | wait_ms(500); |
SomeRandomBloke | 0:99ee879ef5a9 | 381 | |
SomeRandomBloke | 0:99ee879ef5a9 | 382 | if(cmdList) commandList(cmdList); |
SomeRandomBloke | 0:99ee879ef5a9 | 383 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 384 | |
SomeRandomBloke | 0:99ee879ef5a9 | 385 | |
SomeRandomBloke | 0:99ee879ef5a9 | 386 | // Initialization for ST7735B screens |
SomeRandomBloke | 0:99ee879ef5a9 | 387 | void Adafruit_ST7735::initB(void) |
SomeRandomBloke | 0:99ee879ef5a9 | 388 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 389 | commonInit(Bcmd); |
SomeRandomBloke | 0:99ee879ef5a9 | 390 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 391 | |
SomeRandomBloke | 0:99ee879ef5a9 | 392 | |
SomeRandomBloke | 0:99ee879ef5a9 | 393 | // Initialization for ST7735R screens (green or red tabs) |
SomeRandomBloke | 0:99ee879ef5a9 | 394 | void Adafruit_ST7735::initR(uint8_t options) |
SomeRandomBloke | 0:99ee879ef5a9 | 395 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 396 | commonInit(Rcmd1); |
SomeRandomBloke | 0:99ee879ef5a9 | 397 | if(options == INITR_GREENTAB) { |
SomeRandomBloke | 0:99ee879ef5a9 | 398 | commandList(Rcmd2green); |
SomeRandomBloke | 0:99ee879ef5a9 | 399 | colstart = 2; |
SomeRandomBloke | 0:99ee879ef5a9 | 400 | rowstart = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 401 | } else { |
SomeRandomBloke | 0:99ee879ef5a9 | 402 | // colstart, rowstart left at default '0' values |
SomeRandomBloke | 0:99ee879ef5a9 | 403 | commandList(Rcmd2red); |
SomeRandomBloke | 0:99ee879ef5a9 | 404 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 405 | commandList(Rcmd3); |
SomeRandomBloke | 0:99ee879ef5a9 | 406 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 407 | |
SomeRandomBloke | 0:99ee879ef5a9 | 408 | |
SomeRandomBloke | 0:99ee879ef5a9 | 409 | void Adafruit_ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, |
SomeRandomBloke | 0:99ee879ef5a9 | 410 | uint8_t y1) |
SomeRandomBloke | 0:99ee879ef5a9 | 411 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 412 | |
SomeRandomBloke | 0:99ee879ef5a9 | 413 | writecommand(ST7735_CASET); // Column addr set |
SomeRandomBloke | 0:99ee879ef5a9 | 414 | writedata(0x00); |
SomeRandomBloke | 0:99ee879ef5a9 | 415 | writedata(x0+colstart); // XSTART |
SomeRandomBloke | 0:99ee879ef5a9 | 416 | writedata(0x00); |
SomeRandomBloke | 0:99ee879ef5a9 | 417 | writedata(x1+colstart); // XEND |
SomeRandomBloke | 0:99ee879ef5a9 | 418 | |
SomeRandomBloke | 0:99ee879ef5a9 | 419 | writecommand(ST7735_RASET); // Row addr set |
SomeRandomBloke | 0:99ee879ef5a9 | 420 | writedata(0x00); |
SomeRandomBloke | 0:99ee879ef5a9 | 421 | writedata(y0+rowstart); // YSTART |
SomeRandomBloke | 0:99ee879ef5a9 | 422 | writedata(0x00); |
SomeRandomBloke | 0:99ee879ef5a9 | 423 | writedata(y1+rowstart); // YEND |
SomeRandomBloke | 0:99ee879ef5a9 | 424 | |
SomeRandomBloke | 0:99ee879ef5a9 | 425 | writecommand(ST7735_RAMWR); // write to RAM |
SomeRandomBloke | 0:99ee879ef5a9 | 426 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 427 | |
SomeRandomBloke | 0:99ee879ef5a9 | 428 | |
SomeRandomBloke | 0:99ee879ef5a9 | 429 | void Adafruit_ST7735::fillScreen(uint16_t color) |
SomeRandomBloke | 0:99ee879ef5a9 | 430 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 431 | |
SomeRandomBloke | 0:99ee879ef5a9 | 432 | uint8_t x, y, hi = color >> 8, lo = color; |
SomeRandomBloke | 0:99ee879ef5a9 | 433 | |
SomeRandomBloke | 0:99ee879ef5a9 | 434 | setAddrWindow(0, 0, _width-1, _height-1); |
SomeRandomBloke | 0:99ee879ef5a9 | 435 | |
SomeRandomBloke | 0:99ee879ef5a9 | 436 | _rs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 437 | _cs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 438 | |
SomeRandomBloke | 0:99ee879ef5a9 | 439 | for(y=_height; y>0; y--) { |
SomeRandomBloke | 0:99ee879ef5a9 | 440 | for(x=_width; x>0; x--) { |
SomeRandomBloke | 0:99ee879ef5a9 | 441 | lcdPort.write( hi ); |
SomeRandomBloke | 0:99ee879ef5a9 | 442 | lcdPort.write( lo ); |
SomeRandomBloke | 0:99ee879ef5a9 | 443 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 444 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 445 | |
SomeRandomBloke | 0:99ee879ef5a9 | 446 | _cs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 447 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 448 | |
SomeRandomBloke | 0:99ee879ef5a9 | 449 | |
SomeRandomBloke | 0:99ee879ef5a9 | 450 | void Adafruit_ST7735::pushColor(uint16_t color) |
SomeRandomBloke | 0:99ee879ef5a9 | 451 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 452 | _rs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 453 | _cs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 454 | |
SomeRandomBloke | 0:99ee879ef5a9 | 455 | lcdPort.write( color >> 8 ); |
SomeRandomBloke | 0:99ee879ef5a9 | 456 | lcdPort.write( color ); |
SomeRandomBloke | 0:99ee879ef5a9 | 457 | _cs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 458 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 459 | |
SomeRandomBloke | 0:99ee879ef5a9 | 460 | |
SomeRandomBloke | 0:99ee879ef5a9 | 461 | void Adafruit_ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) |
SomeRandomBloke | 0:99ee879ef5a9 | 462 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 463 | |
SomeRandomBloke | 0:99ee879ef5a9 | 464 | if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return; |
SomeRandomBloke | 0:99ee879ef5a9 | 465 | |
SomeRandomBloke | 0:99ee879ef5a9 | 466 | setAddrWindow(x,y,x+1,y+1); |
SomeRandomBloke | 0:99ee879ef5a9 | 467 | |
SomeRandomBloke | 0:99ee879ef5a9 | 468 | _rs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 469 | _cs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 470 | |
SomeRandomBloke | 0:99ee879ef5a9 | 471 | lcdPort.write( color >> 8 ); |
SomeRandomBloke | 0:99ee879ef5a9 | 472 | lcdPort.write( color ); |
SomeRandomBloke | 0:99ee879ef5a9 | 473 | |
SomeRandomBloke | 0:99ee879ef5a9 | 474 | _cs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 475 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 476 | |
SomeRandomBloke | 0:99ee879ef5a9 | 477 | |
SomeRandomBloke | 0:99ee879ef5a9 | 478 | void Adafruit_ST7735::drawFastVLine(int16_t x, int16_t y, int16_t h, |
SomeRandomBloke | 0:99ee879ef5a9 | 479 | uint16_t color) |
SomeRandomBloke | 0:99ee879ef5a9 | 480 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 481 | |
SomeRandomBloke | 0:99ee879ef5a9 | 482 | // Rudimentary clipping |
SomeRandomBloke | 0:99ee879ef5a9 | 483 | if((x >= _width) || (y >= _height)) return; |
SomeRandomBloke | 0:99ee879ef5a9 | 484 | if((y+h-1) >= _height) h = _height-y; |
SomeRandomBloke | 0:99ee879ef5a9 | 485 | setAddrWindow(x, y, x, y+h-1); |
SomeRandomBloke | 0:99ee879ef5a9 | 486 | |
SomeRandomBloke | 0:99ee879ef5a9 | 487 | uint8_t hi = color >> 8, lo = color; |
SomeRandomBloke | 0:99ee879ef5a9 | 488 | _rs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 489 | _cs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 490 | while (h--) { |
SomeRandomBloke | 0:99ee879ef5a9 | 491 | lcdPort.write( hi ); |
SomeRandomBloke | 0:99ee879ef5a9 | 492 | lcdPort.write( lo ); |
SomeRandomBloke | 0:99ee879ef5a9 | 493 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 494 | _cs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 495 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 496 | |
SomeRandomBloke | 0:99ee879ef5a9 | 497 | |
SomeRandomBloke | 0:99ee879ef5a9 | 498 | void Adafruit_ST7735::drawFastHLine(int16_t x, int16_t y, int16_t w, |
SomeRandomBloke | 0:99ee879ef5a9 | 499 | uint16_t color) |
SomeRandomBloke | 0:99ee879ef5a9 | 500 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 501 | |
SomeRandomBloke | 0:99ee879ef5a9 | 502 | // Rudimentary clipping |
SomeRandomBloke | 0:99ee879ef5a9 | 503 | if((x >= _width) || (y >= _height)) return; |
SomeRandomBloke | 0:99ee879ef5a9 | 504 | if((x+w-1) >= _width) w = _width-x; |
SomeRandomBloke | 0:99ee879ef5a9 | 505 | setAddrWindow(x, y, x+w-1, y); |
SomeRandomBloke | 0:99ee879ef5a9 | 506 | |
SomeRandomBloke | 0:99ee879ef5a9 | 507 | uint8_t hi = color >> 8, lo = color; |
SomeRandomBloke | 0:99ee879ef5a9 | 508 | _rs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 509 | _cs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 510 | while (w--) { |
SomeRandomBloke | 0:99ee879ef5a9 | 511 | lcdPort.write( hi ); |
SomeRandomBloke | 0:99ee879ef5a9 | 512 | lcdPort.write( lo ); |
SomeRandomBloke | 0:99ee879ef5a9 | 513 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 514 | _cs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 515 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 516 | |
SomeRandomBloke | 0:99ee879ef5a9 | 517 | |
SomeRandomBloke | 0:99ee879ef5a9 | 518 | // fill a rectangle |
SomeRandomBloke | 0:99ee879ef5a9 | 519 | void Adafruit_ST7735::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, |
SomeRandomBloke | 0:99ee879ef5a9 | 520 | uint16_t color) |
SomeRandomBloke | 0:99ee879ef5a9 | 521 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 522 | |
SomeRandomBloke | 0:99ee879ef5a9 | 523 | // rudimentary clipping (drawChar w/big text requires this) |
SomeRandomBloke | 0:99ee879ef5a9 | 524 | if((x >= _width) || (y >= _height)) return; |
SomeRandomBloke | 0:99ee879ef5a9 | 525 | if((x + w - 1) >= _width) w = _width - x; |
SomeRandomBloke | 0:99ee879ef5a9 | 526 | if((y + h - 1) >= _height) h = _height - y; |
SomeRandomBloke | 0:99ee879ef5a9 | 527 | |
SomeRandomBloke | 0:99ee879ef5a9 | 528 | setAddrWindow(x, y, x+w-1, y+h-1); |
SomeRandomBloke | 0:99ee879ef5a9 | 529 | |
SomeRandomBloke | 0:99ee879ef5a9 | 530 | uint8_t hi = color >> 8, lo = color; |
SomeRandomBloke | 0:99ee879ef5a9 | 531 | _rs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 532 | _cs = 0; |
SomeRandomBloke | 0:99ee879ef5a9 | 533 | for(y=h; y>0; y--) { |
SomeRandomBloke | 0:99ee879ef5a9 | 534 | for(x=w; x>0; x--) { |
SomeRandomBloke | 0:99ee879ef5a9 | 535 | lcdPort.write( hi ); |
SomeRandomBloke | 0:99ee879ef5a9 | 536 | lcdPort.write( lo ); |
SomeRandomBloke | 0:99ee879ef5a9 | 537 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 538 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 539 | |
SomeRandomBloke | 0:99ee879ef5a9 | 540 | _cs = 1; |
SomeRandomBloke | 0:99ee879ef5a9 | 541 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 542 | |
SomeRandomBloke | 0:99ee879ef5a9 | 543 | |
SomeRandomBloke | 0:99ee879ef5a9 | 544 | // Pass 8-bit (each) R,G,B, get back 16-bit packed color |
SomeRandomBloke | 0:99ee879ef5a9 | 545 | uint16_t Adafruit_ST7735::Color565(uint8_t r, uint8_t g, uint8_t b) |
SomeRandomBloke | 0:99ee879ef5a9 | 546 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 547 | return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); |
SomeRandomBloke | 0:99ee879ef5a9 | 548 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 549 | |
SomeRandomBloke | 0:99ee879ef5a9 | 550 | |
SomeRandomBloke | 0:99ee879ef5a9 | 551 | #define MADCTL_MY 0x80 |
SomeRandomBloke | 0:99ee879ef5a9 | 552 | #define MADCTL_MX 0x40 |
SomeRandomBloke | 0:99ee879ef5a9 | 553 | #define MADCTL_MV 0x20 |
SomeRandomBloke | 0:99ee879ef5a9 | 554 | #define MADCTL_ML 0x10 |
SomeRandomBloke | 0:99ee879ef5a9 | 555 | #define MADCTL_RGB 0x08 |
SomeRandomBloke | 0:99ee879ef5a9 | 556 | #define MADCTL_MH 0x04 |
SomeRandomBloke | 0:99ee879ef5a9 | 557 | |
SomeRandomBloke | 0:99ee879ef5a9 | 558 | void Adafruit_ST7735::setRotation(uint8_t m) |
SomeRandomBloke | 0:99ee879ef5a9 | 559 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 560 | |
SomeRandomBloke | 0:99ee879ef5a9 | 561 | writecommand(ST7735_MADCTL); |
SomeRandomBloke | 0:99ee879ef5a9 | 562 | rotation = m % 4; // can't be higher than 3 |
SomeRandomBloke | 0:99ee879ef5a9 | 563 | switch (rotation) { |
SomeRandomBloke | 0:99ee879ef5a9 | 564 | case 0: |
SomeRandomBloke | 0:99ee879ef5a9 | 565 | writedata(MADCTL_MX | MADCTL_MY | MADCTL_RGB); |
SomeRandomBloke | 0:99ee879ef5a9 | 566 | _width = ST7735_TFTWIDTH; |
SomeRandomBloke | 0:99ee879ef5a9 | 567 | _height = ST7735_TFTHEIGHT; |
SomeRandomBloke | 0:99ee879ef5a9 | 568 | break; |
SomeRandomBloke | 0:99ee879ef5a9 | 569 | case 1: |
SomeRandomBloke | 0:99ee879ef5a9 | 570 | writedata(MADCTL_MY | MADCTL_MV | MADCTL_RGB); |
SomeRandomBloke | 0:99ee879ef5a9 | 571 | _width = ST7735_TFTHEIGHT; |
SomeRandomBloke | 0:99ee879ef5a9 | 572 | _height = ST7735_TFTWIDTH; |
SomeRandomBloke | 0:99ee879ef5a9 | 573 | break; |
SomeRandomBloke | 0:99ee879ef5a9 | 574 | case 2: |
SomeRandomBloke | 0:99ee879ef5a9 | 575 | writedata(MADCTL_RGB); |
SomeRandomBloke | 0:99ee879ef5a9 | 576 | _width = ST7735_TFTWIDTH; |
SomeRandomBloke | 0:99ee879ef5a9 | 577 | _height = ST7735_TFTHEIGHT; |
SomeRandomBloke | 0:99ee879ef5a9 | 578 | break; |
SomeRandomBloke | 0:99ee879ef5a9 | 579 | case 3: |
SomeRandomBloke | 0:99ee879ef5a9 | 580 | writedata(MADCTL_MX | MADCTL_MV | MADCTL_RGB); |
SomeRandomBloke | 0:99ee879ef5a9 | 581 | _width = ST7735_TFTHEIGHT; |
SomeRandomBloke | 0:99ee879ef5a9 | 582 | _height = ST7735_TFTWIDTH; |
SomeRandomBloke | 0:99ee879ef5a9 | 583 | break; |
SomeRandomBloke | 0:99ee879ef5a9 | 584 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 585 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 586 | |
SomeRandomBloke | 0:99ee879ef5a9 | 587 | |
SomeRandomBloke | 0:99ee879ef5a9 | 588 | void Adafruit_ST7735::invertDisplay(boolean i) |
SomeRandomBloke | 0:99ee879ef5a9 | 589 | { |
SomeRandomBloke | 0:99ee879ef5a9 | 590 | writecommand(i ? ST7735_INVON : ST7735_INVOFF); |
SomeRandomBloke | 0:99ee879ef5a9 | 591 | } |
SomeRandomBloke | 0:99ee879ef5a9 | 592 | |
SomeRandomBloke | 0:99ee879ef5a9 | 593 |