Skip to content

Commit 5da4fca

Browse files
committed
pbio/drv/display: Add display driver abstraction.
The abstraction provides a way to access the display driver using a platform agnostic way. Refs pybricks/support#2154
1 parent 2190507 commit 5da4fca

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

lib/pbio/drv/display/display_ev3.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "../core.h"
1919

2020
#include <pbdrv/gpio.h>
21+
#include <pbdrv/display.h>
2122
#include <pbio/error.h>
2223
#include <pbio/util.h>
2324

@@ -525,4 +526,20 @@ PROCESS_THREAD(pbdrv_display_ev3_init_process, ev, data) {
525526
PROCESS_END();
526527
}
527528

529+
pbio_image_t *pbdrv_display_get_image(void) {
530+
static pbio_image_t image;
531+
pbio_image_init(&image, (uint8_t *)pbdrv_display_user_frame,
532+
PBDRV_CONFIG_DISPLAY_NUM_COLS, PBDRV_CONFIG_DISPLAY_NUM_ROWS,
533+
PBDRV_CONFIG_DISPLAY_NUM_COLS);
534+
return &image;
535+
}
536+
537+
uint8_t pbdrv_display_get_max_value(void) {
538+
return 3;
539+
}
540+
541+
void pbdrv_display_update(void) {
542+
pbdrv_display_user_frame_update_requested = true;
543+
}
544+
528545
#endif // PBDRV_CONFIG_DISPLAY_EV3

lib/pbio/include/pbdrv/display.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2025 The Pybricks Authors
3+
4+
/**
5+
* @addtogroup DisplayDriver Driver: Display
6+
* @{
7+
*/
8+
9+
#ifndef _PBDRV_DISPLAY_H_
10+
#define _PBDRV_DISPLAY_H_
11+
12+
#include <pbdrv/config.h>
13+
#include <pbio/image.h>
14+
15+
#if PBDRV_CONFIG_DISPLAY
16+
17+
/**
18+
* Get an image container representing the display.
19+
* @return Image container, or NULL if no display.
20+
*/
21+
pbio_image_t *pbdrv_display_get_image(void);
22+
23+
/**
24+
* Get the maximum value of a pixel.
25+
* @return Maximum value, corresponding to black on a LCD screen.
26+
*/
27+
uint8_t pbdrv_display_get_max_value(void);
28+
29+
/**
30+
* Update the display to show current content of image container.
31+
*/
32+
void pbdrv_display_update(void);
33+
34+
#else // PBDRV_CONFIG_DISPLAY
35+
36+
static inline pbio_image_t *pbdrv_display_get_image(void) {
37+
return NULL;
38+
}
39+
40+
static inline uint8_t pbdrv_display_get_max_value(void) {
41+
return 0;
42+
}
43+
44+
static inline void pbdrv_display_update(void) {
45+
}
46+
47+
#endif // PBDRV_CONFIG_DISPLAY
48+
49+
#endif // _PBDRV_DISPLAY_H_
50+
51+
/** @} */

0 commit comments

Comments
 (0)