Retro Invaders a space invaders clone by Chris Favreau. Written for the RetroMbuino development board from outrageouscircuits.com for the game programming contest.

Dependencies:   mbed

This is a space invaders clone written for the Retro Mbuino from outrageous circuits.

Development board: http://www.outrageouscircuits.com/shop/product/15 ).

The game itself is basic space invaders. Shoot them before they get to the bottom of the screen. It has a UFO saucer which you can shoot for extra points. You get 4 shields and each shield can be hit up to 4 times before it is gone. Hmm... as each level increases the speed of the invaders shots goes up. The invaders only speed up when there is less of them. You complete the level when you shoot all the invaders. The game ends when a) you run out of lives (you start with 3) or the invaders get to the bottom.

The LEDs turned out to be a pretty cool addition to the game. I wrote a class that blinks them and turns them on for a specified amount of time. They add a nice extra to the game. I use them on the intro screen and when the UFO is present.

The sound turned out to be really difficult for a few reasons. The biggest was that I had never written a sound engine before. The interrupt service routine working off the timer was the easier part. I also had a lot of trouble because there is no filter to filter out the PWM frequency to the speaker... so I had to run the PWM frequency way up there 30 kHz.

The graphics turned out to be a bit of a bear too. Thanks to Chris Taylor for his really great LCD API. I picked up a couple of frames per second from that. I had modified the DisplayN18 class for blitting a single line buffer to the LCD panel however his is a little faster for some reason? I used a different approach to doing the graphics (as I have very little experience with anything other than double buffered displays). I have a tile map and a list of sprites. Each tile/sprite is 1 bit 8x8. They could be bigger. I ran out of time. That much is not special. What is different from what I can tell is that I use a 1 line buffer that is 160 shorts long. The render function first adds the tile map data into the line buffer first. Then the sprites are added over the existing data. You can have a great deal of different sprites and maps going to the screen and just have to rewrite the LCD memory once per frame. After each line is composited, the line is then drawn to the LCD. Kind of like an Atari 2600. Each sprite/tile has a foreground and background color and can be different from the other tiles/sprites. There is one color reserved for Transparency.

There are 16 colors to choose from. I chose a palette based on the Macintosh OS 4.1 palette I found on WikiPedia. It is a very nice mix of colors.

I found a sprite editor called SpriteX ( https://code.google.com/p/spritesx-ed/ )... it works nicely except that the 16x16 sprites are in a weird format. Time limited me to 8x8 sprites. Oh well.

I used nokring to make the music. It makes RTTTL formatted ring tones which my sound api can play. Here is a useful site that has lots of arcade/video game ring tones with a link to nokring in the utilities page. http://arcadetones.emuunlim.com/files.htm

Other than all that stuff I used state machines to do most of the game logic. Please excuse the horrible coding as I tried to comment a lot of it however it is not very nice to look at. Lots of long functions...

Committer:
cfavreau
Date:
Tue Mar 03 04:26:01 2015 +0000
Revision:
0:c79e1f29f029
Retro Invaders by Chris Favreau for the RetroMbuino Platform - outrageouscircuits.com game programming contest.

Who changed what in which revision?

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