Nathan Leprevier / Mbed OS Grecordeur

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