Class library for a serial lcd implemented on a DISCO-F469NI Development board running specific firmware for this purpose.
DISCOF469SerialLCD.cpp
00001 #include "DISCOF469SerialLCD.h" 00002 #include "mbed.h" 00003 00004 00005 /* ***************************************** Public Functions ***************************************** */ 00006 00007 DISCOF469SerialLCD::DISCOF469SerialLCD(PinName Tx, PinName Rx) : lcd(Tx, Rx, 500, 100, NULL) { 00008 lcd.baud(57600); 00009 00010 mTouches=0; 00011 mRxIdx=0; 00012 00013 00014 mReadPixelColor = 0; 00015 mcnt=0; 00016 Clear(LCD_BLACK); 00017 } 00018 00019 void DISCOF469SerialLCD::Clear(uint32_t Color) { 00020 lcd.printf("CLR %u###", Color); 00021 } 00022 00023 void DISCOF469SerialLCD::DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t Color) { 00024 lcd.printf("DPX %d %d %d###", Xpos, Ypos, Color); 00025 } 00026 00027 uint32_t DISCOF469SerialLCD::ReadPixel(uint16_t Xpos, uint16_t Ypos) { 00028 uint32_t temp; 00029 00030 lcd.printf("RPX %u %u###", Xpos, Ypos); 00031 while(mReadPixelColor == 0) { 00032 ServiceSerialRX(); 00033 } 00034 00035 temp = mReadPixelColor; 00036 mReadPixelColor=0; 00037 return temp; 00038 } 00039 00040 void DISCOF469SerialLCD::DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t Color) { 00041 lcd.printf("DLI %u %u %u %u %u###", x1, y1, x2, y2, Color); 00042 } 00043 00044 void DISCOF469SerialLCD::DrawRectangle(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height, uint32_t Color) { 00045 lcd.printf("DRE %u %u %u %u %u###", Xpos, Ypos, Width, Height, Color); 00046 } 00047 00048 void DISCOF469SerialLCD::FillRectangle(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height, uint32_t Color) { 00049 lcd.printf("FRE %u %u %u %u %u###", Xpos, Ypos, Width, Height, Color); 00050 } 00051 00052 void DISCOF469SerialLCD::DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius, uint32_t Color) { 00053 lcd.printf("DCI %u %u %u %u###", Xpos, Ypos, Radius, Color); 00054 } 00055 00056 void DISCOF469SerialLCD::FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius, uint32_t Color) { 00057 lcd.printf("FCI %u %u %u %u###", Xpos, Ypos, Radius, Color); 00058 } 00059 00060 void DISCOF469SerialLCD::DrawEllipse(uint16_t Xpos, uint16_t Ypos, uint16_t XRadius, uint16_t YRadius, uint32_t Color) { 00061 lcd.printf("DEL %u %u %u %u %u###", Xpos, Ypos, XRadius, YRadius, Color); 00062 } 00063 00064 void DISCOF469SerialLCD::FillEllipse(uint16_t Xpos, uint16_t Ypos, uint16_t XRadius, uint16_t YRadius, uint32_t Color) { 00065 lcd.printf("FEL %u %u %u %u %u###", Xpos, Ypos, XRadius, YRadius, Color); 00066 } 00067 00068 void DISCOF469SerialLCD::DrawStringAtXY(uint16_t Xpos, uint16_t Ypos, uint8_t FontSize, uint32_t TextColor, uint32_t BackColor, char *Text) { 00069 lcd.printf("DSX %u %u %u %u %u %s###", Xpos, Ypos, FontSize, TextColor, BackColor, Text); 00070 } 00071 00072 void DISCOF469SerialLCD::DrawStringAtLine(uint16_t Line, uint8_t FontSize, uint32_t TextColor, uint32_t BackColor, uint8_t Mode, char *Text) { 00073 lcd.printf("DSL %u %u %u %u %u %s###", Line, FontSize, TextColor, BackColor, Mode, Text); 00074 } 00075 00076 uint8_t DISCOF469SerialLCD::Touches(void) { 00077 lcd.printf("TCS###"); 00078 mTouches = 0xff; // dummy setting 00079 while(mTouches == 0xff) { 00080 ServiceSerialRX(); 00081 } 00082 return mTouches; 00083 } 00084 00085 void DISCOF469SerialLCD::GetTouch1(uint16_t *x, uint16_t *y) { 00086 lcd.printf("T1C###"); 00087 mTouch1X = 0xffff; // dummy setting 00088 while(mTouch1X == 0xffff) { 00089 ServiceSerialRX(); 00090 } 00091 *x = mTouch1X; 00092 *y = mTouch1Y; 00093 } 00094 00095 void DISCOF469SerialLCD::GetTouch2(uint16_t *x, uint16_t *y) { 00096 lcd.printf("T2C###"); 00097 mTouch2X = 0xffff; // dummy setting 00098 while(mTouch2X == 0xffff) { 00099 ServiceSerialRX(); 00100 } 00101 *x = mTouch2X; 00102 *y = mTouch2Y; 00103 } 00104 00105 void DISCOF469SerialLCD::LED1(uint8_t OnOff) { 00106 lcd.printf("LD1 %d###", 1-OnOff); 00107 } 00108 00109 void DISCOF469SerialLCD::LED2(uint8_t OnOff) { 00110 lcd.printf("LD2 %d###", 1-OnOff); 00111 } 00112 00113 void DISCOF469SerialLCD::LED3(uint8_t OnOff) { 00114 lcd.printf("LD3 %d###", 1-OnOff); 00115 } 00116 00117 void DISCOF469SerialLCD::LED4(uint8_t OnOff) { 00118 lcd.printf("LD4 %d###", 1-OnOff); 00119 } 00120 00121 /* ***************************************** Private Functions ***************************************** */ 00122 00123 void DISCOF469SerialLCD::ServiceSerialRX(void) { 00124 char c; 00125 00126 if(lcd.readable()) { 00127 c = lcd.getc(); 00128 mRxMsg[mRxIdx] = c; 00129 mRxIdx++; 00130 00131 if ((mRxIdx >= 3) && (mRxMsg[mRxIdx-3] == '#') && (mRxMsg[mRxIdx-2] == '#') && (mRxMsg[mRxIdx-1] == '#')) { //valid rx message 00132 strncpy(cmd, mRxMsg, 3); 00133 mRxMsg[mRxIdx-3]='\0'; 00134 mRxIdx=0; 00135 00136 if(strcmp(cmd, "-PX")==0) // ---------- Read Pixel return 00137 { 00138 sscanf(mRxMsg, "%s %u", cmd, &data32_0); //cmd,Color 00139 mReadPixelColor = data32_0; 00140 } 00141 00142 else if(strcmp(cmd, "-CS")==0) // ---------- Touches return 00143 { 00144 sscanf(mRxMsg, "%s %hhu", cmd, &data8_0); //cmd, numTouches 00145 mTouches = data8_0; 00146 } 00147 00148 else if(strcmp(cmd, "-T1")==0) // ---------- GetTouch1 return 00149 { 00150 sscanf(mRxMsg, "%s %hu %hu", cmd, &data16_0, &data16_1); //cmd,x,y 00151 mTouch1X = data16_0; 00152 mTouch1Y = data16_1; 00153 } 00154 00155 else if(strcmp(cmd, "-T2")==0) // ---------- GetTouch2 return 00156 { 00157 sscanf(mRxMsg, "%s %hu %hu", cmd, &data16_0, &data16_1); //cmd,x,y 00158 mTouch2X = data16_0; 00159 mTouch2Y = data16_1; 00160 } 00161 } 00162 } 00163 }
Generated on Sun Jul 24 2022 08:02:25 by
