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