touch_dev.h
1 /*
2  * Copyright (C) 2020 Inria
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 #include <stdbool.h>
29 
33 #define TOUCH_DEV_VALUE_INVALID ((touch_t){ UINT16_MAX, UINT16_MAX })
34 
38 typedef struct touch_dev touch_dev_t;
39 
43 typedef struct {
44  uint16_t x;
45  uint16_t y;
46 } touch_t;
47 
53 typedef void (*touch_event_cb_t)(void *arg);
54 
58 typedef struct {
59 
67  uint16_t (*height)(const touch_dev_t *dev);
68 
76  uint16_t (*width)(const touch_dev_t *dev);
77 
88  uint8_t (*max_numof)(const touch_dev_t *dev);
89 
100  uint8_t (*touches)(const touch_dev_t *dev, touch_t *touches, size_t len);
101 
109  void (*set_event_callback)(const touch_dev_t *dev, touch_event_cb_t cb, void *arg);
111 
115 struct touch_dev {
117 };
118 
122 typedef struct touch_dev_reg {
123  struct touch_dev_reg *next;
125  uint8_t screen_id;
127 
132 
142 
152 
161 
169 uint16_t touch_dev_width(const touch_dev_t *dev);
170 
178 static inline uint8_t touch_dev_max_numof(const touch_dev_t *dev)
179 {
180  assert(dev);
181  return (dev->driver->max_numof) ? dev->driver->max_numof(dev) : 1;
182 }
183 
196 uint8_t touch_dev_touches(const touch_dev_t *dev, touch_t *touches, size_t len);
197 
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:135
int touch_dev_reg_add(touch_dev_reg_t *dev)
Add pointer to a touch device item to the list of touch items.
static uint8_t touch_dev_max_numof(const touch_dev_t *dev)
Get the maximum number of touches the touch device supports.
Definition: touch_dev.h:178
touch_dev_reg_t * touch_dev_reg_find_screen(uint8_t screen_id)
Find the touch device that is attached to a given screen.
uint8_t touch_dev_touches(const touch_dev_t *dev, touch_t *touches, size_t len)
Get the current touches on the touch device.
void(* touch_event_cb_t)(void *arg)
Signature of touch event callback triggered from interrupt.
Definition: touch_dev.h:53
uint16_t touch_dev_height(const touch_dev_t *dev)
Get the height of the touch device.
struct touch_dev_reg touch_dev_reg_t
Touch dev registry entry.
touch_dev_reg_t * touch_dev_reg
Export the touch device registry as global variable.
uint16_t touch_dev_width(const touch_dev_t *dev)
Get the width of the touch device.
void touch_dev_set_touch_event_callback(const touch_dev_t *dev, touch_event_cb_t cb, void *arg)
Set and configure the touch event callback.
Generic type for a touch driver.
Definition: touch_dev.h:58
uint8_t(* max_numof)(const touch_dev_t *dev)
Get the maximum number of touches the touch device supports.
Definition: touch_dev.h:88
uint8_t(* touches)(const touch_dev_t *dev, touch_t *touches, size_t len)
Get the current touches on the touch device.
Definition: touch_dev.h:100
Touch dev registry entry.
Definition: touch_dev.h:122
struct touch_dev_reg * next
pointer to the next touch device in the list
Definition: touch_dev.h:123
touch_dev_t * dev
pointer to the device descriptor
Definition: touch_dev.h:124
uint8_t screen_id
id of the screen this touch device is attached to
Definition: touch_dev.h:125
Generic type for a touch device.
Definition: touch_dev.h:115
const touch_dev_driver_t * driver
Pointer to driver of the touch device.
Definition: touch_dev.h:116
Touch coordinates.
Definition: touch_dev.h:43
uint16_t y
Y coordinate.
Definition: touch_dev.h:45
uint16_t x
X coordinate.
Definition: touch_dev.h:44