stmpe811.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 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 
21 #ifndef STMPE811_H
22 #define STMPE811_H
23 
24 #include "saul.h"
25 #include "periph/gpio.h"
26 #if IS_USED(MODULE_STMPE811_SPI)
27 #include "periph/spi.h"
28 #else
29 #include "periph/i2c.h"
30 #endif
31 
32 #ifdef MODULE_TOUCH_DEV
33 #include "touch_dev.h"
34 #endif
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 typedef enum {
47 
61 typedef enum {
67 
71 typedef struct {
72  uint16_t x;
73  uint16_t y;
75 
81 typedef void (*stmpe811_event_cb_t)(void *arg);
82 
90 typedef struct {
91 #if IS_USED(MODULE_STMPE811_SPI)
92  /* SPI configuration */
93  spi_t spi;
94  spi_mode_t mode;
95  spi_clk_t clk;
96  gpio_t cs;
97 #else
98  /* I2C details */
100  uint8_t addr;
101 #endif
102  gpio_t int_pin;
103  uint16_t xmax;
104  uint16_t ymax;
108 
112 typedef struct {
113 #ifdef MODULE_TOUCH_DEV
114  touch_dev_t *dev;
115 #endif
118  void *cb_arg;
119  uint16_t prev_x;
120  uint16_t prev_y;
121 } stmpe811_t;
122 
136 int stmpe811_init(stmpe811_t *dev, const stmpe811_params_t * params,
137  stmpe811_event_cb_t cb, void *arg);
138 
149 
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif /* STMPE811_H */
spi_clk_t
Definition: periph_cpu.h:352
Low-level GPIO peripheral driver interface definitions.
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition: i2c.h:145
void(* stmpe811_event_cb_t)(void *arg)
Signature of touch event callback triggered from interrupt.
Definition: stmpe811.h:81
int stmpe811_read_touch_position(stmpe811_t *dev, stmpe811_touch_position_t *position)
Read the touch position.
int stmpe811_read_touch_state(const stmpe811_t *dev, stmpe811_touch_state_t *state)
Read the touch state (pressed or released)
stmpe811_touch_state_t
Touch state enum.
Definition: stmpe811.h:43
int stmpe811_init(stmpe811_t *dev, const stmpe811_params_t *params, stmpe811_event_cb_t cb, void *arg)
Initialize the given STMPE811 device.
stmpe811_touch_conv_t
Touch screen coordinate conversions.
Definition: stmpe811.h:61
@ STMPE811_TOUCH_STATE_RELEASED
Touchscreen is released.
Definition: stmpe811.h:45
@ STMPE811_TOUCH_STATE_PRESSED
Touchscreen is pressed.
Definition: stmpe811.h:44
@ STMPE811_MIRROR_X
Mirror X, applied after optional swapping.
Definition: stmpe811.h:63
@ STMPE811_NO_CONV
No conversion.
Definition: stmpe811.h:62
@ STMPE811_SWAP_XY
Swap XY, applied before optional mirroring.
Definition: stmpe811.h:65
@ STMPE811_MIRROR_Y
Mirror Y, applied after optional swapping.
Definition: stmpe811.h:64
Low-level I2C peripheral driver interface definition.
spi_mode_t
Support SPI modes.
Definition: periph_cpu.h:43
Low-level SPI peripheral driver interface definition.
Device initialization parameters.
Definition: stmpe811.h:90
gpio_t int_pin
Touch screen interrupt pin.
Definition: stmpe811.h:102
uint16_t ymax
Touch screen max Y position.
Definition: stmpe811.h:104
stmpe811_touch_conv_t xyconv
Touch screen coordinates conversion, swapping is applied before mirroring.
Definition: stmpe811.h:105
uint8_t addr
Device I2C address.
Definition: stmpe811.h:100
i2c_t i2c
I2C device which is used.
Definition: stmpe811.h:99
uint16_t xmax
Touch screen max X position.
Definition: stmpe811.h:103
Device descriptor for the STMPE811 sensor.
Definition: stmpe811.h:112
stmpe811_event_cb_t cb
Configured IRQ event callback.
Definition: stmpe811.h:117
uint16_t prev_x
Previous X coordinate.
Definition: stmpe811.h:119
uint16_t prev_y
Previous Y coordinate.
Definition: stmpe811.h:120
void * cb_arg
Extra argument for the callback.
Definition: stmpe811.h:118
stmpe811_params_t params
Device parameters.
Definition: stmpe811.h:116
Touch position structure.
Definition: stmpe811.h:71
uint16_t x
X position.
Definition: stmpe811.h:72
uint16_t y
Y position.
Definition: stmpe811.h:73
Generic type for a touch device.
Definition: touch_dev.h:116
Functionality for reading [S]ensor [A]ctuator [U]ber [L]ayer sensors as SenML.