Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions samples/subsys/display/lvgl/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/

#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/display.h>
#include <zephyr/drivers/gpio.h>
#include <lvgl.h>
#include <stdio.h>
#include <string.h>
Expand All @@ -15,9 +17,28 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(app);

static uint32_t count;

#ifdef CONFIG_GPIO
static struct gpio_dt_spec button_gpio = GPIO_DT_SPEC_GET_OR(
DT_ALIAS(sw0), gpios, {0});
static struct gpio_callback button_callback;

static void button_isr_callback(const struct device *port,
struct gpio_callback *cb,
uint32_t pins)
{
ARG_UNUSED(port);
ARG_UNUSED(cb);
ARG_UNUSED(pins);

count = 0;
}
#endif

void main(void)
{
uint32_t count = 0U;
int err;
char count_str[11] = {0};
const struct device *display_dev;
lv_obj_t *hello_world_label;
Expand All @@ -29,6 +50,32 @@ void main(void)
return;
}

#ifdef CONFIG_GPIO
if (device_is_ready(button_gpio.port)) {
err = gpio_pin_configure_dt(&button_gpio, GPIO_INPUT);
if (err) {
LOG_ERR("failed to configure button gpio: %d", err);
return;
}

gpio_init_callback(&button_callback, button_isr_callback,
BIT(button_gpio.pin));

err = gpio_add_callback(button_gpio.port, &button_callback);
if (err) {
LOG_ERR("failed to add button callback: %d", err);
return;
}

err = gpio_pin_interrupt_configure_dt(&button_gpio,
GPIO_INT_EDGE_TO_ACTIVE);
if (err) {
LOG_ERR("failed to enable button callback: %d", err);
return;
}
}
#endif

if (IS_ENABLED(CONFIG_LV_Z_POINTER_KSCAN)) {
lv_obj_t *hello_world_button;

Expand All @@ -54,7 +101,7 @@ void main(void)
lv_label_set_text(count_label, count_str);
}
lv_task_handler();
k_sleep(K_MSEC(10));
++count;
k_sleep(K_MSEC(10));
}
}