Class library for a serial lcd implemented on a DISCO-F469NI Development board running specific firmware for this purpose.

Dependencies:   BufferedSerial

Committer:
grantphillips
Date:
Sun Feb 18 20:21:55 2018 +0000
Revision:
4:df0201a66e39
Parent:
0:3f62b3c0ec9a
v1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
grantphillips 0:3f62b3c0ec9a 1 #include "DISCOF469SerialLCD.h"
grantphillips 0:3f62b3c0ec9a 2 #include "mbed.h"
grantphillips 0:3f62b3c0ec9a 3
grantphillips 0:3f62b3c0ec9a 4
grantphillips 0:3f62b3c0ec9a 5 /* ***************************************** Public Functions ***************************************** */
grantphillips 0:3f62b3c0ec9a 6
grantphillips 0:3f62b3c0ec9a 7 DISCOF469SerialLCD::DISCOF469SerialLCD(PinName Tx, PinName Rx) : lcd(Tx, Rx, 500, 100, NULL) {
grantphillips 0:3f62b3c0ec9a 8 lcd.baud(57600);
grantphillips 0:3f62b3c0ec9a 9
grantphillips 0:3f62b3c0ec9a 10 mTouches=0;
grantphillips 0:3f62b3c0ec9a 11 mRxIdx=0;
grantphillips 0:3f62b3c0ec9a 12
grantphillips 0:3f62b3c0ec9a 13
grantphillips 0:3f62b3c0ec9a 14 mReadPixelColor = 0;
grantphillips 0:3f62b3c0ec9a 15 mcnt=0;
grantphillips 0:3f62b3c0ec9a 16 Clear(LCD_BLACK);
grantphillips 0:3f62b3c0ec9a 17 }
grantphillips 0:3f62b3c0ec9a 18
grantphillips 0:3f62b3c0ec9a 19 void DISCOF469SerialLCD::Clear(uint32_t Color) {
grantphillips 0:3f62b3c0ec9a 20 lcd.printf("CLR %u###", Color);
grantphillips 0:3f62b3c0ec9a 21 }
grantphillips 0:3f62b3c0ec9a 22
grantphillips 0:3f62b3c0ec9a 23 void DISCOF469SerialLCD::DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t Color) {
grantphillips 0:3f62b3c0ec9a 24 lcd.printf("DPX %d %d %d###", Xpos, Ypos, Color);
grantphillips 0:3f62b3c0ec9a 25 }
grantphillips 0:3f62b3c0ec9a 26
grantphillips 0:3f62b3c0ec9a 27 uint32_t DISCOF469SerialLCD::ReadPixel(uint16_t Xpos, uint16_t Ypos) {
grantphillips 0:3f62b3c0ec9a 28 uint32_t temp;
grantphillips 0:3f62b3c0ec9a 29
grantphillips 0:3f62b3c0ec9a 30 lcd.printf("RPX %u %u###", Xpos, Ypos);
grantphillips 0:3f62b3c0ec9a 31 while(mReadPixelColor == 0) {
grantphillips 0:3f62b3c0ec9a 32 ServiceSerialRX();
grantphillips 0:3f62b3c0ec9a 33 }
grantphillips 0:3f62b3c0ec9a 34
grantphillips 0:3f62b3c0ec9a 35 temp = mReadPixelColor;
grantphillips 0:3f62b3c0ec9a 36 mReadPixelColor=0;
grantphillips 0:3f62b3c0ec9a 37 return temp;
grantphillips 0:3f62b3c0ec9a 38 }
grantphillips 0:3f62b3c0ec9a 39
grantphillips 0:3f62b3c0ec9a 40 void DISCOF469SerialLCD::DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t Color) {
grantphillips 0:3f62b3c0ec9a 41 lcd.printf("DLI %u %u %u %u %u###", x1, y1, x2, y2, Color);
grantphillips 0:3f62b3c0ec9a 42 }
grantphillips 0:3f62b3c0ec9a 43
grantphillips 0:3f62b3c0ec9a 44 void DISCOF469SerialLCD::DrawRectangle(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height, uint32_t Color) {
grantphillips 0:3f62b3c0ec9a 45 lcd.printf("DRE %u %u %u %u %u###", Xpos, Ypos, Width, Height, Color);
grantphillips 0:3f62b3c0ec9a 46 }
grantphillips 0:3f62b3c0ec9a 47
grantphillips 0:3f62b3c0ec9a 48 void DISCOF469SerialLCD::FillRectangle(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height, uint32_t Color) {
grantphillips 0:3f62b3c0ec9a 49 lcd.printf("FRE %u %u %u %u %u###", Xpos, Ypos, Width, Height, Color);
grantphillips 0:3f62b3c0ec9a 50 }
grantphillips 0:3f62b3c0ec9a 51
grantphillips 0:3f62b3c0ec9a 52 void DISCOF469SerialLCD::DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius, uint32_t Color) {
grantphillips 0:3f62b3c0ec9a 53 lcd.printf("DCI %u %u %u %u###", Xpos, Ypos, Radius, Color);
grantphillips 0:3f62b3c0ec9a 54 }
grantphillips 0:3f62b3c0ec9a 55
grantphillips 0:3f62b3c0ec9a 56 void DISCOF469SerialLCD::FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius, uint32_t Color) {
grantphillips 0:3f62b3c0ec9a 57 lcd.printf("FCI %u %u %u %u###", Xpos, Ypos, Radius, Color);
grantphillips 0:3f62b3c0ec9a 58 }
grantphillips 0:3f62b3c0ec9a 59
grantphillips 0:3f62b3c0ec9a 60 void DISCOF469SerialLCD::DrawEllipse(uint16_t Xpos, uint16_t Ypos, uint16_t XRadius, uint16_t YRadius, uint32_t Color) {
grantphillips 0:3f62b3c0ec9a 61 lcd.printf("DEL %u %u %u %u %u###", Xpos, Ypos, XRadius, YRadius, Color);
grantphillips 0:3f62b3c0ec9a 62 }
grantphillips 0:3f62b3c0ec9a 63
grantphillips 0:3f62b3c0ec9a 64 void DISCOF469SerialLCD::FillEllipse(uint16_t Xpos, uint16_t Ypos, uint16_t XRadius, uint16_t YRadius, uint32_t Color) {
grantphillips 0:3f62b3c0ec9a 65 lcd.printf("FEL %u %u %u %u %u###", Xpos, Ypos, XRadius, YRadius, Color);
grantphillips 0:3f62b3c0ec9a 66 }
grantphillips 0:3f62b3c0ec9a 67
grantphillips 0:3f62b3c0ec9a 68 void DISCOF469SerialLCD::DrawStringAtXY(uint16_t Xpos, uint16_t Ypos, uint8_t FontSize, uint32_t TextColor, uint32_t BackColor, char *Text) {
grantphillips 0:3f62b3c0ec9a 69 lcd.printf("DSX %u %u %u %u %u %s###", Xpos, Ypos, FontSize, TextColor, BackColor, Text);
grantphillips 0:3f62b3c0ec9a 70 }
grantphillips 0:3f62b3c0ec9a 71
grantphillips 0:3f62b3c0ec9a 72 void DISCOF469SerialLCD::DrawStringAtLine(uint16_t Line, uint8_t FontSize, uint32_t TextColor, uint32_t BackColor, uint8_t Mode, char *Text) {
grantphillips 0:3f62b3c0ec9a 73 lcd.printf("DSL %u %u %u %u %u %s###", Line, FontSize, TextColor, BackColor, Mode, Text);
grantphillips 0:3f62b3c0ec9a 74 }
grantphillips 0:3f62b3c0ec9a 75
grantphillips 0:3f62b3c0ec9a 76 uint8_t DISCOF469SerialLCD::Touches(void) {
grantphillips 0:3f62b3c0ec9a 77 lcd.printf("TCS###");
grantphillips 0:3f62b3c0ec9a 78 mTouches = 0xff; // dummy setting
grantphillips 0:3f62b3c0ec9a 79 while(mTouches == 0xff) {
grantphillips 0:3f62b3c0ec9a 80 ServiceSerialRX();
grantphillips 0:3f62b3c0ec9a 81 }
grantphillips 0:3f62b3c0ec9a 82 return mTouches;
grantphillips 0:3f62b3c0ec9a 83 }
grantphillips 0:3f62b3c0ec9a 84
grantphillips 0:3f62b3c0ec9a 85 void DISCOF469SerialLCD::GetTouch1(uint16_t *x, uint16_t *y) {
grantphillips 0:3f62b3c0ec9a 86 lcd.printf("T1C###");
grantphillips 0:3f62b3c0ec9a 87 mTouch1X = 0xffff; // dummy setting
grantphillips 0:3f62b3c0ec9a 88 while(mTouch1X == 0xffff) {
grantphillips 0:3f62b3c0ec9a 89 ServiceSerialRX();
grantphillips 0:3f62b3c0ec9a 90 }
grantphillips 0:3f62b3c0ec9a 91 *x = mTouch1X;
grantphillips 0:3f62b3c0ec9a 92 *y = mTouch1Y;
grantphillips 0:3f62b3c0ec9a 93 }
grantphillips 0:3f62b3c0ec9a 94
grantphillips 0:3f62b3c0ec9a 95 void DISCOF469SerialLCD::GetTouch2(uint16_t *x, uint16_t *y) {
grantphillips 0:3f62b3c0ec9a 96 lcd.printf("T2C###");
grantphillips 0:3f62b3c0ec9a 97 mTouch2X = 0xffff; // dummy setting
grantphillips 0:3f62b3c0ec9a 98 while(mTouch2X == 0xffff) {
grantphillips 0:3f62b3c0ec9a 99 ServiceSerialRX();
grantphillips 0:3f62b3c0ec9a 100 }
grantphillips 0:3f62b3c0ec9a 101 *x = mTouch2X;
grantphillips 0:3f62b3c0ec9a 102 *y = mTouch2Y;
grantphillips 0:3f62b3c0ec9a 103 }
grantphillips 0:3f62b3c0ec9a 104
grantphillips 0:3f62b3c0ec9a 105 void DISCOF469SerialLCD::LED1(uint8_t OnOff) {
grantphillips 0:3f62b3c0ec9a 106 lcd.printf("LD1 %d###", 1-OnOff);
grantphillips 0:3f62b3c0ec9a 107 }
grantphillips 0:3f62b3c0ec9a 108
grantphillips 0:3f62b3c0ec9a 109 void DISCOF469SerialLCD::LED2(uint8_t OnOff) {
grantphillips 0:3f62b3c0ec9a 110 lcd.printf("LD2 %d###", 1-OnOff);
grantphillips 0:3f62b3c0ec9a 111 }
grantphillips 0:3f62b3c0ec9a 112
grantphillips 0:3f62b3c0ec9a 113 void DISCOF469SerialLCD::LED3(uint8_t OnOff) {
grantphillips 0:3f62b3c0ec9a 114 lcd.printf("LD3 %d###", 1-OnOff);
grantphillips 0:3f62b3c0ec9a 115 }
grantphillips 0:3f62b3c0ec9a 116
grantphillips 0:3f62b3c0ec9a 117 void DISCOF469SerialLCD::LED4(uint8_t OnOff) {
grantphillips 0:3f62b3c0ec9a 118 lcd.printf("LD4 %d###", 1-OnOff);
grantphillips 0:3f62b3c0ec9a 119 }
grantphillips 0:3f62b3c0ec9a 120
grantphillips 0:3f62b3c0ec9a 121 /* ***************************************** Private Functions ***************************************** */
grantphillips 0:3f62b3c0ec9a 122
grantphillips 0:3f62b3c0ec9a 123 void DISCOF469SerialLCD::ServiceSerialRX(void) {
grantphillips 0:3f62b3c0ec9a 124 char c;
grantphillips 0:3f62b3c0ec9a 125
grantphillips 0:3f62b3c0ec9a 126 if(lcd.readable()) {
grantphillips 0:3f62b3c0ec9a 127 c = lcd.getc();
grantphillips 0:3f62b3c0ec9a 128 mRxMsg[mRxIdx] = c;
grantphillips 0:3f62b3c0ec9a 129 mRxIdx++;
grantphillips 0:3f62b3c0ec9a 130
grantphillips 0:3f62b3c0ec9a 131 if ((mRxIdx >= 3) && (mRxMsg[mRxIdx-3] == '#') && (mRxMsg[mRxIdx-2] == '#') && (mRxMsg[mRxIdx-1] == '#')) { //valid rx message
grantphillips 0:3f62b3c0ec9a 132 strncpy(cmd, mRxMsg, 3);
grantphillips 0:3f62b3c0ec9a 133 mRxMsg[mRxIdx-3]='\0';
grantphillips 0:3f62b3c0ec9a 134 mRxIdx=0;
grantphillips 0:3f62b3c0ec9a 135
grantphillips 0:3f62b3c0ec9a 136 if(strcmp(cmd, "-PX")==0) // ---------- Read Pixel return
grantphillips 0:3f62b3c0ec9a 137 {
grantphillips 0:3f62b3c0ec9a 138 sscanf(mRxMsg, "%s %u", cmd, &data32_0); //cmd,Color
grantphillips 0:3f62b3c0ec9a 139 mReadPixelColor = data32_0;
grantphillips 0:3f62b3c0ec9a 140 }
grantphillips 0:3f62b3c0ec9a 141
grantphillips 0:3f62b3c0ec9a 142 else if(strcmp(cmd, "-CS")==0) // ---------- Touches return
grantphillips 0:3f62b3c0ec9a 143 {
grantphillips 4:df0201a66e39 144 sscanf(mRxMsg, "%s %hhu", cmd, &data8_0); //cmd, numTouches
grantphillips 0:3f62b3c0ec9a 145 mTouches = data8_0;
grantphillips 0:3f62b3c0ec9a 146 }
grantphillips 0:3f62b3c0ec9a 147
grantphillips 0:3f62b3c0ec9a 148 else if(strcmp(cmd, "-T1")==0) // ---------- GetTouch1 return
grantphillips 0:3f62b3c0ec9a 149 {
grantphillips 4:df0201a66e39 150 sscanf(mRxMsg, "%s %hu %hu", cmd, &data16_0, &data16_1); //cmd,x,y
grantphillips 0:3f62b3c0ec9a 151 mTouch1X = data16_0;
grantphillips 0:3f62b3c0ec9a 152 mTouch1Y = data16_1;
grantphillips 0:3f62b3c0ec9a 153 }
grantphillips 0:3f62b3c0ec9a 154
grantphillips 0:3f62b3c0ec9a 155 else if(strcmp(cmd, "-T2")==0) // ---------- GetTouch2 return
grantphillips 0:3f62b3c0ec9a 156 {
grantphillips 4:df0201a66e39 157 sscanf(mRxMsg, "%s %hu %hu", cmd, &data16_0, &data16_1); //cmd,x,y
grantphillips 0:3f62b3c0ec9a 158 mTouch2X = data16_0;
grantphillips 0:3f62b3c0ec9a 159 mTouch2Y = data16_1;
grantphillips 0:3f62b3c0ec9a 160 }
grantphillips 0:3f62b3c0ec9a 161 }
grantphillips 0:3f62b3c0ec9a 162 }
grantphillips 0:3f62b3c0ec9a 163 }