Fork of the Adafruit ST7735R library targeted to the 1.44" TFT with custom high speed monochrome and color drawing routines. Note that this library includes modifications to use a shared SPI module to simplify projects that use the SPI for several peripherals. Read the WIKI to see how to get this library working in your own project.

Fork of Adafruit_ST7735 by Andrew Lindsay

This library is a modification of Andrew Lindsay's ST7735 Adafruit library. It includes custom bitmap drawing routines that work around 15 times faster when using custom byte arrays generated by my png to char array converter.

For more info look to the detailed post explaining the changes and where you can download the converter binaries as well: http://alfredoer.com/microcontrollers-2/adafruit-image-bitmap-generator/

IMPORTANT: One of the main modifications is that this library does not instantiate an SPI object directly, rather it is meant to use a shared SPI object exported in a "board.h" file elsewhere in your project.

The contents of such a file can be something like:

ifndef BOARD_H_

  1. define BOARD_H_
  1. include <mbed.h>
  2. include <rtos.h> extern Mutex spi_mutex; extern SPI spi_port;
  1. endif

And of course, the objects should be instantiated somewhere (like in board.c) like this (for a KL25z, modify as needed):

mosi, miso, sck Mutex spi_mutex; SPI spi_port( PTD2, PTD3, PTD1);

The rationale is that several modules can use the hardware SPI port on several threads and coexist happily with each other.

Committer:
AlfredoER
Date:
Tue Mar 03 20:20:07 2015 +0000
Revision:
5:57e689b2af4f
Parent:
4:2eb7d188ba43
Child:
6:f572731fc65f
-Merged changes.

Who changed what in which revision?

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