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: afero_poc15_180216 afero_poc15_180223 afero_poc15_180302 afero_poc15_180403R ... more
Fork of UniGraphic by
UniGraphic for La Suno Version.
To go with La Suno, WatchDog Reset functions were added in ILI9341.
Display/TFT.h@6:8356d48a07db, 2015-02-16 (annotated)
- Committer:
- Geremia
- Date:
- Mon Feb 16 01:18:29 2015 +0000
- Revision:
- 6:8356d48a07db
- Parent:
- 5:b222a9461d6b
- Child:
- 7:bb0383b91104
updated docs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 2:713844a55c4e | 1 | #ifndef MBED_TFT_H |
Geremia | 2:713844a55c4e | 2 | #define MBED_TFT_H |
Geremia | 2:713844a55c4e | 3 | |
Geremia | 2:713844a55c4e | 4 | #include "GraphicsDisplay.h" |
Geremia | 2:713844a55c4e | 5 | #include "PAR8.h" |
Geremia | 4:12ba0ecc2c1f | 6 | #include "PAR16.h" |
Geremia | 2:713844a55c4e | 7 | #include "SPI8.h" |
Geremia | 2:713844a55c4e | 8 | #include "SPI16.h" |
Geremia | 2:713844a55c4e | 9 | #include "Protocols.h" |
Geremia | 2:713844a55c4e | 10 | |
Geremia | 2:713844a55c4e | 11 | |
Geremia | 6:8356d48a07db | 12 | /** A common base class for color TFT Display |
Geremia | 2:713844a55c4e | 13 | */ |
Geremia | 2:713844a55c4e | 14 | class TFT : public GraphicsDisplay |
Geremia | 2:713844a55c4e | 15 | { |
Geremia | 2:713844a55c4e | 16 | |
Geremia | 2:713844a55c4e | 17 | public: |
Geremia | 2:713844a55c4e | 18 | |
Geremia | 2:713844a55c4e | 19 | /** Create a monochrome LCD Parallel interface |
Geremia | 2:713844a55c4e | 20 | * @param name The name used by the parent class to access the interface |
Geremia | 2:713844a55c4e | 21 | */ |
Geremia | 2:713844a55c4e | 22 | TFT(proto_t displayproto,PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const char* name); |
Geremia | 2:713844a55c4e | 23 | |
Geremia | 2:713844a55c4e | 24 | /** Create a monochrome LCD SPI interface |
Geremia | 2:713844a55c4e | 25 | * @param name The name used by the parent class to access the interface |
Geremia | 2:713844a55c4e | 26 | */ |
Geremia | 2:713844a55c4e | 27 | TFT(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 char* name); |
Geremia | 2:713844a55c4e | 28 | |
Geremia | 2:713844a55c4e | 29 | /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// |
Geremia | 2:713844a55c4e | 30 | /////// ----------------------------------------------------/////////////////////////////////////////////////// |
Geremia | 2:713844a55c4e | 31 | |
Geremia | 2:713844a55c4e | 32 | /** Draw a pixel in the specified color. |
Geremia | 2:713844a55c4e | 33 | * @param x is the horizontal offset to this pixel. |
Geremia | 2:713844a55c4e | 34 | * @param y is the vertical offset to this pixel. |
Geremia | 2:713844a55c4e | 35 | * @param color defines the color for the pixel. |
Geremia | 2:713844a55c4e | 36 | */ |
Geremia | 2:713844a55c4e | 37 | virtual void pixel(int x, int y, unsigned short color); |
Geremia | 2:713844a55c4e | 38 | |
Geremia | 2:713844a55c4e | 39 | /** Set the window, which controls where items are written to the screen. |
Geremia | 2:713844a55c4e | 40 | * When something hits the window width, it wraps back to the left side |
Geremia | 2:713844a55c4e | 41 | * and down a row. If the initial write is outside the window, it will |
Geremia | 2:713844a55c4e | 42 | * be captured into the window when it crosses a boundary. |
Geremia | 2:713844a55c4e | 43 | * @param x is the left edge in pixels. |
Geremia | 2:713844a55c4e | 44 | * @param y is the top edge in pixels. |
Geremia | 2:713844a55c4e | 45 | * @param w is the window width in pixels. |
Geremia | 2:713844a55c4e | 46 | * @param h is the window height in pixels. |
Geremia | 2:713844a55c4e | 47 | */ |
Geremia | 2:713844a55c4e | 48 | virtual void window(int x, int y, int w, int h); |
Geremia | 5:b222a9461d6b | 49 | |
Geremia | 5:b222a9461d6b | 50 | /** Read pixel color at current location |
Geremia | 5:b222a9461d6b | 51 | * @param x is the horizontal offset to this pixel. |
Geremia | 5:b222a9461d6b | 52 | * @param y is the vertical offset to this pixel. |
Geremia | 5:b222a9461d6b | 53 | * @param color defines the color for the pixel. |
Geremia | 5:b222a9461d6b | 54 | */ |
Geremia | 5:b222a9461d6b | 55 | virtual unsigned short pixelread(int x, int y); |
Geremia | 5:b222a9461d6b | 56 | |
Geremia | 5:b222a9461d6b | 57 | /** Set the window from which gram is read from. Autoincrements row/column |
Geremia | 5:b222a9461d6b | 58 | * @param x is the left edge in pixels. |
Geremia | 5:b222a9461d6b | 59 | * @param y is the top edge in pixels. |
Geremia | 5:b222a9461d6b | 60 | * @param w is the window width in pixels. |
Geremia | 5:b222a9461d6b | 61 | * @param h is the window height in pixels. |
Geremia | 5:b222a9461d6b | 62 | */ |
Geremia | 5:b222a9461d6b | 63 | virtual void window4read(int x, int y, int w, int h); |
Geremia | 2:713844a55c4e | 64 | |
Geremia | 2:713844a55c4e | 65 | /** Push a single pixel into the window and increment position. |
Geremia | 2:713844a55c4e | 66 | * You must first call window() then push pixels. |
Geremia | 2:713844a55c4e | 67 | * @param color is the pixel color. |
Geremia | 2:713844a55c4e | 68 | */ |
Geremia | 2:713844a55c4e | 69 | virtual void window_pushpixel(unsigned short color); |
Geremia | 2:713844a55c4e | 70 | |
Geremia | 2:713844a55c4e | 71 | /** Push some pixels of the same color into the window and increment position. |
Geremia | 2:713844a55c4e | 72 | * You must first call window() then push pixels. |
Geremia | 2:713844a55c4e | 73 | * @param color is the pixel color. |
Geremia | 2:713844a55c4e | 74 | * @param count: how many |
Geremia | 2:713844a55c4e | 75 | */ |
Geremia | 2:713844a55c4e | 76 | virtual void window_pushpixel(unsigned short color, unsigned int count); |
Geremia | 2:713844a55c4e | 77 | |
Geremia | 2:713844a55c4e | 78 | /** Push array of pixel colors into the window and increment position. |
Geremia | 2:713844a55c4e | 79 | * You must first call window() then push pixels. |
Geremia | 2:713844a55c4e | 80 | * @param color is the pixel color. |
Geremia | 2:713844a55c4e | 81 | */ |
Geremia | 2:713844a55c4e | 82 | virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght); |
Geremia | 2:713844a55c4e | 83 | |
Geremia | 2:713844a55c4e | 84 | /** Framebuffer is not used for TFT |
Geremia | 2:713844a55c4e | 85 | */ |
Geremia | 2:713844a55c4e | 86 | virtual void copy_to_lcd(){ }; |
Geremia | 2:713844a55c4e | 87 | |
Geremia | 2:713844a55c4e | 88 | /** invert the screen |
Geremia | 2:713844a55c4e | 89 | * |
Geremia | 2:713844a55c4e | 90 | * @param o = 0 normal, 1 invert |
Geremia | 2:713844a55c4e | 91 | */ |
Geremia | 2:713844a55c4e | 92 | void invert(unsigned char o); |
Geremia | 2:713844a55c4e | 93 | |
Geremia | 2:713844a55c4e | 94 | /** clear the entire screen |
Geremia | 2:713844a55c4e | 95 | * The inherited one sets windomax then fill with background color |
Geremia | 2:713844a55c4e | 96 | * We override it to speedup |
Geremia | 2:713844a55c4e | 97 | */ |
Geremia | 2:713844a55c4e | 98 | virtual void cls(); |
Geremia | 2:713844a55c4e | 99 | |
Geremia | 2:713844a55c4e | 100 | /** Set the orientation of the screen |
Geremia | 2:713844a55c4e | 101 | * x,y: 0,0 is always top left |
Geremia | 2:713844a55c4e | 102 | * |
Geremia | 2:713844a55c4e | 103 | * @param o direction to use the screen (0-3) |
Geremia | 2:713844a55c4e | 104 | * 0 = default 0° portrait view |
Geremia | 2:713844a55c4e | 105 | * 1 = +90° landscape view |
Geremia | 2:713844a55c4e | 106 | * 2 = +180° portrait view |
Geremia | 2:713844a55c4e | 107 | * 3 = -90° landscape view |
Geremia | 2:713844a55c4e | 108 | * |
Geremia | 2:713844a55c4e | 109 | */ |
Geremia | 2:713844a55c4e | 110 | virtual void set_orientation(int o); |
Geremia | 2:713844a55c4e | 111 | |
Geremia | 2:713844a55c4e | 112 | /** Set ChipSelect high or low |
Geremia | 2:713844a55c4e | 113 | * @param enable 0/1 |
Geremia | 2:713844a55c4e | 114 | */ |
Geremia | 2:713844a55c4e | 115 | virtual void BusEnable(bool enable); |
Geremia | 2:713844a55c4e | 116 | |
Geremia | 2:713844a55c4e | 117 | |
Geremia | 2:713844a55c4e | 118 | protected: |
Geremia | 2:713844a55c4e | 119 | |
Geremia | 2:713844a55c4e | 120 | |
Geremia | 2:713844a55c4e | 121 | ////// functions needed by parent class /////////////////////////////////////// |
Geremia | 2:713844a55c4e | 122 | ////// -------------------------------- /////////////////////////////////////// |
Geremia | 2:713844a55c4e | 123 | |
Geremia | 2:713844a55c4e | 124 | /** Send 8bit command to display controller |
Geremia | 2:713844a55c4e | 125 | * |
Geremia | 2:713844a55c4e | 126 | * @param cmd: byte to send |
Geremia | 2:713844a55c4e | 127 | * @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 | 2:713844a55c4e | 128 | */ |
Geremia | 2:713844a55c4e | 129 | void wr_cmd8(unsigned char cmd); |
Geremia | 2:713844a55c4e | 130 | |
Geremia | 2:713844a55c4e | 131 | /** Send 8bit data to display controller |
Geremia | 2:713844a55c4e | 132 | * |
Geremia | 2:713844a55c4e | 133 | * @param data: byte to send |
Geremia | 2:713844a55c4e | 134 | * |
Geremia | 2:713844a55c4e | 135 | */ |
Geremia | 2:713844a55c4e | 136 | void wr_data8(unsigned char data); |
Geremia | 2:713844a55c4e | 137 | |
Geremia | 4:12ba0ecc2c1f | 138 | /** Send 2x8bit data to display controller |
Geremia | 2:713844a55c4e | 139 | * |
Geremia | 2:713844a55c4e | 140 | * @param data: halfword to send |
Geremia | 2:713844a55c4e | 141 | * |
Geremia | 2:713844a55c4e | 142 | */ |
Geremia | 2:713844a55c4e | 143 | void wr_data16(unsigned short data); |
Geremia | 2:713844a55c4e | 144 | |
Geremia | 4:12ba0ecc2c1f | 145 | /** Send 16bit pixeldata to display controller |
Geremia | 4:12ba0ecc2c1f | 146 | * |
Geremia | 4:12ba0ecc2c1f | 147 | * @param data: halfword to send |
Geremia | 4:12ba0ecc2c1f | 148 | * |
Geremia | 4:12ba0ecc2c1f | 149 | */ |
Geremia | 4:12ba0ecc2c1f | 150 | virtual void wr_gram(unsigned short data); |
Geremia | 4:12ba0ecc2c1f | 151 | |
Geremia | 4:12ba0ecc2c1f | 152 | /** Send same 16bit pixeldata to display controller multiple times |
Geremia | 2:713844a55c4e | 153 | * |
Geremia | 2:713844a55c4e | 154 | * @param data: halfword to send |
Geremia | 2:713844a55c4e | 155 | * @param count: how many |
Geremia | 2:713844a55c4e | 156 | * |
Geremia | 2:713844a55c4e | 157 | */ |
Geremia | 4:12ba0ecc2c1f | 158 | virtual void wr_gram(unsigned short data, unsigned int count); |
Geremia | 2:713844a55c4e | 159 | |
Geremia | 4:12ba0ecc2c1f | 160 | /** Send array of pixeldata shorts to display controller |
Geremia | 2:713844a55c4e | 161 | * |
Geremia | 4:12ba0ecc2c1f | 162 | * @param data: unsigned short pixeldata array |
Geremia | 2:713844a55c4e | 163 | * @param lenght: lenght (in shorts) |
Geremia | 2:713844a55c4e | 164 | * |
Geremia | 2:713844a55c4e | 165 | */ |
Geremia | 4:12ba0ecc2c1f | 166 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); |
Geremia | 2:713844a55c4e | 167 | |
Geremia | 5:b222a9461d6b | 168 | /** Read 4x8bit data from display controller (with dummy cycle) |
Geremia | 5:b222a9461d6b | 169 | * |
Geremia | 5:b222a9461d6b | 170 | * @returns data as uint |
Geremia | 5:b222a9461d6b | 171 | * |
Geremia | 5:b222a9461d6b | 172 | */ |
Geremia | 5:b222a9461d6b | 173 | virtual unsigned int rd_data32_wdummy(); |
Geremia | 5:b222a9461d6b | 174 | |
Geremia | 5:b222a9461d6b | 175 | /** Read 16bit pixeldata from display controller (with dummy cycle) |
Geremia | 5:b222a9461d6b | 176 | * |
Geremia | 5:b222a9461d6b | 177 | * @returns 16bit color |
Geremia | 5:b222a9461d6b | 178 | */ |
Geremia | 5:b222a9461d6b | 179 | virtual unsigned short rd_gram(); |
Geremia | 5:b222a9461d6b | 180 | |
Geremia | 2:713844a55c4e | 181 | /** HW reset sequence (without display init commands) |
Geremia | 2:713844a55c4e | 182 | */ |
Geremia | 2:713844a55c4e | 183 | void hw_reset(); |
Geremia | 4:12ba0ecc2c1f | 184 | |
Geremia | 4:12ba0ecc2c1f | 185 | unsigned int scrollbugfix; |
Geremia | 4:12ba0ecc2c1f | 186 | bool mipistd; |
Geremia | 2:713844a55c4e | 187 | |
Geremia | 2:713844a55c4e | 188 | private: |
Geremia | 2:713844a55c4e | 189 | |
Geremia | 2:713844a55c4e | 190 | Protocols* proto; |
Geremia | 2:713844a55c4e | 191 | const int LCDSIZE_X; |
Geremia | 2:713844a55c4e | 192 | const int LCDSIZE_Y; |
Geremia | 2:713844a55c4e | 193 | // const int LCDPAGES; |
Geremia | 2:713844a55c4e | 194 | // const int IC_X_SEGS; |
Geremia | 2:713844a55c4e | 195 | // const int IC_Y_COMS; |
Geremia | 2:713844a55c4e | 196 | // const int IC_PAGES; |
Geremia | 2:713844a55c4e | 197 | |
Geremia | 2:713844a55c4e | 198 | // int page_offset; |
Geremia | 2:713844a55c4e | 199 | // int col_offset; |
Geremia | 2:713844a55c4e | 200 | // pixel location |
Geremia | 2:713844a55c4e | 201 | int cur_x; |
Geremia | 2:713844a55c4e | 202 | int cur_y; |
Geremia | 2:713844a55c4e | 203 | // window location |
Geremia | 2:713844a55c4e | 204 | int win_x1; |
Geremia | 2:713844a55c4e | 205 | int win_x2; |
Geremia | 2:713844a55c4e | 206 | int win_y1; |
Geremia | 2:713844a55c4e | 207 | int win_y2; |
Geremia | 2:713844a55c4e | 208 | int orientation; |
Geremia | 2:713844a55c4e | 209 | unsigned int tftID; |
Geremia | 2:713844a55c4e | 210 | bool useNOP; |
Geremia | 2:713844a55c4e | 211 | }; |
Geremia | 2:713844a55c4e | 212 | |
Geremia | 2:713844a55c4e | 213 | #endif |