mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/ft5x06: add touch_dev interface
This commit is contained in:
parent
0080657d63
commit
f5b5af9469
81
drivers/ft5x06/ft5x06_touch_dev.c
Normal file
81
drivers/ft5x06/ft5x06_touch_dev.c
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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_ft5x06
|
||||
* @{
|
||||
*
|
||||
* @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 "periph/gpio.h"
|
||||
|
||||
#include "ft5x06.h"
|
||||
#include "ft5x06_touch_dev.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
uint16_t _ft5x06_height(const touch_dev_t *touch_dev)
|
||||
{
|
||||
const ft5x06_t *dev = (const ft5x06_t *)touch_dev;
|
||||
assert(dev);
|
||||
|
||||
return dev->params.ymax;
|
||||
}
|
||||
|
||||
uint16_t _ft5x06_width(const touch_dev_t *touch_dev)
|
||||
{
|
||||
const ft5x06_t *dev = (const ft5x06_t *)touch_dev;
|
||||
assert(dev);
|
||||
|
||||
return dev->params.xmax;
|
||||
}
|
||||
|
||||
uint8_t _ft5x06_touches(const touch_dev_t *touch_dev, touch_t *touches, size_t len)
|
||||
{
|
||||
ft5x06_t *dev = (ft5x06_t *)touch_dev;
|
||||
assert(dev);
|
||||
|
||||
uint8_t ret;
|
||||
ft5x06_read_touch_count(dev, &ret);
|
||||
|
||||
if (ret && touches != NULL) {
|
||||
assert(len <= FT5X06_TOUCHES_COUNT_MAX);
|
||||
ft5x06_read_touch_positions(dev, (ft5x06_touch_position_t *)touches, len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void _ft5x06_set_event_callback(const touch_dev_t *touch_dev, touch_event_cb_t cb, void *arg)
|
||||
{
|
||||
ft5x06_t *dev = (ft5x06_t *)touch_dev;
|
||||
assert(dev);
|
||||
|
||||
if (gpio_is_valid(dev->params.int_pin)) {
|
||||
gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_RISING, cb, arg);
|
||||
}
|
||||
}
|
||||
|
||||
const touch_dev_driver_t ft5x06_touch_dev_driver = {
|
||||
.height = _ft5x06_height,
|
||||
.width = _ft5x06_width,
|
||||
.touches = _ft5x06_touches,
|
||||
.set_event_callback = _ft5x06_set_event_callback,
|
||||
};
|
38
drivers/ft5x06/include/ft5x06_touch_dev.h
Normal file
38
drivers/ft5x06/include/ft5x06_touch_dev.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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_ft5x06
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Definition of the driver for the touch_dev generic interface
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef FT5X06_TOUCH_DEV_H
|
||||
#define FT5X06_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 ft5x06_touch_dev_driver;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FT5X06_TOUCH_DEV_H */
|
||||
/** @} */
|
52
sys/auto_init/screen/auto_init_ft5x06.c
Normal file
52
sys/auto_init/screen/auto_init_ft5x06.c
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 ft5x06 touch panel device
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "touch_dev.h"
|
||||
|
||||
#include "ft5x06.h"
|
||||
#include "ft5x06_params.h"
|
||||
#include "ft5x06_touch_dev.h"
|
||||
|
||||
#define FT5X06_NUMOF ARRAY_SIZE(ft5x06_params)
|
||||
|
||||
ft5x06_t ft5x06_devs[FT5X06_NUMOF];
|
||||
static touch_dev_reg_t touch_dev_entries[FT5X06_NUMOF];
|
||||
|
||||
void auto_init_ft5x06(void)
|
||||
{
|
||||
assert(FT5X06_NUMOF == ARRAY_SIZE(ft5x06_screen_ids));
|
||||
|
||||
for (size_t i = 0; i < FT5X06_NUMOF; i++) {
|
||||
LOG_DEBUG("[auto_init_screen] initializing ft5x06 #%u\n", i);
|
||||
if (ft5x06_init(&ft5x06_devs[i], &ft5x06_params[i], NULL, NULL) < 0) {
|
||||
LOG_ERROR("[auto_init_screen] error initializing ft5x06 #%u\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
touch_dev_entries[i].dev = (touch_dev_t *)&ft5x06_devs[i];
|
||||
touch_dev_entries[i].screen_id = ft5x06_screen_ids[i];
|
||||
touch_dev_entries[i].dev->driver = &ft5x06_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)
|
||||
extern void auto_init_stmpe811(void);
|
||||
auto_init_stmpe811();
|
||||
}
|
||||
if (IS_USED(MODULE_FT5X06)) {
|
||||
extern void auto_init_ft5x06(void);
|
||||
auto_init_ft5x06();
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_USED(MODULE_LVGL)) {
|
||||
|
Loading…
Reference in New Issue
Block a user