Added SPI burst mode to spi 8 bit.

Dependents:   Bicycl_Computer_NUCLEO-F411RE Bicycl_Computer_NUCLEO-L476RG

Fork of UniGraphic by GraphicsDisplay

Added SPI burst mode to this graphics driver. If whoever wants this rolled in to repository let me know. I replaced _spi.write(); with fastWrite(); and clearRX();

SPI8.cpp

// need to re-create SPI firmware to access SPI handle
static SPI_HandleTypeDef SpiHandle;

void SPI8::fastWrite(int data) {
    
      SpiHandle.Instance = SPI1;
    // Check if data is transmitted
    while ((SpiHandle.Instance->SR & SPI_SR_TXE) == 0);
    SpiHandle.Instance->DR = data;
}
    
void SPI8::clearRX( void ) {
        SpiHandle.Instance = SPI1;
    //Check if the RX buffer is busy
    //While busy, keep checking
    while (SpiHandle.Instance->SR & SPI_SR_BSY){   
        // Check RX buffer readable
        while ((SpiHandle.Instance->SR & SPI_SR_RXNE) == 0);
        int dummy = SpiHandle.Instance->DR;
    }
}      
Committer:
trevieze
Date:
Fri Aug 04 19:47:21 2017 +0000
Revision:
36:0ced7cf0ec8c
Parent:
11:b842b8e332cb
Child:
20:14daa48ffd4c
Added Gimp Graphic Display Routine for Compass

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 2:713844a55c4e 1 #ifndef MBED_TFT_H
Geremia 2:713844a55c4e 2 #define MBED_TFT_H
Geremia 2:713844a55c4e 3
Geremia 2:713844a55c4e 4 #include "GraphicsDisplay.h"
Geremia 2:713844a55c4e 5 #include "PAR8.h"
Geremia 4:12ba0ecc2c1f 6 #include "PAR16.h"
Geremia 2:713844a55c4e 7 #include "SPI8.h"
Geremia 2:713844a55c4e 8 #include "SPI16.h"
Geremia 2:713844a55c4e 9 #include "Protocols.h"
Geremia 2:713844a55c4e 10
Geremia 2:713844a55c4e 11
Geremia 6:8356d48a07db 12 /** A common base class for color TFT Display
Geremia 2:713844a55c4e 13 */
Geremia 2:713844a55c4e 14 class TFT : public GraphicsDisplay
Geremia 2:713844a55c4e 15 {
Geremia 2:713844a55c4e 16
Geremia 2:713844a55c4e 17 public:
Geremia 2:713844a55c4e 18
Geremia 2:713844a55c4e 19 /** Create a monochrome LCD Parallel interface
Geremia 2:713844a55c4e 20 * @param name The name used by the parent class to access the interface
Geremia 2:713844a55c4e 21 */
Geremia 2:713844a55c4e 22 TFT(proto_t displayproto,PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const char* name);
Geremia 2:713844a55c4e 23
Geremia 2:713844a55c4e 24 /** Create a monochrome LCD SPI interface
Geremia 2:713844a55c4e 25 * @param name The name used by the parent class to access the interface
Geremia 2:713844a55c4e 26 */
Geremia 2:713844a55c4e 27 TFT(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const char* name);
Geremia 2:713844a55c4e 28
Geremia 2:713844a55c4e 29 /////// functions that come for free, but can be overwritten///////////////////////////////////////////////////
Geremia 2:713844a55c4e 30 /////// ----------------------------------------------------///////////////////////////////////////////////////
Geremia 2:713844a55c4e 31
Geremia 2:713844a55c4e 32 /** Draw a pixel in the specified color.
Geremia 2:713844a55c4e 33 * @param x is the horizontal offset to this pixel.
Geremia 2:713844a55c4e 34 * @param y is the vertical offset to this pixel.
Geremia 2:713844a55c4e 35 * @param color defines the color for the pixel.
Geremia 2:713844a55c4e 36 */
Geremia 2:713844a55c4e 37 virtual void pixel(int x, int y, unsigned short color);
Geremia 2:713844a55c4e 38
Geremia 2:713844a55c4e 39 /** Set the window, which controls where items are written to the screen.
Geremia 2:713844a55c4e 40 * When something hits the window width, it wraps back to the left side
Geremia 2:713844a55c4e 41 * and down a row. If the initial write is outside the window, it will
Geremia 2:713844a55c4e 42 * be captured into the window when it crosses a boundary.
Geremia 2:713844a55c4e 43 * @param x is the left edge in pixels.
Geremia 2:713844a55c4e 44 * @param y is the top edge in pixels.
Geremia 2:713844a55c4e 45 * @param w is the window width in pixels.
Geremia 2:713844a55c4e 46 * @param h is the window height in pixels.
Geremia 2:713844a55c4e 47 */
Geremia 2:713844a55c4e 48 virtual void window(int x, int y, int w, int h);
Geremia 5:b222a9461d6b 49
Geremia 8:26757296c79d 50 /** Read pixel color at location
Geremia 5:b222a9461d6b 51 * @param x is the horizontal offset to this pixel.
Geremia 5:b222a9461d6b 52 * @param y is the vertical offset to this pixel.
Geremia 8:26757296c79d 53 * @returns 16bit color.
Geremia 5:b222a9461d6b 54 */
Geremia 5:b222a9461d6b 55 virtual unsigned short pixelread(int x, int y);
Geremia 5:b222a9461d6b 56
Geremia 5:b222a9461d6b 57 /** Set the window from which gram is read from. Autoincrements row/column
Geremia 5:b222a9461d6b 58 * @param x is the left edge in pixels.
Geremia 5:b222a9461d6b 59 * @param y is the top edge in pixels.
Geremia 5:b222a9461d6b 60 * @param w is the window width in pixels.
Geremia 5:b222a9461d6b 61 * @param h is the window height in pixels.
Geremia 5:b222a9461d6b 62 */
Geremia 5:b222a9461d6b 63 virtual void window4read(int x, int y, int w, int h);
Geremia 2:713844a55c4e 64
Geremia 2:713844a55c4e 65 /** Push a single pixel into the window and increment position.
Geremia 2:713844a55c4e 66 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 67 * @param color is the pixel color.
Geremia 2:713844a55c4e 68 */
Geremia 2:713844a55c4e 69 virtual void window_pushpixel(unsigned short color);
Geremia 2:713844a55c4e 70
Geremia 2:713844a55c4e 71 /** Push some pixels of the same color into the window and increment position.
Geremia 2:713844a55c4e 72 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 73 * @param color is the pixel color.
Geremia 2:713844a55c4e 74 * @param count: how many
Geremia 2:713844a55c4e 75 */
Geremia 2:713844a55c4e 76 virtual void window_pushpixel(unsigned short color, unsigned int count);
Geremia 2:713844a55c4e 77
Geremia 2:713844a55c4e 78 /** Push array of pixel colors into the window and increment position.
Geremia 2:713844a55c4e 79 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 80 * @param color is the pixel color.
Geremia 2:713844a55c4e 81 */
Geremia 2:713844a55c4e 82 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght);
Geremia 2:713844a55c4e 83
Geremia 2:713844a55c4e 84 /** Framebuffer is not used for TFT
Geremia 2:713844a55c4e 85 */
Geremia 2:713844a55c4e 86 virtual void copy_to_lcd(){ };
Geremia 2:713844a55c4e 87
Geremia 7:bb0383b91104 88 /** display inverted colors
Geremia 2:713844a55c4e 89 *
Geremia 2:713844a55c4e 90 * @param o = 0 normal, 1 invert
Geremia 2:713844a55c4e 91 */
Geremia 2:713844a55c4e 92 void invert(unsigned char o);
Geremia 2:713844a55c4e 93
Geremia 2:713844a55c4e 94 /** clear the entire screen
Geremia 2:713844a55c4e 95 * The inherited one sets windomax then fill with background color
Geremia 2:713844a55c4e 96 * We override it to speedup
Geremia 2:713844a55c4e 97 */
Geremia 2:713844a55c4e 98 virtual void cls();
Geremia 2:713844a55c4e 99
Geremia 2:713844a55c4e 100 /** Set the orientation of the screen
Geremia 2:713844a55c4e 101 * x,y: 0,0 is always top left
Geremia 2:713844a55c4e 102 *
Geremia 2:713844a55c4e 103 * @param o direction to use the screen (0-3)
Geremia 2:713844a55c4e 104 * 0 = default 0° portrait view
Geremia 2:713844a55c4e 105 * 1 = +90° landscape view
Geremia 2:713844a55c4e 106 * 2 = +180° portrait view
Geremia 2:713844a55c4e 107 * 3 = -90° landscape view
Geremia 2:713844a55c4e 108 *
Geremia 2:713844a55c4e 109 */
Geremia 2:713844a55c4e 110 virtual void set_orientation(int o);
Geremia 2:713844a55c4e 111
Geremia 2:713844a55c4e 112 /** Set ChipSelect high or low
Geremia 10:668cf78ff93a 113 * @param enable true/false
Geremia 2:713844a55c4e 114 */
Geremia 2:713844a55c4e 115 virtual void BusEnable(bool enable);
Geremia 2:713844a55c4e 116
Geremia 10:668cf78ff93a 117 /** Enable fast window (default disabled)
Geremia 10:668cf78ff93a 118 * used to speedup functions that plots single pixels, like circle, oblique lines or just sparse pixels
Geremia 10:668cf78ff93a 119 * @param enable true/false
Geremia 10:668cf78ff93a 120 * @note most but not all controllers support this, even if datasheet tells they should
Geremia 10:668cf78ff93a 121 */
Geremia 10:668cf78ff93a 122 void FastWindow(bool enable);
Geremia 10:668cf78ff93a 123
Geremia 7:bb0383b91104 124 /** Set scroll area boundaries
Geremia 7:bb0383b91104 125 * scroll is done in hw but only on the native vertical axis
Geremia 7:bb0383b91104 126 * TFTs are mainly native protrait view, so horizontal scroll if rotated in landscape view
Geremia 7:bb0383b91104 127 *
Geremia 7:bb0383b91104 128 * @param startY boundary offset from top (or left if rotated), 0 for fullscreen scroll
Geremia 7:bb0383b91104 129 * @param areasize size of the scroll area, 480 for fullscreen scroll of a 320x480 display
Geremia 7:bb0383b91104 130 */
Geremia 7:bb0383b91104 131 void setscrollarea (int startY, int areasize);
Geremia 7:bb0383b91104 132
Geremia 7:bb0383b91104 133 /** Scroll up(or left) the scrollarea
Geremia 7:bb0383b91104 134 *
Geremia 7:bb0383b91104 135 * @param lines number of lines to scroll, 1= scrollup 1, areasize-1= scrolldown 1
Geremia 7:bb0383b91104 136 */
Geremia 7:bb0383b91104 137 void scroll (int lines);
Geremia 7:bb0383b91104 138
Geremia 7:bb0383b91104 139 /** Reset the scrollarea and display un-scrolled screen
Geremia 7:bb0383b91104 140 *
Geremia 7:bb0383b91104 141 */
Geremia 7:bb0383b91104 142 void scrollreset();
Geremia 7:bb0383b91104 143
Geremia 7:bb0383b91104 144 /** get display X size in pixels (native, orientation independent)
Geremia 7:bb0383b91104 145 * @returns X size in pixels
Geremia 7:bb0383b91104 146 */
Geremia 7:bb0383b91104 147 int sizeX();
Geremia 7:bb0383b91104 148
Geremia 7:bb0383b91104 149 /** get display X size in pixels (native, orientation independent)
Geremia 7:bb0383b91104 150 * @returns screen height in pixels.
Geremia 7:bb0383b91104 151 */
Geremia 7:bb0383b91104 152 int sizeY();
Geremia 7:bb0383b91104 153
Geremia 7:bb0383b91104 154 unsigned int tftID;
Geremia 7:bb0383b91104 155
Geremia 7:bb0383b91104 156
Geremia 7:bb0383b91104 157
Geremia 2:713844a55c4e 158
Geremia 2:713844a55c4e 159 protected:
Geremia 2:713844a55c4e 160
Geremia 2:713844a55c4e 161
Geremia 2:713844a55c4e 162 ////// functions needed by parent class ///////////////////////////////////////
Geremia 2:713844a55c4e 163 ////// -------------------------------- ///////////////////////////////////////
Geremia 2:713844a55c4e 164
Geremia 2:713844a55c4e 165 /** Send 8bit command to display controller
Geremia 2:713844a55c4e 166 *
Geremia 2:713844a55c4e 167 * @param cmd: byte to send
Geremia 2:713844a55c4e 168 * @note if protocol is SPI16, it will insert NOP cmd before, so if cmd is a 2byte cmd, the second cmd will be broken. Use wr_cmd16 for 2bytes cmds
Geremia 2:713844a55c4e 169 */
Geremia 2:713844a55c4e 170 void wr_cmd8(unsigned char cmd);
Geremia 2:713844a55c4e 171
Geremia 2:713844a55c4e 172 /** Send 8bit data to display controller
Geremia 2:713844a55c4e 173 *
Geremia 2:713844a55c4e 174 * @param data: byte to send
Geremia 2:713844a55c4e 175 *
Geremia 2:713844a55c4e 176 */
Geremia 2:713844a55c4e 177 void wr_data8(unsigned char data);
Geremia 2:713844a55c4e 178
Geremia 4:12ba0ecc2c1f 179 /** Send 2x8bit data to display controller
Geremia 2:713844a55c4e 180 *
Geremia 2:713844a55c4e 181 * @param data: halfword to send
Geremia 2:713844a55c4e 182 *
Geremia 2:713844a55c4e 183 */
Geremia 2:713844a55c4e 184 void wr_data16(unsigned short data);
Geremia 2:713844a55c4e 185
Geremia 4:12ba0ecc2c1f 186 /** Send 16bit pixeldata to display controller
Geremia 4:12ba0ecc2c1f 187 *
Geremia 4:12ba0ecc2c1f 188 * @param data: halfword to send
Geremia 4:12ba0ecc2c1f 189 *
Geremia 4:12ba0ecc2c1f 190 */
Geremia 4:12ba0ecc2c1f 191 virtual void wr_gram(unsigned short data);
Geremia 4:12ba0ecc2c1f 192
Geremia 4:12ba0ecc2c1f 193 /** Send same 16bit pixeldata to display controller multiple times
Geremia 2:713844a55c4e 194 *
Geremia 2:713844a55c4e 195 * @param data: halfword to send
Geremia 2:713844a55c4e 196 * @param count: how many
Geremia 2:713844a55c4e 197 *
Geremia 2:713844a55c4e 198 */
Geremia 4:12ba0ecc2c1f 199 virtual void wr_gram(unsigned short data, unsigned int count);
Geremia 2:713844a55c4e 200
Geremia 4:12ba0ecc2c1f 201 /** Send array of pixeldata shorts to display controller
Geremia 2:713844a55c4e 202 *
Geremia 4:12ba0ecc2c1f 203 * @param data: unsigned short pixeldata array
Geremia 2:713844a55c4e 204 * @param lenght: lenght (in shorts)
Geremia 2:713844a55c4e 205 *
Geremia 2:713844a55c4e 206 */
Geremia 4:12ba0ecc2c1f 207 virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
Geremia 2:713844a55c4e 208
Geremia 5:b222a9461d6b 209 /** Read 16bit pixeldata from display controller (with dummy cycle)
Geremia 5:b222a9461d6b 210 *
Geremia 11:b842b8e332cb 211 * @note autoconverts 18to16bit based on display identify info
Geremia 5:b222a9461d6b 212 * @returns 16bit color
Geremia 5:b222a9461d6b 213 */
Geremia 5:b222a9461d6b 214 virtual unsigned short rd_gram();
Geremia 5:b222a9461d6b 215
Geremia 7:bb0383b91104 216 /** Read 4x8bit register data (with dummy cycle)
Geremia 7:bb0383b91104 217 * @param reg the register to read
Geremia 7:bb0383b91104 218 * @returns data as uint
Geremia 7:bb0383b91104 219 *
Geremia 7:bb0383b91104 220 */
Geremia 7:bb0383b91104 221 virtual unsigned int rd_reg_data32(unsigned char reg);
Geremia 7:bb0383b91104 222
Geremia 7:bb0383b91104 223 /** Read 3x8bit ExtendedCommands register data
Geremia 7:bb0383b91104 224 * @param reg the register to read
Geremia 7:bb0383b91104 225 * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers
Geremia 7:bb0383b91104 226 * @returns data as uint
Geremia 7:bb0383b91104 227 * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode
Geremia 7:bb0383b91104 228 */
Geremia 7:bb0383b91104 229 virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd);
Geremia 7:bb0383b91104 230
Geremia 2:713844a55c4e 231 /** HW reset sequence (without display init commands)
Geremia 2:713844a55c4e 232 */
Geremia 2:713844a55c4e 233 void hw_reset();
Geremia 4:12ba0ecc2c1f 234
Geremia 11:b842b8e332cb 235 /** Try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR
Geremia 11:b842b8e332cb 236 * autoset internal flags so pixelread() will always return correct value.
Geremia 11:b842b8e332cb 237 */
Geremia 11:b842b8e332cb 238 virtual void auto_gram_read_format();
Geremia 11:b842b8e332cb 239
Geremia 7:bb0383b91104 240 /** Try to identify display ID
Geremia 7:bb0383b91104 241 * @note support ILI9341,94xx, MIPI standard. May be be overridden in Init class for other specific IC
Geremia 7:bb0383b91104 242 */
Geremia 7:bb0383b91104 243 virtual void identify();
Geremia 7:bb0383b91104 244
Geremia 4:12ba0ecc2c1f 245 unsigned int scrollbugfix;
Geremia 11:b842b8e332cb 246
Geremia 2:713844a55c4e 247
Geremia 10:668cf78ff93a 248
Geremia 2:713844a55c4e 249 private:
Geremia 2:713844a55c4e 250
Geremia 2:713844a55c4e 251 Protocols* proto;
Geremia 7:bb0383b91104 252 const int screensize_X;
Geremia 7:bb0383b91104 253 const int screensize_Y;
Geremia 2:713844a55c4e 254 // pixel location
Geremia 2:713844a55c4e 255 int cur_x;
Geremia 2:713844a55c4e 256 int cur_y;
Geremia 2:713844a55c4e 257 // window location
Geremia 2:713844a55c4e 258 int win_x1;
Geremia 2:713844a55c4e 259 int win_x2;
Geremia 2:713844a55c4e 260 int win_y1;
Geremia 2:713844a55c4e 261 int win_y2;
Geremia 2:713844a55c4e 262 int orientation;
Geremia 7:bb0383b91104 263 int topfixedareasize;
Geremia 7:bb0383b91104 264 int scrollareasize;
Geremia 2:713844a55c4e 265 bool useNOP;
Geremia 10:668cf78ff93a 266 bool usefastwindow;
Geremia 10:668cf78ff93a 267 bool fastwindowready;
Geremia 11:b842b8e332cb 268 bool mipistd;
Geremia 11:b842b8e332cb 269 bool is18bit;
Geremia 11:b842b8e332cb 270 bool isBGR;
Geremia 10:668cf78ff93a 271
Geremia 2:713844a55c4e 272 };
Geremia 2:713844a55c4e 273
Geremia 2:713844a55c4e 274 #endif