drivers/stmpe811: provide adaption to touch_dev interface

This commit is contained in:
Alexandre Abadie 2020-02-10 15:55:42 +01:00
parent 3d557556e0
commit c0f46c06bb
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
3 changed files with 118 additions and 3 deletions

View File

@ -25,6 +25,10 @@
#include "periph/gpio.h"
#include "periph/i2c.h"
#ifdef MODULE_TOUCH_DEV
#include "touch_dev.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -77,9 +81,12 @@ typedef struct {
* @brief Device descriptor for the STMPE811 sensor
*/
typedef struct {
stmpe811_params_t params; /**< Device parameters */
uint16_t prev_x; /**< Previous X coordinate */
uint16_t prev_y; /**< Previous Y coordinate */
#ifdef MODULE_TOUCH_DEV
touch_dev_t *dev; /**< Pointer to the generic touch device */
#endif
stmpe811_params_t params; /**< Device parameters */
uint16_t prev_x; /**< Previous X coordinate */
uint16_t prev_y; /**< Previous Y coordinate */
} stmpe811_t;
/**

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2020 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.
*/
/**
* @ingroup drivers_stmpe811
* @{
*
* @file
* @brief Definition of the driver for the touch_dev generic interface
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*/
#ifndef STMPE811_TOUCH_DEV_H
#define STMPE811_TOUCH_DEV_H
#include "touch_dev.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Reference to the touch device driver struct
*/
extern const touch_dev_driver_t stmpe811_touch_dev_driver;
#ifdef __cplusplus
}
#endif
#endif /* STMPE811_TOUCH_DEV_H */

View File

@ -0,0 +1,71 @@
/*
* Copyright (C) 2020 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.
*/
/**
* @ingroup drivers_stmpe811
* @{
*
* @file
* @brief Driver adaption to touch_dev generic interface
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
* @}
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <assert.h>
#include "kernel_defines.h"
#include "stmpe811.h"
#include "stmpe811_touch_dev.h"
uint16_t _stmpe811_height(const touch_dev_t *touch_dev)
{
const stmpe811_t *dev = (const stmpe811_t *)touch_dev;
assert(dev);
return dev->params.ymax;
}
uint16_t _stmpe811_width(const touch_dev_t *touch_dev)
{
const stmpe811_t *dev = (const stmpe811_t *)touch_dev;
assert(dev);
return dev->params.xmax;
}
uint8_t _stmpe811_touches(const touch_dev_t *touch_dev, touch_t *touches, size_t len)
{
(void)len;
stmpe811_t *dev = (stmpe811_t *)touch_dev;
assert(dev);
stmpe811_touch_state_t state;
stmpe811_read_touch_state(dev, &state);
uint8_t ret = (state == STMPE811_TOUCH_STATE_PRESSED);
if (ret && touches != NULL) {
stmpe811_touch_position_t pos;
stmpe811_read_touch_position(dev, &pos);
touches[0].x = pos.x;
touches[0].y = pos.y;
}
return ret;
}
const touch_dev_driver_t stmpe811_touch_dev_driver = {
.height = _stmpe811_height,
.width = _stmpe811_width,
.touches = _stmpe811_touches,
};