Skip to content

Commit

Permalink
modules: lvgl: fix initialization order depedencies
Browse files Browse the repository at this point in the history
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 zephyrproject-rtos#62753.

Signed-off-by: Fabian Blatz <[email protected]>
  • Loading branch information
faxe1008 authored and coran21 committed Sep 21, 2023
1 parent e57f2c3 commit ac09125
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 19 deletions.
4 changes: 0 additions & 4 deletions modules/lvgl/Kconfig.input
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions modules/lvgl/include/lvgl_button_input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2023 Fabian Blatz <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_MODULES_LVGL_LVGL_BUTTON_INPUT_H_
#define ZEPHYR_MODULES_LVGL_LVGL_BUTTON_INPUT_H_

#include <zephyr/device.h>

#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_ */
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 22 additions & 0 deletions modules/lvgl/include/lvgl_encoder_input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2023 Fabian Blatz <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_MODULES_LVGL_LVGL_ENCODER_INPUT_H_
#define ZEPHYR_MODULES_LVGL_LVGL_ENCODER_INPUT_H_

#include <zephyr/device.h>

#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_ */
22 changes: 22 additions & 0 deletions modules/lvgl/include/lvgl_pointer_input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2023 Fabian Blatz <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_MODULES_LVGL_LVGL_POINTER_INPUT_H_
#define ZEPHYR_MODULES_LVGL_LVGL_POINTER_INPUT_H_

#include <zephyr/device.h>

#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_ */
7 changes: 4 additions & 3 deletions modules/lvgl/input/lvgl_button_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define DT_DRV_COMPAT zephyr_lvgl_button_input

#include "lvgl_common_input.h"
#include "lvgl_button_input.h"

#include <zephyr/logging/log.h>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
30 changes: 30 additions & 0 deletions modules/lvgl/input/lvgl_common_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <lvgl_input_device.h>
#include "lvgl_pointer_input.h"
#include "lvgl_button_input.h"
#include "lvgl_encoder_input.h"

LOG_MODULE_DECLARE(lvgl);

Expand Down Expand Up @@ -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;
}
7 changes: 4 additions & 3 deletions modules/lvgl/input/lvgl_encoder_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define DT_DRV_COMPAT zephyr_lvgl_encoder_input

#include "lvgl_common_input.h"
#include "lvgl_encoder_input.h"

#include <zephyr/logging/log.h>

Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
7 changes: 4 additions & 3 deletions modules/lvgl/input/lvgl_pointer_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define DT_DRV_COMPAT zephyr_lvgl_pointer_input

#include "lvgl_common_input.h"
#include "lvgl_pointer_input.h"

#include <lvgl_display.h>
#include <zephyr/logging/log.h>
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
2 changes: 1 addition & 1 deletion modules/lvgl/input/lvgl_pointer_kscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 7 additions & 5 deletions modules/lvgl/lvgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <zephyr/kernel.h>
#include <lvgl.h>
#include "lvgl_display.h"
#include "lvgl_common_input.h"
#ifdef CONFIG_LV_Z_USE_FILESYSTEM
#include "lvgl_fs.h"
#endif
Expand Down Expand Up @@ -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);

0 comments on commit ac09125

Please sign in to comment.