Description
When pressing the button on the the Zephyr sample I am getting an error:
[00:00:01.159,332] <err> cst816s: failed reading chip id
*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
[00:00:01.163,635] <inf> app: Starting...
[00:00:42.109,527] <err> cst816s: Could not read x data
[00:00:42.609,710] <err> cst816s: Could not read x data
[00:00:43.109,863] <err> cst816s: Could not read x data
[00:00:43.130,889] <err> cst816s: Could not read x data
[00:00:45.089,874] <err> cst816s: Could not read x data
[00:00:45.589,996] <err> cst816s: Could not read x data
What MCU/Processor/Board and compiler are you using?
nrf5340 DK with nRF Connect for Visual Studio Code and Zephyr RTOS. The display is a Waveshare 1.69 inch screen.
What LVGL version are you using?
8.3
What do you want to achieve?
Pressing the button. Swipe left, right, up, and down next.
What have you tried so far?
Searching for similar bugs and resolution.
Code to reproduce
main.c
#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>
#include <zephyr/kernel.h>
#include <lvgl_input_device.h>
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#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 /* 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)
{
LOG_INF("lv_btn_click_callback called");
ARG_UNUSED(e);
count = 0;
}
int main(void)
{
char count_str[11] = {0};
const struct device *display_dev;
lv_obj_t *hello_world_label;
lv_obj_t *count_label;
LOG_INF("Starting...");
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
LOG_ERR("Device not ready, aborting test");
return 0;
}
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_black(), LV_PART_MAIN);
lv_obj_set_style_text_color(lv_scr_act(), lv_color_white(), LV_PART_MAIN);
#ifdef CONFIG_GPIO
if (gpio_is_ready_dt(&button_gpio)) {
int err;
err = gpio_pin_configure_dt(&button_gpio, GPIO_INPUT);
if (err) {
LOG_ERR("failed to configure button gpio: %d", err);
return 0;
}
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 0;
}
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 0;
}
}
#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;
hello_world_button = lv_btn_create(lv_scr_act());
lv_obj_align(hello_world_button, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(hello_world_button, lv_btn_click_callback, LV_EVENT_CLICKED,
NULL);
hello_world_label = lv_label_create(hello_world_button);
} else {
hello_world_label = lv_label_create(lv_scr_act());
}
lv_label_set_text(hello_world_label, "Hello world!");
lv_obj_align(hello_world_label, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_style_text_font(hello_world_label, &lv_font_montserrat_16, LV_PART_MAIN);
count_label = lv_label_create(lv_scr_act());
lv_obj_align(count_label, LV_ALIGN_BOTTOM_MID, 0, 0);
lv_obj_set_style_text_font(count_label, &lv_font_montserrat_16, LV_PART_MAIN);
lv_task_handler();
display_blanking_off(display_dev);
while (1) {
if ((count % 100) == 0U) {
sprintf(count_str, "%d", count/100U);
lv_label_set_text(count_label, count_str);
}
lv_task_handler();
++count;
k_sleep(K_MSEC(10));
}
}
prj.conf
CONFIG_LV_Z_MEM_POOL_SIZE=16384
CONFIG_LV_Z_SHELL=y
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_DISPLAY=y
CONFIG_DISPLAY_LOG_LEVEL_ERR=y
CONFIG_DISPLAY_LOG_LEVEL_INF=y
CONFIG_LOG=y
CONFIG_SHELL=y
CONFIG_LVGL=y
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_16=y
#added to get touch working
CONFIG_INPUT=y
CONFIG_LV_Z_POINTER_INPUT=y
CONFIG_LV_Z_ENCODER_INPUT=y
nrf5340dk_nrf5340_cpuapp.overlay
&pinctrl {
spi4_default: spi4_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 6)>,
<NRF_PSEL(SPIM_MOSI, 0, 25)>;
};
};
spi4_sleep: spi4_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 6)>,
<NRF_PSEL(SPIM_MOSI, 0, 25)>;
low-power-enable;
};
};
// Set to I2C pins that the touch screen is connected to
i2c2_default: i2c2_default {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 1, 2)>,
<NRF_PSEL(TWIM_SCL, 1, 3)>;
};
};
i2c2_sleep: i2c2_sleep {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 1, 2)>,
<NRF_PSEL(TWIM_SCL, 1, 3)>;
low-power-enable;
};
};
};
&spi4 {
compatible = "nordic,nrf-spim";
status = "okay";
pinctrl-0 = <&spi4_default>;
pinctrl-1 = <&spi4_sleep>;
pinctrl-names = "default", "sleep";
cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
st7789v_st7789v_tl019fqv01: st7789v@0 {
compatible = "sitronix,st7789v";
spi-max-frequency = <20000000>;
reg = <0>;
cmd-data-gpios = < &gpio1 11 GPIO_ACTIVE_LOW>;
reset-gpios = < &gpio1 10 GPIO_ACTIVE_LOW>;
width = <240>;
height = <280>;
x-offset = <0>;
y-offset = <0>;
vcom = <0x19>;
gctrl = <0x35>;
vrhs = <0x12>;
vdvs = <0x20>;
mdac = <0x00>;
gamma = <0x01>;
colmod = <0x05>;
lcm = <0x2c>;
porch-param = [0c 0c 00 33 33];
cmd2en-param = [5a 69 02 01];
pwctrl1-param = [a4 a1];
pvgam-param = [D0 04 0D 11 13 2B 3F 54 4C 18 0D 0B 1F 23];
nvgam-param = [D0 04 0C 11 13 2C 3F 44 51 2F 1F 1F 20 23];
ram-param = [00 F0];
rgb-param = [CD 08 14];
};
};
&i2c2 {
compatible = "nordic,nrf-twim";
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
pinctrl-0 = <&i2c2_default>;
pinctrl-1 = <&i2c2_sleep>;
pinctrl-names = "default", "sleep";
cst816s: cst816s@15 {
compatible = "hynitron,cst816s";
reg = <0x15>;
irq-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
rst-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>;
};
};
/ {
fstab {
compatible = "zephyr,fstab";
lfs: lfs {
compatible = "zephyr,fstab,littlefs";
mount-point = "/lfs";
partition = <&littlefs_storage>;
automount;
read-size = <16>;
prog-size = <16>;
cache-size = <64>;
lookahead-size = <32>;
block-cycles = <512>;
};
};
};
/delete-node/ &storage_partition;
&mx25r64 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
littlefs_storage: partition@0 {
label = "littlefs_storage";
reg = <0x00000000 0x00200000>;
};
lvgl_raw_partition: partition@200000 {
label = "lvgl_raw_partition";
reg = <0x00200000 0x00200000>;
};
settings_partition: partition@400000 {
label = "settings_partition";
reg = <0x400000 0x100000 >;
};
};
};
/ {
chosen {
nordic,pm-ext-flash = &mx25r64;
zephyr,display = &st7789v_st7789v_tl019fqv01;
zephyr,keyboard-scan = &cst816s;
};
/*
aliases {
vibrator_pwm = &led0;
};
*/
lvgl_pointer_input: lvgl_pointer {
compatible = "zephyr,lvgl-pointer-input";
input = <&cst816s>;
swap-xy;
invert-x;
};
aliases {
input = &cst816s;
};
vib_pwr: vib-pwr-ctrl {
compatible = "regulator-fixed";
regulator-name = "vib-pwr-ctrl";
enable-gpios = <&gpio1 14 GPIO_ACTIVE_HIGH>;
};
};