1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/ft5x06: allow multiple device types

This commit is contained in:
Leandro Lanzieri 2022-01-19 18:13:25 +01:00
parent c21730a765
commit 4eb58d74b5
No known key found for this signature in database
GPG Key ID: F4E9A721761C7593
10 changed files with 130 additions and 22 deletions

View File

@ -68,6 +68,7 @@ extern "C" {
#define FT5X06_PARAM_INT_PIN GPIO_PIN(PORT_I, 9) /**< Interrupt pin */
#define FT5X06_PARAM_XMAX (240) /**< Max width */
#define FT5X06_PARAM_YMAX (240) /**< Max height */
#define FT5X06_PARAM_TYPE FT5X06_TYPE_FT6X06 /**< Device type */
/** @} */
/**

View File

@ -73,6 +73,7 @@ extern "C" {
#define FT5X06_PARAM_INT_PIN GPIO_PIN(PORT_I, 13) /**< Interrupt pin */
#define FT5X06_PARAM_XMAX (480) /**< Max width */
#define FT5X06_PARAM_YMAX (272) /**< Max height */
#define FT5X06_PARAM_TYPE FT5X06_TYPE_FT5336 /**< Device type */
/** @} */
/**

View File

@ -14705,3 +14705,4 @@ drivers/ft5x06/include/ft5x06_constants\.h:[0-9]+: warning: Member FT5X06_G_MODE
drivers/ft5x06/include/ft5x06_constants\.h:[0-9]+: warning: Member FT5X06_G_MODE_INTERRUPT_SHIFT \(macro definition\) of file ft5x06_constants\.h is not documented\.
drivers/ft5x06/include/ft5x06_constants\.h:[0-9]+: warning: Member FT5X06_G_MODE_INTERRUPT_POLLING \(macro definition\) of file ft5x06_constants\.h is not documented\.
drivers/ft5x06/include/ft5x06_constants\.h:[0-9]+: warning: Member FT5X06_G_MODE_INTERRUPT_TRIGGER \(macro definition\) of file ft5x06_constants\.h is not documented\.
drivers/ft5x06/include/ft5x06_params\.h:[0-9]+: warning: Member FT5X06_PARAM_TYPE \(macro definition\) of file ft5x06_params\.h is not documented\.

View File

@ -27,6 +27,7 @@
#include "ztimer.h"
#include "ft5x06.h"
#include "ft5x06_internal.h"
#include "ft5x06_constants.h"
#include "ft5x06_params.h"
@ -53,15 +54,24 @@ int ft5x06_init(ft5x06_t *dev, const ft5x06_params_t *params, ft5x06_event_cb_t
return -EPROTO;
}
if (vendor_id != FT5X06_VENDOR_ID) {
uint8_t expected_id;
if (dev->params.type == FT5X06_TYPE_FT6X06 || dev->params.type == FT5X06_TYPE_FT6X36) {
expected_id = FT6XX6_VENDOR_ID;
}
else {
expected_id = FT5X06_VENDOR_ID;
}
if (expected_id != vendor_id) {
DEBUG("[ft5x06] init: invalid vendor ID: '0x%02x' (expected: 0x%02x)\n",
vendor_id, FT5X06_VENDOR_ID);
vendor_id, expected_id);
i2c_release(FT5X06_BUS);
return -ENODEV;
}
/* Auto-calibrate if needed */
if (IS_ACTIVE(FT5X06_AUTO_CALIB_NEEDED)) {
if (dev->params.type == FT5X06_TYPE_FT5606|| dev->params.type == FT5X06_TYPE_FT5X16 ||
dev->params.type == FT5X06_TYPE_FT5X06I) {
DEBUG("[ft5x06] init: enable device auto-calibration\n");
i2c_write_reg(FT5X06_BUS, FT5X06_ADDR, FT5X06_G_AUTO_CLB_MODE_REG, 0, 0);
}
@ -81,11 +91,9 @@ int ft5x06_init(ft5x06_t *dev, const ft5x06_params_t *params, ft5x06_event_cb_t
static const uint8_t touch_reg_map[FT5X06_TOUCHES_COUNT_MAX] = {
FT5X06_TOUCH1_XH_REG,
FT5X06_TOUCH2_XH_REG,
#if FT5X06_TOUCHES_COUNT_MAX > 2
FT5X06_TOUCH3_XH_REG,
FT5X06_TOUCH4_XH_REG,
FT5X06_TOUCH5_XH_REG,
#endif
};
int ft5x06_read_touch_positions(const ft5x06_t *dev, ft5x06_touch_position_t *positions, size_t len)
@ -113,7 +121,7 @@ int ft5x06_read_touch_count(const ft5x06_t *dev, uint8_t *count)
i2c_release(FT5X06_BUS);
*count &= FT5X06_TD_STATUS_MASK;
if (*count > FT5X06_TOUCHES_COUNT_MAX) {
if (*count > ft5x06_get_touches_count_max(dev)) {
*count = 0;
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 HAW Hamburg
*
* 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.
*/
/**
* @{
* @file
* @brief Implementation of internal functions for ft5x06
*
* @author Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
* @}
*/
#include <inttypes.h>
#include "ft5x06.h"
#include "ft5x06_internal.h"
uint8_t ft5x06_get_touches_count_max(const ft5x06_t *dev) {
if (dev->params.type == FT5X06_TYPE_FT6X06 || dev->params.type == FT5X06_TYPE_FT6X36) {
return FT6XX6_TOUCHES_COUNT_MAX;
}
else {
return FT5X06_TOUCHES_COUNT_MAX;
}
}

View File

@ -26,6 +26,7 @@
#include "periph/gpio.h"
#include "ft5x06.h"
#include "ft5x06_internal.h"
#include "ft5x06_touch_dev.h"
#define ENABLE_DEBUG 0
@ -56,7 +57,7 @@ uint8_t _ft5x06_touches(const touch_dev_t *touch_dev, touch_t *touches, size_t l
ft5x06_read_touch_count(dev, &ret);
if (ret && touches != NULL) {
assert(len <= FT5X06_TOUCHES_COUNT_MAX);
assert(len <= ft5x06_get_touches_count_max(dev));
ft5x06_read_touch_positions(dev, (ft5x06_touch_position_t *)touches, len);
}

View File

@ -30,23 +30,27 @@ extern "C" {
* @{
*/
#define FT5X06_I2C_DEFAULT_ADDRESS (0x38)
#if IS_USED(MODULE_FT6X06) || IS_USED(MODULE_FT6X36)
#define FT5X06_VENDOR_ID (0xcd)
#else
/**
* @brief Vendor ID for FT6X06 and FT6X36 models.
*/
#define FT6XX6_VENDOR_ID (0xcd)
/**
* @brief Vendor ID for FT5606, FT5X16, FT5X06I, FT5336, FT3316, FT5436I, FT5336I, FT5X46 models.
*/
#define FT5X06_VENDOR_ID (0x51)
#endif
#if IS_USED(MODULE_FT6X06) || IS_USED(MODULE_FT6X36)
#define FT5X06_TOUCHES_COUNT_MAX (2)
#else
/**
* @brief Maximum touches count for FT6X06 and FT6X36 models.
*/
#define FT6XX6_TOUCHES_COUNT_MAX (2)
/**
* @brief Maximum touches count for FT5606, FT5X16, FT5X06I, FT5336, FT3316, FT5436I, FT5336I,
* FT5X46 models.
*/
#define FT5X06_TOUCHES_COUNT_MAX (5)
#endif
#if IS_USED(MODULE_FT6X06) || IS_USED(MODULE_FT6X36) || IS_USED(MODULE_FT5336) || \
IS_USED(MODULE_FT3316) || IS_USED(MODULE_FT5436I) || IS_USED(MODULE_FT5336I) || \
IS_USED(MODULE_FT5X46)
#define FT5X06_AUTO_CALIB_NEEDED 0
#else
#define FT5X06_AUTO_CALIB_NEEDED 1
#endif
/** @} */
/**

View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2022 HAW Hamburg
*
* 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.
*/
/**
* @{
* @file
* @brief FT5X06 internal functions
*
* @author Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
*/
#ifndef FT5X06_INTERNAL_H
#define FT5X06_INTERNAL_H
#include <inttypes.h>
#include "ft5x06.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Get the maximum touches count of a device, based on its model.
*
* @param[in] dev Device descriptor of the driver
*
* @return Maximum touches count
*/
uint8_t ft5x06_get_touches_count_max(const ft5x06_t *dev);
#ifdef __cplusplus
}
#endif
#endif /* FT5X06_INTERNAL_H */
/** @} */

View File

@ -49,6 +49,9 @@ extern "C" {
#ifndef FT5X06_PARAM_YMAX
#define FT5X06_PARAM_YMAX (272U)
#endif
#ifndef FT5X06_PARAM_TYPE
#define FT5X06_PARAM_TYPE FT5X06_TYPE_FT5336
#endif
#define FT5X06_PARAMS { \
.i2c = FT5X06_PARAM_I2C_DEV, \
@ -56,6 +59,7 @@ extern "C" {
.int_pin = FT5X06_PARAM_INT_PIN, \
.xmax = FT5X06_PARAM_XMAX, \
.ymax = FT5X06_PARAM_YMAX, \
.type = FT5X06_PARAM_TYPE \
}
/**@}*/

View File

@ -60,6 +60,23 @@ typedef enum {
FT5X06_TOUCH_ZOOM_OUT, /**< Zoom out gesture detected */
} ft5x06_touch_gesture_t;
/**
* @brief Device type
*/
typedef enum {
FT5X06_TYPE_FT5X06, /**< FT5X06 */
FT5X06_TYPE_FT5606, /**< FT5606 */
FT5X06_TYPE_FT5X16, /**< FT5X16 */
FT5X06_TYPE_FT6X06, /**< FT6X06 */
FT5X06_TYPE_FT6X36, /**< FT6X36 */
FT5X06_TYPE_FT5X06I, /**< FT5X06I */
FT5X06_TYPE_FT5336, /**< FT5336 */
FT5X06_TYPE_FT3316, /**< FT3316 */
FT5X06_TYPE_FT5436I, /**< FT5436I */
FT5X06_TYPE_FT5336I, /**< FT5336I */
FT5X06_TYPE_FT5X46, /**< FT5X46 */
} ft5x06_type_t;
/**
* @brief Signature of the touch event callback triggered from interrupt
*
@ -76,6 +93,7 @@ typedef struct {
gpio_t int_pin; /**< Touch screen interrupt pin */
uint16_t xmax; /**< Touch screen max X position */
uint16_t ymax; /**< Touch screen max Y position */
ft5x06_type_t type; /**< Device type */
} ft5x06_params_t;
/**