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