lab 2
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI
main.cpp@0:a5dadd221532, 2021-12-16 (annotated)
- Committer:
- ovcharka132
- Date:
- Thu Dec 16 12:13:34 2021 +0000
- Revision:
- 0:a5dadd221532
initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ovcharka132 | 0:a5dadd221532 | 1 | #include "mbed.h" |
ovcharka132 | 0:a5dadd221532 | 2 | #include "TS_DISCO_F429ZI.h" |
ovcharka132 | 0:a5dadd221532 | 3 | #include "LCD_DISCO_F429ZI.h" |
ovcharka132 | 0:a5dadd221532 | 4 | #include "stlogo.h" |
ovcharka132 | 0:a5dadd221532 | 5 | |
ovcharka132 | 0:a5dadd221532 | 6 | #define TOUCH_STRING_IDX 0 |
ovcharka132 | 0:a5dadd221532 | 7 | #define COORD_STRING_IDX 2 |
ovcharka132 | 0:a5dadd221532 | 8 | |
ovcharka132 | 0:a5dadd221532 | 9 | LCD_DISCO_F429ZI lcd; |
ovcharka132 | 0:a5dadd221532 | 10 | TS_DISCO_F429ZI ts; |
ovcharka132 | 0:a5dadd221532 | 11 | int main() |
ovcharka132 | 0:a5dadd221532 | 12 | { |
ovcharka132 | 0:a5dadd221532 | 13 | TS_StateTypeDef TS_State; |
ovcharka132 | 0:a5dadd221532 | 14 | uint32_t x, y; |
ovcharka132 | 0:a5dadd221532 | 15 | uint8_t text[30]; |
ovcharka132 | 0:a5dadd221532 | 16 | uint8_t status; |
ovcharka132 | 0:a5dadd221532 | 17 | uint8_t idx; |
ovcharka132 | 0:a5dadd221532 | 18 | bool cleared = false; |
ovcharka132 | 0:a5dadd221532 | 19 | |
ovcharka132 | 0:a5dadd221532 | 20 | BSP_LCD_SetFont(&Font20); |
ovcharka132 | 0:a5dadd221532 | 21 | |
ovcharka132 | 0:a5dadd221532 | 22 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); |
ovcharka132 | 0:a5dadd221532 | 23 | lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"DEMO", CENTER_MODE); |
ovcharka132 | 0:a5dadd221532 | 24 | wait(1); |
ovcharka132 | 0:a5dadd221532 | 25 | |
ovcharka132 | 0:a5dadd221532 | 26 | status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); |
ovcharka132 | 0:a5dadd221532 | 27 | |
ovcharka132 | 0:a5dadd221532 | 28 | if (status != TS_OK) |
ovcharka132 | 0:a5dadd221532 | 29 | { |
ovcharka132 | 0:a5dadd221532 | 30 | lcd.Clear(LCD_COLOR_RED); |
ovcharka132 | 0:a5dadd221532 | 31 | lcd.SetBackColor(LCD_COLOR_RED); |
ovcharka132 | 0:a5dadd221532 | 32 | lcd.SetTextColor(LCD_COLOR_WHITE); |
ovcharka132 | 0:a5dadd221532 | 33 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); |
ovcharka132 | 0:a5dadd221532 | 34 | lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE); |
ovcharka132 | 0:a5dadd221532 | 35 | } |
ovcharka132 | 0:a5dadd221532 | 36 | else |
ovcharka132 | 0:a5dadd221532 | 37 | { |
ovcharka132 | 0:a5dadd221532 | 38 | lcd.Clear(LCD_COLOR_GREEN); |
ovcharka132 | 0:a5dadd221532 | 39 | lcd.SetBackColor(LCD_COLOR_GREEN); |
ovcharka132 | 0:a5dadd221532 | 40 | lcd.SetTextColor(LCD_COLOR_WHITE); |
ovcharka132 | 0:a5dadd221532 | 41 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); |
ovcharka132 | 0:a5dadd221532 | 42 | lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE); |
ovcharka132 | 0:a5dadd221532 | 43 | } |
ovcharka132 | 0:a5dadd221532 | 44 | |
ovcharka132 | 0:a5dadd221532 | 45 | wait(1); |
ovcharka132 | 0:a5dadd221532 | 46 | lcd.Clear(LCD_COLOR_BLUE); |
ovcharka132 | 0:a5dadd221532 | 47 | lcd.SetBackColor(LCD_COLOR_BLUE); |
ovcharka132 | 0:a5dadd221532 | 48 | lcd.SetTextColor(LCD_COLOR_WHITE); |
ovcharka132 | 0:a5dadd221532 | 49 | |
ovcharka132 | 0:a5dadd221532 | 50 | while(1) { |
ovcharka132 | 0:a5dadd221532 | 51 | lcd.DrawBitmap(x, y, (uint8_t *)stlogo); |
ovcharka132 | 0:a5dadd221532 | 52 | ts.GetState(&TS_State); |
ovcharka132 | 0:a5dadd221532 | 53 | if (TS_State.TouchDetected) { |
ovcharka132 | 0:a5dadd221532 | 54 | cleared = 0; |
ovcharka132 | 0:a5dadd221532 | 55 | |
ovcharka132 | 0:a5dadd221532 | 56 | lcd.ClearStringLine(TOUCH_STRING_IDX); |
ovcharka132 | 0:a5dadd221532 | 57 | lcd.DisplayStringAt(0, LINE(TOUCH_STRING_IDX), (uint8_t *)"TOUCH", LEFT_MODE); |
ovcharka132 | 0:a5dadd221532 | 58 | |
ovcharka132 | 0:a5dadd221532 | 59 | lcd.SetTextColor(LCD_COLOR_BLUE); |
ovcharka132 | 0:a5dadd221532 | 60 | lcd.FillRect(x,y,80,60); |
ovcharka132 | 0:a5dadd221532 | 61 | lcd.SetTextColor(LCD_COLOR_WHITE); |
ovcharka132 | 0:a5dadd221532 | 62 | |
ovcharka132 | 0:a5dadd221532 | 63 | x = TS_State.X; |
ovcharka132 | 0:a5dadd221532 | 64 | y = lcd.GetYSize() - TS_State.Y; |
ovcharka132 | 0:a5dadd221532 | 65 | |
ovcharka132 | 0:a5dadd221532 | 66 | lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"COORDS:", LEFT_MODE); |
ovcharka132 | 0:a5dadd221532 | 67 | lcd.ClearStringLine(COORD_STRING_IDX); |
ovcharka132 | 0:a5dadd221532 | 68 | sprintf((char*)text, "x=%d y=%d", x, y); |
ovcharka132 | 0:a5dadd221532 | 69 | lcd.DisplayStringAt(0, LINE(COORD_STRING_IDX), (uint8_t *)&text, LEFT_MODE); |
ovcharka132 | 0:a5dadd221532 | 70 | lcd.DrawBitmap(x, y, (uint8_t *)stlogo); |
ovcharka132 | 0:a5dadd221532 | 71 | |
ovcharka132 | 0:a5dadd221532 | 72 | } else { |
ovcharka132 | 0:a5dadd221532 | 73 | if (!cleared) { |
ovcharka132 | 0:a5dadd221532 | 74 | lcd.DisplayStringAt(0, LINE(0), (uint8_t *)"NO TOUCH", LEFT_MODE); |
ovcharka132 | 0:a5dadd221532 | 75 | cleared = 1; |
ovcharka132 | 0:a5dadd221532 | 76 | } |
ovcharka132 | 0:a5dadd221532 | 77 | } |
ovcharka132 | 0:a5dadd221532 | 78 | wait_ms(50); // debounce for loading frame |
ovcharka132 | 0:a5dadd221532 | 79 | } |
ovcharka132 | 0:a5dadd221532 | 80 | } |
ovcharka132 | 0:a5dadd221532 | 81 |