mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/ft5x06: use a const pointer to params instead of a copy
There is no need to copy the configuration parameter set to the device descriptor. A const pointer to the configuration parameter set in ROM is sufficient. It saves some 16 byte of RAM.
This commit is contained in:
parent
2a4496b32a
commit
d88e46b3d5
@ -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);
|
||||
@ -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);
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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];
|
||||
@ -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);
|
||||
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -37,7 +37,7 @@ 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)
|
||||
@ -45,7 +45,7 @@ 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)
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user