![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Use of double buffer on the DISCO_F746NG board
Dependencies: BSP_DISCO_F746NG
main.cpp@3:9f66aabe7b3b, 2019-11-20 (annotated)
- Committer:
- Jerome Coutant
- Date:
- Wed Nov 20 11:49:15 2019 +0100
- Revision:
- 3:9f66aabe7b3b
- Parent:
- 0:9933f7db9a9b
- Child:
- 4:571a6b9cefbf
Update with STM32Cube_FW_F7_V1.15.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:9933f7db9a9b | 1 | #include "mbed.h" |
Jerome Coutant
3:9f66aabe7b3b
|
2
|
#include "stm32746g_discovery_lcd.h"
|
|
Jerome Coutant
3:9f66aabe7b3b
|
3
|
#include "stm32746g_discovery_ts.h"
|
|
bcostm | 0:9933f7db9a9b | 4 | |
bcostm | 0:9933f7db9a9b | 5 | int main() |
bcostm | 0:9933f7db9a9b | 6 | { |
bcostm | 0:9933f7db9a9b | 7 | TS_StateTypeDef TS_State; |
bcostm | 0:9933f7db9a9b | 8 | uint16_t x, y; |
bcostm | 0:9933f7db9a9b | 9 | uint8_t text[30]; |
bcostm | 0:9933f7db9a9b | 10 | uint8_t status; |
bcostm | 0:9933f7db9a9b | 11 | uint8_t idx; |
bcostm | 0:9933f7db9a9b | 12 | uint8_t cleared = 0; |
bcostm | 0:9933f7db9a9b | 13 | uint8_t prev_nb_touches = 0; |
bcostm | 0:9933f7db9a9b | 14 | |
Jerome Coutant
3:9f66aabe7b3b
|
15
|
BSP_LCD_Init();
|
|
Jerome Coutant
3:9f66aabe7b3b
|
16
|
BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
17
|
BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
|
|
bcostm | 0:9933f7db9a9b | 18 | |
Jerome Coutant
3:9f66aabe7b3b
|
19
|
BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
20
|
HAL_Delay(1000);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
21
|
|
|
Jerome Coutant
3:9f66aabe7b3b
|
22
|
status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
|
|
bcostm | 0:9933f7db9a9b | 23 | if (status != TS_OK) { |
Jerome Coutant
3:9f66aabe7b3b
|
24
|
BSP_LCD_Clear(LCD_COLOR_RED);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
25
|
BSP_LCD_SetBackColor(LCD_COLOR_RED);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
26
|
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
27
|
BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
|
|
bcostm | 0:9933f7db9a9b | 28 | } else { |
Jerome Coutant
3:9f66aabe7b3b
|
29
|
BSP_LCD_Clear(LCD_COLOR_GREEN);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
30
|
BSP_LCD_SetBackColor(LCD_COLOR_GREEN);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
31
|
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
32
|
BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
|
|
bcostm | 0:9933f7db9a9b | 33 | } |
bcostm | 0:9933f7db9a9b | 34 | |
Jerome Coutant
3:9f66aabe7b3b
|
35
|
HAL_Delay(1000);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
36
|
BSP_LCD_SetFont(&Font12);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
37
|
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
38
|
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
|
|
bcostm | 0:9933f7db9a9b | 39 | |
bcostm | 0:9933f7db9a9b | 40 | while(1) { |
bcostm | 0:9933f7db9a9b | 41 | |
Jerome Coutant
3:9f66aabe7b3b
|
42
|
BSP_TS_GetState(&TS_State);
|
|
bcostm | 0:9933f7db9a9b | 43 | if (TS_State.touchDetected) { |
bcostm | 0:9933f7db9a9b | 44 | // Clear lines corresponding to old touches coordinates |
bcostm | 0:9933f7db9a9b | 45 | if (TS_State.touchDetected < prev_nb_touches) { |
bcostm | 0:9933f7db9a9b | 46 | for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) { |
Jerome Coutant
3:9f66aabe7b3b
|
47
|
BSP_LCD_ClearStringLine(idx);
|
|
bcostm | 0:9933f7db9a9b | 48 | } |
bcostm | 0:9933f7db9a9b | 49 | } |
bcostm | 0:9933f7db9a9b | 50 | prev_nb_touches = TS_State.touchDetected; |
bcostm | 0:9933f7db9a9b | 51 | |
bcostm | 0:9933f7db9a9b | 52 | cleared = 0; |
bcostm | 0:9933f7db9a9b | 53 | |
bcostm | 0:9933f7db9a9b | 54 | sprintf((char*)text, "Touches: %d", TS_State.touchDetected); |
Jerome Coutant
3:9f66aabe7b3b
|
55
|
BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
|
|
bcostm | 0:9933f7db9a9b | 56 | |
bcostm | 0:9933f7db9a9b | 57 | for (idx = 0; idx < TS_State.touchDetected; idx++) { |
bcostm | 0:9933f7db9a9b | 58 | x = TS_State.touchX[idx]; |
bcostm | 0:9933f7db9a9b | 59 | y = TS_State.touchY[idx]; |
bcostm | 0:9933f7db9a9b | 60 | sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); |
Jerome Coutant
3:9f66aabe7b3b
|
61
|
BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE);
|
|
bcostm | 0:9933f7db9a9b | 62 | } |
bcostm | 0:9933f7db9a9b | 63 | |
Jerome Coutant
3:9f66aabe7b3b
|
64
|
BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE);
|
|
bcostm | 0:9933f7db9a9b | 65 | } else { |
bcostm | 0:9933f7db9a9b | 66 | if (!cleared) { |
Jerome Coutant
3:9f66aabe7b3b
|
67
|
BSP_LCD_Clear(LCD_COLOR_BLUE);
|
|
bcostm | 0:9933f7db9a9b | 68 | sprintf((char*)text, "Touches: 0"); |
Jerome Coutant
3:9f66aabe7b3b
|
69
|
BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
|
|
bcostm | 0:9933f7db9a9b | 70 | cleared = 1; |
bcostm | 0:9933f7db9a9b | 71 | } |
bcostm | 0:9933f7db9a9b | 72 | } |
bcostm | 0:9933f7db9a9b | 73 | } |
bcostm | 0:9933f7db9a9b | 74 | } |