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.
DISCOF469SerialLCD.h
00001 /* DISCOF469SerialLCD Library v1.0 00002 * Copyright (c) 2018 Grant Phillips 00003 * grant.phillips@mandela.ac.za 00004 * 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a copy 00007 * of this software and associated documentation files (the "Software"), to deal 00008 * in the Software without restriction, including without limitation the rights 00009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00010 * copies of the Software, and to permit persons to whom the Software is 00011 * furnished to do so, subject to the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be included in 00014 * all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00022 * THE SOFTWARE. 00023 */ 00024 00025 #ifndef DISCOF469SerialLCD_H 00026 #define DISCOF469SerialLCD_H 00027 00028 #include "mbed.h" 00029 #include "BufferedSerial.h" 00030 #include <inttypes.h> 00031 00032 #define LCD_WHITE 0xffffffff 00033 #define LCD_SILVER 0xffC0C0C0 00034 #define LCD_GRAY 0xff808080 00035 #define LCD_BLACK 0xff000000 00036 #define LCD_RED 0xffff0000 00037 #define LCD_MAROON 0xff800000 00038 #define LCD_YELLOW 0xffffff00 00039 #define LCD_OLIVE 0xff808000 00040 #define LCD_LIME 0xff00ff00 00041 #define LCD_GREEN 0xff008000 00042 #define LCD_AQUA 0xff00ffff 00043 #define LCD_TEAL 0xff008080 00044 #define LCD_BLUE 0xff0000ff 00045 #define LCD_NAVY 0xff000080 00046 #define LCD_FUCHSIA 0xffff00ff 00047 #define LCD_PURPLE 0xff800080 00048 00049 /** Class library for a serial lcd implemented on a DISCO-F469NI Development board running 00050 * specific firmware for this purpose. 00051 * 00052 * Example: 00053 * @code 00054 * #include "mbed.h" 00055 * #include "DISCOF469SerialLCD.h" 00056 * 00057 * DISCOF469SerialLCD lcd(PA_0, PA_1); //tx, rx 00058 * 00059 * void DisplayPattern(void); 00060 * 00061 * int main() { 00062 * char buf[40]; 00063 * int numtouches; 00064 * bool cleared = false; 00065 * uint16_t x1, y1, x2, y2; 00066 * 00067 * DisplayPattern(); 00068 * lcd.LED1(1); 00069 * wait(1.0); 00070 * lcd.LED2(1); 00071 * wait(1.0); 00072 * lcd.LED3(1); 00073 * wait(1.0); 00074 * lcd.LED4(1); 00075 * wait(1.0); 00076 * lcd.Clear(LCD_WHITE); 00077 * lcd.LED1(0); 00078 * lcd.LED2(0); 00079 * lcd.LED3(0); 00080 * lcd.LED4(0); 00081 * 00082 * while(1) 00083 * { 00084 * numtouches = lcd.Touches(); //read if the screen is touched 00085 * if(numtouches > 0) //has the screen been touched? 00086 * { 00087 * cleared = false; //reset clear flag 00088 * if(numtouches == 1) //if one finger is on the screen 00089 * { 00090 * lcd.GetTouch1(&x1, &y1); 00091 * sprintf(buf, "Touch 1: x=%3u y=%3u", x1, y1); 00092 * lcd.DrawStringAtLine(0,4,LCD_BLUE, LCD_WHITE, 0, buf); 00093 * lcd.FillCircle(x1, y1, 50, LCD_RED); 00094 * } 00095 * else if(numtouches == 2) //if two fingers are on the screen 00096 * { 00097 * lcd.GetTouch1(&x1, &y1); 00098 * lcd.GetTouch2(&x2, &y2); 00099 * sprintf(buf, "Touch 1: x=%3u y=%3u", x1, y1); 00100 * lcd.DrawStringAtLine(0,4,LCD_BLUE, LCD_WHITE, 0, buf); 00101 * sprintf(buf, "Touch 2: x=%3u y=%3u", x2, y2); 00102 * lcd.DrawStringAtLine(1,4,LCD_BLUE, LCD_WHITE, 0, buf); 00103 * lcd.FillCircle(x1, y1, 50, LCD_RED); 00104 * lcd.FillCircle(x2, y2, 50, LCD_BLUE); 00105 * } 00106 * } 00107 * else 00108 * { 00109 * if(!cleared) //if the screen hasn't been cleared 00110 * { 00111 * lcd.Clear(LCD_WHITE); //clear the screen after fingers left screen 00112 * cleared = true; 00113 * } 00114 * } 00115 * } 00116 * } 00117 * 00118 * void DisplayPattern(void) 00119 * { 00120 * lcd.FillRectangle(0, 0, 50, 479,LCD_WHITE); 00121 * lcd.FillRectangle(50, 0, 50, 479,LCD_SILVER); 00122 * lcd.FillRectangle(100, 0, 50, 479,LCD_GRAY); 00123 * lcd.FillRectangle(150, 0, 50, 479,LCD_BLACK); 00124 * lcd.FillRectangle(200, 0, 50, 479,LCD_RED); 00125 * lcd.FillRectangle(250, 0, 50, 479,LCD_MAROON); 00126 * lcd.FillRectangle(300, 0, 50, 479,LCD_YELLOW); 00127 * lcd.FillRectangle(350, 0, 50, 479,LCD_OLIVE); 00128 * lcd.FillRectangle(400, 0, 50, 479,LCD_LIME); 00129 * lcd.FillRectangle(450, 0, 50, 479,LCD_GREEN); 00130 * lcd.FillRectangle(500, 0, 50, 479,LCD_AQUA); 00131 * lcd.FillRectangle(550, 0, 50, 479,LCD_TEAL); 00132 * lcd.FillRectangle(600, 0, 50, 479,LCD_BLUE); 00133 * lcd.FillRectangle(650, 0, 50, 479,LCD_NAVY); 00134 * lcd.FillRectangle(700, 0, 50, 479,LCD_FUCHSIA); 00135 * lcd.FillRectangle(750, 0, 50, 479,LCD_PURPLE); 00136 * lcd.DrawStringAtXY(0, 0, 1, LCD_WHITE, LCD_BLACK, "White"); 00137 * lcd.DrawStringAtXY(50, 0, 1, LCD_WHITE, LCD_BLACK, "Silver"); 00138 * lcd.DrawStringAtXY(100, 0, 1, LCD_WHITE, LCD_BLACK, "Gray"); 00139 * lcd.DrawStringAtXY(150, 0, 1, LCD_WHITE, LCD_BLACK, "Black"); 00140 * lcd.DrawStringAtXY(200, 0, 1, LCD_WHITE, LCD_BLACK, "Red"); 00141 * lcd.DrawStringAtXY(250, 0, 1, LCD_WHITE, LCD_BLACK, "Maroon"); 00142 * lcd.DrawStringAtXY(300, 0, 1, LCD_WHITE, LCD_BLACK, "Yellow"); 00143 * lcd.DrawStringAtXY(350, 0, 1, LCD_WHITE, LCD_BLACK, "Olive"); 00144 * lcd.DrawStringAtXY(400, 0, 1, LCD_WHITE, LCD_BLACK, "Lime"); 00145 * lcd.DrawStringAtXY(450, 0, 1, LCD_WHITE, LCD_BLACK, "Green"); 00146 * lcd.DrawStringAtXY(500, 0, 1, LCD_WHITE, LCD_BLACK, "Aqua"); 00147 * lcd.DrawStringAtXY(550, 0, 1, LCD_WHITE, LCD_BLACK, "Teal"); 00148 * lcd.DrawStringAtXY(600, 0, 1, LCD_WHITE, LCD_BLACK, "Blue"); 00149 * lcd.DrawStringAtXY(650, 0, 1, LCD_WHITE, LCD_BLACK, "Navy"); 00150 * lcd.DrawStringAtXY(700, 0, 1, LCD_WHITE, LCD_BLACK, "Fuchsia"); 00151 * lcd.DrawStringAtXY(750, 0, 1, LCD_WHITE, LCD_BLACK, "Purple"); 00152 * } 00153 * @endcode 00154 */ 00155 00156 class DISCOF469SerialLCD { 00157 public: 00158 /** Create a DISCOF469SerialLCD object for a graphics LCD connected to the specified pins. 00159 * @param Tx USART TX pin used to connect to Nextion LCD's RX pin 00160 * @param Rx USART RX pin used to connect to Nextion LCD's TX pin 00161 */ 00162 DISCOF469SerialLCD(PinName Tx, PinName Rx); 00163 00164 /** 00165 * @brief Clears the LCD by filling it with the specified color pixels. 00166 * @param Color Color to fill the screen with - represented in ARGB8888 color space format. 00167 */ 00168 void Clear(uint32_t Color); 00169 00170 /** 00171 * @brief Draws a pixel on the LCD. 00172 * @param Xpos X position 00173 * @param Ypos Y position 00174 * @param Color Pixel color in ARGB mode (8-8-8-8) 00175 */ 00176 void DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t Color); 00177 00178 /** 00179 * @brief Reads the color of an LCD pixel. 00180 * @param Xpos X position 00181 * @param Ypos Y position 00182 * @retval uint32_t Pixel color in ARGB mode (8-8-8-8) 00183 */ 00184 uint32_t ReadPixel(uint16_t Xpos, uint16_t Ypos); 00185 00186 /** 00187 * @brief Draws a line on the LCD. 00188 * @param x1 Point 1 X position 00189 * @param y1 Point 1 Y position 00190 * @param x2 Point 2 X position 00191 * @param y2 Point 2 Y position 00192 * @param Color Line color in ARGB mode (8-8-8-8) 00193 */ 00194 void DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t Color); 00195 00196 /** 00197 * @brief Draws a rectangle on the LCD. 00198 * @param Xpos X position 00199 * @param Ypos Y position 00200 * @param Width Rectangle width 00201 * @param Height Rectangle height 00202 * @param Color Rectangle color in ARGB mode (8-8-8-8) 00203 */ 00204 void DrawRectangle(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height, uint32_t Color); 00205 00206 /** 00207 * @brief Draws a filled rectangle on the LCD. 00208 * @param Xpos X position 00209 * @param Ypos Y position 00210 * @param Width Rectangle width 00211 * @param Height Rectangle height 00212 * @param Color Rectangle color in ARGB mode (8-8-8-8) 00213 */ 00214 void FillRectangle(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height, uint32_t Color); 00215 00216 /** 00217 * @brief Draws a circle on the LCD. 00218 * @param Xpos X position 00219 * @param Ypos Y position 00220 * @param Radius Circle radius 00221 * @param Color Circle color in ARGB mode (8-8-8-8) 00222 */ 00223 void DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius, uint32_t Color); 00224 00225 /** 00226 * @brief Draws a filled circle on the LCD. 00227 * @param Xpos X position 00228 * @param Ypos Y position 00229 * @param Radius Circle radius 00230 * @param Color Circle color in ARGB mode (8-8-8-8) 00231 */ 00232 void FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius, uint32_t Color); 00233 00234 /** 00235 * @brief Draws an ellipse on the LCD. 00236 * @param Xpos X position 00237 * @param Ypos Y position 00238 * @param XRadius Ellipse X radius 00239 * @param YRadius Ellipse Y radius 00240 * @param Color Ellipse color in ARGB mode (8-8-8-8) 00241 */ 00242 void DrawEllipse(uint16_t Xpos, uint16_t Ypos, uint16_t XRadius, uint16_t YRadius, uint32_t Color); 00243 00244 /** 00245 * @brief Draws a filled ellipse on the LCD. 00246 * @param Xpos X position 00247 * @param Ypos Y position 00248 * @param XRadius Ellipse X radius 00249 * @param YRadius Ellipse Y radius 00250 * @param Color Ellipse color in ARGB mode (8-8-8-8) 00251 */ 00252 void FillEllipse(uint16_t Xpos, uint16_t Ypos, uint16_t XRadius, uint16_t YRadius, uint32_t Color); 00253 00254 /** 00255 * @brief Displays a string on the LCD at Xpos,Ypos. 00256 * @param Xpos X position (in pixel) 00257 * @param Ypos Y position (in pixel) 00258 * @param FontSize The size of the text (0 - 4) 00259 * @param TextColor The text foreground color 00260 * @param BackColor The text background color 00261 * @param Text String to display on LCD 00262 */ 00263 void DrawStringAtXY(uint16_t Xpos, uint16_t Ypos, uint8_t FontSize, uint32_t TextColor, uint32_t BackColor, char *Text); 00264 00265 /** 00266 * @brief Displays a string on the LCD at a certain line based on the font size. 00267 * @param Line Line where to display the string 00268 * @param FontSize The size of the text (0 - 4) 00269 * @param TextColor The text foreground color 00270 * @param BackColor The text background color 00271 * @param Mode Display mode (0=LEFT mode; 1=CENTER mode; 2=RIGHT mode) 00272 * @param Text String to display on LCD 00273 */ 00274 void DrawStringAtLine(uint16_t Line, uint8_t FontSize, uint32_t TextColor, uint32_t BackColor, uint8_t Mode, char *Text); 00275 00276 /** Determines if the touchscreen is being touched or not. 00277 * 00278 * @retval uint8_t Number of simulantanous touches on screen. 0 = not touched. 00279 */ 00280 uint8_t Touches(void); 00281 00282 /** 00283 * @brief Gets the x and y coordinates of the first touch on the touchscreen. 00284 * @param x Pointer to the x coordinate 00285 * @param y Pointer to the y coordinate 00286 */ 00287 void GetTouch1(uint16_t *x, uint16_t *y); 00288 00289 /** 00290 * @brief Gets the x and y coordinates of the second touch on the touchscreen. 00291 * @param x Pointer to the x coordinate 00292 * @param y Pointer to the y coordinate 00293 */ 00294 void GetTouch2(uint16_t *x, uint16_t *y); 00295 00296 /** 00297 * @brief Writes to the LCD's LED1. 00298 * @param OnOff 1 = On; 0 = Off 00299 */ 00300 void LED1(uint8_t OnOff); 00301 00302 /** 00303 * @brief Writes to the LCD's LED1. 00304 * @param OnOff 1 = On; 0 = Off 00305 */ 00306 void LED2(uint8_t OnOff); 00307 00308 /** 00309 * @brief Writes to the LCD's LED1. 00310 * @param OnOff 1 = On; 0 = Off 00311 */ 00312 void LED3(uint8_t OnOff); 00313 00314 /** 00315 * @brief Writes to the LCD's LED1. 00316 * @param OnOff 1 = On; 0 = Off 00317 */ 00318 void LED4(uint8_t OnOff); 00319 00320 00321 00322 private: 00323 00324 00325 BufferedSerial lcd; //Serial object for connecting to LCD 00326 //Serial pc; 00327 uint8_t mTouches; 00328 uint16_t mTouch1X, mTouch1Y,mTouch2X, mTouch2Y; 00329 uint32_t mReadPixelColor; 00330 int mcnt; 00331 00332 char mRxMsg[40]; 00333 int mRxIdx; 00334 char cmd[5]; 00335 uint32_t data32_0; 00336 uint16_t data16_0, data16_1; 00337 uint8_t data8_0; 00338 void ServiceSerialRX(void); //Rx Interrupt 00339 }; 00340 00341 #endif
Generated on Sun Jul 24 2022 08:02:25 by
1.7.2