1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_hal/lv_hal_indev.c

134 lines
3.1 KiB
C
Raw Normal View History

/**
* @file hal_indev.c
*
* @description Input device HAL interface
2018-06-19 09:49:58 +02:00
*
*/
/*********************
* INCLUDES
*********************/
#include "../lv_hal/lv_hal_indev.h"
2017-11-23 20:42:14 +01:00
#include "../lv_misc/lv_mem.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
2018-06-19 09:49:58 +02:00
static lv_indev_t * indev_list = NULL;
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* 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-12-17 01:54:09 +01:00
driver->read = NULL;
driver->type = LV_INDEV_TYPE_NONE;
2018-02-23 17:03:00 +01:00
driver->user_data = NULL;
}
/**
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
*/
2018-06-19 09:49:58 +02:00
lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver)
{
2018-06-19 09:49:58 +02:00
lv_indev_t * node;
2017-11-23 21:28:36 +01:00
node = lv_mem_alloc(sizeof(lv_indev_t));
2018-06-19 09:49:58 +02:00
if(!node) return NULL;
memset(node, 0, sizeof(lv_indev_t));
memcpy(&node->driver, driver, sizeof(lv_indev_drv_t));
node->next = NULL;
node->proc.reset_query = 1;
node->cursor = NULL;
node->group = NULL;
node->btn_points = NULL;
2018-06-19 09:49:58 +02:00
if(indev_list == NULL) {
indev_list = node;
} else {
2018-06-19 09:49:58 +02:00
lv_indev_t * last = indev_list;
while(last->next)
last = last->next;
last->next = node;
}
return node;
}
/**
* Get the next input device.
* @param indev pointer to the current input device. NULL to initialize.
* @return the next input devise or NULL if no more. Give the first input device when the parameter is NULL
*/
lv_indev_t * lv_indev_next(lv_indev_t * indev)
{
if(indev == NULL) {
return indev_list;
} else {
2017-11-19 19:28:45 +01:00
if(indev->next == NULL) return NULL;
else return indev->next;
}
}
/**
* 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)
{
bool cont = false;
2017-12-17 01:54:09 +01:00
if(indev->driver.read) {
2018-02-23 17:03:00 +01:00
data->user_data = indev->driver.user_data;
2018-07-25 17:57:08 +02:00
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "Indev read called");
2018-07-25 17:57:08 +02:00
#endif
2017-12-17 01:54:09 +01:00
cont = indev->driver.read(data);
2018-07-25 17:57:08 +02:00
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "Indev read ready");
2018-07-25 17:57:08 +02:00
#endif
} else {
2018-07-25 17:57:08 +02:00
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, "Indev read: function not set");
#endif
memset(data, 0, sizeof(lv_indev_data_t));
}
return cont;
}
/**********************
* STATIC FUNCTIONS
**********************/