2017-10-18 14:09:10 +02:00
|
|
|
/**
|
|
|
|
* @file hal_indev.c
|
|
|
|
*
|
|
|
|
* @description Input device HAL interface
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
|
|
|
#include "../lv_hal/lv_hal_indev.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_mem.h"
|
2017-10-18 14:09:10 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
static lv_indev_t *indev_list = NULL;
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2017-11-19 21:16:53 +01:00
|
|
|
lv_indev_t * lv_indev_register(lv_indev_drv_t *driver)
|
2017-10-18 14:09:10 +02:00
|
|
|
{
|
|
|
|
lv_indev_t *node;
|
|
|
|
|
2017-11-23 21:28:36 +01:00
|
|
|
node = lv_mem_alloc(sizeof(lv_indev_t));
|
2017-10-18 14:09:10 +02:00
|
|
|
if (!node) return NULL;
|
|
|
|
|
2017-10-20 22:11:18 +02:00
|
|
|
memcpy(&node->driver, driver, sizeof(lv_indev_drv_t));
|
2017-10-18 14:09:10 +02:00
|
|
|
|
|
|
|
node->next = NULL;
|
|
|
|
|
|
|
|
if (indev_list == NULL) {
|
|
|
|
indev_list = node;
|
|
|
|
} else {
|
|
|
|
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;
|
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)
|
|
|
|
*/
|
2017-10-20 22:11:18 +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;
|
|
|
|
|
2017-11-27 00:48:16 +01:00
|
|
|
if(indev->driver.read_fp) {
|
|
|
|
cont = indev->driver.read_fp(data);
|
2017-10-18 14:09:10 +02:00
|
|
|
} else {
|
2017-10-20 22:11:18 +02:00
|
|
|
memset(data, 0, sizeof(lv_indev_data_t));
|
2017-10-18 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return cont;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|