ST / Mbed OS DISCO-F769NI_TOUCHSCREEN_demo

Dependencies:   BSP_DISCO_F769NI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "stm32f769i_discovery.h"
00003 #include "stm32f769i_discovery_ts.h"
00004 #include "stm32f769i_discovery_lcd.h"
00005 
00006 TS_StateTypeDef  TS_State = {0};
00007 
00008 int main()
00009 {
00010     uint16_t x1, y1;
00011 
00012     printf("\n\n TOUCHSCREEN EXAMPLE FOR DISCO-F769NI START:\n");
00013 
00014     BSP_LCD_Init();
00015     BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
00016     BSP_LCD_SelectLayer(0);
00017 
00018     /* Touchscreen initialization */
00019     if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) == TS_ERROR) {
00020         printf("BSP_TS_Init error\n");
00021     }
00022 
00023     /* Clear the LCD */
00024     BSP_LCD_Clear(LCD_COLOR_WHITE);
00025 
00026     /* Set Touchscreen Demo1 description */
00027     BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
00028     BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40);
00029     BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
00030     BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
00031     BSP_LCD_SetFont(&Font24);
00032     BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"Touchscreen basic example", CENTER_MODE);
00033 
00034     while (1) {
00035         BSP_TS_GetState(&TS_State);
00036         if (TS_State.touchDetected) {
00037             /* One or dual touch have been detected          */
00038 
00039             /* Get X and Y position of the first touch post calibrated */
00040             x1 = TS_State.touchX[0];
00041             y1 = TS_State.touchY[0];
00042             printf("Touch Detected x=%d y=%d\n", x1, y1);
00043 
00044             BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
00045             BSP_LCD_FillCircle(x1, y1, 20);
00046 
00047             HAL_Delay(100);
00048         }
00049     }
00050 }