Jan Kamidra / Mbed OS DISCO-F746NG_MbedOs_LvGL_example

Dependencies:   BSP_DISCO_F746NG

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers touchpad.c Source File

touchpad.c

00001 /**
00002  * @file indev.c
00003  *
00004  */
00005 
00006 /*********************
00007  *      INCLUDES
00008  *********************/
00009 #include "hal_stm_lvgl/tft/tft.h "
00010 #include "lvgl/src/hal/lv_hal.h"
00011 
00012 #include "stm32746g_discovery.h"
00013 #include "stm32746g_discovery_ts.h"
00014 
00015 /*********************
00016  *      DEFINES
00017  *********************/
00018 
00019 /**********************
00020  *      TYPEDEFS
00021  **********************/
00022 
00023 /**********************
00024  *  STATIC PROTOTYPES
00025  **********************/
00026 static void touchpad_read(lv_indev_drv_t *drv, lv_indev_data_t *data);
00027 
00028 /**********************
00029  *  STATIC VARIABLES
00030  **********************/
00031 static TS_StateTypeDef  TS_State;
00032 
00033 /**********************
00034  *      MACROS
00035  **********************/
00036 
00037 /**********************
00038  *   GLOBAL FUNCTIONS
00039  **********************/
00040 
00041 /**
00042  * Initialize your input devices here
00043  */
00044 void touchpad_init(void)
00045 {
00046     BSP_TS_Init(TFT_HOR_RES, TFT_VER_RES);
00047 
00048     static lv_indev_drv_t indev_drv;                       /*Descriptor of an input device driver*/
00049     lv_indev_drv_init(&indev_drv);                  /*Basic initialization*/
00050     indev_drv.type = LV_INDEV_TYPE_POINTER;         /*The touchpad is pointer type device*/
00051     indev_drv.read_cb = touchpad_read;
00052 
00053     lv_indev_drv_register(&indev_drv);
00054 }
00055 
00056 /**********************
00057  *   STATIC FUNCTIONS
00058  **********************/
00059 
00060 /**
00061  * Read an input device
00062  * @param indev_id id of the input device to read
00063  * @param x put the x coordinate here
00064  * @param y put the y coordinate here
00065  * @return true: the device is pressed, false: released
00066  */
00067 static void touchpad_read(lv_indev_drv_t *indev, lv_indev_data_t *data)
00068 {
00069     /* Read your touchpad */
00070     static int16_t last_x = 0;
00071     static int16_t last_y = 0;
00072     //BSP_LED_Toggle(LED1);
00073 
00074     BSP_TS_GetState(&TS_State);
00075     if(TS_State.touchDetected) {
00076             data->point.x = TS_State.touchX[0];
00077             data->point.y = TS_State.touchY[0];
00078             last_x = data->point.x;
00079             last_y = data->point.y;
00080             data->state = LV_INDEV_STATE_PRESSED;
00081     } else {
00082             data->point.x = last_x;
00083             data->point.y = last_y;
00084             data->state = LV_INDEV_STATE_RELEASED;
00085     }
00086 }