Skip to content

Commit

Permalink
samples: subsys: display: lvgl: Add lvgl-encoder-input device
Browse files Browse the repository at this point in the history
Adds a zephyr,lvgl-encoder-input compatible to the native_posix board
overlay and the required code to control an arc widget.

Signed-off-by: Fabian Blatz <[email protected]>
  • Loading branch information
faxe1008 authored and carlescufi committed Sep 13, 2023
1 parent 0943428 commit c64724e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
24 changes: 22 additions & 2 deletions samples/subsys/display/lvgl/boards/native_posix.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
sw0 = &button0;
};

qdec {
compatible = "gpio-qdec";
gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>, <&gpio0 5 GPIO_ACTIVE_HIGH>;
steps-per-period = <4>;
zephyr,axis = <INPUT_REL_WHEEL>;
sample-time-us = <2000>;
idle-timeout-ms = <200>;
};

keys: keys {
compatible = "gpio-keys";
button0: button0 {
Expand All @@ -23,6 +32,11 @@
gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
zephyr,code = <INPUT_KEY_1>;
};

encoder_button: encoder_button {
gpios = <&gpio0 3 GPIO_ACTIVE_HIGH>;
zephyr,code = <INPUT_KEY_ENTER>;
};
};

lvgl_button_input {
Expand All @@ -31,15 +45,21 @@
input-codes = <INPUT_KEY_1>;
coordinates = <160 120>;
};

lvgl_encoder_input {
compatible = "zephyr,lvgl-encoder-input";
rotation-input-code = <INPUT_REL_WHEEL>;
button-input-code = <INPUT_KEY_ENTER>;
};
};

&gpio0 {
ngpios = <3>;
ngpios = <6>;

sdl_gpio {
status = "okay";
compatible = "zephyr,gpio-emul-sdl";
/* Skip pin 0 with the unknown code 0 */
scancodes = <0 21 5>;
scancodes = <0 21 5 30 31 32>;
};
};
1 change: 1 addition & 0 deletions samples/subsys/display/lvgl/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CONFIG_LV_MEM_CUSTOM=y
CONFIG_LV_USE_LOG=y
CONFIG_LV_USE_LABEL=y
CONFIG_LV_USE_BTN=y
CONFIG_LV_USE_ARC=y
CONFIG_LV_USE_IMG=y
CONFIG_LV_USE_MONKEY=y
CONFIG_LV_FONT_MONTSERRAT_14=y
23 changes: 21 additions & 2 deletions samples/subsys/display/lvgl/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <stdio.h>
#include <string.h>
#include <zephyr/kernel.h>
#include <lvgl_input_device.h>

#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <zephyr/logging/log.h>
Expand All @@ -34,7 +35,12 @@ static void button_isr_callback(const struct device *port,

count = 0;
}
#endif
#endif /* CONFIG_GPIO */

#ifdef CONFIG_LV_Z_ENCODER_INPUT
static const struct device *lvgl_encoder =
DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(zephyr_lvgl_encoder_input));
#endif /* CONFIG_LV_Z_ENCODER_INPUT */

static void lv_btn_click_callback(lv_event_t *e)
{
Expand Down Expand Up @@ -82,7 +88,20 @@ int main(void)
return 0;
}
}
#endif
#endif /* CONFIG_GPIO */

#ifdef CONFIG_LV_Z_ENCODER_INPUT
lv_obj_t *arc;
lv_group_t *arc_group;

arc = lv_arc_create(lv_scr_act());
lv_obj_align(arc, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_size(arc, 150, 150);

arc_group = lv_group_create();
lv_group_add_obj(arc_group, arc);
lv_indev_set_group(lvgl_input_get_indev(lvgl_encoder), arc_group);
#endif /* CONFIG_LV_Z_ENCODER_INPUT */

if (IS_ENABLED(CONFIG_LV_Z_POINTER_KSCAN) || IS_ENABLED(CONFIG_LV_Z_POINTER_INPUT)) {
lv_obj_t *hello_world_button;
Expand Down

0 comments on commit c64724e

Please sign in to comment.