.

Committer:
dreschpe
Date:
Mon Feb 06 12:29:33 2017 +0000
Revision:
33:f87f06292637
Parent:
27:acb2594b8aa4
Add I2C protocol. ; Add SSD1306 i2C modus

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