From 528d884b5d88967f9d5011c27f6d509c60022412 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 20 Jul 2020 16:37:51 +0200 Subject: [PATCH] drivers/touch_dev: extend API to set event callback function --- drivers/include/touch_dev.h | 25 +++++++++++++++++++++++++ drivers/touch_dev/touch_dev.c | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/drivers/include/touch_dev.h b/drivers/include/touch_dev.h index 14f6157248..49bba79586 100644 --- a/drivers/include/touch_dev.h +++ b/drivers/include/touch_dev.h @@ -41,6 +41,13 @@ typedef struct { uint16_t y; /**< Y coordinate */ } touch_t; +/** + * @brief Signature of touch event callback triggered from interrupt + * + * @param[in] arg optional context for the callback + */ +typedef void (*touch_event_cb_t)(void *arg); + /** * @brief Generic type for a touch driver */ @@ -75,6 +82,15 @@ typedef struct { * @return number of touch positions, 0 means no touch */ uint8_t (*touches)(const touch_dev_t *dev, touch_t *touches, size_t len); + + /** + * @brief Set and configure the touch event callback + * + * @param[in] dev Pointer to the touch device + * @param[in] cb The callback function + * @param[in] arg Context argument + */ + void (*set_event_callback)(const touch_dev_t *dev, touch_event_cb_t cb, void *arg); } touch_dev_driver_t; /** @@ -150,6 +166,15 @@ uint16_t touch_dev_width(const touch_dev_t *dev); */ uint8_t touch_dev_touches(const touch_dev_t *dev, touch_t *touches, size_t len); +/** + * @brief Set and configure the touch event callback + * + * @param[in] dev Pointer to the touch device + * @param[in] cb The callback function + * @param[in] arg Context argument + */ +void touch_dev_set_touch_event_callback(const touch_dev_t *dev, touch_event_cb_t cb, void *arg); + #ifdef __cplusplus } #endif diff --git a/drivers/touch_dev/touch_dev.c b/drivers/touch_dev/touch_dev.c index 9e08638a63..8076ca416f 100644 --- a/drivers/touch_dev/touch_dev.c +++ b/drivers/touch_dev/touch_dev.c @@ -82,3 +82,9 @@ uint8_t touch_dev_touches(const touch_dev_t *dev, touch_t *touches, size_t len) return dev->driver->touches(dev, touches, len); } + +void touch_dev_set_touch_event_callback(const touch_dev_t *dev, touch_event_cb_t cb, void *arg) +{ + assert(dev); + dev->driver->set_event_callback(dev, cb, arg); +}