input: add a user_data pointer to the callback

Add a void *user_data pointer to the input callback structure. This is
useful for driver to get back the driver data structure and avoid
defining wrapper functions.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
Fabio Baltieri 2024-07-27 18:20:01 +01:00 committed by Carles Cufí
commit 716fa268f4
18 changed files with 65 additions and 60 deletions

View file

@ -195,7 +195,7 @@ static int last_checked_event_count;
zassert_equal(_val, test_event_data.val); \
}
static void test_cb(struct input_event *evt)
static void test_cb(struct input_event *evt, void *user_data)
{
static int row, col, val;
@ -220,7 +220,7 @@ static void test_cb(struct input_event *evt)
test_event_data.event_count, row, col, val);
}
}
INPUT_CALLBACK_DEFINE(NULL, test_cb);
INPUT_CALLBACK_DEFINE(NULL, test_cb, NULL);
/* actual tests */

View file

@ -35,7 +35,7 @@ ZTEST_SUITE(gpio_keys, NULL, NULL, NULL, NULL, NULL);
static int event_count;
static uint16_t last_code;
static bool last_val;
static void test_gpio_keys_cb_handler(struct input_event *evt)
static void test_gpio_keys_cb_handler(struct input_event *evt, void *user_data)
{
TC_PRINT("GPIO_KEY %s pressed, zephyr_code=%u, value=%d\n",
evt->dev->name, evt->code, evt->value);
@ -43,7 +43,7 @@ static void test_gpio_keys_cb_handler(struct input_event *evt)
last_code = evt->code;
last_val = evt->value;
}
INPUT_CALLBACK_DEFINE(test_gpio_keys_dev, test_gpio_keys_cb_handler);
INPUT_CALLBACK_DEFINE(test_gpio_keys_dev, test_gpio_keys_cb_handler, NULL);
/**
* @brief TestPurpose: Verify gpio_keys_config pressed raw.

View file

@ -103,7 +103,7 @@ static int last_checked_event_count;
zassert_equal(_val, test_event_data.val); \
}
static void test_cb(struct input_event *evt)
static void test_cb(struct input_event *evt, void *user_data)
{
static int row, col, val;
@ -128,7 +128,7 @@ static void test_cb(struct input_event *evt)
test_event_data.event_count, row, col, val);
}
}
INPUT_CALLBACK_DEFINE(test_dev, test_cb);
INPUT_CALLBACK_DEFINE(test_dev, test_cb, NULL);
#define WAIT_FOR_IDLE_TIMEOUT_US (5 * USEC_PER_SEC)

View file

@ -17,7 +17,7 @@ static int message_count_unfiltered;
static K_SEM_DEFINE(cb_start, 1, 1);
static K_SEM_DEFINE(cb_done, 1, 1);
static void input_cb_filtered(struct input_event *evt)
static void input_cb_filtered(struct input_event *evt, void *user_data)
{
TC_PRINT("%s: %d\n", __func__, message_count_filtered);
@ -29,9 +29,9 @@ static void input_cb_filtered(struct input_event *evt)
k_sem_give(&cb_start);
}
INPUT_CALLBACK_DEFINE(&fake_dev, input_cb_filtered);
INPUT_CALLBACK_DEFINE(&fake_dev, input_cb_filtered, NULL);
static void input_cb_unfiltered(struct input_event *evt)
static void input_cb_unfiltered(struct input_event *evt, void *user_data)
{
TC_PRINT("%s: %d\n", __func__, message_count_unfiltered);
@ -42,7 +42,7 @@ static void input_cb_unfiltered(struct input_event *evt)
k_sem_give(&cb_done);
}
}
INPUT_CALLBACK_DEFINE(NULL, input_cb_unfiltered);
INPUT_CALLBACK_DEFINE(NULL, input_cb_unfiltered, NULL);
ZTEST(input_api, test_sequence_thread)
{
@ -85,19 +85,19 @@ ZTEST(input_api, test_sequence_thread)
#else /* CONFIG_INPUT_MODE_THREAD */
static void input_cb_filtered(struct input_event *evt)
static void input_cb_filtered(struct input_event *evt, void *user_data)
{
if (evt->dev == &fake_dev) {
message_count_filtered++;
}
}
INPUT_CALLBACK_DEFINE(&fake_dev, input_cb_filtered);
INPUT_CALLBACK_DEFINE(&fake_dev, input_cb_filtered, NULL);
static void input_cb_unfiltered(struct input_event *evt)
static void input_cb_unfiltered(struct input_event *evt, void *user_data)
{
message_count_unfiltered++;
}
INPUT_CALLBACK_DEFINE(NULL, input_cb_unfiltered);
INPUT_CALLBACK_DEFINE(NULL, input_cb_unfiltered, NULL);
ZTEST(input_api, test_synchronous)
{
@ -118,11 +118,11 @@ ZTEST(input_api, test_synchronous)
static struct input_event last_event;
static void input_cb_last_event(struct input_event *evt)
static void input_cb_last_event(struct input_event *evt, void *user_data)
{
memcpy(&last_event, evt, sizeof(last_event));
}
INPUT_CALLBACK_DEFINE(NULL, input_cb_last_event);
INPUT_CALLBACK_DEFINE(NULL, input_cb_last_event, NULL);
ZTEST(input_api, test_report_apis)
{

View file

@ -22,7 +22,7 @@ DEVICE_DT_DEFINE(DT_INST(0, vnd_input_device), NULL, NULL, NULL, NULL,
static int event_count;
static struct input_event last_events[2];
static void test_cb(struct input_event *evt)
static void test_cb(struct input_event *evt, void *user_data)
{
TC_PRINT("%s: %d %x %d\n", __func__, event_count, evt->code, evt->value);
@ -30,11 +30,11 @@ static void test_cb(struct input_event *evt)
memcpy(&last_events[1], &last_events[0], sizeof(struct input_event));
memcpy(&last_events[0], evt, sizeof(struct input_event));
}
INPUT_CALLBACK_DEFINE(longpress_dev, test_cb);
INPUT_CALLBACK_DEFINE(longpress_dev, test_cb, NULL);
static int event_count_no_short;
static struct input_event last_events_no_short[2];
static void test_cb_no_short(struct input_event *evt)
static void test_cb_no_short(struct input_event *evt, void *user_data)
{
TC_PRINT("%s: %d %x %d\n", __func__, event_count_no_short, evt->code, evt->value);
@ -42,7 +42,7 @@ static void test_cb_no_short(struct input_event *evt)
memcpy(&last_events_no_short[1], &last_events_no_short[0], sizeof(struct input_event));
memcpy(&last_events_no_short[0], evt, sizeof(struct input_event));
}
INPUT_CALLBACK_DEFINE(longpress_no_short_dev, test_cb_no_short);
INPUT_CALLBACK_DEFINE(longpress_no_short_dev, test_cb_no_short, NULL);
ZTEST(longpress, test_longpress_test)
{