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