Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/ft5x06: use a pointer to config parameters instead of copying them #19866

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions drivers/ft5x06/ft5x06.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
#define ENABLE_DEBUG 0
#include "debug.h"

#define FT5X06_BUS (dev->params.i2c)
#define FT5X06_ADDR (dev->params.addr)
#define FT5X06_BUS (dev->params->i2c)
#define FT5X06_ADDR (dev->params->addr)

#define FT5X06_RESET_DELAY_MS (200)

int ft5x06_init(ft5x06_t *dev, const ft5x06_params_t *params, ft5x06_event_cb_t cb, void *arg)
{
dev->params = *params;
assert(dev);
assert(params);

dev->params = params;

/* Wait at least 200ms after power up before accessing registers */
ztimer_sleep(ZTIMER_MSEC, FT5X06_RESET_DELAY_MS);
Expand All @@ -54,7 +57,7 @@ int ft5x06_init(ft5x06_t *dev, const ft5x06_params_t *params, ft5x06_event_cb_t
return -EPROTO;
}

if (dev->params.type == FT5X06_TYPE_FT6X06 || dev->params.type == FT5X06_TYPE_FT6X36) {
if (dev->params->type == FT5X06_TYPE_FT6X06 || dev->params->type == FT5X06_TYPE_FT6X36) {
if ((vendor_id != FT5X06_VENDOR_ID_2) && (vendor_id != FT5X06_VENDOR_ID_3)) {
DEBUG("[ft5x06] init: invalid vendor ID: '0x%02x' (expected: 0x%02x or 0x%02x)\n",
vendor_id, FT5X06_VENDOR_ID_2, FT5X06_VENDOR_ID_3);
Expand All @@ -70,16 +73,16 @@ int ft5x06_init(ft5x06_t *dev, const ft5x06_params_t *params, ft5x06_event_cb_t
}

/* Auto-calibrate if needed */
if (dev->params.type == FT5X06_TYPE_FT5606|| dev->params.type == FT5X06_TYPE_FT5X16 ||
dev->params.type == FT5X06_TYPE_FT5X06I) {
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);
}

/* Configure interrupt */
if (gpio_is_valid(dev->params.int_pin)) {
if (gpio_is_valid(dev->params->int_pin)) {
DEBUG("[ft5x06] init: configuring touchscreen interrupt\n");
gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_RISING, cb, arg);
gpio_init_int(dev->params->int_pin, GPIO_IN, GPIO_RISING, cb, arg);
i2c_write_reg(FT5X06_BUS, FT5X06_ADDR, FT5X06_G_MODE_REG, FT5X06_G_MODE_INTERRUPT_TRIGGER & 0x01, 0);
}

Expand All @@ -98,6 +101,9 @@ static const uint8_t touch_reg_map[FT5X06_TOUCHES_COUNT_MAX] = {

int ft5x06_read_touch_positions(const ft5x06_t *dev, ft5x06_touch_position_t *positions, size_t len)
{
assert(dev);
assert(positions);

i2c_acquire(FT5X06_BUS);
for (uint8_t touch = 0; touch < len; touch++) {
uint8_t regs[4];
Expand All @@ -116,6 +122,9 @@ int ft5x06_read_touch_positions(const ft5x06_t *dev, ft5x06_touch_position_t *po

int ft5x06_read_touch_count(const ft5x06_t *dev, uint8_t *count)
{
assert(dev);
assert(count);

i2c_acquire(FT5X06_BUS);
i2c_read_reg(FT5X06_BUS, FT5X06_ADDR, FT5X06_TD_STATUS_REG, count, 0);
i2c_release(FT5X06_BUS);
Expand All @@ -130,6 +139,9 @@ int ft5x06_read_touch_count(const ft5x06_t *dev, uint8_t *count)

int ft5x06_read_touch_gesture(const ft5x06_t *dev, ft5x06_touch_gesture_t *gesture)
{
assert(dev);
assert(gesture);

uint8_t gesture_id = 0;
i2c_acquire(FT5X06_BUS);
i2c_read_reg(FT5X06_BUS, FT5X06_ADDR, FT5X06_GESTURE_ID_REG, &gesture_id, 0);
Expand Down
2 changes: 1 addition & 1 deletion drivers/ft5x06/ft5x06_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#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) {
if (dev->params->type == FT5X06_TYPE_FT6X06 || dev->params->type == FT5X06_TYPE_FT6X36) {
return FT6XX6_TOUCHES_COUNT_MAX;
}
else {
Expand Down
8 changes: 4 additions & 4 deletions drivers/ft5x06/ft5x06_touch_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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;
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;
return dev->params->xmax;
}

uint8_t _ft5x06_touches(const touch_dev_t *touch_dev, touch_t *touches, size_t len)
Expand All @@ -69,8 +69,8 @@ void _ft5x06_set_event_callback(const touch_dev_t *touch_dev, touch_event_cb_t c
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);
if (gpio_is_valid(dev->params->int_pin)) {
gpio_init_int(dev->params->int_pin, GPIO_IN, GPIO_RISING, cb, arg);
}
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/include/ft5x06.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ typedef struct {
*/
typedef struct {
#ifdef MODULE_TOUCH_DEV
touch_dev_t *dev; /**< Pointer to the generic touch device */
touch_dev_t *dev; /**< Pointer to the generic touch device */
#endif
ft5x06_params_t params; /**< Initialization parameters */
const ft5x06_params_t *params; /**< Initialization parameters */
} ft5x06_t;

/**
Expand Down