ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_display_pal.c
Go to the documentation of this file.
1
18
19#include "ra8_display_pal.h"
20
21#include <stddef.h>
22#include <stdint.h>
23
24#include "ra8_attributes.h"
25#include "ra8_check.h"
27#include "ra8_err.h"
28#include "ra8_log.h"
29
30/* =============================================================================
31 * Module-static storage
32 * =============================================================================
33 */
34
36static const char* const s_tag = "ra8_display_pal";
37
40
42static bool s_initialized = false;
43
44/* =============================================================================
45 * Internal helpers
46 * =============================================================================
47 */
48
75{
76 if (d == nullptr) {
77 return k_ra8_err_null_ptr;
78 }
79 if (!s_initialized) {
81 }
82 if (d != &s_handle) {
84 }
85 return k_ra8_ok;
86}
87
88/* =============================================================================
89 * Public API
90 * =============================================================================
91 */
92
94{
95 RA8_CHECK_NULL_PTR(cfg, s_tag, "cfg must not be nullptr");
96 RA8_CHECK_NULL_PTR(out_handle, s_tag, "out_handle must not be nullptr");
97 RA8_CHECK_NULL_PTR(cfg->iface, s_tag, "cfg->iface must not be nullptr");
98 RA8_CHECK_NULL_PTR(cfg->iface->init, s_tag, "iface->init must not be nullptr");
99
100 if (s_initialized) {
101 ra8_log_error(s_tag, "display_init: PAL already initialised");
102 return k_ra8_err_busy;
103 }
104
105 void* backend_ctx = nullptr;
106 const ra8_err_t err = cfg->iface->init(cfg, &backend_ctx);
107 if (err != k_ra8_ok) {
108 return err;
109 }
110
111 s_handle.iface = cfg->iface;
112 s_handle.ctx = backend_ctx;
113 s_initialized = true;
114 *out_handle = &s_handle;
115 ra8_log_info(s_tag, "display_init: backend bound");
116 return k_ra8_ok;
117}
118
120{
122 if (v != k_ra8_ok) {
123 return v;
124 }
125 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
126 return s_handle.iface->get_caps(s_handle.ctx, out);
127}
128
130{
132 if (v != k_ra8_ok) {
133 return v;
134 }
135 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
136 return s_handle.iface->get_framebuffer(s_handle.ctx, out);
137}
138
140{
142 if (v != k_ra8_ok) {
143 return v;
144 }
145 return s_handle.iface->flush(s_handle.ctx, rect, hint);
146}
147
148ra8_err_t display_clear(const display_handle_t* d, uint32_t color)
149{
151 if (v != k_ra8_ok) {
152 return v;
153 }
154 return s_handle.iface->clear(s_handle.ctx, color);
155}
156
158{
160 if (v != k_ra8_ok) {
161 return v;
162 }
163 const ra8_err_t err = s_handle.iface->deinit(s_handle.ctx);
164 /* Always drop the handle on deinit so a follow-up init can run, even
165 * if the backend reported a tear-down error. The deinit error is
166 * still returned to the caller. */
167 s_handle.iface = nullptr;
168 s_handle.ctx = nullptr;
169 s_initialized = false;
170 return err;
171}
172
174{
175 const display_rect_t empty = {0U, 0U, 0U, 0U};
177 return empty;
178 }
179 display_caps_t caps = {};
180 const ra8_err_t e = s_handle.iface->get_caps(s_handle.ctx, &caps);
181 if (e != k_ra8_ok) {
182 return empty;
183 }
184 const display_rect_t full = {0U, 0U, caps.width_px, caps.height_px};
185 return full;
186}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
ra8_err_t display_get_caps(const display_handle_t *d, display_caps_t *out)
Query the bound backend's runtime capabilities.
display_rect_t display_full_rect(const display_handle_t *d)
Convenience helper returning the rect covering the whole framebuffer.
ra8_err_t display_deinit(const display_handle_t *d)
Release the backend and invalidate the PAL handle.
ra8_err_t display_get_framebuffer(const display_handle_t *d, display_fb_t *out)
Return the framebuffer descriptor the backend is targeting.
ra8_err_t display_clear(const display_handle_t *d, uint32_t color)
Clear the entire framebuffer to color.
static bool s_initialized
True once display_init has succeeded.
static ra8_err_t internal_validate_handle(const display_handle_t *d)
Reject d if it is NULL or refers to an un-initialised handle.
ra8_err_t display_flush(const display_handle_t *d, display_rect_t rect, display_refresh_hint_t hint)
Commit pending framebuffer changes to the panel.
ra8_err_t display_init(const display_cfg_t *cfg, display_handle_t **out_handle)
Initialise the display PAL and bring the selected backend up to a state where display_flush succeeds.
static struct display_handle s_handle
Single PAL handle – one display per board.
Display Platform Abstraction Layer for the RA8D2.
struct display_handle display_handle_t
display_refresh_hint_t
Intent passed into display_flush; backends map this onto whatever waveform/mode their controller offe...
Internal vtable + handle types for the display PAL.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_busy
Resource busy – blocking operation cannot proceed.
Definition ra8_err.h:195
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364
#define ra8_log_error(tag, message)
RA8 log error.
Definition ra8_log.h:335
ra8_err_t(* init)(const display_cfg_t *cfg, void **out_ctx)
Bring the backend up against cfg and return its private context pointer through *out_ctx.
Capabilities a backend reports after display_init.
uint16_t width_px
Display visible width.
uint16_t height_px
Display visible height.
Configuration descriptor passed into display_init.
const display_backend_iface_t * iface
Backend vtable (one of the k_display_backend_* consts).
Framebuffer descriptor returned by display_get_framebuffer.
Opaque handle returned by display_init.
Rectangle in framebuffer coordinates passed into display_flush.