2017-10-18 14:09:10 +02:00
|
|
|
/**
|
|
|
|
* @file hal_indev.c
|
|
|
|
*
|
|
|
|
* @description Input device HAL interface
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2017-10-18 14:09:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
|
|
|
#include "../lv_hal/lv_hal_indev.h"
|
2019-04-02 12:15:35 +02:00
|
|
|
#include "../lv_core/lv_indev.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_mem.h"
|
2019-01-12 01:07:34 +02:00
|
|
|
#include "../lv_misc/lv_gc.h"
|
2019-02-12 12:21:34 +01:00
|
|
|
#include "lv_hal_disp.h"
|
2019-01-12 01:07:34 +02:00
|
|
|
|
|
|
|
#if defined(LV_GC_INCLUDE)
|
2019-04-04 07:15:40 +02:00
|
|
|
#include LV_GC_INCLUDE
|
2019-01-12 01:07:34 +02:00
|
|
|
#endif /* LV_ENABLE_GC */
|
|
|
|
|
2017-10-18 14:09:10 +02:00
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
2017-11-27 09:38:10 +01:00
|
|
|
/**
|
|
|
|
* Initialize an input device driver with default values.
|
|
|
|
* It is used to surly have known values in the fields ant not memory junk.
|
|
|
|
* After it you can set the fields.
|
|
|
|
* @param driver pointer to driver variable to initialize
|
|
|
|
*/
|
2018-06-19 09:49:58 +02:00
|
|
|
void lv_indev_drv_init(lv_indev_drv_t * driver)
|
2017-11-27 09:38:10 +01:00
|
|
|
{
|
2019-02-20 23:58:13 +01:00
|
|
|
memset(driver, 0, sizeof(lv_indev_drv_t));
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
driver->type = LV_INDEV_TYPE_NONE;
|
|
|
|
driver->drag_limit = LV_INDEV_DEF_DRAG_LIMIT;
|
|
|
|
driver->drag_throw = LV_INDEV_DEF_DRAG_THROW;
|
|
|
|
driver->long_press_time = LV_INDEV_DEF_LONG_PRESS_TIME;
|
2019-04-02 12:15:35 +02:00
|
|
|
driver->long_press_rep_time = LV_INDEV_DEF_LONG_PRESS_REP_TIME;
|
2017-11-27 09:38:10 +01:00
|
|
|
}
|
|
|
|
|
2017-10-18 14:09:10 +02:00
|
|
|
/**
|
2017-10-20 22:41:10 +02:00
|
|
|
* Register an initialized input device driver.
|
|
|
|
* @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)
|
|
|
|
* @return pointer to the new input device or NULL on error
|
2017-10-18 14:09:10 +02:00
|
|
|
*/
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver)
|
2017-10-18 14:09:10 +02:00
|
|
|
{
|
|
|
|
|
2019-02-20 10:16:33 +01:00
|
|
|
if(driver->disp == NULL) driver->disp = lv_disp_get_default();
|
2019-02-10 11:06:47 +01:00
|
|
|
|
|
|
|
if(driver->disp == NULL) {
|
2019-04-04 07:15:40 +02:00
|
|
|
LV_LOG_WARN("lv_indev_drv_register: no display registered hence can't attache the indev to "
|
|
|
|
"a display");
|
2019-02-10 11:06:47 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-04-02 12:15:35 +02:00
|
|
|
lv_indev_t * indev = lv_ll_ins_head(&LV_GC_ROOT(_lv_indev_ll));
|
|
|
|
if(!indev) {
|
|
|
|
lv_mem_assert(indev);
|
2019-02-10 11:06:47 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-10-18 14:09:10 +02:00
|
|
|
|
2019-04-02 12:15:35 +02:00
|
|
|
memset(indev, 0, sizeof(lv_indev_t));
|
|
|
|
memcpy(&indev->driver, driver, sizeof(lv_indev_drv_t));
|
2017-10-18 14:09:10 +02:00
|
|
|
|
2019-04-02 12:15:35 +02:00
|
|
|
indev->proc.reset_query = 1;
|
2019-04-04 07:15:40 +02:00
|
|
|
indev->cursor = NULL;
|
|
|
|
indev->group = NULL;
|
|
|
|
indev->btn_points = NULL;
|
2017-10-18 14:09:10 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
indev->driver.read_task =
|
|
|
|
lv_task_create(lv_indev_read_task, LV_INDEV_DEF_READ_PERIOD, LV_TASK_PRIO_MID, indev);
|
2019-04-02 12:15:35 +02:00
|
|
|
|
|
|
|
return indev;
|
2017-10-18 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 07:07:17 +02:00
|
|
|
/**
|
|
|
|
* Update the driver in run time.
|
|
|
|
* @param indev pointer to a input device. (return value of `lv_indev_drv_register`)
|
|
|
|
* @param new_drv pointer to the new driver
|
|
|
|
*/
|
|
|
|
void lv_indev_drv_update(lv_indev_t * indev, lv_indev_drv_t * new_drv)
|
|
|
|
{
|
|
|
|
memcpy(&indev->driver, new_drv, sizeof(lv_indev_drv_t));
|
|
|
|
}
|
|
|
|
|
2017-10-18 14:09:10 +02:00
|
|
|
/**
|
|
|
|
* Get the next input device.
|
|
|
|
* @param indev pointer to the current input device. NULL to initialize.
|
2019-04-04 07:15:40 +02:00
|
|
|
* @return the next input devise or NULL if no more. Give the first input device when the parameter
|
|
|
|
* is NULL
|
2017-10-18 14:09:10 +02:00
|
|
|
*/
|
2019-04-04 07:07:17 +02:00
|
|
|
lv_indev_t * lv_indev_get_next(lv_indev_t * indev)
|
2017-10-18 14:09:10 +02:00
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
if(indev == NULL)
|
|
|
|
return lv_ll_get_head(&LV_GC_ROOT(_lv_indev_ll));
|
|
|
|
else
|
|
|
|
return lv_ll_get_next(&LV_GC_ROOT(_lv_indev_ll), indev);
|
2017-10-18 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read data from an input device.
|
|
|
|
* @param indev pointer to an input device
|
|
|
|
* @param data input device will write its data here
|
|
|
|
* @return false: no more data; true: there more data to read (buffered)
|
|
|
|
*/
|
2018-06-19 09:49:58 +02:00
|
|
|
bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
|
2017-10-18 14:09:10 +02:00
|
|
|
{
|
|
|
|
bool cont = false;
|
|
|
|
|
2018-11-24 07:41:18 +01:00
|
|
|
memset(data, 0, sizeof(lv_indev_data_t));
|
|
|
|
|
2019-03-07 01:26:04 +01:00
|
|
|
/* For touchpad sometimes users don't the last pressed coordinate on release.
|
|
|
|
* So be sure a coordinates are initialized to the last point */
|
|
|
|
if(indev->driver.type == LV_INDEV_TYPE_POINTER) {
|
|
|
|
data->point.x = indev->proc.types.pointer.act_point.x;
|
|
|
|
data->point.y = indev->proc.types.pointer.act_point.y;
|
|
|
|
}
|
2019-03-17 07:59:38 +01:00
|
|
|
/*Similarly set at least the last key in case of the the user doesn't set it on release*/
|
|
|
|
else if(indev->driver.type == LV_INDEV_TYPE_KEYPAD) {
|
|
|
|
data->key = indev->proc.types.keypad.last_key;
|
|
|
|
}
|
2018-07-25 20:39:24 +02:00
|
|
|
|
2019-03-07 01:26:04 +01:00
|
|
|
if(indev->driver.read_cb) {
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("idnev read started");
|
2019-02-24 21:20:51 +01:00
|
|
|
cont = indev->driver.read_cb(&indev->driver, data);
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("idnev read finished");
|
2017-10-18 14:09:10 +02:00
|
|
|
} else {
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_WARN("indev function registered");
|
2017-10-18 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return cont;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|