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.

Fork of UniGraphic by GraphicsDisplay

Committer:
Geremia
Date:
Sun Feb 15 20:06:07 2015 +0000
Revision:
4:12ba0ecc2c1f
Parent:
2:713844a55c4e
Child:
5:b222a9461d6b
Added PAR16, separated 16bit writes for cmd parameters and pixeldata

Who changed what in which revision?

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