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 
9 #pragma once
10 
23 #include "saul.h"
24 #include "periph/gpio.h"
25 #if IS_USED(MODULE_STMPE811_SPI)
26 #include "periph/spi.h"
27 #else
28 #include "periph/i2c.h"
29 #endif
30 
31 #ifdef MODULE_TOUCH_DEV
32 #include "touch_dev.h"
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
42 typedef enum {
46 
60 typedef enum {
66 
70 typedef struct {
71  uint16_t x;
72  uint16_t y;
74 
80 typedef void (*stmpe811_event_cb_t)(void *arg);
81 
89 typedef struct {
90 #if IS_USED(MODULE_STMPE811_SPI)
91  /* SPI configuration */
92  spi_t spi;
93  spi_mode_t mode;
94  spi_clk_t clk;
95  gpio_t cs;
96 #else
97  /* I2C details */
99  uint8_t addr;
100 #endif
101  gpio_t int_pin;
102  uint16_t xmax;
103  uint16_t ymax;
107 
111 typedef struct {
112 #ifdef MODULE_TOUCH_DEV
113  touch_dev_t *dev;
114 #endif
117  void *cb_arg;
118  uint16_t prev_x;
119  uint16_t prev_y;
120 } stmpe811_t;
121 
135 int stmpe811_init(stmpe811_t *dev, const stmpe811_params_t * params,
136  stmpe811_event_cb_t cb, void *arg);
137 
148 
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
spi_clk_t
Definition: periph_cpu.h:351
Low-level GPIO peripheral driver interface definitions.
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition: i2c.h:144
void(* stmpe811_event_cb_t)(void *arg)
Signature of touch event callback triggered from interrupt.
Definition: stmpe811.h:80
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:42
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:60
@ STMPE811_TOUCH_STATE_RELEASED
Touchscreen is released.
Definition: stmpe811.h:44
@ STMPE811_TOUCH_STATE_PRESSED
Touchscreen is pressed.
Definition: stmpe811.h:43
@ STMPE811_MIRROR_X
Mirror X, applied after optional swapping.
Definition: stmpe811.h:62
@ STMPE811_NO_CONV
No conversion.
Definition: stmpe811.h:61
@ STMPE811_SWAP_XY
Swap XY, applied before optional mirroring.
Definition: stmpe811.h:64
@ STMPE811_MIRROR_Y
Mirror Y, applied after optional swapping.
Definition: stmpe811.h:63
Low-level I2C peripheral driver interface definition.
spi_mode_t
Support SPI modes.
Definition: periph_cpu.h:42
Low-level SPI peripheral driver interface definition.
Device initialization parameters.
Definition: stmpe811.h:89
gpio_t int_pin
Touch screen interrupt pin.
Definition: stmpe811.h:101
uint16_t ymax
Touch screen max Y position.
Definition: stmpe811.h:103
stmpe811_touch_conv_t xyconv
Touch screen coordinates conversion, swapping is applied before mirroring.
Definition: stmpe811.h:104
uint8_t addr
Device I2C address.
Definition: stmpe811.h:99
i2c_t i2c
I2C device which is used.
Definition: stmpe811.h:98
uint16_t xmax
Touch screen max X position.
Definition: stmpe811.h:102
Device descriptor for the STMPE811 sensor.
Definition: stmpe811.h:111
stmpe811_event_cb_t cb
Configured IRQ event callback.
Definition: stmpe811.h:116
uint16_t prev_x
Previous X coordinate.
Definition: stmpe811.h:118
uint16_t prev_y
Previous Y coordinate.
Definition: stmpe811.h:119
void * cb_arg
Extra argument for the callback.
Definition: stmpe811.h:117
stmpe811_params_t params
Device parameters.
Definition: stmpe811.h:115
Touch position structure.
Definition: stmpe811.h:70
uint16_t x
X position.
Definition: stmpe811.h:71
uint16_t y
Y position.
Definition: stmpe811.h:72
Generic type for a touch device.
Definition: touch_dev.h:115
Functionality for reading [S]ensor [A]ctuator [U]ber [L]ayer sensors as SenML.