Platform game written for the GHI/OutrageousCircuits RETRO game device. Navigate the caves collecting all the pickups and avoiding the creatures and haunted mine carts that patrol the caves. Oh and remember to watch out for the poisonous plants... This game demonstrates the ability to have multiple animated sprites where the sprites can overlap the background environment. See how the player moves past the fence and climbs the wall in the 3rd screen.

Dependencies:   mbed

Committer:
taylorza
Date:
Sat Nov 29 06:40:50 2014 +0000
Revision:
0:2ee0812e2615
Child:
3:a93fe5f207f5
Working engine with patrolling enemies

Who changed what in which revision?

UserRevisionLine numberNew contents of line
taylorza 0:2ee0812e2615 1 ///////////////////////////////////////////////////////////////////////////////
taylorza 0:2ee0812e2615 2 // LCD_ST7735 - Driver for ST7735 LCD display controller
taylorza 0:2ee0812e2615 3 // Author: Chris Taylor (taylorza)
taylorza 0:2ee0812e2615 4
taylorza 0:2ee0812e2615 5 #ifndef __LCD_ST7735__
taylorza 0:2ee0812e2615 6 #define __LCD_ST7735__
taylorza 0:2ee0812e2615 7
taylorza 0:2ee0812e2615 8 /** LCD_ST7735 is a simple driver for the ST7735 LCD controller. It provides basic drawing primitives sa well as text and font capabilities.
taylorza 0:2ee0812e2615 9 * The driver is currently hardcoded to support 65K colors using a 565 RGB pixel format.
taylorza 0:2ee0812e2615 10 */
taylorza 0:2ee0812e2615 11 class LCD_ST7735
taylorza 0:2ee0812e2615 12 {
taylorza 0:2ee0812e2615 13 public:
taylorza 0:2ee0812e2615 14 /** Orientation of the display */
taylorza 0:2ee0812e2615 15 enum Orientation
taylorza 0:2ee0812e2615 16 {
taylorza 0:2ee0812e2615 17 /** No rotation of the display image*/
taylorza 0:2ee0812e2615 18 Rotate0,
taylorza 0:2ee0812e2615 19 /** Rotate the display image 90 degrees */
taylorza 0:2ee0812e2615 20 Rotate90,
taylorza 0:2ee0812e2615 21 /** Rotate the display image 180 degrees */
taylorza 0:2ee0812e2615 22 Rotate180,
taylorza 0:2ee0812e2615 23 /** Rotate the display image 270 degrees */
taylorza 0:2ee0812e2615 24 Rotate270
taylorza 0:2ee0812e2615 25 };
taylorza 0:2ee0812e2615 26
taylorza 0:2ee0812e2615 27 /** Type of color filter of the panel */
taylorza 0:2ee0812e2615 28 enum PanelColorFilter
taylorza 0:2ee0812e2615 29 {
taylorza 0:2ee0812e2615 30 /** RGB color filter panel */
taylorza 0:2ee0812e2615 31 RGB = 0,
taylorza 0:2ee0812e2615 32
taylorza 0:2ee0812e2615 33 /** BGR color filter panel */
taylorza 0:2ee0812e2615 34 BGR = 8,
taylorza 0:2ee0812e2615 35 };
taylorza 0:2ee0812e2615 36
taylorza 0:2ee0812e2615 37 public:
taylorza 0:2ee0812e2615 38 /**Creates an instance of the LCD_ST7735 driver
taylorza 0:2ee0812e2615 39 * @param backlightPin pin used to control the backlight
taylorza 0:2ee0812e2615 40 * @param resetPin pin used to reset the display controller
taylorza 0:2ee0812e2615 41 * @param dsPin pin used to put the display controller into data mode
taylorza 0:2ee0812e2615 42 * @param mosiPin SPI channel MOSI pin
taylorza 0:2ee0812e2615 43 * @param misoPin SPI channel MISO pin
taylorza 0:2ee0812e2615 44 * @param clkPin SPI channel clock pin
taylorza 0:2ee0812e2615 45 * @param csPin SPI chip select pin
taylorza 0:2ee0812e2615 46 */
taylorza 0:2ee0812e2615 47 LCD_ST7735(
taylorza 0:2ee0812e2615 48 PinName backlightPin,
taylorza 0:2ee0812e2615 49 PinName resetPin,
taylorza 0:2ee0812e2615 50 PinName dsPin,
taylorza 0:2ee0812e2615 51 PinName mosiPin,
taylorza 0:2ee0812e2615 52 PinName misoPin,
taylorza 0:2ee0812e2615 53 PinName clkPin,
taylorza 0:2ee0812e2615 54 PinName csPin,
taylorza 0:2ee0812e2615 55 PanelColorFilter colorFilter = BGR
taylorza 0:2ee0812e2615 56 );
taylorza 0:2ee0812e2615 57
taylorza 0:2ee0812e2615 58 /** Set the orientation of the display
taylorza 0:2ee0812e2615 59 * @param orientation Orientation of the display.
taylorza 0:2ee0812e2615 60 * @param flip Flips the display direction
taylorza 0:2ee0812e2615 61 */
taylorza 0:2ee0812e2615 62 void setOrientation(Orientation orientation, bool flip);
taylorza 0:2ee0812e2615 63
taylorza 0:2ee0812e2615 64 /** Get the width of the display given the current orientation */
taylorza 0:2ee0812e2615 65 int getWidth();
taylorza 0:2ee0812e2615 66
taylorza 0:2ee0812e2615 67 /** Get the height of the display given the current orientation */
taylorza 0:2ee0812e2615 68 int getHeight();
taylorza 0:2ee0812e2615 69
taylorza 0:2ee0812e2615 70 /** Control the display's backlight
taylorza 0:2ee0812e2615 71 * @param state true to turn the backlight on, false to turn it off
taylorza 0:2ee0812e2615 72 */
taylorza 0:2ee0812e2615 73 void setBacklight(bool state);
taylorza 0:2ee0812e2615 74
taylorza 0:2ee0812e2615 75 /** Clear the screen
taylorza 0:2ee0812e2615 76 * @param color The color used to clear the screen. Defaults to black if not passed.
taylorza 0:2ee0812e2615 77 */
taylorza 0:2ee0812e2615 78 void clearScreen(uint16_t color = 0x0000);
taylorza 0:2ee0812e2615 79
taylorza 0:2ee0812e2615 80 /** Set a pixel on the display to the specified color
taylorza 0:2ee0812e2615 81 * @param x The X coordinate of the pixel (0..127)
taylorza 0:2ee0812e2615 82 * @param y The Y coordinate of the pixel (0..159)
taylorza 0:2ee0812e2615 83 * @param color Color to set the pixel to.
taylorza 0:2ee0812e2615 84 */
taylorza 0:2ee0812e2615 85 void setPixel(int x, int y, uint16_t color);
taylorza 0:2ee0812e2615 86
taylorza 0:2ee0812e2615 87 /** Draw a line on the display
taylorza 0:2ee0812e2615 88 * @param x1 The X coordinate of the starting point on the line
taylorza 0:2ee0812e2615 89 * @param y1 The Y coordinate of the starting point on the line
taylorza 0:2ee0812e2615 90 * @param x2 The X coordinate of the end point on the line
taylorza 0:2ee0812e2615 91 * @param y2 The Y coordinate of the end point on the line
taylorza 0:2ee0812e2615 92 * @param color The color used to draw the pixel
taylorza 0:2ee0812e2615 93 */
taylorza 0:2ee0812e2615 94 void drawLine(int x1, int y1, int x2, int y2, uint16_t color);
taylorza 0:2ee0812e2615 95
taylorza 0:2ee0812e2615 96 /** Draw a rectangle on the display
taylorza 0:2ee0812e2615 97 * @param x1 The X coordinate of the upper left corner
taylorza 0:2ee0812e2615 98 * @param y1 The Y coordinate of the upper left corner
taylorza 0:2ee0812e2615 99 * @param x2 The X coordinate of the lower right corner
taylorza 0:2ee0812e2615 100 * @param y2 The Y coordinate of the lower right corner
taylorza 0:2ee0812e2615 101 * @param color The color used to draw the rectangle
taylorza 0:2ee0812e2615 102 */
taylorza 0:2ee0812e2615 103 void drawRect(int x1, int y1, int x2, int y2, uint16_t color);
taylorza 0:2ee0812e2615 104
taylorza 0:2ee0812e2615 105 /** Draw a circle on the display
taylorza 0:2ee0812e2615 106 * @param x The X coordinate of the center of the circle
taylorza 0:2ee0812e2615 107 * @param y The Y coordinate of the center of the circle
taylorza 0:2ee0812e2615 108 * @param r The radius of the circle
taylorza 0:2ee0812e2615 109 * @param color The color used to draw the circle
taylorza 0:2ee0812e2615 110 */
taylorza 0:2ee0812e2615 111 void drawCircle(int x, int y, int r, uint16_t color);
taylorza 0:2ee0812e2615 112
taylorza 0:2ee0812e2615 113 /** Draw an ellipse on the display
taylorza 0:2ee0812e2615 114 * @param x The X coordinate of the center of the ellipse
taylorza 0:2ee0812e2615 115 * @param y The Y coordinate of the center of the ellipse
taylorza 0:2ee0812e2615 116 * @param rx The X radius of the ellipse
taylorza 0:2ee0812e2615 117 * @param ry The X radius of the ellipse
taylorza 0:2ee0812e2615 118 * @param color The color used to draw the ellipse
taylorza 0:2ee0812e2615 119 */
taylorza 0:2ee0812e2615 120 void drawEllipse(int x, int y, int rx, int ry, uint16_t color);
taylorza 0:2ee0812e2615 121
taylorza 0:2ee0812e2615 122 /** Draw a filled rectangle on the display
taylorza 0:2ee0812e2615 123 * @param x1 The X coordinate of the upper left corner
taylorza 0:2ee0812e2615 124 * @param y1 The Y coordinate of the upper left corner
taylorza 0:2ee0812e2615 125 * @param x2 The X coordinate of the lower right corner
taylorza 0:2ee0812e2615 126 * @param y2 The Y coordinate of the lower right corner
taylorza 0:2ee0812e2615 127 * @param fillColor The color used to fill the rectangle
taylorza 0:2ee0812e2615 128 */
taylorza 0:2ee0812e2615 129 void fillRect(int x1, int y1, int x2, int y2, uint16_t fillColor);
taylorza 0:2ee0812e2615 130
taylorza 0:2ee0812e2615 131 /** Draw a filled rectangle on the display
taylorza 0:2ee0812e2615 132 * @param x1 The X coordinate of the upper left corner
taylorza 0:2ee0812e2615 133 * @param y1 The Y coordinate of the upper left corner
taylorza 0:2ee0812e2615 134 * @param x2 The X coordinate of the lower right corner
taylorza 0:2ee0812e2615 135 * @param y2 The Y coordinate of the lower right corner
taylorza 0:2ee0812e2615 136 * @param borderColor The color used to draw the rectangle frame
taylorza 0:2ee0812e2615 137 * @param fillColor The color used to fill the rectangle
taylorza 0:2ee0812e2615 138 */
taylorza 0:2ee0812e2615 139 void fillRect(int x1, int y1, int x2, int y2, uint16_t borderColor, uint16_t fillColor);
taylorza 0:2ee0812e2615 140
taylorza 0:2ee0812e2615 141 /** Draw a filled circle on the display
taylorza 0:2ee0812e2615 142 * @param x The X coordinate of the center of the circle
taylorza 0:2ee0812e2615 143 * @param y The Y coordinate of the center of the circle
taylorza 0:2ee0812e2615 144 * @param borderColor The color used to draw the circumference of the circle
taylorza 0:2ee0812e2615 145 * @param fillColor The color used to fill the circle
taylorza 0:2ee0812e2615 146 */
taylorza 0:2ee0812e2615 147 void fillCircle(int x, int y, int r, uint16_t borderColor, uint16_t fillColor);
taylorza 0:2ee0812e2615 148
taylorza 0:2ee0812e2615 149 /** Draw a filled ellipse on the display
taylorza 0:2ee0812e2615 150 * @param x The X coordinate of the center of the ellipse
taylorza 0:2ee0812e2615 151 * @param y The Y coordinate of the center of the ellipse
taylorza 0:2ee0812e2615 152 * @param rx The X radius of the ellipse
taylorza 0:2ee0812e2615 153 * @param ry The X radius of the ellipse
taylorza 0:2ee0812e2615 154 * @param borderColor The color used to draw the circumference of the circle
taylorza 0:2ee0812e2615 155 * @param fillColor The color used to fill the circle
taylorza 0:2ee0812e2615 156 */
taylorza 0:2ee0812e2615 157 void fillEllipse(int x, int y, int rx, int ry, uint16_t borderColor, uint16_t fillColor);
taylorza 0:2ee0812e2615 158
taylorza 0:2ee0812e2615 159 /** Draw a bitmap on the screen
taylorza 0:2ee0812e2615 160 * @param x The X coordinate location to draw the bitmap.
taylorza 0:2ee0812e2615 161 * @param y The Y coordinate location to draw the bitmap.
taylorza 0:2ee0812e2615 162 * @param pbmp Pointer to the bitmap.
taylorza 0:2ee0812e2615 163 * @note The bitmap is an single dimensional uint8_t (unsigned short) array.
taylorza 0:2ee0812e2615 164 * The first to elements of the array indicate the width and height of the bitmap repectively.
taylorza 0:2ee0812e2615 165 * The rest of the entries int the array make up the pixel data for the array.
taylorza 0:2ee0812e2615 166 */
taylorza 0:2ee0812e2615 167 void drawBitmap(int x, int y, const uint16_t *pbmp);
taylorza 0:2ee0812e2615 168
taylorza 0:2ee0812e2615 169 /** Extracts a portion of a bitmap and draws it on the screen
taylorza 0:2ee0812e2615 170 * @param x The X coordinate location to draw the bitmap.
taylorza 0:2ee0812e2615 171 * @param y The Y coordinate location to draw the bitmap.
taylorza 0:2ee0812e2615 172 * @param pbmp Pointer to the bitmap.
taylorza 0:2ee0812e2615 173 * @param srcX X offset into the source bitmap of the portion to extract
taylorza 0:2ee0812e2615 174 * @param srcY Y offset into the source bitmap of the portion to extract
taylorza 0:2ee0812e2615 175 * @param srcWidth Width of the bitmap portion to draw
taylorza 0:2ee0812e2615 176 * @param srcHeight Height of the bitmap portion to draw
taylorza 0:2ee0812e2615 177 * @note The bitmap is an single dimensional uint8_t (unsigned short) array.
taylorza 0:2ee0812e2615 178 * The first to elements of the array indicate the width and height of the bitmap repectively.
taylorza 0:2ee0812e2615 179 * The rest of the entries int the array make up the pixel data for the array.
taylorza 0:2ee0812e2615 180 */
taylorza 0:2ee0812e2615 181 void drawBitmap(int x, int y, const uint16_t *pbmp, int srcX, int srcY, int srcWidth, int srcHeight);
taylorza 0:2ee0812e2615 182
taylorza 0:2ee0812e2615 183 /** Extracts a portion of a bitmap and draws it on the screen
taylorza 0:2ee0812e2615 184 * @param x The X coordinate location to draw the bitmap.
taylorza 0:2ee0812e2615 185 * @param y The Y coordinate location to draw the bitmap.
taylorza 0:2ee0812e2615 186 * @param pbmp Pointer to the bitmap.
taylorza 0:2ee0812e2615 187 * @param srcX X offset into the source bitmap of the portion to extract
taylorza 0:2ee0812e2615 188 * @param srcY Y offset into the source bitmap of the portion to extract
taylorza 0:2ee0812e2615 189 * @param srcWidth Width of the bitmap portion to draw
taylorza 0:2ee0812e2615 190 * @param srcHeight Height of the bitmap portion to draw
taylorza 0:2ee0812e2615 191 * @note The bitmap is an single dimensional uint8_t (unsigned short) array.
taylorza 0:2ee0812e2615 192 * The first to elements of the array indicate the width and height of the bitmap repectively.
taylorza 0:2ee0812e2615 193 * The rest of the entries int the array make up the pixel data for the array.
taylorza 0:2ee0812e2615 194 */
taylorza 0:2ee0812e2615 195 void drawBitmap(int x, int y, Bitmap4bpp &bmp, int srcX, int srcY, int srcWidth, int srcHeight);
taylorza 0:2ee0812e2615 196
taylorza 0:2ee0812e2615 197 /** Extracts a portion of a bitmap and draws it on the screen
taylorza 0:2ee0812e2615 198 * @param x The X coordinate location to draw the bitmap.
taylorza 0:2ee0812e2615 199 * @param y The Y coordinate location to draw the bitmap.
taylorza 0:2ee0812e2615 200 * @param pbmp Pointer to the bitmap.
taylorza 0:2ee0812e2615 201 * @param srcX X offset into the source bitmap of the portion to extract
taylorza 0:2ee0812e2615 202 * @param srcY Y offset into the source bitmap of the portion to extract
taylorza 0:2ee0812e2615 203 * @param srcWidth Width of the bitmap portion to draw
taylorza 0:2ee0812e2615 204 * @param srcHeight Height of the bitmap portion to draw
taylorza 0:2ee0812e2615 205 * @note The bitmap is an single dimensional uint8_t (unsigned short) array.
taylorza 0:2ee0812e2615 206 * The first to elements of the array indicate the width and height of the bitmap repectively.
taylorza 0:2ee0812e2615 207 * The rest of the entries int the array make up the pixel data for the array.
taylorza 0:2ee0812e2615 208 */
taylorza 0:2ee0812e2615 209 void drawGlyph(int x, int y, uint16_t foregroundColor, uint16_t backgroundColor, const uint8_t *pbmp, int srcX, int srcY, int srcWidth, int srcHeight, bool flipHorizontal);
taylorza 0:2ee0812e2615 210
taylorza 0:2ee0812e2615 211 /** Set the foreground color used to render text
taylorza 0:2ee0812e2615 212 * @param color Color used when drawing text to the display
taylorza 0:2ee0812e2615 213 * @note The color can be changed multiple times to render text in various colors on the display
taylorza 0:2ee0812e2615 214 */
taylorza 0:2ee0812e2615 215 void setForegroundColor(uint16_t color);
taylorza 0:2ee0812e2615 216
taylorza 0:2ee0812e2615 217 /** Set the background color used to render text
taylorza 0:2ee0812e2615 218 * @param color Color used when drawing background portions of the text
taylorza 0:2ee0812e2615 219 * @note The color can be changed multiple times to render text with various background colors on the display
taylorza 0:2ee0812e2615 220 */
taylorza 0:2ee0812e2615 221 void setBackgroundColor(uint16_t color);
taylorza 0:2ee0812e2615 222
taylorza 0:2ee0812e2615 223 /** Draw a string to the screen using the currently active foreground and background colors
taylorza 0:2ee0812e2615 224 * @param pFont Pointer to the font used to render the string to the display
taylorza 0:2ee0812e2615 225 * @param x The X coordinate location to draw the string.
taylorza 0:2ee0812e2615 226 * @param y The Y coordinate location to draw the string.
taylorza 0:2ee0812e2615 227 * @param pString ASCIIZ string to draw to the display.
taylorza 0:2ee0812e2615 228 * @note The font is currently limited to an 8x8 font. See the font_IBM.h file for an example font.
taylorza 0:2ee0812e2615 229 */
taylorza 0:2ee0812e2615 230 void drawString(const uint8_t *pFont, int x, int y, const char *pString);
taylorza 0:2ee0812e2615 231
taylorza 0:2ee0812e2615 232 /** Select the device on the SPI bus.
taylorza 0:2ee0812e2615 233 selectDevice needs to be called before accessing the screen if there are multiple devices on the SPI bus.
taylorza 0:2ee0812e2615 234 */
taylorza 0:2ee0812e2615 235 void selectDevice();
taylorza 0:2ee0812e2615 236
taylorza 0:2ee0812e2615 237 private:
taylorza 0:2ee0812e2615 238 void drawVertLine(int x1, int y1, int y2, uint16_t color);
taylorza 0:2ee0812e2615 239 void drawHorizLine(int x1, int y1, int x2, uint16_t color);
taylorza 0:2ee0812e2615 240 void drawChar(const uint8_t *pFont, int x, int y, char c);
taylorza 0:2ee0812e2615 241
taylorza 0:2ee0812e2615 242 private:
taylorza 0:2ee0812e2615 243 void swap(int &a, int &b);
taylorza 0:2ee0812e2615 244
taylorza 0:2ee0812e2615 245 private:
taylorza 0:2ee0812e2615 246 void initDisplay();
taylorza 0:2ee0812e2615 247 void reset();
taylorza 0:2ee0812e2615 248
taylorza 0:2ee0812e2615 249 void writeCommand(uint8_t cmd);
taylorza 0:2ee0812e2615 250 void write(uint8_t cmd, uint8_t data[], int dataLen);
taylorza 0:2ee0812e2615 251 void write(uint8_t cmd, uint16_t data);
taylorza 0:2ee0812e2615 252
taylorza 0:2ee0812e2615 253 void beginBatchCommand(uint8_t cmd);
taylorza 0:2ee0812e2615 254 void writeBatchData(uint8_t data);
taylorza 0:2ee0812e2615 255 void writeBatchData(uint8_t dataHigh, uint8_t dataLow);
taylorza 0:2ee0812e2615 256 void writeBatchData(uint16_t data);
taylorza 0:2ee0812e2615 257 void endBatchCommand();
taylorza 0:2ee0812e2615 258
taylorza 0:2ee0812e2615 259 void clip(int x, int y, int w, int h);
taylorza 0:2ee0812e2615 260 void clipRect(int x1, int y1, int x2, int y2);
taylorza 0:2ee0812e2615 261
taylorza 0:2ee0812e2615 262 private:
taylorza 0:2ee0812e2615 263 int _width;
taylorza 0:2ee0812e2615 264 int _height;
taylorza 0:2ee0812e2615 265 Orientation _orientation;
taylorza 0:2ee0812e2615 266 PanelColorFilter _colorFilter;
taylorza 0:2ee0812e2615 267 bool _flip;
taylorza 0:2ee0812e2615 268 uint8_t _foregroundColorHigh;
taylorza 0:2ee0812e2615 269 uint8_t _foregroundColorLow;
taylorza 0:2ee0812e2615 270 uint8_t _backgroundColorHigh;
taylorza 0:2ee0812e2615 271 uint8_t _backgroundColorLow;
taylorza 0:2ee0812e2615 272
taylorza 0:2ee0812e2615 273 private:
taylorza 0:2ee0812e2615 274 class LCDSPI : public SPI
taylorza 0:2ee0812e2615 275 {
taylorza 0:2ee0812e2615 276 public:
taylorza 0:2ee0812e2615 277 LCDSPI(PinName mosi, PinName miso, PinName sclk) :
taylorza 0:2ee0812e2615 278 SPI(mosi, miso, sclk)
taylorza 0:2ee0812e2615 279 {
taylorza 0:2ee0812e2615 280 }
taylorza 0:2ee0812e2615 281
taylorza 0:2ee0812e2615 282 void prepareFastSPI()
taylorza 0:2ee0812e2615 283 {
taylorza 0:2ee0812e2615 284 #ifdef TARGET_LPC11U24
taylorza 0:2ee0812e2615 285 aquire();
taylorza 0:2ee0812e2615 286 #endif
taylorza 0:2ee0812e2615 287 }
taylorza 0:2ee0812e2615 288
taylorza 0:2ee0812e2615 289 inline void waitWhileBusy()
taylorza 0:2ee0812e2615 290 {
taylorza 0:2ee0812e2615 291 #ifdef TARGET_LPC11U24
taylorza 0:2ee0812e2615 292 while (((_spi.spi->SR) & 0x10) != 0);
taylorza 0:2ee0812e2615 293 #endif
taylorza 0:2ee0812e2615 294 }
taylorza 0:2ee0812e2615 295
taylorza 0:2ee0812e2615 296 inline void fastWrite(uint8_t data)
taylorza 0:2ee0812e2615 297 {
taylorza 0:2ee0812e2615 298 #ifdef TARGET_LPC11U24
taylorza 0:2ee0812e2615 299 while (((_spi.spi->SR) & 0x01) == 0);
taylorza 0:2ee0812e2615 300 _spi.spi->DR = data;
taylorza 0:2ee0812e2615 301 #else
taylorza 0:2ee0812e2615 302 SPI::write(data);
taylorza 0:2ee0812e2615 303 #endif
taylorza 0:2ee0812e2615 304 }
taylorza 0:2ee0812e2615 305
taylorza 0:2ee0812e2615 306 void clearRx()
taylorza 0:2ee0812e2615 307 {
taylorza 0:2ee0812e2615 308 #ifdef TARGET_LPC11U24
taylorza 0:2ee0812e2615 309 while (((_spi.spi->SR) & 0x14) != 0)
taylorza 0:2ee0812e2615 310 {
taylorza 0:2ee0812e2615 311 while (((_spi.spi->SR) & 0x04) == 0);
taylorza 0:2ee0812e2615 312 int data = _spi.spi->DR;
taylorza 0:2ee0812e2615 313 }
taylorza 0:2ee0812e2615 314 #endif
taylorza 0:2ee0812e2615 315 }
taylorza 0:2ee0812e2615 316 };
taylorza 0:2ee0812e2615 317
taylorza 0:2ee0812e2615 318 private:
taylorza 0:2ee0812e2615 319 DigitalOut _backlight;
taylorza 0:2ee0812e2615 320 DigitalOut _reset;
taylorza 0:2ee0812e2615 321 DigitalOut _ds;
taylorza 0:2ee0812e2615 322 DigitalOut _cs;
taylorza 0:2ee0812e2615 323 LCDSPI _spi;
taylorza 0:2ee0812e2615 324
taylorza 0:2ee0812e2615 325 uint16_t *_palette;
taylorza 0:2ee0812e2615 326
taylorza 0:2ee0812e2615 327 static const uint16_t DefaultPalette[];
taylorza 0:2ee0812e2615 328 private:
taylorza 0:2ee0812e2615 329 static const uint8_t CMD_SLPOUT = 0x11;
taylorza 0:2ee0812e2615 330 static const uint8_t CMD_DISPON = 0x29;
taylorza 0:2ee0812e2615 331 static const uint8_t CMD_CASET = 0x2a;
taylorza 0:2ee0812e2615 332 static const uint8_t CMD_RASET = 0x2b;
taylorza 0:2ee0812e2615 333 static const uint8_t CMD_RAMWR = 0x2c;
taylorza 0:2ee0812e2615 334
taylorza 0:2ee0812e2615 335 static const uint8_t CMD_MADCTL = 0x36;
taylorza 0:2ee0812e2615 336 static const uint8_t CMD_COLMOD = 0x3a;
taylorza 0:2ee0812e2615 337
taylorza 0:2ee0812e2615 338 static const uint8_t CMD_FRMCTR1 = 0xb1;
taylorza 0:2ee0812e2615 339 static const uint8_t CMD_FRMCTR2 = 0xb2;
taylorza 0:2ee0812e2615 340 static const uint8_t CMD_FRMCTR3 = 0xb3;
taylorza 0:2ee0812e2615 341 static const uint8_t CMD_INVCTR = 0xb4;
taylorza 0:2ee0812e2615 342
taylorza 0:2ee0812e2615 343 static const uint8_t CMD_PWCTR1 = 0xc0;
taylorza 0:2ee0812e2615 344 static const uint8_t CMD_PWCTR2 = 0xc1;
taylorza 0:2ee0812e2615 345 static const uint8_t CMD_PWCTR3 = 0xc2;
taylorza 0:2ee0812e2615 346 static const uint8_t CMD_PWCTR4 = 0xc3;
taylorza 0:2ee0812e2615 347 static const uint8_t CMD_PWCTR5 = 0xc4;
taylorza 0:2ee0812e2615 348 static const uint8_t CMD_VMCTR1 = 0xc5;
taylorza 0:2ee0812e2615 349
taylorza 0:2ee0812e2615 350 static const uint8_t CMD_GAMCTRP1 = 0xe0;
taylorza 0:2ee0812e2615 351 static const uint8_t CMD_GAMCTRN1 = 0xe1;
taylorza 0:2ee0812e2615 352
taylorza 0:2ee0812e2615 353 static const uint8_t CMD_EXTCTRL = 0xf0;
taylorza 0:2ee0812e2615 354 };
taylorza 0:2ee0812e2615 355
taylorza 0:2ee0812e2615 356 #endif // __LCD_ST7735__