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:   testUniGraphic_150217 maze_TFT_MMA8451Q TFT_test_frdm-kl25z TFT_test_NUCLEO-F411RE ... more

Committer:
dreschpe
Date:
Sun Oct 18 13:53:20 2015 +0000
Revision:
25:daacdcf34e52
Parent:
21:ae0a4eedfc90
Child:
27:acb2594b8aa4
Add check if platform supports par port mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 0:75ec1b3cde17 1
Geremia 0:75ec1b3cde17 2 #ifndef MBED_LCD_H
Geremia 0:75ec1b3cde17 3 #define MBED_LCD_H
Geremia 0:75ec1b3cde17 4
Geremia 0:75ec1b3cde17 5 #include "GraphicsDisplay.h"
dreschpe 25:daacdcf34e52 6
dreschpe 25:daacdcf34e52 7 #if DEVICE_PORTINOUT
Geremia 0:75ec1b3cde17 8 #include "PAR8.h"
dreschpe 25:daacdcf34e52 9 #endif
dreschpe 25:daacdcf34e52 10
Geremia 21:ae0a4eedfc90 11 #include "BUS8.h"
Geremia 0:75ec1b3cde17 12 #include "SPI8.h"
Geremia 1:ff019d22b275 13 #include "SPI16.h"
Geremia 0:75ec1b3cde17 14 #include "Protocols.h"
Geremia 0:75ec1b3cde17 15
Geremia 15:b9483ba842c8 16 // undefine the KL43Z and KL46Z LCD macro
Geremia 15:b9483ba842c8 17 #ifdef LCD
Geremia 15:b9483ba842c8 18 #undef LCD
Geremia 15:b9483ba842c8 19 #endif
Geremia 1:ff019d22b275 20
Geremia 0:75ec1b3cde17 21 /** Draw mode
Geremia 0:75ec1b3cde17 22 * NORMAl
Geremia 0:75ec1b3cde17 23 * XOR set pixel by xor the screen
Geremia 0:75ec1b3cde17 24 */
Geremia 0:75ec1b3cde17 25 enum {NORMAL,XOR};
Geremia 0:75ec1b3cde17 26
Geremia 0:75ec1b3cde17 27 /** Mirror mode */
Geremia 0:75ec1b3cde17 28 enum mirror_t {X,Y,XY,NONE};
Geremia 0:75ec1b3cde17 29
Geremia 0:75ec1b3cde17 30
Geremia 0:75ec1b3cde17 31 /** A common base class for monochrome Display
Geremia 0:75ec1b3cde17 32 */
Geremia 0:75ec1b3cde17 33 class LCD : public GraphicsDisplay
Geremia 0:75ec1b3cde17 34 {
Geremia 0:75ec1b3cde17 35
Geremia 0:75ec1b3cde17 36 public:
Geremia 0:75ec1b3cde17 37
Geremia 21:ae0a4eedfc90 38 /** Create a monochrome LCD Parallel Port interface
Geremia 0:75ec1b3cde17 39 * @param name The name used by the parent class to access the interface
Geremia 0:75ec1b3cde17 40 */
Geremia 0:75ec1b3cde17 41 LCD(proto_t displayproto,PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
Geremia 0:75ec1b3cde17 42
Geremia 21:ae0a4eedfc90 43 /** Create a monochrome LCD Parallel Bus interface
Geremia 21:ae0a4eedfc90 44 * @param name The name used by the parent class to access the interface
Geremia 21:ae0a4eedfc90 45 */
Geremia 21:ae0a4eedfc90 46 LCD(proto_t displayproto,PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
Geremia 21:ae0a4eedfc90 47
Geremia 0:75ec1b3cde17 48 /** Create a monochrome LCD SPI interface
Geremia 0:75ec1b3cde17 49 * @param name The name used by the parent class to access the interface
Geremia 0:75ec1b3cde17 50 */
Geremia 1:ff019d22b275 51 LCD(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 int ic_x_segs, const int ic_y_coms, const char* name);
Geremia 0:75ec1b3cde17 52
Geremia 0:75ec1b3cde17 53 /** Destructor
Geremia 0:75ec1b3cde17 54 * will free framebuffer
Geremia 0:75ec1b3cde17 55 */
Geremia 0:75ec1b3cde17 56 virtual ~LCD();
Geremia 0:75ec1b3cde17 57
Geremia 0:75ec1b3cde17 58
Geremia 0:75ec1b3cde17 59
Geremia 0:75ec1b3cde17 60 /////// functions that come for free, but can be overwritten///////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 61 /////// ----------------------------------------------------///////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 62
Geremia 0:75ec1b3cde17 63 /** Draw a pixel in the specified color.
Geremia 0:75ec1b3cde17 64 * @param x is the horizontal offset to this pixel.
Geremia 0:75ec1b3cde17 65 * @param y is the vertical offset to this pixel.
Geremia 0:75ec1b3cde17 66 * @param color defines the color for the pixel.
Geremia 0:75ec1b3cde17 67 */
Geremia 0:75ec1b3cde17 68 virtual void pixel(int x, int y, unsigned short color);
Geremia 0:75ec1b3cde17 69
Geremia 0:75ec1b3cde17 70 /** Set the window, which controls where items are written to the screen.
Geremia 0:75ec1b3cde17 71 * When something hits the window width, it wraps back to the left side
Geremia 0:75ec1b3cde17 72 * and down a row. If the initial write is outside the window, it will
Geremia 0:75ec1b3cde17 73 * be captured into the window when it crosses a boundary.
Geremia 0:75ec1b3cde17 74 * @param x is the left edge in pixels.
Geremia 0:75ec1b3cde17 75 * @param y is the top edge in pixels.
Geremia 0:75ec1b3cde17 76 * @param w is the window width in pixels.
Geremia 0:75ec1b3cde17 77 * @param h is the window height in pixels.
Geremia 0:75ec1b3cde17 78 */
Geremia 0:75ec1b3cde17 79 virtual void window(int x, int y, int w, int h);
Geremia 7:bb0383b91104 80
Geremia 20:14daa48ffd4c 81 /** Read pixel color at location
Geremia 20:14daa48ffd4c 82 * @param x is the horizontal offset to this pixel.
Geremia 20:14daa48ffd4c 83 * @param y is the vertical offset to this pixel.
Geremia 20:14daa48ffd4c 84 * @returns 16bit color, 0000=Black(pixel set), FFFF=White(pixel clear).
Geremia 20:14daa48ffd4c 85 */
Geremia 20:14daa48ffd4c 86 virtual unsigned short pixelread(int x, int y);
Geremia 0:75ec1b3cde17 87
Geremia 0:75ec1b3cde17 88 /** Push a single pixel into the window and increment position.
Geremia 0:75ec1b3cde17 89 * You must first call window() then push pixels in loop.
Geremia 0:75ec1b3cde17 90 * @param color is the pixel color.
Geremia 0:75ec1b3cde17 91 */
Geremia 0:75ec1b3cde17 92 virtual void window_pushpixel(unsigned short color);
Geremia 2:713844a55c4e 93
Geremia 2:713844a55c4e 94 /** Push some pixels of the same color into the window and increment position.
Geremia 2:713844a55c4e 95 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 96 * @param color is the pixel color.
Geremia 2:713844a55c4e 97 * @param count: how many
Geremia 2:713844a55c4e 98 */
Geremia 2:713844a55c4e 99 virtual void window_pushpixel(unsigned short color, unsigned int count);
Geremia 2:713844a55c4e 100
Geremia 2:713844a55c4e 101 /** Push array of pixel colors into the window and increment position.
Geremia 2:713844a55c4e 102 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 103 * @param color is the pixel color.
Geremia 2:713844a55c4e 104 */
Geremia 2:713844a55c4e 105 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght);
Geremia 0:75ec1b3cde17 106
Geremia 0:75ec1b3cde17 107 /** Framebuffer is used, it needs to be sent to LCD from time to time
Geremia 0:75ec1b3cde17 108 */
Geremia 0:75ec1b3cde17 109 virtual void copy_to_lcd();
Geremia 0:75ec1b3cde17 110
Geremia 0:75ec1b3cde17 111 /** set the contrast of the screen
Geremia 0:75ec1b3cde17 112 *
Geremia 0:75ec1b3cde17 113 * @param o contrast 0-63
Geremia 0:75ec1b3cde17 114 * @note may be overrided in case of not standard command
Geremia 0:75ec1b3cde17 115 */
Geremia 0:75ec1b3cde17 116 virtual void set_contrast(int o);
Geremia 0:75ec1b3cde17 117
Geremia 0:75ec1b3cde17 118 /** read the contrast level
Geremia 0:75ec1b3cde17 119 *
Geremia 0:75ec1b3cde17 120 */
Geremia 0:75ec1b3cde17 121 int get_contrast(void);
Geremia 0:75ec1b3cde17 122
Geremia 7:bb0383b91104 123 /** display inverted colors
Geremia 0:75ec1b3cde17 124 *
Geremia 0:75ec1b3cde17 125 * @param o = 0 normal, 1 invert
Geremia 0:75ec1b3cde17 126 */
Geremia 0:75ec1b3cde17 127 void invert(unsigned char o);
Geremia 0:75ec1b3cde17 128
Geremia 0:75ec1b3cde17 129 /** clear the entire screen
Geremia 0:75ec1b3cde17 130 * The inherited one sets windomax then fill with background color
Geremia 0:75ec1b3cde17 131 * We override it to speedup
Geremia 0:75ec1b3cde17 132 */
Geremia 0:75ec1b3cde17 133 virtual void cls();
Geremia 0:75ec1b3cde17 134
Geremia 0:75ec1b3cde17 135 /** Set the orientation of the screen
Geremia 0:75ec1b3cde17 136 * x,y: 0,0 is always top left
Geremia 0:75ec1b3cde17 137 *
Geremia 0:75ec1b3cde17 138 * @param o direction to use the screen (0-3)
Geremia 0:75ec1b3cde17 139 * 0 = -90°
Geremia 0:75ec1b3cde17 140 * 1 = default 0°
Geremia 0:75ec1b3cde17 141 * 2 = +90°
Geremia 0:75ec1b3cde17 142 * 3 = +180°
Geremia 0:75ec1b3cde17 143 *
Geremia 0:75ec1b3cde17 144 */
Geremia 0:75ec1b3cde17 145 void set_orientation(int o);
Geremia 0:75ec1b3cde17 146
Geremia 0:75ec1b3cde17 147 /** Set ChipSelect high or low
Geremia 0:75ec1b3cde17 148 * @param enable 0/1
Geremia 0:75ec1b3cde17 149 */
Geremia 0:75ec1b3cde17 150 virtual void BusEnable(bool enable);
Geremia 0:75ec1b3cde17 151
Geremia 7:bb0383b91104 152 /** get display X size in pixels (native, orientation independent)
Geremia 7:bb0383b91104 153 * @returns X size in pixels
Geremia 7:bb0383b91104 154 */
Geremia 7:bb0383b91104 155 int sizeX();
Geremia 7:bb0383b91104 156
Geremia 20:14daa48ffd4c 157 /** get display Y size in pixels (native, orientation independent)
Geremia 20:14daa48ffd4c 158 * @returns Y size in pixels
Geremia 7:bb0383b91104 159 */
Geremia 7:bb0383b91104 160 int sizeY();
Geremia 7:bb0383b91104 161
Geremia 7:bb0383b91104 162 ////////////////////////////////////////////////////////////////////////////////
Geremia 7:bb0383b91104 163 // not implemented yet
Geremia 7:bb0383b91104 164 //////////////////////////////////////////////////////////////////
Geremia 20:14daa48ffd4c 165 // virtual unsigned short pixelread(int x, int y){return 0;};
Geremia 7:bb0383b91104 166 virtual void window4read(int x, int y, int w, int h){};
Geremia 7:bb0383b91104 167 void setscrollarea (int startY, int areasize){};
Geremia 7:bb0383b91104 168 void scroll (int lines){};
Geremia 7:bb0383b91104 169 void scrollreset(){};
Geremia 10:668cf78ff93a 170 void FastWindow(bool enable){};
Geremia 7:bb0383b91104 171
Geremia 7:bb0383b91104 172 unsigned int tftID;
Geremia 7:bb0383b91104 173
Geremia 7:bb0383b91104 174
Geremia 7:bb0383b91104 175
Geremia 0:75ec1b3cde17 176
Geremia 0:75ec1b3cde17 177 protected:
Geremia 0:75ec1b3cde17 178
Geremia 0:75ec1b3cde17 179 /** set mirror mode
Geremia 0:75ec1b3cde17 180 * @note may be overridden by specific display init class in case of not standard cmds or inverted wiring
Geremia 0:75ec1b3cde17 181 * @param mode NONE, X, Y, XY
Geremia 0:75ec1b3cde17 182 */
Geremia 0:75ec1b3cde17 183 virtual void mirrorXY(mirror_t mode);
Geremia 0:75ec1b3cde17 184
Geremia 0:75ec1b3cde17 185 ////// functions needed by parent class ///////////////////////////////////////
Geremia 0:75ec1b3cde17 186 ////// -------------------------------- ///////////////////////////////////////
Geremia 0:75ec1b3cde17 187
Geremia 1:ff019d22b275 188 /** Send 8bit command to display controller
Geremia 1:ff019d22b275 189 *
Geremia 1:ff019d22b275 190 * @param cmd: byte to send
Geremia 1:ff019d22b275 191 * @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 1:ff019d22b275 192 */
Geremia 1:ff019d22b275 193 void wr_cmd8(unsigned char cmd);
Geremia 0:75ec1b3cde17 194
Geremia 1:ff019d22b275 195 /** Send 8bit data to display controller
Geremia 1:ff019d22b275 196 *
Geremia 1:ff019d22b275 197 * @param data: byte to send
Geremia 1:ff019d22b275 198 *
Geremia 1:ff019d22b275 199 */
Geremia 1:ff019d22b275 200 void wr_data8(unsigned char data);
Geremia 0:75ec1b3cde17 201
Geremia 1:ff019d22b275 202 /** Send 16bit command to display controller
Geremia 1:ff019d22b275 203 *
Geremia 1:ff019d22b275 204 * @param cmd: halfword to send
Geremia 1:ff019d22b275 205 *
Geremia 1:ff019d22b275 206 */
Geremia 1:ff019d22b275 207 void wr_cmd16(unsigned short cmd);
Geremia 1:ff019d22b275 208
Geremia 4:12ba0ecc2c1f 209 /** Send same 16bit pixeldata to display controller multiple times
Geremia 1:ff019d22b275 210 *
Geremia 1:ff019d22b275 211 * @param data: halfword to send
Geremia 1:ff019d22b275 212 * @param count: how many
Geremia 1:ff019d22b275 213 *
Geremia 1:ff019d22b275 214 */
Geremia 4:12ba0ecc2c1f 215 virtual void wr_gram(unsigned short data, unsigned int count);
Geremia 1:ff019d22b275 216
Geremia 4:12ba0ecc2c1f 217 /** Send array of pixeldata shorts to display controller
Geremia 1:ff019d22b275 218 *
Geremia 4:12ba0ecc2c1f 219 * @param data: unsigned short pixeldata array
Geremia 1:ff019d22b275 220 * @param lenght: lenght (in shorts)
Geremia 1:ff019d22b275 221 *
Geremia 1:ff019d22b275 222 */
Geremia 4:12ba0ecc2c1f 223 virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
Geremia 0:75ec1b3cde17 224
Geremia 0:75ec1b3cde17 225 /** HW reset sequence (without display init commands)
Geremia 0:75ec1b3cde17 226 */
Geremia 0:75ec1b3cde17 227 void hw_reset();
Geremia 0:75ec1b3cde17 228
Geremia 0:75ec1b3cde17 229 int draw_mode;
Geremia 0:75ec1b3cde17 230 int contrast;
Geremia 0:75ec1b3cde17 231
Geremia 0:75ec1b3cde17 232 private:
Geremia 0:75ec1b3cde17 233
Geremia 2:713844a55c4e 234 Protocols* proto;
Geremia 0:75ec1b3cde17 235 unsigned char *buffer;
Geremia 1:ff019d22b275 236 unsigned short *buffer16;
Geremia 7:bb0383b91104 237 const int screensize_X;
Geremia 7:bb0383b91104 238 const int screensize_Y;
Geremia 7:bb0383b91104 239 const int _LCDPAGES;
Geremia 7:bb0383b91104 240 const int _IC_X_SEGS;
Geremia 7:bb0383b91104 241 const int _IC_Y_COMS;
Geremia 7:bb0383b91104 242 const int _IC_PAGES;
Geremia 0:75ec1b3cde17 243
Geremia 0:75ec1b3cde17 244 int page_offset;
Geremia 0:75ec1b3cde17 245 int col_offset;
Geremia 0:75ec1b3cde17 246 // pixel location
Geremia 0:75ec1b3cde17 247 int cur_x;
Geremia 0:75ec1b3cde17 248 int cur_y;
Geremia 0:75ec1b3cde17 249 // window location
Geremia 0:75ec1b3cde17 250 int win_x1;
Geremia 0:75ec1b3cde17 251 int win_x2;
Geremia 0:75ec1b3cde17 252 int win_y1;
Geremia 0:75ec1b3cde17 253 int win_y2;
Geremia 0:75ec1b3cde17 254 int orientation;
Geremia 1:ff019d22b275 255 bool useNOP;
Geremia 0:75ec1b3cde17 256 };
Geremia 0:75ec1b3cde17 257
Geremia 0:75ec1b3cde17 258 #endif