mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/cst816s: add touch_dev interface
This commit is contained in:
parent
b1ac9e124d
commit
a2fc925a0e
@ -1 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
include $(RIOTMAKE)/driver_with_touch_dev.mk
|
||||
|
93
drivers/cst816s/cst816s_touch_dev.c
Normal file
93
drivers/cst816s/cst816s_touch_dev.c
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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_cst816s
|
||||
* @{
|
||||
*
|
||||
* @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 "board.h"
|
||||
#include "cst816s.h"
|
||||
#include "cst816s_touch_dev.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
#ifndef CST816S_XMAX
|
||||
#define CST816S_XMAX 240
|
||||
#endif
|
||||
|
||||
#ifndef CST816S_YMAX
|
||||
#define CST816S_YMAX 240
|
||||
#endif
|
||||
|
||||
uint16_t _cst816s_height(const touch_dev_t *touch_dev)
|
||||
{
|
||||
const cst816s_t *dev = (const cst816s_t *)touch_dev;
|
||||
assert(dev);
|
||||
|
||||
return CST816S_YMAX;
|
||||
}
|
||||
|
||||
uint16_t _cst816s_width(const touch_dev_t *touch_dev)
|
||||
{
|
||||
const cst816s_t *dev = (const cst816s_t *)touch_dev;
|
||||
assert(dev);
|
||||
|
||||
return CST816S_XMAX;
|
||||
}
|
||||
|
||||
uint8_t _cst816s_touches(const touch_dev_t *touch_dev, touch_t *touches, size_t len)
|
||||
{
|
||||
(void)len;
|
||||
|
||||
cst816s_t *dev = (cst816s_t *)touch_dev;
|
||||
assert(dev);
|
||||
|
||||
cst816s_touch_data_t data;
|
||||
cst816s_read(dev, &data);
|
||||
uint8_t ret = (data.action == CST816S_TOUCH_DOWN);
|
||||
|
||||
if (ret && touches != NULL) {
|
||||
touches[0].x = data.x;
|
||||
touches[0].y = data.y;
|
||||
|
||||
DEBUG("X: %i, Y: %i\n", touches[0].x, touches[0].y);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void _cst816s_set_event_callback(const touch_dev_t *touch_dev, touch_event_cb_t cb, void *arg)
|
||||
{
|
||||
cst816s_t *dev = (cst816s_t *)touch_dev;
|
||||
assert(dev);
|
||||
|
||||
dev->cb = (cst816s_irq_cb_t)cb;
|
||||
dev->cb_arg = arg;
|
||||
}
|
||||
|
||||
const touch_dev_driver_t cst816s_touch_dev_driver = {
|
||||
.height = _cst816s_height,
|
||||
.width = _cst816s_width,
|
||||
.touches = _cst816s_touches,
|
||||
.set_event_callback = _cst816s_set_event_callback,
|
||||
};
|
@ -75,6 +75,21 @@ static const cst816s_params_t cst816s_params[] =
|
||||
*/
|
||||
#define CST816S_NUMOF ARRAY_SIZE(cst816s_params)
|
||||
|
||||
/**
|
||||
* @brief Default screen identifiers
|
||||
*/
|
||||
#ifndef CST816S_PARAM_SCREEN_IDS
|
||||
#define CST816S_PARAM_SCREEN_IDS 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Configure screen identifiers
|
||||
*/
|
||||
static const uint8_t cst816s_screen_ids[] =
|
||||
{
|
||||
CST816S_PARAM_SCREEN_IDS,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
38
drivers/cst816s/include/cst816s_touch_dev.h
Normal file
38
drivers/cst816s/include/cst816s_touch_dev.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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_cst816s
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Definition of the driver for the touch_dev generic interface
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef CST816S_TOUCH_DEV_H
|
||||
#define CST816S_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 cst816s_touch_dev_driver;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CST816S_TOUCH_DEV_H */
|
||||
/** @} */
|
@ -46,6 +46,10 @@
|
||||
#include "periph/i2c.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
#ifdef MODULE_TOUCH_DEV
|
||||
#include "touch_dev.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -108,6 +112,9 @@ typedef struct {
|
||||
* @brief cst816s device descriptor
|
||||
*/
|
||||
typedef struct {
|
||||
#ifdef MODULE_TOUCH_DEV
|
||||
touch_dev_t *dev; /**< Pointer to the generic touch device */
|
||||
#endif
|
||||
const cst816s_params_t *params; /**< Device parameters */
|
||||
cst816s_irq_cb_t cb; /**< Configured IRQ event callback */
|
||||
void *cb_arg; /**< Extra argument for the callback */
|
||||
|
50
sys/auto_init/screen/auto_init_cst816s.c
Normal file
50
sys/auto_init/screen/auto_init_cst816s.c
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 sys_auto_init
|
||||
* @{
|
||||
* @file
|
||||
* @brief initializes cst816s display device
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "touch_dev.h"
|
||||
|
||||
#include "cst816s.h"
|
||||
#include "cst816s_params.h"
|
||||
#include "cst816s_touch_dev.h"
|
||||
|
||||
cst816s_t cst816s_devs[CST816S_NUMOF];
|
||||
static touch_dev_reg_t touch_dev_entries[CST816S_NUMOF];
|
||||
|
||||
void auto_init_cst816s(void)
|
||||
{
|
||||
assert(CST816S_NUMOF == ARRAY_SIZE(cst816s_screen_ids));
|
||||
|
||||
for (size_t i = 0; i < CST816S_NUMOF; i++) {
|
||||
LOG_DEBUG("[auto_init_screen] initializing cst816s #%u\n", i);
|
||||
if (cst816s_init(&cst816s_devs[i], &cst816s_params[i], NULL, NULL) < 0) {
|
||||
LOG_ERROR("[auto_init_screen] error initializing cst816s #%u\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
touch_dev_entries[i].dev = (touch_dev_t *)&cst816s_devs[i];
|
||||
touch_dev_entries[i].screen_id = cst816s_screen_ids[i];
|
||||
touch_dev_entries[i].dev->driver = &cst816s_touch_dev_driver;
|
||||
|
||||
/* add to touch_dev registry */
|
||||
touch_dev_reg_add(&(touch_dev_entries[i]));
|
||||
}
|
||||
}
|
@ -41,6 +41,10 @@ void auto_init_screen(void)
|
||||
|
||||
if (IS_USED(MODULE_TOUCH_DEV)) {
|
||||
DEBUG("auto_init_screen: init touch drivers\n");
|
||||
if (IS_USED(MODULE_CST816S)) {
|
||||
extern void auto_init_cst816s(void);
|
||||
auto_init_cst816s();
|
||||
}
|
||||
if (IS_USED(MODULE_STMPE811)) {
|
||||
extern void auto_init_stmpe811(void);
|
||||
auto_init_stmpe811();
|
||||
|
Loading…
Reference in New Issue
Block a user