From 3d557556e0971e0050f8dbff7d6e5a757f89681d Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 10 Feb 2020 15:55:02 +0100 Subject: [PATCH] sys: add interface for generic touch device --- drivers/include/touch_dev.h | 122 ++++++++++++++++++++++++++++++++++ drivers/touch_dev/Makefile | 1 + drivers/touch_dev/touch_dev.c | 47 +++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 drivers/include/touch_dev.h create mode 100644 drivers/touch_dev/Makefile create mode 100644 drivers/touch_dev/touch_dev.c diff --git a/drivers/include/touch_dev.h b/drivers/include/touch_dev.h new file mode 100644 index 0000000000..eb7df40d2a --- /dev/null +++ b/drivers/include/touch_dev.h @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2020 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup drivers_touch_dev Touch device generic API + * @ingroup drivers_misc + * @brief Define the generic API of a touch device + * @experimental This API is experimental and in an early state - expect + * changes! + * @{ + * + * @author Alexandre Abadie + */ + +#ifndef TOUCH_DEV_H +#define TOUCH_DEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** + * @brief Forward declaration for touch device struct + */ +typedef struct touch_dev touch_dev_t; + +/** + * @brief Touch coordinates + */ +typedef struct { + uint16_t x; /**< X coordinate */ + uint16_t y; /**< Y coordinate */ +} touch_t; + +/** + * @brief Generic type for a touch driver + */ +typedef struct { + + /** + * @brief Get the height of the touch device + * + * @param[in] dev Pointer to the touch device + * + * @return Height in points + */ + uint16_t (*height)(const touch_dev_t *dev); + + /** + * @brief Get the width of the touch device + * + * @param[in] dev Pointer to the touch device + * + * @return Width in points + */ + uint16_t (*width)(const touch_dev_t *dev); + + /** + * @brief Get the current touches on the touch device + * + * If @p touches is NULL, this function only returns the number of touches. + * + * @param[in] dev Pointer to the touch device + * @param[out] touches The array of touches + * @param[in] len The touches array len + * @return number of touch positions, 0 means no touch + */ + uint8_t (*touches)(const touch_dev_t *dev, touch_t *touches, size_t len); +} touch_dev_driver_t; + +/** + * @brief Generic type for a touch device + */ +struct touch_dev { + const touch_dev_driver_t *driver; /**< Pointer to driver of the touch device */ +}; + +/** + * @brief Get the height of the touch device + * + * @param[in] dev Pointer to the touch device + * + * @return Height in points + */ +uint16_t touch_dev_height(const touch_dev_t *dev); + +/** + * @brief Get the width of the touch device + * + * @param[in] dev Pointer to the touch device + * + * @return Width in points + */ +uint16_t touch_dev_width(const touch_dev_t *dev); + +/** + * @brief Get the current touches on the touch device + * + * If @p touches is NULL, this function only returns the number of touches. + * + * @param[in] dev Pointer to the touch device + * @param[out] touches The array of touches + * @param[in] len The touches array len + * @return number of touch positions, 0 means no touch + */ +uint8_t touch_dev_touches(const touch_dev_t *dev, touch_t *touches, size_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* TOUCH_DEV_H */ +/** @} */ diff --git a/drivers/touch_dev/Makefile b/drivers/touch_dev/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/drivers/touch_dev/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/drivers/touch_dev/touch_dev.c b/drivers/touch_dev/touch_dev.c new file mode 100644 index 0000000000..913e504691 --- /dev/null +++ b/drivers/touch_dev/touch_dev.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2020 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_touch_dev + * @{ + * + * @file + * @brief Helper functions for generic API of touch device + * + * @author Alexandre Abadie + * + * @} + */ + +#include +#include +#include +#include + +#include "touch_dev.h" + +uint16_t touch_dev_height(const touch_dev_t *dev) +{ + assert(dev); + + return dev->driver->height(dev); +} + +uint16_t touch_dev_width(const touch_dev_t *dev) +{ + assert(dev); + + return dev->driver->width(dev); +} + +uint8_t touch_dev_touches(const touch_dev_t *dev, touch_t *touches, size_t len) +{ + assert(dev); + + return dev->driver->touches(dev, touches, len); +}