Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
LCD.h
00001 00002 #ifndef MBED_LCD_H 00003 #define MBED_LCD_H 00004 00005 #if DEVICE_PORTINOUT 00006 #include "PAR8.h" 00007 #include "PAR16.h" 00008 #endif 00009 00010 #include "BUS8.h" 00011 #include "SPI8.h" 00012 #include "SPI16.h" 00013 #include "I2C_bus.h" 00014 #include "Protocols.h " 00015 00016 #include "GraphicsDisplay.h" 00017 00018 // undefine the KL43Z and KL46Z LCD macro 00019 #ifdef LCD 00020 #undef LCD 00021 #endif 00022 00023 /** Draw mode 00024 * NORMAl 00025 * XOR set pixel by xor the screen 00026 */ 00027 enum {NORMAL,XOR}; 00028 00029 /** Mirror mode */ 00030 enum mirror_t {X,Y,XY,NONE}; 00031 00032 00033 /** A common base class for monochrome Display 00034 */ 00035 class LCD : public GraphicsDisplay 00036 { 00037 00038 public: 00039 00040 /** Create a monochrome LCD Parallel Port interface 00041 * @param name The name used by the parent class to access the interface 00042 */ 00043 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); 00044 00045 /** Create a monochrome LCD Parallel Bus interface 00046 * @param name The name used by the parent class to access the interface 00047 */ 00048 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); 00049 00050 /** Create a monochrome LCD SPI interface 00051 * @param name The name used by the parent class to access the interface 00052 */ 00053 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); 00054 00055 /** Create a monochrome LCD I2C interface 00056 * @param name The name used by the parent class to access the interface 00057 */ 00058 LCD(proto_t displayproto, int Hz, int address,PinName sda, PinName scl, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name); 00059 00060 00061 /** Destructor 00062 * will free framebuffer 00063 */ 00064 virtual ~LCD(); 00065 00066 00067 00068 /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// 00069 /////// ----------------------------------------------------/////////////////////////////////////////////////// 00070 00071 /** Draw a pixel in the specified color. 00072 * @param x is the horizontal offset to this pixel. 00073 * @param y is the vertical offset to this pixel. 00074 * @param color defines the color for the pixel. 00075 */ 00076 virtual void pixel(int x, int y, unsigned short color); 00077 00078 /** Set the window, which controls where items are written to the screen. 00079 * When something hits the window width, it wraps back to the left side 00080 * and down a row. If the initial write is outside the window, it will 00081 * be captured into the window when it crosses a boundary. 00082 * @param x is the left edge in pixels. 00083 * @param y is the top edge in pixels. 00084 * @param w is the window width in pixels. 00085 * @param h is the window height in pixels. 00086 */ 00087 virtual void window(int x, int y, int w, int h); 00088 00089 /** Read pixel color at location 00090 * @param x is the horizontal offset to this pixel. 00091 * @param y is the vertical offset to this pixel. 00092 * @returns 16bit color, 0000=Black(pixel set), FFFF=White(pixel clear). 00093 */ 00094 virtual unsigned short pixelread(int x, int y); 00095 00096 /** Push a single pixel into the window and increment position. 00097 * You must first call window() then push pixels in loop. 00098 * @param color is the pixel color. 00099 */ 00100 virtual void window_pushpixel(unsigned short color); 00101 00102 /** Push some pixels of the same color into the window and increment position. 00103 * You must first call window() then push pixels. 00104 * @param color is the pixel color. 00105 * @param count: how many 00106 */ 00107 virtual void window_pushpixel(unsigned short color, unsigned int count); 00108 00109 /** Push array of pixel colors into the window and increment position. 00110 * You must first call window() then push pixels. 00111 * @param color is the pixel color. 00112 */ 00113 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght); 00114 00115 /** Framebuffer is used, it needs to be sent to LCD from time to time 00116 */ 00117 virtual void copy_to_lcd(); 00118 00119 /** set the contrast of the screen 00120 * 00121 * @param o contrast 0-63 00122 * @note may be overrided in case of not standard command 00123 */ 00124 virtual void set_contrast(int o); 00125 00126 /** read the contrast level 00127 * 00128 */ 00129 int get_contrast(void); 00130 00131 /** display inverted colors 00132 * 00133 * @param o = 0 normal, 1 invert 00134 */ 00135 void invert(unsigned char o); 00136 00137 /** clear the entire screen 00138 * The inherited one sets windomax then fill with background color 00139 * We override it to speedup 00140 */ 00141 virtual void cls(); 00142 00143 /** Set the orientation of the screen 00144 * x,y: 0,0 is always top left 00145 * 00146 * @param o direction to use the screen (0-3) 00147 * 0 = -90° 00148 * 1 = default 0° 00149 * 2 = +90° 00150 * 3 = +180° 00151 * 00152 */ 00153 void set_orientation(int o); 00154 00155 /** Set ChipSelect high or low 00156 * @param enable 0/1 00157 */ 00158 virtual void BusEnable(bool enable); 00159 00160 /** get display X size in pixels (native, orientation independent) 00161 * @returns X size in pixels 00162 */ 00163 int sizeX(); 00164 00165 /** get display Y size in pixels (native, orientation independent) 00166 * @returns Y size in pixels 00167 */ 00168 int sizeY(); 00169 00170 //////////////////////////////////////////////////////////////////////////////// 00171 // not implemented yet 00172 ////////////////////////////////////////////////////////////////// 00173 // virtual unsigned short pixelread(int x, int y){return 0;}; 00174 virtual void window4read(int x, int y, int w, int h){}; 00175 void setscrollarea (int startY, int areasize){}; 00176 void scroll (int lines){}; 00177 void scrollreset(){}; 00178 void FastWindow(bool enable){}; 00179 00180 unsigned int tftID; 00181 00182 00183 00184 00185 protected: 00186 00187 /** set mirror mode 00188 * @note may be overridden by specific display init class in case of not standard cmds or inverted wiring 00189 * @param mode NONE, X, Y, XY 00190 */ 00191 virtual void mirrorXY(mirror_t mode); 00192 00193 ////// functions needed by parent class /////////////////////////////////////// 00194 ////// -------------------------------- /////////////////////////////////////// 00195 00196 /** Send 8bit command to display controller 00197 * 00198 * @param cmd: byte to send 00199 * @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 00200 */ 00201 void wr_cmd8(unsigned char cmd); 00202 00203 /** Send 8bit data to display controller 00204 * 00205 * @param data: byte to send 00206 * 00207 */ 00208 void wr_data8(unsigned char data); 00209 00210 /** Send 16bit command to display controller 00211 * 00212 * @param cmd: halfword to send 00213 * 00214 */ 00215 void wr_cmd16(unsigned short cmd); 00216 00217 /** Send same 16bit pixeldata to display controller multiple times 00218 * 00219 * @param data: halfword to send 00220 * @param count: how many 00221 * 00222 */ 00223 virtual void wr_gram(unsigned short data, unsigned int count); 00224 00225 /** Send array of pixeldata shorts to display controller 00226 * 00227 * @param data: unsigned short pixeldata array 00228 * @param lenght: lenght (in shorts) 00229 * 00230 */ 00231 virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 00232 00233 /** HW reset sequence (without display init commands) 00234 */ 00235 void hw_reset(); 00236 00237 int draw_mode; 00238 int contrast; 00239 00240 private: 00241 00242 Protocols* proto; 00243 unsigned char *buffer; 00244 unsigned short *buffer16; 00245 const int screensize_X; 00246 const int screensize_Y; 00247 const int _LCDPAGES; 00248 const int _IC_X_SEGS; 00249 const int _IC_Y_COMS; 00250 const int _IC_PAGES; 00251 00252 int page_offset; 00253 int col_offset; 00254 // pixel location 00255 int cur_x; 00256 int cur_y; 00257 // window location 00258 int win_x1; 00259 int win_x2; 00260 int win_y1; 00261 int win_y2; 00262 int orientation; 00263 bool useNOP; 00264 }; 00265 00266 #endif
Generated on Fri Jul 15 2022 13:58:04 by
