Zephyr API Documentation 4.4.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
display.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
3 * SPDX-FileCopyrightText: 2026 Abderrahmane JARMOUNI
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13
14#ifndef ZEPHYR_INCLUDE_DRIVERS_DISPLAY_H_
15#define ZEPHYR_INCLUDE_DRIVERS_DISPLAY_H_
16
30
31#include <zephyr/device.h>
32#include <errno.h>
33#include <stddef.h>
34#include <zephyr/types.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
224
233#define DISPLAY_BITS_PER_PIXEL(fmt) \
234 ((((fmt & PIXEL_FORMAT_RGB_888) >> 0) * 24U) + \
235 (((fmt & PIXEL_FORMAT_MONO01) >> 1) * 1U) + \
236 (((fmt & PIXEL_FORMAT_MONO10) >> 2) * 1U) + \
237 (((fmt & PIXEL_FORMAT_ARGB_8888) >> 3) * 32U) + \
238 (((fmt & PIXEL_FORMAT_RGB_565) >> 4) * 16U) + \
239 (((fmt & PIXEL_FORMAT_RGB_565X) >> 5) * 16U) + \
240 (((fmt & PIXEL_FORMAT_L_8) >> 6) * 8U) + \
241 (((fmt & PIXEL_FORMAT_AL_88) >> 7) * 16U) + \
242 (((fmt & PIXEL_FORMAT_XRGB_8888) >> 8) * 32U) + \
243 (((fmt & PIXEL_FORMAT_BGR_888) >> 9) * 24U) + \
244 (((fmt & PIXEL_FORMAT_ABGR_8888) >> 10) * 32U) + \
245 (((fmt & PIXEL_FORMAT_RGBA_8888) >> 11) * 32U) + \
246 (((fmt & PIXEL_FORMAT_BGRA_8888) >> 12) * 32U))
247
274
284
300
314
329
339
349
366typedef enum display_event_result (*display_event_cb_t)(const struct device *dev,
367 uint32_t evt,
368 const struct display_event_data *data,
369 void *user_data);
370
375
380typedef int (*display_blanking_on_api)(const struct device *dev);
381
386typedef int (*display_blanking_off_api)(const struct device *dev);
387
392typedef int (*display_write_api)(const struct device *dev, const uint16_t x,
393 const uint16_t y,
394 const struct display_buffer_descriptor *desc,
395 const void *buf);
396
401typedef int (*display_read_api)(const struct device *dev, const uint16_t x,
402 const uint16_t y,
403 const struct display_buffer_descriptor *desc,
404 void *buf);
405
410typedef int (*display_clear_api)(const struct device *dev);
411
416typedef void *(*display_get_framebuffer_api)(const struct device *dev);
417
422typedef int (*display_set_brightness_api)(const struct device *dev,
423 const uint8_t brightness);
424
429typedef int (*display_set_contrast_api)(const struct device *dev,
430 const uint8_t contrast);
431
436typedef void (*display_get_capabilities_api)(const struct device *dev,
437 struct display_capabilities *
438 capabilities);
439
444typedef int (*display_set_pixel_format_api)(const struct device *dev,
445 const enum display_pixel_format
446 pixel_format);
447
452typedef int (*display_set_orientation_api)(const struct device *dev,
453 const enum display_orientation
454 orientation);
455
460typedef int (*display_register_event_cb_api)(const struct device *dev,
461 display_event_cb_t cb, void *user_data,
462 uint32_t event_mask, bool in_isr,
463 uint32_t *out_reg_handle);
464
469typedef int (*display_unregister_event_cb_api)(const struct device *dev, uint32_t reg_handle);
470
528
531
543static inline int display_write(const struct device *dev, const uint16_t x,
544 const uint16_t y,
545 const struct display_buffer_descriptor *desc,
546 const void *buf)
547{
548 struct display_driver_api *api =
549 (struct display_driver_api *)dev->api;
550
551 return api->write(dev, x, y, desc, buf);
552}
553
566static inline int display_read(const struct device *dev, const uint16_t x,
567 const uint16_t y,
568 const struct display_buffer_descriptor *desc,
569 void *buf)
570{
571 struct display_driver_api *api =
572 (struct display_driver_api *)dev->api;
573
574 if (api->read == NULL) {
575 return -ENOSYS;
576 }
577
578 return api->read(dev, x, y, desc, buf);
579}
580
589static inline int display_clear(const struct device *dev)
590{
591 struct display_driver_api *api =
592 (struct display_driver_api *)dev->api;
593
594 if (api->clear == NULL) {
595 return -ENOSYS;
596 }
597
598 return api->clear(dev);
599}
600
610static inline void *display_get_framebuffer(const struct device *dev)
611{
612 struct display_driver_api *api =
613 (struct display_driver_api *)dev->api;
614
615 if (api->get_framebuffer == NULL) {
616 return NULL;
617 }
618
619 return api->get_framebuffer(dev);
620}
621
641static inline int display_blanking_on(const struct device *dev)
642{
643 struct display_driver_api *api =
644 (struct display_driver_api *)dev->api;
645
646 if (api->blanking_on == NULL) {
647 return -ENOSYS;
648 }
649
650 return api->blanking_on(dev);
651}
652
665static inline int display_blanking_off(const struct device *dev)
666{
667 struct display_driver_api *api =
668 (struct display_driver_api *)dev->api;
669
670 if (api->blanking_off == NULL) {
671 return -ENOSYS;
672 }
673
674 return api->blanking_off(dev);
675}
676
689static inline int display_set_brightness(const struct device *dev,
690 uint8_t brightness)
691{
692 struct display_driver_api *api =
693 (struct display_driver_api *)dev->api;
694
695 if (api->set_brightness == NULL) {
696 return -ENOSYS;
697 }
698
699 return api->set_brightness(dev, brightness);
700}
701
714static inline int display_set_contrast(const struct device *dev, uint8_t contrast)
715{
716 struct display_driver_api *api =
717 (struct display_driver_api *)dev->api;
718
719 if (api->set_contrast == NULL) {
720 return -ENOSYS;
721 }
722
723 return api->set_contrast(dev, contrast);
724}
725
732static inline void display_get_capabilities(const struct device *dev,
733 struct display_capabilities *
734 capabilities)
735{
736 struct display_driver_api *api =
737 (struct display_driver_api *)dev->api;
738
739 api->get_capabilities(dev, capabilities);
740}
741
751static inline int
753 const enum display_pixel_format pixel_format)
754{
755 struct display_driver_api *api =
756 (struct display_driver_api *)dev->api;
757
758 if (api->set_pixel_format == NULL) {
759 return -ENOSYS;
760 }
761
762 return api->set_pixel_format(dev, pixel_format);
763}
764
774static inline int display_set_orientation(const struct device *dev,
775 const enum display_orientation
776 orientation)
777{
778 struct display_driver_api *api =
779 (struct display_driver_api *)dev->api;
780
781 if (api->set_orientation == NULL) {
782 return -ENOSYS;
783 }
784
785 return api->set_orientation(dev, orientation);
786}
787
813static inline int display_register_event_cb(const struct device *dev,
814 display_event_cb_t cb, void *user_data,
815 uint32_t event_mask, bool in_isr,
816 uint32_t *out_reg_handle)
817{
818 struct display_driver_api *api = (struct display_driver_api *)dev->api;
819
820 if (api->register_event_cb == NULL) {
821 return -ENOSYS;
822 }
823
824 return api->register_event_cb(dev, cb, user_data, event_mask, in_isr, out_reg_handle);
825}
826
838static inline int display_unregister_event_cb(const struct device *dev, uint32_t reg_handle)
839{
840 struct display_driver_api *api = (struct display_driver_api *)dev->api;
841
842 if (api->unregister_event_cb == NULL || api->register_event_cb == NULL) {
843 return -ENOSYS;
844 }
845
846 return api->unregister_event_cb(dev, reg_handle);
847}
848
849#ifdef __cplusplus
850}
851#endif
852
856
857#endif /* ZEPHYR_INCLUDE_DRIVERS_DISPLAY_H_ */
System error numbers.
int(* display_set_pixel_format_api)(const struct device *dev, const enum display_pixel_format pixel_format)
Callback API to set pixel format used by the display.
Definition display.h:444
void(* display_get_capabilities_api)(const struct device *dev, struct display_capabilities *capabilities)
Callback API to get display capabilities.
Definition display.h:436
int(* display_write_api)(const struct device *dev, const uint16_t x, const uint16_t y, const struct display_buffer_descriptor *desc, const void *buf)
Callback API for writing data to the display.
Definition display.h:392
int(* display_set_brightness_api)(const struct device *dev, const uint8_t brightness)
Callback API to set display brightness.
Definition display.h:422
void *(* display_get_framebuffer_api)(const struct device *dev)
Callback API to get framebuffer pointer.
Definition display.h:416
int(* display_read_api)(const struct device *dev, const uint16_t x, const uint16_t y, const struct display_buffer_descriptor *desc, void *buf)
Callback API for reading data from the display.
Definition display.h:401
int(* display_blanking_off_api)(const struct device *dev)
Callback API to turn off display blanking.
Definition display.h:386
int(* display_register_event_cb_api)(const struct device *dev, display_event_cb_t cb, void *user_data, uint32_t event_mask, bool in_isr, uint32_t *out_reg_handle)
Callback API to register display event callback.
Definition display.h:460
int(* display_blanking_on_api)(const struct device *dev)
Callback API to turn on display blanking.
Definition display.h:380
int(* display_unregister_event_cb_api)(const struct device *dev, uint32_t reg_handle)
Callback API to unregister display event callback.
Definition display.h:469
int(* display_set_contrast_api)(const struct device *dev, const uint8_t contrast)
Callback API to set display contrast.
Definition display.h:429
int(* display_clear_api)(const struct device *dev)
Callback API for clearing the screen of the display.
Definition display.h:410
int(* display_set_orientation_api)(const struct device *dev, const enum display_orientation orientation)
Callback API to set orientation used by the display.
Definition display.h:452
display_event
Display event types.
Definition display.h:331
display_screen_info
Display screen information.
Definition display.h:250
static int display_write(const struct device *dev, const uint16_t x, const uint16_t y, const struct display_buffer_descriptor *desc, const void *buf)
Write data to display.
Definition display.h:543
static int display_read(const struct device *dev, const uint16_t x, const uint16_t y, const struct display_buffer_descriptor *desc, void *buf)
Read data from display.
Definition display.h:566
static void * display_get_framebuffer(const struct device *dev)
Get pointer to framebuffer for direct access.
Definition display.h:610
static int display_blanking_off(const struct device *dev)
Turn display blanking off.
Definition display.h:665
static int display_set_orientation(const struct device *dev, const enum display_orientation orientation)
Set display orientation.
Definition display.h:774
display_event_result
Display event callback return flags.
Definition display.h:341
static int display_clear(const struct device *dev)
Clear the screen of the display device.
Definition display.h:589
static void display_get_capabilities(const struct device *dev, struct display_capabilities *capabilities)
Get display capabilities.
Definition display.h:732
static int display_set_pixel_format(const struct device *dev, const enum display_pixel_format pixel_format)
Set pixel format used by the display.
Definition display.h:752
static int display_set_contrast(const struct device *dev, uint8_t contrast)
Set the contrast of the display.
Definition display.h:714
static int display_register_event_cb(const struct device *dev, display_event_cb_t cb, void *user_data, uint32_t event_mask, bool in_isr, uint32_t *out_reg_handle)
Register event callback for a display device.
Definition display.h:813
static int display_unregister_event_cb(const struct device *dev, uint32_t reg_handle)
Unregister event callback for a display device.
Definition display.h:838
display_pixel_format
Display pixel formats.
Definition display.h:49
display_orientation
Enumeration with possible display orientation.
Definition display.h:278
static int display_blanking_on(const struct device *dev)
Turn display blanking on.
Definition display.h:641
static int display_set_brightness(const struct device *dev, uint8_t brightness)
Set the brightness of the display.
Definition display.h:689
enum display_event_result(* display_event_cb_t)(const struct device *dev, uint32_t evt, const struct display_event_data *data, void *user_data)
Called either in ISR context (if arg in_isr=true at register time, see display_register_event_cb ) or...
Definition display.h:366
@ DISPLAY_EVENT_LINE_INT
Fired when controller reaches a configured scanline.
Definition display.h:333
@ DISPLAY_EVENT_FRAME_DONE
Fired when a frame transfer to the panel or frame buffer update completes.
Definition display.h:337
@ DISPLAY_EVENT_VSYNC
Fired at vertical sync / start of new frame.
Definition display.h:335
@ SCREEN_INFO_X_ALIGNMENT_WIDTH
Screen has x alignment constrained to width.
Definition display.h:272
@ SCREEN_INFO_EPD
Electrophoretic Display.
Definition display.h:264
@ SCREEN_INFO_DOUBLE_BUFFER
Screen has two alternating ram buffers.
Definition display.h:268
@ SCREEN_INFO_MONO_VTILED
If selected, one octet represents 8 pixels ordered vertically, otherwise ordered horizontally.
Definition display.h:255
@ SCREEN_INFO_MONO_MSB_FIRST
If selected, the MSB represents the first pixel, otherwise MSB represents the last pixel.
Definition display.h:260
@ DISPLAY_EVENT_RESULT_CONTINUE
Let the driver execute its default handling.
Definition display.h:343
@ DISPLAY_EVENT_RESULT_HANDLED
The callback handled the event and the driver should skip its default processing for that event.
Definition display.h:347
@ PIXEL_FORMAT_ABGR_8888
32-bit BGR format with 8 bits per component and 8 bits for alpha.
Definition display.h:188
@ PIXEL_FORMAT_RGB_565X
16-bit RGB format packed into two bytes.
Definition display.h:119
@ PIXEL_FORMAT_BGRA_8888
32-bit BGR format with 8 bits per component and 8 bits for alpha.
Definition display.h:216
@ PIXEL_FORMAT_L_8
8-bit Greyscale format
Definition display.h:132
@ PIXEL_FORMAT_XRGB_8888
32-bit RGB format with 8 bits per component and 8 bits unused.
Definition display.h:160
@ PIXEL_FORMAT_BGR_888
24-bit BGR format with 8 bits per component.
Definition display.h:174
@ PIXEL_FORMAT_MONO10
Monochrome (1=Black 0=White).
Definition display.h:78
@ PIXEL_FORMAT_ARGB_8888
32-bit RGB format with 8 bits per component and 8 bits for alpha.
Definition display.h:92
@ PIXEL_FORMAT_AL_88
16-bit Greyscale format with 8-bit luminance and 8-bit for alpha
Definition display.h:146
@ PIXEL_FORMAT_RGBA_8888
32-bit RGB format with 8 bits per component and 8 bits for alpha.
Definition display.h:202
@ PIXEL_FORMAT_PRIV_START
This and higher values are display specific.
Definition display.h:222
@ PIXEL_FORMAT_MONO01
1-bit monochrome format with 1 bit per pixel, thus each byte represent 8 pixels Two variants,...
Definition display.h:77
@ PIXEL_FORMAT_RGB_565
16-bit RGB format packed into two bytes: 5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0].
Definition display.h:107
@ PIXEL_FORMAT_RGB_888
24-bit RGB format with 8 bits per component.
Definition display.h:62
@ DISPLAY_ORIENTATION_ROTATED_90
Rotated 90 degrees clockwise.
Definition display.h:280
@ DISPLAY_ORIENTATION_ROTATED_180
Rotated 180 degrees clockwise.
Definition display.h:281
@ DISPLAY_ORIENTATION_NORMAL
No rotation.
Definition display.h:279
@ DISPLAY_ORIENTATION_ROTATED_270
Rotated 270 degrees clockwise.
Definition display.h:282
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
Structure to describe display data buffer layout.
Definition display.h:302
uint16_t pitch
Number of pixels between consecutive rows in the data buffer.
Definition display.h:310
bool frame_incomplete
Indicates that this is not the last write buffer of the frame.
Definition display.h:312
uint16_t height
Data buffer column height in pixels.
Definition display.h:308
uint16_t width
Data buffer row width in pixels.
Definition display.h:306
uint32_t buf_size
Data buffer size in bytes.
Definition display.h:304
Structure holding display capabilities.
Definition display.h:286
uint32_t supported_pixel_formats
Bitwise or of pixel formats supported by the display.
Definition display.h:292
uint16_t x_resolution
Display resolution in the X direction.
Definition display.h:288
enum display_orientation current_orientation
Current display orientation.
Definition display.h:298
uint16_t y_resolution
Display resolution in the Y direction.
Definition display.h:290
uint32_t screen_info
Information about display panel.
Definition display.h:294
enum display_pixel_format current_pixel_format
Currently active pixel format for the display.
Definition display.h:296
<span class="mlabel">Driver Operations</span> Display driver operations
Definition display.h:474
display_blanking_off_api blanking_off
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:482
display_register_event_cb_api register_event_cb
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:522
display_set_pixel_format_api set_pixel_format
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:514
display_read_api read
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:490
display_set_orientation_api set_orientation
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:518
display_write_api write
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition display.h:486
display_unregister_event_cb_api unregister_event_cb
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:526
display_clear_api clear
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:494
display_set_brightness_api set_brightness
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:502
display_get_framebuffer_api get_framebuffer
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:498
display_blanking_on_api blanking_on
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:478
display_get_capabilities_api get_capabilities
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition display.h:510
display_set_contrast_api set_contrast
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition display.h:506
Display event payload.
Definition display.h:316
uint64_t timestamp
Timestamp to differentiate between events of the same type.
Definition display.h:320
union display_event_data::@254130275177060223307037326371161170306162100075 info
Event info passed by driver to callback.
int buffer_id
For DISPLAY_EVENT_FRAME_DONE events, set to -1 if unavailable.
Definition display.h:326
int line
For DISPLAY_EVENT_LINE_INT events, set to -1 if unavailable.
Definition display.h:324