Skip to content

Commit 639b04f

Browse files
author
Alain Volmat
committed
samples: add proper display api functions return value checks
Ensure that display api function return values are checked. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
1 parent 91b1b84 commit 639b04f

File tree

9 files changed

+135
-22
lines changed

9 files changed

+135
-22
lines changed

samples/drivers/display/src/main.c

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ int main(void)
222222
struct display_buffer_descriptor buf_desc;
223223
size_t buf_size = 0;
224224
fill_buffer fill_buffer_fnc = NULL;
225+
int ret;
225226

226227
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
227228
if (!device_is_ready(display_dev)) {
@@ -362,7 +363,15 @@ int main(void)
362363
if ((capabilities.y_resolution - idx) < h_step) {
363364
buf_desc.height = (capabilities.y_resolution - idx);
364365
}
365-
display_write(display_dev, 0, idx, &buf_desc, buf);
366+
ret = display_write(display_dev, 0, idx, &buf_desc, buf);
367+
if (ret < 0) {
368+
LOG_ERR("Failed to write to display (error %d)", ret);
369+
#ifdef CONFIG_ARCH_POSIX
370+
posix_exit_main(1);
371+
#else
372+
return 0;
373+
#endif
374+
}
366375
}
367376

368377
buf_desc.pitch = rect_w;
@@ -372,12 +381,28 @@ int main(void)
372381
fill_buffer_fnc(TOP_LEFT, 0, buf, buf_size);
373382
x = 0;
374383
y = 0;
375-
display_write(display_dev, x, y, &buf_desc, buf);
384+
ret = display_write(display_dev, x, y, &buf_desc, buf);
385+
if (ret < 0) {
386+
LOG_ERR("Failed to write to display (error %d)", ret);
387+
#ifdef CONFIG_ARCH_POSIX
388+
posix_exit_main(1);
389+
#else
390+
return 0;
391+
#endif
392+
}
376393

377394
fill_buffer_fnc(TOP_RIGHT, 0, buf, buf_size);
378395
x = capabilities.x_resolution - rect_w;
379396
y = 0;
380-
display_write(display_dev, x, y, &buf_desc, buf);
397+
ret = display_write(display_dev, x, y, &buf_desc, buf);
398+
if (ret < 0) {
399+
LOG_ERR("Failed to write to display (error %d)", ret);
400+
#ifdef CONFIG_ARCH_POSIX
401+
posix_exit_main(1);
402+
#else
403+
return 0;
404+
#endif
405+
}
381406

382407
/*
383408
* This is the last write of the frame, so turn this off.
@@ -389,9 +414,25 @@ int main(void)
389414
fill_buffer_fnc(BOTTOM_RIGHT, 0, buf, buf_size);
390415
x = capabilities.x_resolution - rect_w;
391416
y = capabilities.y_resolution - rect_h;
392-
display_write(display_dev, x, y, &buf_desc, buf);
417+
ret = display_write(display_dev, x, y, &buf_desc, buf);
418+
if (ret < 0) {
419+
LOG_ERR("Failed to write to display (error %d)", ret);
420+
#ifdef CONFIG_ARCH_POSIX
421+
posix_exit_main(1);
422+
#else
423+
return 0;
424+
#endif
425+
}
393426

394-
display_blanking_off(display_dev);
427+
ret = display_blanking_off(display_dev);
428+
if (ret < 0 && ret != -ENOSYS) {
429+
LOG_ERR("Failed to turn blanking off (error %d)", ret);
430+
#ifdef CONFIG_ARCH_POSIX
431+
posix_exit_main(1);
432+
#else
433+
return 0;
434+
#endif
435+
}
395436

396437
grey_count = 0;
397438
x = 0;
@@ -400,7 +441,16 @@ int main(void)
400441
LOG_INF("Display starts");
401442
while (1) {
402443
fill_buffer_fnc(BOTTOM_LEFT, grey_count, buf, buf_size);
403-
display_write(display_dev, x, y, &buf_desc, buf);
444+
ret = display_write(display_dev, x, y, &buf_desc, buf);
445+
if (ret < 0) {
446+
LOG_ERR("Failed to write to display (error %d)", ret);
447+
#ifdef CONFIG_ARCH_POSIX
448+
posix_exit_main(1);
449+
#else
450+
return 0;
451+
#endif
452+
}
453+
404454
++grey_count;
405455
k_msleep(grey_scale_sleep);
406456
#if CONFIG_TEST

samples/drivers/video/capture_to_lvgl/src/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ int main(void)
160160
return 0;
161161
}
162162

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

165169
const lv_img_dsc_t video_img = {
166170
.header.w = CONFIG_VIDEO_WIDTH,

samples/modules/lvgl/accelerometer_chart/src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static void create_accelerometer_chart(lv_obj_t *parent)
6868
int main(void)
6969
{
7070
const struct device *display_dev;
71+
int ret;
7172

7273
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
7374
if (!device_is_ready(display_dev)) {
@@ -86,7 +87,11 @@ int main(void)
8687
1000 / CONFIG_SAMPLE_ACCEL_SAMPLING_RATE,
8788
NULL);
8889
lv_timer_handler();
89-
display_blanking_off(display_dev);
90+
ret = display_blanking_off(display_dev);
91+
if (ret < 0 && ret != -ENOSYS) {
92+
LOG_ERR("Failed to turn blanking off (error %d)", ret);
93+
return 0;
94+
}
9095

9196
while (1) {
9297
uint32_t sleep_ms = lv_timer_handler();

samples/modules/lvgl/demos/src/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int main(void)
2323
k_timepoint_t next_scene_switch;
2424
lv_demo_render_scene_t cur_scene = LV_DEMO_RENDER_SCENE_FILL;
2525
#endif /* CONFIG_LV_Z_DEMO_RENDER_SCENE_DYNAMIC */
26+
int ret;
2627

2728
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
2829
if (!device_is_ready(display_dev)) {
@@ -61,7 +62,12 @@ int main(void)
6162
#endif
6263
lvgl_unlock();
6364

64-
display_blanking_off(display_dev);
65+
ret = display_blanking_off(display_dev);
66+
if (ret < 0 && ret != -ENOSYS) {
67+
LOG_ERR("Failed to turn blanking off (error %d)", ret);
68+
return 0;
69+
}
70+
6571
#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
6672
lvgl_print_heap_info(false);
6773
#else

samples/modules/lvgl/multi_display/src/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@ int main(void)
7676

7777
lv_timer_handler();
7878
for (int i = 0; i < DT_ZEPHYR_DISPLAYS_COUNT; i++) {
79-
display_blanking_off(display_dev[i]);
79+
int ret;
80+
81+
ret = display_blanking_off(display_dev[i]);
82+
if (ret < 0 && ret != -ENOSYS) {
83+
LOG_ERR("Failed to turn display %s blanking off (error %d)",
84+
display_dev[i]->name, ret);
85+
return 0;
86+
}
8087
}
8188

8289
#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP

samples/modules/lvgl/screen_transparency/src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static void initialize_gui(void)
4646
int main(void)
4747
{
4848
const struct device *display_dev;
49+
int ret;
4950

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

5859
lv_timer_handler();
59-
display_blanking_off(display_dev);
60+
ret = display_blanking_off(display_dev);
61+
if (ret < 0 && ret != -ENOSYS) {
62+
LOG_ERR("Failed to turn blanking off (error %d)", ret);
63+
return 0;
64+
}
6065

6166
while (1) {
6267
uint32_t sleep_ms = lv_timer_handler();

samples/subsys/display/lvgl/src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ int main(void)
6060
const struct device *display_dev;
6161
lv_obj_t *hello_world_label;
6262
lv_obj_t *count_label;
63+
int ret;
6364

6465
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
6566
if (!device_is_ready(display_dev)) {
@@ -142,7 +143,11 @@ int main(void)
142143
lv_obj_align(count_label, LV_ALIGN_BOTTOM_MID, 0, 0);
143144

144145
lv_timer_handler();
145-
display_blanking_off(display_dev);
146+
ret = display_blanking_off(display_dev);
147+
if (ret < 0 && ret != -ENOSYS) {
148+
LOG_ERR("Failed to turn blanking off (error %d)", ret);
149+
return 0;
150+
}
146151

147152
while (1) {
148153
if ((count % 100) == 0U) {

samples/subsys/input/draw_touch_events/src/main.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ static void touch_event_callback(struct input_event *evt, void *user_data)
6363
}
6464
INPUT_CALLBACK_DEFINE(touch_dev, touch_event_callback, NULL);
6565

66-
static void clear_screen(void)
66+
static int clear_screen(void)
6767
{
6868
int x;
6969
int y;
70+
int ret;
7071

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

81-
display_write(display_dev, x, y, &ddesc, buffer_cross_empty);
82+
ret = display_write(display_dev, x, y, &ddesc, buffer_cross_empty);
83+
if (ret < 0) {
84+
LOG_ERR("Failed to write to display (error %d)", ret);
85+
return ret;
86+
}
8287
}
8388
}
89+
90+
return 0;
8491
}
8592

8693
static void fill_cross_buffer(void)
@@ -117,6 +124,7 @@ static int get_draw_position(int value, int upper_bound)
117124

118125
int main(void)
119126
{
127+
int ret;
120128

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

@@ -135,9 +143,18 @@ int main(void)
135143
return 0;
136144
}
137145
fill_cross_buffer();
138-
display_blanking_off(display_dev);
146+
ret = display_blanking_off(display_dev);
147+
if (ret < 0 && ret != -ENOSYS) {
148+
LOG_ERR("Failed to turn blanking off (error %d)", ret);
149+
return 0;
150+
}
151+
152+
ret = clear_screen();
153+
if (ret < 0) {
154+
LOG_ERR("Failed to clear the screen");
155+
return 0;
156+
}
139157

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

154-
display_write(display_dev, get_draw_position(touch_point_drawn.x, WIDTH),
155-
get_draw_position(touch_point_drawn.y, HEIGHT), &buf_desc,
156-
buffer_cross_empty);
171+
ret = display_write(display_dev, get_draw_position(touch_point_drawn.x, WIDTH),
172+
get_draw_position(touch_point_drawn.y, HEIGHT), &buf_desc,
173+
buffer_cross_empty);
174+
if (ret < 0) {
175+
LOG_ERR("Failed to write to display (error %d)", ret);
176+
return 0;
177+
}
157178

158-
display_write(display_dev, get_draw_position(touch_point.x, WIDTH),
159-
get_draw_position(touch_point.y, HEIGHT), &buf_desc, buffer_cross);
179+
ret = display_write(display_dev, get_draw_position(touch_point.x, WIDTH),
180+
get_draw_position(touch_point.y, HEIGHT), &buf_desc,
181+
buffer_cross);
182+
if (ret < 0) {
183+
LOG_ERR("Failed to write to display (error %d)", ret);
184+
return 0;
185+
}
160186

161187
touch_point_drawn.x = touch_point.x;
162188
touch_point_drawn.y = touch_point.y;

samples/subsys/smf/smf_calculator/src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static void lv_btn_matrix_click_callback(lv_event_t *e)
112112
static int setup_display(void)
113113
{
114114
const struct device *display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
115+
int ret;
115116

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

167168
lv_task_handler();
168-
display_blanking_off(display_dev);
169+
ret = display_blanking_off(display_dev);
170+
if (ret < 0 && ret != -ENOSYS) {
171+
LOG_ERR("Failed to turn blanking off (error %d)", ret);
172+
return ret;
173+
}
169174

170175
return 0;
171176
}

0 commit comments

Comments
 (0)