1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

drivers/touch_dev: add touch driver registry

This commit is contained in:
Alexandre Abadie 2020-06-21 18:16:33 +02:00
parent f4bc980236
commit 0f9693b18f
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
2 changed files with 71 additions and 0 deletions

View File

@ -84,6 +84,40 @@ struct touch_dev {
const touch_dev_driver_t *driver; /**< Pointer to driver of the touch device */
};
/**
* @brief Touch dev registry entry
*/
typedef struct touch_dev_reg {
struct touch_dev_reg *next; /**< pointer to the next touch device in the list */
touch_dev_t *dev; /**< pointer to the device descriptor */
uint8_t screen_id; /**< id of the screen this touch device is attached to */
} touch_dev_reg_t;
/**
* @brief Export the touch device registry as global variable
*/
extern touch_dev_reg_t *touch_dev_reg;
/**
* @brief Add pointer to a touch device item to the list of touch items
*
* @param[in] dev Pointer to the touch device
*
* @return 0 on success
* @return -ENODEV on invalid entry
*/
int touch_dev_reg_add(touch_dev_reg_t *dev);
/**
* @brief Find the touch device that is attached to a given screen
*
* @param[in] screen_id Identifier (number) of the screen
*
* @return pointer to the touch device in the registry
* @return NULL if there's no match
*/
touch_dev_reg_t *touch_dev_reg_find_screen(uint8_t screen_id);
/**
* @brief Get the height of the touch device
*

View File

@ -22,9 +22,46 @@
#include <stddef.h>
#include <inttypes.h>
#include <stdbool.h>
#include <errno.h>
#include "touch_dev.h"
touch_dev_reg_t *touch_dev_reg = NULL;
int touch_dev_reg_add(touch_dev_reg_t *dev)
{
touch_dev_reg_t *tmp = touch_dev_reg;
if (dev == NULL) {
return -ENODEV;
}
/* prepare new entry */
dev->next = NULL;
/* add to registry */
if (touch_dev_reg == NULL) {
touch_dev_reg = dev;
}
else {
while (tmp->next != NULL) {
tmp = tmp->next;
}
tmp->next = dev;
}
return 0;
}
touch_dev_reg_t *touch_dev_reg_find_screen(uint8_t screen_id)
{
touch_dev_reg_t *tmp = touch_dev_reg;
while (tmp && tmp->screen_id != screen_id) {
tmp = tmp->next;
}
return tmp;
}
uint16_t touch_dev_height(const touch_dev_t *dev)
{
assert(dev);