From ac091252f1ee7495a348309ec9fb2b92d31fceee Mon Sep 17 00:00:00 2001 From: Fabian Blatz Date: Mon, 18 Sep 2023 07:05:22 +0200 Subject: [PATCH] modules: lvgl: fix initialization order depedencies Removes the pseudo device prerequisite that the LVGL setup routine has been executed before initialization. The pseudo devices are now registered at the end of the LVGL setup routine, the driver is not concerned with configuring the devices anymore. This also removes the need for enforcing certain priorities within the same init level. This resolves issue #62753. Signed-off-by: Fabian Blatz --- modules/lvgl/Kconfig.input | 4 --- modules/lvgl/include/lvgl_button_input.h | 22 ++++++++++++++ .../{input => include}/lvgl_common_input.h | 1 + modules/lvgl/include/lvgl_encoder_input.h | 22 ++++++++++++++ modules/lvgl/include/lvgl_pointer_input.h | 22 ++++++++++++++ modules/lvgl/input/lvgl_button_input.c | 7 +++-- modules/lvgl/input/lvgl_common_input.c | 30 +++++++++++++++++++ modules/lvgl/input/lvgl_encoder_input.c | 7 +++-- modules/lvgl/input/lvgl_pointer_input.c | 7 +++-- modules/lvgl/input/lvgl_pointer_kscan.c | 2 +- modules/lvgl/lvgl.c | 12 ++++---- 11 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 modules/lvgl/include/lvgl_button_input.h rename modules/lvgl/{input => include}/lvgl_common_input.h (97%) create mode 100644 modules/lvgl/include/lvgl_encoder_input.h create mode 100644 modules/lvgl/include/lvgl_pointer_input.h diff --git a/modules/lvgl/Kconfig.input b/modules/lvgl/Kconfig.input index dc1a747fb0d166b..b6cbdad0c283b80 100644 --- a/modules/lvgl/Kconfig.input +++ b/modules/lvgl/Kconfig.input @@ -4,10 +4,6 @@ menu "Input device settings" -config LV_Z_INPUT_INIT_PRIORITY - int - default 91 - config LV_Z_POINTER_KSCAN bool "Keyboard scan pointer input" depends on KSCAN diff --git a/modules/lvgl/include/lvgl_button_input.h b/modules/lvgl/include/lvgl_button_input.h new file mode 100644 index 000000000000000..dd97b5e7c7f196c --- /dev/null +++ b/modules/lvgl/include/lvgl_button_input.h @@ -0,0 +1,22 @@ +/* + * Copyright 2023 Fabian Blatz + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_MODULES_LVGL_LVGL_BUTTON_INPUT_H_ +#define ZEPHYR_MODULES_LVGL_LVGL_BUTTON_INPUT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int lvgl_button_input_init(const struct device *dev); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_MODULES_LVGL_LVGL_BUTTON_INPUT_H_ */ diff --git a/modules/lvgl/input/lvgl_common_input.h b/modules/lvgl/include/lvgl_common_input.h similarity index 97% rename from modules/lvgl/input/lvgl_common_input.h rename to modules/lvgl/include/lvgl_common_input.h index e9d0ef34f8480b9..a218ed29647d569 100644 --- a/modules/lvgl/input/lvgl_common_input.h +++ b/modules/lvgl/include/lvgl_common_input.h @@ -26,6 +26,7 @@ struct lvgl_common_input_data { }; int lvgl_input_register_driver(lv_indev_type_t indev_type, const struct device *dev); +int lvgl_init_input_devices(void); #define LVGL_INPUT_EVENT_MSGQ(inst, type) lvgl_input_msgq_##type##_##inst #define LVGL_INPUT_DEVICE(inst) DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE(inst, input)) diff --git a/modules/lvgl/include/lvgl_encoder_input.h b/modules/lvgl/include/lvgl_encoder_input.h new file mode 100644 index 000000000000000..1fe9a23c2c4f348 --- /dev/null +++ b/modules/lvgl/include/lvgl_encoder_input.h @@ -0,0 +1,22 @@ +/* + * Copyright 2023 Fabian Blatz + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_MODULES_LVGL_LVGL_ENCODER_INPUT_H_ +#define ZEPHYR_MODULES_LVGL_LVGL_ENCODER_INPUT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int lvgl_encoder_input_init(const struct device *dev); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_MODULES_LVGL_LVGL_ENCODER_INPUT_H_ */ diff --git a/modules/lvgl/include/lvgl_pointer_input.h b/modules/lvgl/include/lvgl_pointer_input.h new file mode 100644 index 000000000000000..f168477b982da72 --- /dev/null +++ b/modules/lvgl/include/lvgl_pointer_input.h @@ -0,0 +1,22 @@ +/* + * Copyright 2023 Fabian Blatz + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_MODULES_LVGL_LVGL_POINTER_INPUT_H_ +#define ZEPHYR_MODULES_LVGL_LVGL_POINTER_INPUT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int lvgl_pointer_input_init(const struct device *dev); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_MODULES_LVGL_LVGL_POINTER_INPUT_H_ */ diff --git a/modules/lvgl/input/lvgl_button_input.c b/modules/lvgl/input/lvgl_button_input.c index 5d6f64c82b6dcd2..f9c9d59f4d53655 100644 --- a/modules/lvgl/input/lvgl_button_input.c +++ b/modules/lvgl/input/lvgl_button_input.c @@ -7,6 +7,7 @@ #define DT_DRV_COMPAT zephyr_lvgl_button_input #include "lvgl_common_input.h" +#include "lvgl_button_input.h" #include @@ -44,7 +45,7 @@ static void lvgl_button_process_event(const struct device *dev, struct input_eve } } -static int lvgl_button_input_init(const struct device *dev) +int lvgl_button_input_init(const struct device *dev) { struct lvgl_common_input_data *data = dev->data; const struct lvgl_button_input_config *cfg = dev->config; @@ -79,8 +80,8 @@ static int lvgl_button_input_init(const struct device *dev) .coordinates = lvgl_button_coordinates_##inst, \ }; \ static struct lvgl_common_input_data lvgl_common_input_data_##inst; \ - DEVICE_DT_INST_DEFINE(inst, lvgl_button_input_init, NULL, &lvgl_common_input_data_##inst, \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &lvgl_common_input_data_##inst, \ &lvgl_button_input_config_##inst, POST_KERNEL, \ - CONFIG_LV_Z_INPUT_INIT_PRIORITY, NULL); + CONFIG_INPUT_INIT_PRIORITY, NULL); DT_INST_FOREACH_STATUS_OKAY(LVGL_BUTTON_INPUT_DEFINE) diff --git a/modules/lvgl/input/lvgl_common_input.c b/modules/lvgl/input/lvgl_common_input.c index 82814f53fae2afb..5e7e1474368ea1b 100644 --- a/modules/lvgl/input/lvgl_common_input.c +++ b/modules/lvgl/input/lvgl_common_input.c @@ -9,6 +9,9 @@ #include #include #include +#include "lvgl_pointer_input.h" +#include "lvgl_button_input.h" +#include "lvgl_encoder_input.h" LOG_MODULE_DECLARE(lvgl); @@ -52,3 +55,30 @@ int lvgl_input_register_driver(lv_indev_type_t indev_type, const struct device * return 0; } + +#define LV_DEV_INIT(node_id, init_fn) \ + do { \ + int ret = init_fn(DEVICE_DT_GET(node_id)); \ + if (ret) { \ + return ret; \ + } \ + } while (0) + +int lvgl_init_input_devices(void) +{ +#ifdef CONFIG_LV_Z_POINTER_INPUT + DT_FOREACH_STATUS_OKAY_VARGS(zephyr_lvgl_pointer_input, LV_DEV_INIT, + lvgl_pointer_input_init); +#endif /* CONFIG_LV_Z_POINTER_INPUT */ + +#ifdef CONFIG_LV_Z_BUTTON_INPUT + DT_FOREACH_STATUS_OKAY_VARGS(zephyr_lvgl_button_input, LV_DEV_INIT, lvgl_button_input_init); +#endif /* CONFIG_LV_Z_BUTTON_INPUT */ + +#ifdef CONFIG_LV_Z_ENCODER_INPUT + DT_FOREACH_STATUS_OKAY_VARGS(zephyr_lvgl_encoder_input, LV_DEV_INIT, + lvgl_encoder_input_init); +#endif /* CONFIG_LV_Z_ENCODER_INPUT */ + + return 0; +} diff --git a/modules/lvgl/input/lvgl_encoder_input.c b/modules/lvgl/input/lvgl_encoder_input.c index 655275c7264c73d..a49f1eeca299e36 100644 --- a/modules/lvgl/input/lvgl_encoder_input.c +++ b/modules/lvgl/input/lvgl_encoder_input.c @@ -7,6 +7,7 @@ #define DT_DRV_COMPAT zephyr_lvgl_encoder_input #include "lvgl_common_input.h" +#include "lvgl_encoder_input.h" #include @@ -37,7 +38,7 @@ static void lvgl_encoder_process_event(const struct device *dev, struct input_ev } } -static int lvgl_encoder_input_init(const struct device *dev) +int lvgl_encoder_input_init(const struct device *dev) { return lvgl_input_register_driver(LV_INDEV_TYPE_ENCODER, dev); } @@ -64,8 +65,8 @@ static int lvgl_encoder_input_init(const struct device *dev) .button_input_code = BUTTON_CODE(inst), \ }; \ static struct lvgl_common_input_data lvgl_common_input_data_##inst; \ - DEVICE_DT_INST_DEFINE(inst, lvgl_encoder_input_init, NULL, &lvgl_common_input_data_##inst, \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &lvgl_common_input_data_##inst, \ &lvgl_encoder_input_config_##inst, POST_KERNEL, \ - CONFIG_LV_Z_INPUT_INIT_PRIORITY, NULL); + CONFIG_INPUT_INIT_PRIORITY, NULL); DT_INST_FOREACH_STATUS_OKAY(LVGL_ENCODER_INPUT_DEFINE) diff --git a/modules/lvgl/input/lvgl_pointer_input.c b/modules/lvgl/input/lvgl_pointer_input.c index ed01a1d1515950a..19c71eb197217d4 100644 --- a/modules/lvgl/input/lvgl_pointer_input.c +++ b/modules/lvgl/input/lvgl_pointer_input.c @@ -7,6 +7,7 @@ #define DT_DRV_COMPAT zephyr_lvgl_pointer_input #include "lvgl_common_input.h" +#include "lvgl_pointer_input.h" #include #include @@ -108,7 +109,7 @@ static void lvgl_pointer_process_event(const struct device *dev, struct input_ev } } -static int lvgl_pointer_input_init(const struct device *dev) +int lvgl_pointer_input_init(const struct device *dev) { return lvgl_input_register_driver(LV_INDEV_TYPE_POINTER, dev); } @@ -123,8 +124,8 @@ static int lvgl_pointer_input_init(const struct device *dev) .invert_y = DT_INST_PROP(inst, invert_y), \ }; \ static struct lvgl_common_input_data lvgl_common_input_data_##inst; \ - DEVICE_DT_INST_DEFINE(inst, lvgl_pointer_input_init, NULL, &lvgl_common_input_data_##inst, \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &lvgl_common_input_data_##inst, \ &lvgl_pointer_input_config_##inst, POST_KERNEL, \ - CONFIG_LV_Z_INPUT_INIT_PRIORITY, NULL); + CONFIG_INPUT_INIT_PRIORITY, NULL); DT_INST_FOREACH_STATUS_OKAY(LVGL_POINTER_INPUT_DEFINE) diff --git a/modules/lvgl/input/lvgl_pointer_kscan.c b/modules/lvgl/input/lvgl_pointer_kscan.c index f3115ffa029db36..197106e4f2c3a5b 100644 --- a/modules/lvgl/input/lvgl_pointer_kscan.c +++ b/modules/lvgl/input/lvgl_pointer_kscan.c @@ -146,4 +146,4 @@ static int lvgl_kscan_pointer_init(void) return 0; } -SYS_INIT(lvgl_kscan_pointer_init, APPLICATION, CONFIG_LV_Z_INPUT_INIT_PRIORITY); +SYS_INIT(lvgl_kscan_pointer_init, APPLICATION, CONFIG_INPUT_INIT_PRIORITY); diff --git a/modules/lvgl/lvgl.c b/modules/lvgl/lvgl.c index ec242924e0a4882..0f4c24e9a34f257 100644 --- a/modules/lvgl/lvgl.c +++ b/modules/lvgl/lvgl.c @@ -8,6 +8,7 @@ #include #include #include "lvgl_display.h" +#include "lvgl_common_input.h" #ifdef CONFIG_LV_Z_USE_FILESYSTEM #include "lvgl_fs.h" #endif @@ -241,12 +242,13 @@ static int lvgl_init(void) return -EPERM; } + err = lvgl_init_input_devices(); + if (err < 0) { + LOG_ERR("Failed to initialize input devices."); + return err; + } + return 0; } -BUILD_ASSERT(CONFIG_APPLICATION_INIT_PRIORITY < CONFIG_LV_Z_INPUT_INIT_PRIORITY); -#ifdef CONFIG_INPUT -BUILD_ASSERT(CONFIG_INPUT_INIT_PRIORITY < CONFIG_LV_Z_INPUT_INIT_PRIORITY); -#endif /* CONFIG_INPUT */ - SYS_INIT(lvgl_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);