Arunkumar Mourougappane / UniGraphic

Dependents:   TFT_ILI9341_UniGraphic TFT_ILI9341_os6

Committer:
amouroug
Date:
Thu Oct 08 18:11:03 2020 -0500
Revision:
2:59188908eb60
Parent:
0:bb2bda4f5846
Added GraphicsDisplay GFX API to draw triangle.

Who changed what in which revision?

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