2019-04-28 17:54:09 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 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_stmpe811 STMPE811 Touchscreen Controller
|
|
|
|
* @ingroup drivers_sensors
|
|
|
|
* @brief Device driver interface for the STMPE811 touchscreen controller
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef STMPE811_H
|
|
|
|
#define STMPE811_H
|
|
|
|
|
|
|
|
#include "saul.h"
|
|
|
|
#include "periph/gpio.h"
|
2021-10-23 12:09:27 +02:00
|
|
|
#if IS_USED(MODULE_STMPE811_SPI)
|
|
|
|
#include "periph/spi.h"
|
|
|
|
#else
|
2019-04-28 17:54:09 +02:00
|
|
|
#include "periph/i2c.h"
|
2021-10-23 12:09:27 +02:00
|
|
|
#endif
|
2019-04-28 17:54:09 +02:00
|
|
|
|
2020-02-10 15:55:42 +01:00
|
|
|
#ifdef MODULE_TOUCH_DEV
|
|
|
|
#include "touch_dev.h"
|
|
|
|
#endif
|
|
|
|
|
2019-04-28 17:54:09 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Touch state enum
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
STMPE811_TOUCH_STATE_PRESSED, /**< Touchscreen is pressed */
|
|
|
|
STMPE811_TOUCH_STATE_RELEASED, /**< Touchscreen is released */
|
|
|
|
} stmpe811_touch_state_t;
|
|
|
|
|
2023-08-14 15:25:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Touch screen coordinate conversions
|
|
|
|
*
|
|
|
|
* Normally the coordinates of the touch device must be converted to the
|
|
|
|
* screen coordinates by swapping and/or mirroring. The flags defined by
|
|
|
|
* this enumeration can be ORed for a combined conversion. In this case,
|
|
|
|
* the swapping is performed before the mirroring.
|
|
|
|
*
|
|
|
|
* @note The maximum X and Y screen coordinates defined by
|
|
|
|
* @ref stmpe811_params_t::xmax and @ref stmpe811_params_t::ymax
|
|
|
|
* define the dimension of the touch device in screen coordinates,
|
|
|
|
* i.e. after conversion.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
STMPE811_NO_CONV = 0x00, /**< No conversion */
|
|
|
|
STMPE811_MIRROR_X = 0x01, /**< Mirror X, applied after optional swapping */
|
|
|
|
STMPE811_MIRROR_Y = 0x02, /**< Mirror Y, applied after optional swapping */
|
|
|
|
STMPE811_SWAP_XY = 0x04, /**< Swap XY, applied before optional mirroring */
|
|
|
|
} stmpe811_touch_conv_t;
|
|
|
|
|
2019-04-28 17:54:09 +02:00
|
|
|
/**
|
|
|
|
* @brief Touch position structure
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
uint16_t x; /**< X position */
|
|
|
|
uint16_t y; /**< Y position */
|
|
|
|
} stmpe811_touch_position_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Signature of touch event callback triggered from interrupt
|
|
|
|
*
|
|
|
|
* @param[in] arg optional context for the callback
|
|
|
|
*/
|
2020-07-21 22:02:10 +02:00
|
|
|
typedef void (*stmpe811_event_cb_t)(void *arg);
|
2019-04-28 17:54:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Device initialization parameters
|
2023-08-14 15:25:29 +02:00
|
|
|
*
|
|
|
|
* @note stmpe811_params_t::xmax and stmpe811_params_t::ymax define the
|
|
|
|
* maximum X and Y values in screen coordinates after the optional
|
|
|
|
* conversion defined by stmpe811_params_t::xmax.
|
2019-04-28 17:54:09 +02:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2021-10-23 12:09:27 +02:00
|
|
|
#if IS_USED(MODULE_STMPE811_SPI)
|
|
|
|
/* SPI configuration */
|
|
|
|
spi_t spi; /**< SPI bus */
|
|
|
|
spi_mode_t mode; /**< SPI mode */
|
|
|
|
spi_clk_t clk; /**< clock speed for the SPI bus */
|
|
|
|
gpio_t cs; /**< chip select pin */
|
|
|
|
#else
|
|
|
|
/* I2C details */
|
2019-04-28 17:54:09 +02:00
|
|
|
i2c_t i2c; /**< I2C device which is used */
|
|
|
|
uint8_t addr; /**< Device I2C address */
|
2021-10-23 12:09:27 +02:00
|
|
|
#endif
|
2019-04-28 17:54:09 +02:00
|
|
|
gpio_t int_pin; /**< Touch screen interrupt pin */
|
|
|
|
uint16_t xmax; /**< Touch screen max X position */
|
|
|
|
uint16_t ymax; /**< Touch screen max Y position */
|
2023-08-14 15:25:29 +02:00
|
|
|
stmpe811_touch_conv_t xyconv; /**< Touch screen coordinates conversion,
|
|
|
|
swapping is applied before mirroring */
|
2019-04-28 17:54:09 +02:00
|
|
|
} stmpe811_params_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Device descriptor for the STMPE811 sensor
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2020-02-10 15:55:42 +01:00
|
|
|
#ifdef MODULE_TOUCH_DEV
|
|
|
|
touch_dev_t *dev; /**< Pointer to the generic touch device */
|
|
|
|
#endif
|
|
|
|
stmpe811_params_t params; /**< Device parameters */
|
2020-07-21 22:02:10 +02:00
|
|
|
stmpe811_event_cb_t cb; /**< Configured IRQ event callback */
|
|
|
|
void *cb_arg; /**< Extra argument for the callback */
|
2020-02-10 15:55:42 +01:00
|
|
|
uint16_t prev_x; /**< Previous X coordinate */
|
|
|
|
uint16_t prev_y; /**< Previous Y coordinate */
|
2019-04-28 17:54:09 +02:00
|
|
|
} stmpe811_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize the given STMPE811 device
|
|
|
|
*
|
|
|
|
* @param[inout] dev Device descriptor of the STMPE811
|
|
|
|
* @param[in] params Initialization parameters of the STMPE811 device
|
|
|
|
* @param[in] cb Callback function called on touch interrupts
|
|
|
|
* @param[in] arg Context argument used in callback function
|
|
|
|
*
|
2021-10-23 11:50:02 +02:00
|
|
|
* @return 0 on success
|
|
|
|
* @return -ENODEV when no valid device
|
|
|
|
* @return -EIO when software reset failed
|
2021-10-23 12:09:27 +02:00
|
|
|
* @return -EPROTO on any bus error
|
2019-04-28 17:54:09 +02:00
|
|
|
*/
|
|
|
|
int stmpe811_init(stmpe811_t *dev, const stmpe811_params_t * params,
|
2020-07-21 22:02:10 +02:00
|
|
|
stmpe811_event_cb_t cb, void *arg);
|
2019-04-28 17:54:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read the touch position
|
|
|
|
*
|
|
|
|
* @param[in] dev Device descriptor of the STMPE811
|
|
|
|
* @param[out] position Touch position
|
|
|
|
*
|
2021-10-23 11:50:02 +02:00
|
|
|
* @return 0 on success
|
2021-10-23 12:09:27 +02:00
|
|
|
* @return -EPROTO on any bus error
|
2019-04-28 17:54:09 +02:00
|
|
|
*/
|
|
|
|
int stmpe811_read_touch_position(stmpe811_t *dev, stmpe811_touch_position_t *position);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read the touch state (pressed or released)
|
|
|
|
*
|
|
|
|
* @param[in] dev Device descriptor of the STMPE811
|
|
|
|
* @param[out] state Touch state
|
|
|
|
*
|
2021-10-23 11:50:02 +02:00
|
|
|
* @return 0 on success
|
2021-10-23 12:09:27 +02:00
|
|
|
* @return -EPROTO on any busI2aC error
|
2019-04-28 17:54:09 +02:00
|
|
|
*/
|
|
|
|
int stmpe811_read_touch_state(const stmpe811_t *dev, stmpe811_touch_state_t *state);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* STMPE811_H */
|
|
|
|
/** @} */
|