1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-28 16:01:18 +01:00

Merge pull request #17459 from aabadie/pr/drivers/cst816s_enh

drivers/cst816s: add touch_dev interface + add Kconfig + migrate to ztimer
This commit is contained in:
Alexandre Abadie 2022-04-19 11:43:34 +02:00 committed by GitHub
commit 718b1e350d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 226 additions and 10 deletions

View File

@ -16,6 +16,7 @@ config BOARD_PINETIME
select HAS_PERIPH_SPI
select HAS_VDD_LC_FILTER_REG1
select HAVE_CST816S
select HAVE_ILI9341
select HAVE_MTD_SPI_NOR

View File

@ -11,5 +11,9 @@ ifneq (,$(filter disp_dev,$(USEMODULE)))
USEMODULE += ili9341
endif
ifneq (,$(filter touch_dev,$(USEMODULE)))
USEMODULE += cst816s
endif
# include common nrf52 dependencies
include $(RIOTBOARD)/common/nrf52/Makefile.dep

View File

@ -77,6 +77,7 @@ rsource "bmp180/Kconfig"
rsource "bmx055/Kconfig"
rsource "bmx280/Kconfig"
rsource "ccs811/Kconfig"
rsource "cst816s/Kconfig"
rsource "dcf77/Kconfig"
rsource "dht/Kconfig"
rsource "ds18/Kconfig"

View File

@ -12,9 +12,11 @@ config MODULE_CST816S
depends on TEST_KCONFIG
select MODULE_PERIPH_GPIO_IRQ
select MODULE_PERIPH_I2C
select MODULE_XTIMER
select MODULE_ZTIMER
select MODULE_ZTIMER_MSEC
config HAVE_CST816S
bool
select MODULE_CST816S if MODULE_TOUCH_DEV
help
Indicates that a cst816s touch screen is present.

View File

@ -1 +1 @@
include $(RIOTBASE)/Makefile.base
include $(RIOTMAKE)/driver_with_touch_dev.mk

View File

@ -1,3 +1,4 @@
FEATURES_REQUIRED += periph_gpio_irq
FEATURES_REQUIRED += periph_i2c
USEMODULE += xtimer
USEMODULE += ztimer
USEMODULE += ztimer_msec

View File

@ -21,7 +21,7 @@
#include "log.h"
#include "periph/gpio.h"
#include "periph/i2c.h"
#include "xtimer.h"
#include "ztimer.h"
#include "cst816s.h"
#include "cst816s_internal.h"
@ -55,9 +55,9 @@ static void _cst816s_reset(const cst816s_t *dev)
/* Reset, sleep durations based on
* https://github.com/lupyuen/hynitron_i2c_cst0xxse/blob/master/cst0xx_core.c#L1078-L1085 */
gpio_clear(dev->params->reset);
xtimer_usleep(CST816S_RESET_DURATION_LOW);
ztimer_sleep(ZTIMER_MSEC, CST816S_RESET_DURATION_LOW_MS);
gpio_set(dev->params->reset);
xtimer_usleep(CST816S_RESET_DURATION_HIGH);
ztimer_sleep(ZTIMER_MSEC, CST816S_RESET_DURATION_HIGH_MS);
}
int cst816s_read(const cst816s_t *dev, cst816s_touch_data_t *data)
@ -89,12 +89,12 @@ int cst816s_init(cst816s_t *dev, const cst816s_params_t *params,
dev->cb = cb;
dev->cb_arg = arg;
if (dev->params->reset != GPIO_UNDEF) {
if (gpio_is_valid(dev->params->reset)) {
gpio_init(dev->params->reset, GPIO_OUT);
_cst816s_reset(dev);
}
if ((dev->params->irq != GPIO_UNDEF) && cb) {
if (gpio_is_valid(dev->params->irq) && cb) {
if (gpio_init_int(dev->params->irq, GPIO_IN,
dev->params->irq_flank,
_gpio_irq, dev) < 0) {

View 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,
};

View File

@ -25,8 +25,8 @@ extern "C" {
* @name cst816s timing constants
* @{
*/
#define CST816S_RESET_DURATION_LOW (20 * US_PER_MS)
#define CST816S_RESET_DURATION_HIGH (400 * US_PER_MS)
#define CST816S_RESET_DURATION_LOW_MS (20) /**< Duration of reset pin low (in ms) */
#define CST816S_RESET_DURATION_HIGH_MS (400) /**< Duration of reset pin high (in ms) */
/** @} */
#ifdef __cplusplus

View File

@ -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

View 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 */
/** @} */

View File

@ -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 */

View 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]));
}
}

View File

@ -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();