DISCO_F413ZH-touch-screen-demo
Dependencies: mbed BSP_DISCO_F413ZH
main.cpp@0:de2ab3e4f804, 2020-02-06 (annotated)
- Committer:
- anoney180133
- Date:
- Thu Feb 06 19:46:47 2020 +0000
- Revision:
- 0:de2ab3e4f804
DISCO_F413ZH_touch_screen_demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
anoney180133 | 0:de2ab3e4f804 | 1 | #include "mbed.h" |
anoney180133 | 0:de2ab3e4f804 | 2 | #include "stm32f413h_discovery.h" |
anoney180133 | 0:de2ab3e4f804 | 3 | #include "stm32f413h_discovery_ts.h" |
anoney180133 | 0:de2ab3e4f804 | 4 | #include "stm32f413h_discovery_lcd.h" |
anoney180133 | 0:de2ab3e4f804 | 5 | |
anoney180133 | 0:de2ab3e4f804 | 6 | TS_StateTypeDef TS_State = {0}; |
anoney180133 | 0:de2ab3e4f804 | 7 | |
anoney180133 | 0:de2ab3e4f804 | 8 | int main() |
anoney180133 | 0:de2ab3e4f804 | 9 | { |
anoney180133 | 0:de2ab3e4f804 | 10 | uint16_t x1, y1; |
anoney180133 | 0:de2ab3e4f804 | 11 | |
anoney180133 | 0:de2ab3e4f804 | 12 | BSP_LCD_Init(); |
anoney180133 | 0:de2ab3e4f804 | 13 | |
anoney180133 | 0:de2ab3e4f804 | 14 | /* Touchscreen initialization */ |
anoney180133 | 0:de2ab3e4f804 | 15 | if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) == TS_ERROR) { |
anoney180133 | 0:de2ab3e4f804 | 16 | printf("BSP_TS_Init error\n"); |
anoney180133 | 0:de2ab3e4f804 | 17 | } |
anoney180133 | 0:de2ab3e4f804 | 18 | |
anoney180133 | 0:de2ab3e4f804 | 19 | /* Clear the LCD */ |
anoney180133 | 0:de2ab3e4f804 | 20 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
anoney180133 | 0:de2ab3e4f804 | 21 | |
anoney180133 | 0:de2ab3e4f804 | 22 | /* Set Touchscreen Demo1 description */ |
anoney180133 | 0:de2ab3e4f804 | 23 | BSP_LCD_SetTextColor(LCD_COLOR_GREEN); |
anoney180133 | 0:de2ab3e4f804 | 24 | BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40); |
anoney180133 | 0:de2ab3e4f804 | 25 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
anoney180133 | 0:de2ab3e4f804 | 26 | BSP_LCD_SetBackColor(LCD_COLOR_GREEN); |
anoney180133 | 0:de2ab3e4f804 | 27 | BSP_LCD_SetFont(&Font16); |
anoney180133 | 0:de2ab3e4f804 | 28 | BSP_LCD_DisplayStringAt(0, 15, (uint8_t *)"Touch the screen", CENTER_MODE); |
anoney180133 | 0:de2ab3e4f804 | 29 | |
anoney180133 | 0:de2ab3e4f804 | 30 | while (1) { |
anoney180133 | 0:de2ab3e4f804 | 31 | BSP_TS_GetState(&TS_State); |
anoney180133 | 0:de2ab3e4f804 | 32 | if(TS_State.touchDetected) { |
anoney180133 | 0:de2ab3e4f804 | 33 | /* One or dual touch have been detected */ |
anoney180133 | 0:de2ab3e4f804 | 34 | |
anoney180133 | 0:de2ab3e4f804 | 35 | /* Get X and Y position of the first touch post calibrated */ |
anoney180133 | 0:de2ab3e4f804 | 36 | x1 = TS_State.touchX[0]; |
anoney180133 | 0:de2ab3e4f804 | 37 | y1 = TS_State.touchY[0]; |
anoney180133 | 0:de2ab3e4f804 | 38 | printf("Touch Detected x=%d y=%d\n", x1, y1); |
anoney180133 | 0:de2ab3e4f804 | 39 | |
anoney180133 | 0:de2ab3e4f804 | 40 | BSP_LCD_SetTextColor(LCD_COLOR_GREEN); |
anoney180133 | 0:de2ab3e4f804 | 41 | BSP_LCD_FillCircle(x1, y1, 20); |
anoney180133 | 0:de2ab3e4f804 | 42 | |
anoney180133 | 0:de2ab3e4f804 | 43 | wait_ms(10); |
anoney180133 | 0:de2ab3e4f804 | 44 | } |
anoney180133 | 0:de2ab3e4f804 | 45 | } |
anoney180133 | 0:de2ab3e4f804 | 46 | } |