Code commenté du projet LED
Dependencies: BSP_DISCO_F746NG
Diff: hal_stm_lvgl/touchpad/touchpad.c
- Revision:
- 3:4f5dc253eb7b
- Child:
- 5:071136c3eefa
diff -r afc050526249 -r 4f5dc253eb7b hal_stm_lvgl/touchpad/touchpad.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hal_stm_lvgl/touchpad/touchpad.c Sat Apr 24 19:08:28 2021 +0000 @@ -0,0 +1,89 @@ +/** + * @file indev.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "hal_stm_lvgl/tft/tft.h" +#include "lvgl/src/lv_hal/lv_hal.h" + +#include "stm32746g_discovery.h" +#include "stm32746g_discovery_ts.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool touchpad_read(lv_indev_drv_t *drv, lv_indev_data_t *data); + +/********************** + * STATIC VARIABLES + **********************/ +static TS_StateTypeDef TS_State; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize your input devices here + */ +void touchpad_init(void) +{ + BSP_TS_Init(TFT_HOR_RES, TFT_VER_RES); + + lv_indev_drv_t indev_drv; /*Descriptor of an input device driver*/ + lv_indev_drv_init(&indev_drv); /*Basic initialization*/ + indev_drv.type = LV_INDEV_TYPE_POINTER; /*The touchpad is pointer type device*/ + indev_drv.read_cb = touchpad_read; + + lv_indev_drv_register(&indev_drv); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Read an input device + * @param indev_id id of the input device to read + * @param x put the x coordinate here + * @param y put the y coordinate here + * @return true: the device is pressed, false: released + */ +static bool touchpad_read(lv_indev_drv_t *indev, lv_indev_data_t *data) +{ + /* Read your touchpad */ + static int16_t last_x = 0; + static int16_t last_y = 0; + //BSP_LED_Toggle(LED1); + + BSP_TS_GetState(&TS_State); + if(TS_State.touchDetected) { + data->point.x = TS_State.touchX[0]; + data->point.y = TS_State.touchY[0]; + last_x = data->point.x; + last_y = data->point.y; + data->state = LV_INDEV_STATE_PR; + } else { + data->point.x = last_x; + data->point.y = last_y; + data->state = LV_INDEV_STATE_REL; + } + + return false; /*false: no more data to read because we are no buffering*/ +} +