Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Dependents:   Brew

Committer:
Geremia
Date:
Mon Feb 16 00:52:24 2015 +0000
Revision:
5:b222a9461d6b
Parent:
4:12ba0ecc2c1f
Child:
6:8356d48a07db
Added pixelread for TFTs

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 2:713844a55c4e 12
Geremia 2:713844a55c4e 13
Geremia 2:713844a55c4e 14
Geremia 2:713844a55c4e 15
Geremia 2:713844a55c4e 16 /** A common base class for monochrome Display
Geremia 2:713844a55c4e 17 */
Geremia 2:713844a55c4e 18 class TFT : public GraphicsDisplay
Geremia 2:713844a55c4e 19 {
Geremia 2:713844a55c4e 20
Geremia 2:713844a55c4e 21 public:
Geremia 2:713844a55c4e 22
Geremia 2:713844a55c4e 23 /** Create a monochrome LCD Parallel interface
Geremia 2:713844a55c4e 24 * @param name The name used by the parent class to access the interface
Geremia 2:713844a55c4e 25 */
Geremia 2:713844a55c4e 26 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 27
Geremia 2:713844a55c4e 28 /** Create a monochrome LCD SPI interface
Geremia 2:713844a55c4e 29 * @param name The name used by the parent class to access the interface
Geremia 2:713844a55c4e 30 */
Geremia 2:713844a55c4e 31 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 32
Geremia 2:713844a55c4e 33 /////// functions that come for free, but can be overwritten///////////////////////////////////////////////////
Geremia 2:713844a55c4e 34 /////// ----------------------------------------------------///////////////////////////////////////////////////
Geremia 2:713844a55c4e 35
Geremia 2:713844a55c4e 36 /** Draw a pixel in the specified color.
Geremia 2:713844a55c4e 37 * @param x is the horizontal offset to this pixel.
Geremia 2:713844a55c4e 38 * @param y is the vertical offset to this pixel.
Geremia 2:713844a55c4e 39 * @param color defines the color for the pixel.
Geremia 2:713844a55c4e 40 */
Geremia 2:713844a55c4e 41 virtual void pixel(int x, int y, unsigned short color);
Geremia 2:713844a55c4e 42
Geremia 2:713844a55c4e 43 /** Set the window, which controls where items are written to the screen.
Geremia 2:713844a55c4e 44 * When something hits the window width, it wraps back to the left side
Geremia 2:713844a55c4e 45 * and down a row. If the initial write is outside the window, it will
Geremia 2:713844a55c4e 46 * be captured into the window when it crosses a boundary.
Geremia 2:713844a55c4e 47 * @param x is the left edge in pixels.
Geremia 2:713844a55c4e 48 * @param y is the top edge in pixels.
Geremia 2:713844a55c4e 49 * @param w is the window width in pixels.
Geremia 2:713844a55c4e 50 * @param h is the window height in pixels.
Geremia 2:713844a55c4e 51 */
Geremia 2:713844a55c4e 52 virtual void window(int x, int y, int w, int h);
Geremia 5:b222a9461d6b 53
Geremia 5:b222a9461d6b 54 /** Read pixel color at current location
Geremia 5:b222a9461d6b 55 * @param x is the horizontal offset to this pixel.
Geremia 5:b222a9461d6b 56 * @param y is the vertical offset to this pixel.
Geremia 5:b222a9461d6b 57 * @param color defines the color for the pixel.
Geremia 5:b222a9461d6b 58 */
Geremia 5:b222a9461d6b 59 virtual unsigned short pixelread(int x, int y);
Geremia 5:b222a9461d6b 60
Geremia 5:b222a9461d6b 61 /** Set the window from which gram is read from. Autoincrements row/column
Geremia 5:b222a9461d6b 62 * @param x is the left edge in pixels.
Geremia 5:b222a9461d6b 63 * @param y is the top edge in pixels.
Geremia 5:b222a9461d6b 64 * @param w is the window width in pixels.
Geremia 5:b222a9461d6b 65 * @param h is the window height in pixels.
Geremia 5:b222a9461d6b 66 */
Geremia 5:b222a9461d6b 67 virtual void window4read(int x, int y, int w, int h);
Geremia 2:713844a55c4e 68
Geremia 2:713844a55c4e 69 /** Push a single pixel into the window and increment position.
Geremia 2:713844a55c4e 70 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 71 * @param color is the pixel color.
Geremia 2:713844a55c4e 72 */
Geremia 2:713844a55c4e 73 virtual void window_pushpixel(unsigned short color);
Geremia 2:713844a55c4e 74
Geremia 2:713844a55c4e 75 /** Push some pixels of the same color into the window and increment position.
Geremia 2:713844a55c4e 76 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 77 * @param color is the pixel color.
Geremia 2:713844a55c4e 78 * @param count: how many
Geremia 2:713844a55c4e 79 */
Geremia 2:713844a55c4e 80 virtual void window_pushpixel(unsigned short color, unsigned int count);
Geremia 2:713844a55c4e 81
Geremia 2:713844a55c4e 82 /** Push array of pixel colors into the window and increment position.
Geremia 2:713844a55c4e 83 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 84 * @param color is the pixel color.
Geremia 2:713844a55c4e 85 */
Geremia 2:713844a55c4e 86 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght);
Geremia 2:713844a55c4e 87
Geremia 2:713844a55c4e 88 /** Framebuffer is not used for TFT
Geremia 2:713844a55c4e 89 */
Geremia 2:713844a55c4e 90 virtual void copy_to_lcd(){ };
Geremia 2:713844a55c4e 91
Geremia 2:713844a55c4e 92 /** invert the screen
Geremia 2:713844a55c4e 93 *
Geremia 2:713844a55c4e 94 * @param o = 0 normal, 1 invert
Geremia 2:713844a55c4e 95 */
Geremia 2:713844a55c4e 96 void invert(unsigned char o);
Geremia 2:713844a55c4e 97
Geremia 2:713844a55c4e 98 /** clear the entire screen
Geremia 2:713844a55c4e 99 * The inherited one sets windomax then fill with background color
Geremia 2:713844a55c4e 100 * We override it to speedup
Geremia 2:713844a55c4e 101 */
Geremia 2:713844a55c4e 102 virtual void cls();
Geremia 2:713844a55c4e 103
Geremia 2:713844a55c4e 104 /** Set the orientation of the screen
Geremia 2:713844a55c4e 105 * x,y: 0,0 is always top left
Geremia 2:713844a55c4e 106 *
Geremia 2:713844a55c4e 107 * @param o direction to use the screen (0-3)
Geremia 2:713844a55c4e 108 * 0 = default 0° portrait view
Geremia 2:713844a55c4e 109 * 1 = +90° landscape view
Geremia 2:713844a55c4e 110 * 2 = +180° portrait view
Geremia 2:713844a55c4e 111 * 3 = -90° landscape view
Geremia 2:713844a55c4e 112 *
Geremia 2:713844a55c4e 113 */
Geremia 2:713844a55c4e 114 virtual void set_orientation(int o);
Geremia 2:713844a55c4e 115
Geremia 2:713844a55c4e 116 /** Set ChipSelect high or low
Geremia 2:713844a55c4e 117 * @param enable 0/1
Geremia 2:713844a55c4e 118 */
Geremia 2:713844a55c4e 119 virtual void BusEnable(bool enable);
Geremia 2:713844a55c4e 120
Geremia 2:713844a55c4e 121
Geremia 2:713844a55c4e 122 protected:
Geremia 2:713844a55c4e 123
Geremia 2:713844a55c4e 124
Geremia 2:713844a55c4e 125 ////// functions needed by parent class ///////////////////////////////////////
Geremia 2:713844a55c4e 126 ////// -------------------------------- ///////////////////////////////////////
Geremia 2:713844a55c4e 127
Geremia 2:713844a55c4e 128 /** Send 8bit command to display controller
Geremia 2:713844a55c4e 129 *
Geremia 2:713844a55c4e 130 * @param cmd: byte to send
Geremia 2:713844a55c4e 131 * @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 132 */
Geremia 2:713844a55c4e 133 void wr_cmd8(unsigned char cmd);
Geremia 2:713844a55c4e 134
Geremia 2:713844a55c4e 135 /** Send 8bit data to display controller
Geremia 2:713844a55c4e 136 *
Geremia 2:713844a55c4e 137 * @param data: byte to send
Geremia 2:713844a55c4e 138 *
Geremia 2:713844a55c4e 139 */
Geremia 2:713844a55c4e 140 void wr_data8(unsigned char data);
Geremia 2:713844a55c4e 141
Geremia 4:12ba0ecc2c1f 142 /** Send 2x8bit data to display controller
Geremia 2:713844a55c4e 143 *
Geremia 2:713844a55c4e 144 * @param data: halfword to send
Geremia 2:713844a55c4e 145 *
Geremia 2:713844a55c4e 146 */
Geremia 2:713844a55c4e 147 void wr_data16(unsigned short data);
Geremia 2:713844a55c4e 148
Geremia 4:12ba0ecc2c1f 149 /** Send 16bit pixeldata to display controller
Geremia 4:12ba0ecc2c1f 150 *
Geremia 4:12ba0ecc2c1f 151 * @param data: halfword to send
Geremia 4:12ba0ecc2c1f 152 *
Geremia 4:12ba0ecc2c1f 153 */
Geremia 4:12ba0ecc2c1f 154 virtual void wr_gram(unsigned short data);
Geremia 4:12ba0ecc2c1f 155
Geremia 4:12ba0ecc2c1f 156 /** Send same 16bit pixeldata to display controller multiple times
Geremia 2:713844a55c4e 157 *
Geremia 2:713844a55c4e 158 * @param data: halfword to send
Geremia 2:713844a55c4e 159 * @param count: how many
Geremia 2:713844a55c4e 160 *
Geremia 2:713844a55c4e 161 */
Geremia 4:12ba0ecc2c1f 162 virtual void wr_gram(unsigned short data, unsigned int count);
Geremia 2:713844a55c4e 163
Geremia 4:12ba0ecc2c1f 164 /** Send array of pixeldata shorts to display controller
Geremia 2:713844a55c4e 165 *
Geremia 4:12ba0ecc2c1f 166 * @param data: unsigned short pixeldata array
Geremia 2:713844a55c4e 167 * @param lenght: lenght (in shorts)
Geremia 2:713844a55c4e 168 *
Geremia 2:713844a55c4e 169 */
Geremia 4:12ba0ecc2c1f 170 virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
Geremia 2:713844a55c4e 171
Geremia 5:b222a9461d6b 172 /** Read 4x8bit data from display controller (with dummy cycle)
Geremia 5:b222a9461d6b 173 *
Geremia 5:b222a9461d6b 174 * @returns data as uint
Geremia 5:b222a9461d6b 175 *
Geremia 5:b222a9461d6b 176 */
Geremia 5:b222a9461d6b 177 virtual unsigned int rd_data32_wdummy();
Geremia 5:b222a9461d6b 178
Geremia 5:b222a9461d6b 179 /** Read 16bit pixeldata from display controller (with dummy cycle)
Geremia 5:b222a9461d6b 180 *
Geremia 5:b222a9461d6b 181 * @returns 16bit color
Geremia 5:b222a9461d6b 182 */
Geremia 5:b222a9461d6b 183 virtual unsigned short rd_gram();
Geremia 5:b222a9461d6b 184
Geremia 2:713844a55c4e 185 /** HW reset sequence (without display init commands)
Geremia 2:713844a55c4e 186 */
Geremia 2:713844a55c4e 187 void hw_reset();
Geremia 4:12ba0ecc2c1f 188
Geremia 4:12ba0ecc2c1f 189 unsigned int scrollbugfix;
Geremia 4:12ba0ecc2c1f 190 bool mipistd;
Geremia 2:713844a55c4e 191
Geremia 2:713844a55c4e 192 private:
Geremia 2:713844a55c4e 193
Geremia 2:713844a55c4e 194 Protocols* proto;
Geremia 2:713844a55c4e 195 const int LCDSIZE_X;
Geremia 2:713844a55c4e 196 const int LCDSIZE_Y;
Geremia 2:713844a55c4e 197 // const int LCDPAGES;
Geremia 2:713844a55c4e 198 // const int IC_X_SEGS;
Geremia 2:713844a55c4e 199 // const int IC_Y_COMS;
Geremia 2:713844a55c4e 200 // const int IC_PAGES;
Geremia 2:713844a55c4e 201
Geremia 2:713844a55c4e 202 // int page_offset;
Geremia 2:713844a55c4e 203 // int col_offset;
Geremia 2:713844a55c4e 204 // pixel location
Geremia 2:713844a55c4e 205 int cur_x;
Geremia 2:713844a55c4e 206 int cur_y;
Geremia 2:713844a55c4e 207 // window location
Geremia 2:713844a55c4e 208 int win_x1;
Geremia 2:713844a55c4e 209 int win_x2;
Geremia 2:713844a55c4e 210 int win_y1;
Geremia 2:713844a55c4e 211 int win_y2;
Geremia 2:713844a55c4e 212 int orientation;
Geremia 2:713844a55c4e 213 unsigned int tftID;
Geremia 2:713844a55c4e 214 bool useNOP;
Geremia 2:713844a55c4e 215 };
Geremia 2:713844a55c4e 216
Geremia 2:713844a55c4e 217 #endif