HAL Library 23- TOUCH for STM32Fxxx
The TOUCH library is a “high” level library for touch operations. It requires low-level drivers for communication with your sensor/device, but for high level for user, always the same functions are used. This allows you flexibility between multiple low-level device drivers to be used with in your project if needed and also allows single lib to have the same features for all projects.
Library
Features
- Custom selectable driver
- Built-in drivers for STM32F429-EVAL and STM32F7-Discovery
- Allows multi-touch up to 10 fingers
- Allows rotation like LCD to have the same coordinates
Dependencies
- HAL
- TM
- STM32Fxxx HAL
- defines.h configuration file
- TM I2C
- TM TOUCH FT5336 for STM32F7-Discovery board
- TM TOUCH TS3510 for STM32F429-EVAL board
Functions and enumerations
For all functions list, including setting up custom driver, please check my library API.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
/** * Keil project example for TOUCH controllers * * Before you start, select your target, on the right of the "Load" button * * @author Tilen Majerle * @email tilen@majerle.eu * @website http://stm32f4-discovery.net * @ide Keil uVision 5 * @conf PLL parameters are set in "Options for Target" -> "C/C++" -> "Defines" * @packs STM32F4xx/STM32F7xx Keil packs are requred with HAL driver support * @stdperiph STM32F4xx/STM32F7xx HAL drivers required */ /* Include core modules */ #include "stm32fxxx_hal.h" /* Include my libraries here */ #include "defines.h" #include "tm_stm32_disco.h" #include "tm_stm32_delay.h" #include "tm_stm32_touch.h" #include "tm_stm32_lcd.h" /* Touch screen data structure */ TM_TOUCH_t TS; /* For string drawings */ char str[200]; /* Colors used for drawing for touch pressed */ uint16_t TOUCH_Colors[10] = { LCD_COLOR_BLACK, LCD_COLOR_BLUE, LCD_COLOR_RED, LCD_COLOR_GREEN, LCD_COLOR_YELLOW }; int main(void) { uint8_t i; /* Init system clock for maximum system speed */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay functions */ TM_DELAY_Init(); /* Init LCD */ TM_LCD_Init(); /* Fill LCD with color */ TM_LCD_Fill(0xFFFF); /* Set custom orientation for LCD */ TM_LCD_SetOrientation(1); /* Get orientation from LCD and save to Touch Screen structure */ TS.Orientation = TM_LCD_GetOrientation(); /* Init touch, use default drivers, depends on defines in library */ /* Check library description for more information */ TM_TOUCH_Init(NULL, &TS); while (1) { /* Read touch */ TM_TOUCH_Read(&TS); /* Check if pressed */ if (TS.NumPresses) { /* Go through all presses on LCD */ for (i = 0; i < TS.NumPresses; i++) { /* Draw circle */ TM_LCD_DrawFilledCircle(TS.X[i], TS.Y[i], 5, TOUCH_Colors[i]); /* Format string */ sprintf(str, "X: %3d Y: %3d", TS.X[i], TS.Y[i]); /* Print on LCD */ TM_LCD_SetXY(10, 10 + i * 20); TM_LCD_Puts(str); } } Delayms(5); } } |
Projects are available on Github, download all libraries below.
STM32 libraries based on STM32Fxxx HAL drivers.
Recent comments