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