DISCO-F469NI_LCDTS_Test

Dependencies:   mbed LCD_DISCO_F469NI BSP_DISCO_F469NI

Committer:
junpapa
Date:
Tue Apr 27 10:55:10 2021 +0000
Revision:
0:7082d958eabc
TSLCD_TEST

Who changed what in which revision?

UserRevisionLine numberNew contents of line
junpapa 0:7082d958eabc 1 #include "mbed.h"
junpapa 0:7082d958eabc 2 #include "TS_DISCO_F469NI.h"
junpapa 0:7082d958eabc 3 #include "LCD_DISCO_F469NI.h"
junpapa 0:7082d958eabc 4
junpapa 0:7082d958eabc 5 LCD_DISCO_F469NI lcd;
junpapa 0:7082d958eabc 6 TS_DISCO_F469NI ts;
junpapa 0:7082d958eabc 7
junpapa 0:7082d958eabc 8 DigitalIn Key_Chk(USER_BUTTON);
junpapa 0:7082d958eabc 9 DigitalOut led1(LED1);
junpapa 0:7082d958eabc 10
junpapa 0:7082d958eabc 11 int main()
junpapa 0:7082d958eabc 12 {
junpapa 0:7082d958eabc 13 TS_StateTypeDef TS_State;
junpapa 0:7082d958eabc 14 uint16_t x, y;
junpapa 0:7082d958eabc 15 uint8_t text[30];
junpapa 0:7082d958eabc 16 uint8_t status;
junpapa 0:7082d958eabc 17 uint8_t idx;
junpapa 0:7082d958eabc 18 uint8_t cleared = 0;
junpapa 0:7082d958eabc 19 uint8_t prev_nb_touches = 0;
junpapa 0:7082d958eabc 20 //cs.
junpapa 0:7082d958eabc 21 uint8_t i, key, key_buf;
junpapa 0:7082d958eabc 22
junpapa 0:7082d958eabc 23 //if(Key_Chk) wait(1); //Key Pressed, 1
junpapa 0:7082d958eabc 24 //else wait(10);
junpapa 0:7082d958eabc 25
junpapa 0:7082d958eabc 26 BSP_LCD_SetFont(&Font24);
junpapa 0:7082d958eabc 27
junpapa 0:7082d958eabc 28 for (i=0; i<32; i++)
junpapa 0:7082d958eabc 29 {
junpapa 0:7082d958eabc 30 lcd.DisplayStringAt(0, LINE(i), (uint8_t *)"TOUCHSCREEN DEMO ", CENTER_MODE);
junpapa 0:7082d958eabc 31 }
junpapa 0:7082d958eabc 32
junpapa 0:7082d958eabc 33 //wait(10);
junpapa 0:7082d958eabc 34 while(1)
junpapa 0:7082d958eabc 35 {
junpapa 0:7082d958eabc 36 if(Key_Chk) break; //Key Pressed
junpapa 0:7082d958eabc 37 };
junpapa 0:7082d958eabc 38
junpapa 0:7082d958eabc 39 status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
junpapa 0:7082d958eabc 40 if (status != TS_OK)
junpapa 0:7082d958eabc 41 {
junpapa 0:7082d958eabc 42 lcd.Clear(LCD_COLOR_RED);
junpapa 0:7082d958eabc 43 lcd.SetBackColor(LCD_COLOR_RED);
junpapa 0:7082d958eabc 44 lcd.SetTextColor(LCD_COLOR_WHITE);
junpapa 0:7082d958eabc 45 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
junpapa 0:7082d958eabc 46 }
junpapa 0:7082d958eabc 47 else
junpapa 0:7082d958eabc 48 {
junpapa 0:7082d958eabc 49 lcd.Clear(LCD_COLOR_GREEN);
junpapa 0:7082d958eabc 50 lcd.SetBackColor(LCD_COLOR_GREEN);
junpapa 0:7082d958eabc 51 lcd.SetTextColor(LCD_COLOR_WHITE);
junpapa 0:7082d958eabc 52 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
junpapa 0:7082d958eabc 53 }
junpapa 0:7082d958eabc 54
junpapa 0:7082d958eabc 55 while(1)
junpapa 0:7082d958eabc 56 {
junpapa 0:7082d958eabc 57 if(Key_Chk) break; //Key Pressed
junpapa 0:7082d958eabc 58 };
junpapa 0:7082d958eabc 59
junpapa 0:7082d958eabc 60 wait(1);
junpapa 0:7082d958eabc 61 lcd.SetBackColor(LCD_COLOR_BLUE);
junpapa 0:7082d958eabc 62 lcd.SetTextColor(LCD_COLOR_WHITE);
junpapa 0:7082d958eabc 63
junpapa 0:7082d958eabc 64 while(1)
junpapa 0:7082d958eabc 65 {
junpapa 0:7082d958eabc 66
junpapa 0:7082d958eabc 67 ts.GetState(&TS_State);
junpapa 0:7082d958eabc 68 if (TS_State.touchDetected)
junpapa 0:7082d958eabc 69 {
junpapa 0:7082d958eabc 70 // Clear lines corresponding to old touches coordinates
junpapa 0:7082d958eabc 71 if (TS_State.touchDetected < prev_nb_touches)
junpapa 0:7082d958eabc 72 {
junpapa 0:7082d958eabc 73 for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++)
junpapa 0:7082d958eabc 74 {
junpapa 0:7082d958eabc 75 lcd.ClearStringLine(idx);
junpapa 0:7082d958eabc 76 }
junpapa 0:7082d958eabc 77 }
junpapa 0:7082d958eabc 78 prev_nb_touches = TS_State.touchDetected;
junpapa 0:7082d958eabc 79
junpapa 0:7082d958eabc 80 cleared = 0;
junpapa 0:7082d958eabc 81
junpapa 0:7082d958eabc 82 sprintf((char*)text, "Touches: %d", TS_State.touchDetected);
junpapa 0:7082d958eabc 83 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
junpapa 0:7082d958eabc 84
junpapa 0:7082d958eabc 85 for (idx = 0; idx < TS_State.touchDetected; idx++)
junpapa 0:7082d958eabc 86 {
junpapa 0:7082d958eabc 87 x = TS_State.touchX[idx];
junpapa 0:7082d958eabc 88 y = TS_State.touchY[idx];
junpapa 0:7082d958eabc 89 sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y);
junpapa 0:7082d958eabc 90 lcd.DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE);
junpapa 0:7082d958eabc 91 lcd.FillCircle(TS_State.touchX[idx], TS_State.touchY[idx], 20);
junpapa 0:7082d958eabc 92 }
junpapa 0:7082d958eabc 93 }
junpapa 0:7082d958eabc 94 else
junpapa 0:7082d958eabc 95 {
junpapa 0:7082d958eabc 96 if (!cleared)
junpapa 0:7082d958eabc 97 {
junpapa 0:7082d958eabc 98 lcd.Clear(LCD_COLOR_BLUE);
junpapa 0:7082d958eabc 99 sprintf((char*)text, "Touches: 0");
junpapa 0:7082d958eabc 100 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
junpapa 0:7082d958eabc 101 cleared = 1;
junpapa 0:7082d958eabc 102 }
junpapa 0:7082d958eabc 103 }
junpapa 0:7082d958eabc 104 }
junpapa 0:7082d958eabc 105 }