STM32L476
Dependencies: MbedJSONValue SDFileSystem WConstants mbed-dev DS1820 TinyGPSPlus epd1in54
Fork of A_SSL_Main by
main.cpp@0:eafcd0445e97, 2018-04-11 (annotated)
- Committer:
- bcostm
- Date:
- Wed Apr 11 13:32:17 2018 +0200
- Revision:
- 0:eafcd0445e97
- Child:
- 2:b14aac0ec647
Add main.cpp file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:eafcd0445e97 | 1 | #include "mbed.h" |
bcostm | 0:eafcd0445e97 | 2 | #include "stm32l496g_discovery_lcd.h" |
bcostm | 0:eafcd0445e97 | 3 | #include "stm32l496g_discovery_ts.h" |
bcostm | 0:eafcd0445e97 | 4 | |
bcostm | 0:eafcd0445e97 | 5 | int main() |
bcostm | 0:eafcd0445e97 | 6 | { |
bcostm | 0:eafcd0445e97 | 7 | TS_StateTypeDef TS_State; |
bcostm | 0:eafcd0445e97 | 8 | uint16_t x, y; |
bcostm | 0:eafcd0445e97 | 9 | uint8_t text[30]; |
bcostm | 0:eafcd0445e97 | 10 | uint8_t idx; |
bcostm | 0:eafcd0445e97 | 11 | uint8_t cleared = 0; |
bcostm | 0:eafcd0445e97 | 12 | uint8_t prev_nb_touches = 0; |
bcostm | 0:eafcd0445e97 | 13 | |
bcostm | 0:eafcd0445e97 | 14 | BSP_LCD_Init(); |
bcostm | 0:eafcd0445e97 | 15 | BSP_LCD_SetFont(&Font20); |
bcostm | 0:eafcd0445e97 | 16 | BSP_LCD_Clear(LCD_COLOR_BLUE); |
bcostm | 0:eafcd0445e97 | 17 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
bcostm | 0:eafcd0445e97 | 18 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
bcostm | 0:eafcd0445e97 | 19 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"DISCO_L496AG", CENTER_MODE); |
bcostm | 0:eafcd0445e97 | 20 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"LCDTS DEMO", CENTER_MODE); |
bcostm | 0:eafcd0445e97 | 21 | wait(1); |
bcostm | 0:eafcd0445e97 | 22 | |
bcostm | 0:eafcd0445e97 | 23 | if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) != TS_OK) |
bcostm | 0:eafcd0445e97 | 24 | { |
bcostm | 0:eafcd0445e97 | 25 | BSP_LCD_Clear(LCD_COLOR_RED); |
bcostm | 0:eafcd0445e97 | 26 | BSP_LCD_SetBackColor(LCD_COLOR_RED); |
bcostm | 0:eafcd0445e97 | 27 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
bcostm | 0:eafcd0445e97 | 28 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TS INIT FAIL", CENTER_MODE); |
bcostm | 0:eafcd0445e97 | 29 | } |
bcostm | 0:eafcd0445e97 | 30 | else |
bcostm | 0:eafcd0445e97 | 31 | { |
bcostm | 0:eafcd0445e97 | 32 | BSP_LCD_Clear(LCD_COLOR_GREEN); |
bcostm | 0:eafcd0445e97 | 33 | BSP_LCD_SetBackColor(LCD_COLOR_GREEN); |
bcostm | 0:eafcd0445e97 | 34 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
bcostm | 0:eafcd0445e97 | 35 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TS INIT OK", CENTER_MODE); |
bcostm | 0:eafcd0445e97 | 36 | } |
bcostm | 0:eafcd0445e97 | 37 | wait(0.5); |
bcostm | 0:eafcd0445e97 | 38 | |
bcostm | 0:eafcd0445e97 | 39 | BSP_LCD_SetFont(&Font16); |
bcostm | 0:eafcd0445e97 | 40 | BSP_LCD_Clear(LCD_COLOR_BLUE); |
bcostm | 0:eafcd0445e97 | 41 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
bcostm | 0:eafcd0445e97 | 42 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
bcostm | 0:eafcd0445e97 | 43 | |
bcostm | 0:eafcd0445e97 | 44 | while(1) { |
bcostm | 0:eafcd0445e97 | 45 | |
bcostm | 0:eafcd0445e97 | 46 | BSP_TS_GetState(&TS_State); |
bcostm | 0:eafcd0445e97 | 47 | |
bcostm | 0:eafcd0445e97 | 48 | if (TS_State.touchDetected) |
bcostm | 0:eafcd0445e97 | 49 | { |
bcostm | 0:eafcd0445e97 | 50 | // Clear lines corresponding to old touches coordinates |
bcostm | 0:eafcd0445e97 | 51 | if (TS_State.touchDetected < prev_nb_touches) |
bcostm | 0:eafcd0445e97 | 52 | { |
bcostm | 0:eafcd0445e97 | 53 | for (idx = (TS_State.touchDetected + 1); idx <= TS_MAX_NB_TOUCH; idx++) |
bcostm | 0:eafcd0445e97 | 54 | { |
bcostm | 0:eafcd0445e97 | 55 | BSP_LCD_ClearStringLine(idx); |
bcostm | 0:eafcd0445e97 | 56 | } |
bcostm | 0:eafcd0445e97 | 57 | } |
bcostm | 0:eafcd0445e97 | 58 | prev_nb_touches = TS_State.touchDetected; |
bcostm | 0:eafcd0445e97 | 59 | |
bcostm | 0:eafcd0445e97 | 60 | cleared = 0; |
bcostm | 0:eafcd0445e97 | 61 | |
bcostm | 0:eafcd0445e97 | 62 | sprintf((char*)text, "Touches: %d", TS_State.touchDetected); |
bcostm | 0:eafcd0445e97 | 63 | BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); |
bcostm | 0:eafcd0445e97 | 64 | |
bcostm | 0:eafcd0445e97 | 65 | for (idx = 0; idx < TS_State.touchDetected; idx++) |
bcostm | 0:eafcd0445e97 | 66 | { |
bcostm | 0:eafcd0445e97 | 67 | x = TS_State.touchX[idx]; |
bcostm | 0:eafcd0445e97 | 68 | y = TS_State.touchY[idx]; |
bcostm | 0:eafcd0445e97 | 69 | sprintf((char*)text, "Touch %d: x=%d y=%d", idx+1, x, y); |
bcostm | 0:eafcd0445e97 | 70 | BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); |
bcostm | 0:eafcd0445e97 | 71 | BSP_LCD_DrawHLine(x-10, y, 20); |
bcostm | 0:eafcd0445e97 | 72 | BSP_LCD_DrawVLine(x, y-10, 20); |
bcostm | 0:eafcd0445e97 | 73 | } |
bcostm | 0:eafcd0445e97 | 74 | } |
bcostm | 0:eafcd0445e97 | 75 | else |
bcostm | 0:eafcd0445e97 | 76 | { |
bcostm | 0:eafcd0445e97 | 77 | if (!cleared) |
bcostm | 0:eafcd0445e97 | 78 | { |
bcostm | 0:eafcd0445e97 | 79 | sprintf((char*)text, "Touches: 0"); |
bcostm | 0:eafcd0445e97 | 80 | BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); |
bcostm | 0:eafcd0445e97 | 81 | cleared = 1; |
bcostm | 0:eafcd0445e97 | 82 | } |
bcostm | 0:eafcd0445e97 | 83 | } |
bcostm | 0:eafcd0445e97 | 84 | |
bcostm | 0:eafcd0445e97 | 85 | } |
bcostm | 0:eafcd0445e97 | 86 | |
bcostm | 0:eafcd0445e97 | 87 | } |