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