Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions drivers/display/display_stm32_ltdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ static int stm32_ltdc_write(const struct device *dev, const uint16_t x,
const uint8_t *src = buf;
uint16_t row;

/* Validate the given parameters */
if (x + desc->width > config->width || y + desc->height > config->height) {
LOG_ERR("Rectangle does not fit into the display");
return -EINVAL;
}

if ((x == 0) && (y == 0) &&
(desc->width == config->width) &&
(desc->height == config->height) &&
Expand Down Expand Up @@ -249,6 +255,12 @@ static int stm32_ltdc_read(const struct device *dev, const uint16_t x,
const uint8_t *src = data->front_buf;
uint16_t row;

/* Validate the given parameters */
if (x + desc->width > config->width || y + desc->height > config->height) {
LOG_ERR("Rectangle does not fit into the display");
return -EINVAL;
}

/* src = pointer to upper left pixel of the rectangle to be read from frame buffer */
src += (x * data->current_pixel_size);
src += (y * config->width * data->current_pixel_size);
Expand Down
62 changes: 56 additions & 6 deletions samples/drivers/display/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ int main(void)
struct display_buffer_descriptor buf_desc;
size_t buf_size = 0;
fill_buffer fill_buffer_fnc = NULL;
int ret;

display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
Expand Down Expand Up @@ -362,7 +363,15 @@ int main(void)
if ((capabilities.y_resolution - idx) < h_step) {
buf_desc.height = (capabilities.y_resolution - idx);
}
display_write(display_dev, 0, idx, &buf_desc, buf);
ret = display_write(display_dev, 0, idx, &buf_desc, buf);
if (ret < 0) {
LOG_ERR("Failed to write to display (error %d)", ret);
#ifdef CONFIG_ARCH_POSIX
posix_exit_main(1);
#else
return 0;
#endif
}
}

buf_desc.pitch = rect_w;
Expand All @@ -372,12 +381,28 @@ int main(void)
fill_buffer_fnc(TOP_LEFT, 0, buf, buf_size);
x = 0;
y = 0;
display_write(display_dev, x, y, &buf_desc, buf);
ret = display_write(display_dev, x, y, &buf_desc, buf);
if (ret < 0) {
LOG_ERR("Failed to write to display (error %d)", ret);
#ifdef CONFIG_ARCH_POSIX
posix_exit_main(1);
#else
return 0;
#endif
}

fill_buffer_fnc(TOP_RIGHT, 0, buf, buf_size);
x = capabilities.x_resolution - rect_w;
y = 0;
display_write(display_dev, x, y, &buf_desc, buf);
ret = display_write(display_dev, x, y, &buf_desc, buf);
if (ret < 0) {
LOG_ERR("Failed to write to display (error %d)", ret);
#ifdef CONFIG_ARCH_POSIX
posix_exit_main(1);
#else
return 0;
#endif
}

/*
* This is the last write of the frame, so turn this off.
Expand All @@ -389,9 +414,25 @@ int main(void)
fill_buffer_fnc(BOTTOM_RIGHT, 0, buf, buf_size);
x = capabilities.x_resolution - rect_w;
y = capabilities.y_resolution - rect_h;
display_write(display_dev, x, y, &buf_desc, buf);
ret = display_write(display_dev, x, y, &buf_desc, buf);
if (ret < 0) {
LOG_ERR("Failed to write to display (error %d)", ret);
#ifdef CONFIG_ARCH_POSIX
posix_exit_main(1);
#else
return 0;
#endif
}

display_blanking_off(display_dev);
ret = display_blanking_off(display_dev);
if (ret < 0 && ret != -ENOSYS) {
LOG_ERR("Failed to turn blanking off (error %d)", ret);
#ifdef CONFIG_ARCH_POSIX
posix_exit_main(1);
#else
return 0;
#endif
}

grey_count = 0;
x = 0;
Expand All @@ -400,7 +441,16 @@ int main(void)
LOG_INF("Display starts");
while (1) {
fill_buffer_fnc(BOTTOM_LEFT, grey_count, buf, buf_size);
display_write(display_dev, x, y, &buf_desc, buf);
ret = display_write(display_dev, x, y, &buf_desc, buf);
if (ret < 0) {
LOG_ERR("Failed to write to display (error %d)", ret);
#ifdef CONFIG_ARCH_POSIX
posix_exit_main(1);
#else
return 0;
#endif
}

++grey_count;
k_msleep(grey_scale_sleep);
#if CONFIG_TEST
Expand Down
6 changes: 5 additions & 1 deletion samples/drivers/video/capture_to_lvgl/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ int main(void)
return 0;
}

display_blanking_off(display_dev);
err = display_blanking_off(display_dev);
if (err < 0 && err != -ENOSYS) {
LOG_ERR("Failed to turn blanking off (error %d)", err);
return 0;
}

const lv_img_dsc_t video_img = {
.header.w = CONFIG_VIDEO_WIDTH,
Expand Down
7 changes: 6 additions & 1 deletion samples/modules/lvgl/accelerometer_chart/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static void create_accelerometer_chart(lv_obj_t *parent)
int main(void)
{
const struct device *display_dev;
int ret;

display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
Expand All @@ -86,7 +87,11 @@ int main(void)
1000 / CONFIG_SAMPLE_ACCEL_SAMPLING_RATE,
NULL);
lv_timer_handler();
display_blanking_off(display_dev);
ret = display_blanking_off(display_dev);
if (ret < 0 && ret != -ENOSYS) {
LOG_ERR("Failed to turn blanking off (error %d)", ret);
return 0;
}

while (1) {
uint32_t sleep_ms = lv_timer_handler();
Expand Down
8 changes: 7 additions & 1 deletion samples/modules/lvgl/demos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int main(void)
k_timepoint_t next_scene_switch;
lv_demo_render_scene_t cur_scene = LV_DEMO_RENDER_SCENE_FILL;
#endif /* CONFIG_LV_Z_DEMO_RENDER_SCENE_DYNAMIC */
int ret;

display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
Expand Down Expand Up @@ -61,7 +62,12 @@ int main(void)
#endif
lvgl_unlock();

display_blanking_off(display_dev);
ret = display_blanking_off(display_dev);
if (ret < 0 && ret != -ENOSYS) {
LOG_ERR("Failed to turn blanking off (error %d)", ret);
return 0;
}

#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
lvgl_print_heap_info(false);
#else
Expand Down
9 changes: 8 additions & 1 deletion samples/modules/lvgl/multi_display/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ int main(void)

lv_timer_handler();
for (int i = 0; i < DT_ZEPHYR_DISPLAYS_COUNT; i++) {
display_blanking_off(display_dev[i]);
int ret;

ret = display_blanking_off(display_dev[i]);
if (ret < 0 && ret != -ENOSYS) {
LOG_ERR("Failed to turn display %s blanking off (error %d)",
display_dev[i]->name, ret);
return 0;
}
}

#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
Expand Down
7 changes: 6 additions & 1 deletion samples/modules/lvgl/screen_transparency/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static void initialize_gui(void)
int main(void)
{
const struct device *display_dev;
int ret;

display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
Expand All @@ -56,7 +57,11 @@ int main(void)
initialize_gui();

lv_timer_handler();
display_blanking_off(display_dev);
ret = display_blanking_off(display_dev);
if (ret < 0 && ret != -ENOSYS) {
LOG_ERR("Failed to turn blanking off (error %d)", ret);
return 0;
}

while (1) {
uint32_t sleep_ms = lv_timer_handler();
Expand Down
7 changes: 6 additions & 1 deletion samples/subsys/display/lvgl/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ int main(void)
const struct device *display_dev;
lv_obj_t *hello_world_label;
lv_obj_t *count_label;
int ret;

display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
Expand Down Expand Up @@ -142,7 +143,11 @@ int main(void)
lv_obj_align(count_label, LV_ALIGN_BOTTOM_MID, 0, 0);

lv_timer_handler();
display_blanking_off(display_dev);
ret = display_blanking_off(display_dev);
if (ret < 0 && ret != -ENOSYS) {
LOG_ERR("Failed to turn blanking off (error %d)", ret);
return 0;
}

while (1) {
if ((count % 100) == 0U) {
Expand Down
44 changes: 35 additions & 9 deletions samples/subsys/input/draw_touch_events/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ static void touch_event_callback(struct input_event *evt, void *user_data)
}
INPUT_CALLBACK_DEFINE(touch_dev, touch_event_callback, NULL);

static void clear_screen(void)
static int clear_screen(void)
{
int x;
int y;
int ret;

for (x = 0; x < WIDTH; x += CROSS_DIM) {
for (y = 0; y < HEIGHT; y += CROSS_DIM) {
Expand All @@ -78,9 +79,15 @@ static void clear_screen(void)
ddesc.height = MIN(buf_desc.height, rem_h);
ddesc.buf_size = ddesc.width * ddesc.height * BPP;

display_write(display_dev, x, y, &ddesc, buffer_cross_empty);
ret = display_write(display_dev, x, y, &ddesc, buffer_cross_empty);
if (ret < 0) {
LOG_ERR("Failed to write to display (error %d)", ret);
return ret;
}
}
}

return 0;
}

static void fill_cross_buffer(void)
Expand Down Expand Up @@ -117,6 +124,7 @@ static int get_draw_position(int value, int upper_bound)

int main(void)
{
int ret;

LOG_INF("Touch sample for touchscreen: %s, dc: %s", touch_dev->name, display_dev->name);

Expand All @@ -135,9 +143,18 @@ int main(void)
return 0;
}
fill_cross_buffer();
display_blanking_off(display_dev);
ret = display_blanking_off(display_dev);
if (ret < 0 && ret != -ENOSYS) {
LOG_ERR("Failed to turn blanking off (error %d)", ret);
return 0;
}

ret = clear_screen();
if (ret < 0) {
LOG_ERR("Failed to clear the screen");
return 0;
}

clear_screen();
touch_point_drawn.x = CROSS_DIM / 2;
touch_point_drawn.y = CROSS_DIM / 2;
touch_point.x = -1;
Expand All @@ -151,12 +168,21 @@ int main(void)
LOG_INF("TOUCH %s X, Y: (%d, %d)", touch_point.pressed ? "PRESS" : "RELEASE",
touch_point.x, touch_point.y);

display_write(display_dev, get_draw_position(touch_point_drawn.x, WIDTH),
get_draw_position(touch_point_drawn.y, HEIGHT), &buf_desc,
buffer_cross_empty);
ret = display_write(display_dev, get_draw_position(touch_point_drawn.x, WIDTH),
get_draw_position(touch_point_drawn.y, HEIGHT), &buf_desc,
buffer_cross_empty);
if (ret < 0) {
LOG_ERR("Failed to write to display (error %d)", ret);
return 0;
}

display_write(display_dev, get_draw_position(touch_point.x, WIDTH),
get_draw_position(touch_point.y, HEIGHT), &buf_desc, buffer_cross);
ret = display_write(display_dev, get_draw_position(touch_point.x, WIDTH),
get_draw_position(touch_point.y, HEIGHT), &buf_desc,
buffer_cross);
if (ret < 0) {
LOG_ERR("Failed to write to display (error %d)", ret);
return 0;
}

touch_point_drawn.x = touch_point.x;
touch_point_drawn.y = touch_point.y;
Expand Down
7 changes: 6 additions & 1 deletion samples/subsys/smf/smf_calculator/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static void lv_btn_matrix_click_callback(lv_event_t *e)
static int setup_display(void)
{
const struct device *display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
int ret;

if (!device_is_ready(display_dev)) {
LOG_ERR("Device not ready, aborting setup");
Expand Down Expand Up @@ -165,7 +166,11 @@ static int setup_display(void)
update_display("0");

lv_task_handler();
display_blanking_off(display_dev);
ret = display_blanking_off(display_dev);
if (ret < 0 && ret != -ENOSYS) {
LOG_ERR("Failed to turn blanking off (error %d)", ret);
return ret;
}

return 0;
}
Expand Down