ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_epaper_geom.c
Go to the documentation of this file.
1
40
41#include <stddef.h>
42#include <stdint.h>
43
44#include "ra8_attributes.h"
45#include "ra8_check.h"
46#include "ra8_epaper.h"
47#include "ra8_err.h"
48
53static const char* const s_tag = "EPAPER";
54
63
74
91
104static const char* const s_lut_m641 = "M641";
105
107{
108 switch (pf) {
110 return (uint8_t)k_ra8_epaper_bpp_1;
112 return (uint8_t)k_ra8_epaper_bpp_2;
114 return (uint8_t)k_ra8_epaper_bpp_4;
116 default:
117 return (uint8_t)k_ra8_epaper_bpp_8;
118 }
119}
120
123 size_t* out_bytes)
124{
125 RA8_CHECK_NULL_PTR(area, s_tag, "image_bytes: area null");
126 RA8_CHECK_NULL_PTR(out_bytes, s_tag, "image_bytes: out null");
127 if ((area->width == 0U) || (area->height == 0U)) {
129 }
130 const size_t bpp = (size_t)ra8_epaper_bits_per_pixel(pf);
131 const size_t bits_per_byte = (size_t)k_ra8_epaper_geom_bits_per_byte;
132 /* Rows are packed independently and each starts on a byte boundary. */
133 const size_t row_bytes = (((size_t)area->width * bpp) + (bits_per_byte - 1U)) / bits_per_byte;
134 *out_bytes = row_bytes * (size_t)area->height;
135 return k_ra8_ok;
136}
137
138[[nodiscard]] bool ra8_epaper_area_is_aligned(const ra8_epaper_area_t* area,
140{
141 if (area == nullptr) {
142 return false;
143 }
144 if (pf != k_ra8_epaper_pf_1bpp) {
145 return true;
146 }
147 const uint16_t grid = (uint16_t)k_ra8_epaper_align_1bpp_px;
148 return ((area->x % grid) == 0U) && ((area->width % grid) == 0U);
149}
150
151[[nodiscard]] ra8_err_t
153{
154 RA8_CHECK_NULL_PTR(area, s_tag, "align_area: area null");
155 if (panel_width == 0U) {
157 }
158 if (((uint32_t)area->x + (uint32_t)area->width) > (uint32_t)panel_width) {
160 }
161 if (pf != k_ra8_epaper_pf_1bpp) {
162 return k_ra8_ok;
163 }
164 const uint32_t grid = (uint32_t)k_ra8_epaper_align_1bpp_px;
165 const uint32_t right = (uint32_t)area->x + (uint32_t)area->width;
166 const uint32_t x_lo = ((uint32_t)area->x / grid) * grid;
167 /* Grow outward so the caller's rectangle stays wholly covered. */
168 uint32_t x_hi = ((right + grid - 1U) / grid) * grid;
169 if (x_hi > (uint32_t)panel_width) {
170 x_hi = (uint32_t)panel_width;
171 }
172 if ((x_hi <= x_lo) || (((x_hi - x_lo) % grid) != 0U)) {
173 /* The clamp cut the window off the grid: the panel width is itself not
174 * a multiple of the 1 bpp grid, so no aligned superset exists here. */
176 }
177 area->x = (uint16_t)x_lo;
178 area->width = (uint16_t)(x_hi - x_lo);
179 return k_ra8_ok;
180}
181
182[[nodiscard]] ra8_err_t ra8_epaper_waveform_cfg_for_lut(const char* lut_version,
184{
185 RA8_CHECK_NULL_PTR(lut_version, s_tag, "waveform_cfg: lut null");
186 RA8_CHECK_NULL_PTR(out_cfg, s_tag, "waveform_cfg: out null");
187 bool is_m641 = true;
188 for (uint32_t i = 0U; s_lut_m641[i] != '\0'; i++) {
189 if (lut_version[i] != s_lut_m641[i]) {
190 is_m641 = false;
191 break;
192 }
193 }
194 out_cfg->init = (uint8_t)k_ra8_epaper_lut_init;
195 out_cfg->du = (uint8_t)k_ra8_epaper_lut_du;
196 out_cfg->gc16 = (uint8_t)k_ra8_epaper_lut_gc16;
197 out_cfg->a2 = is_m641 ? (uint8_t)k_ra8_epaper_lut_a2_m641 : (uint8_t)k_ra8_epaper_lut_a2_gen;
198 return k_ra8_ok;
199}
200
224[[nodiscard]] static ra8_err_t
226{
227 if ((wf->du == 0U) || (wf->gc16 == 0U) || (wf->a2 == 0U)) {
229 }
230 if ((wf->init > (uint8_t)k_ra8_epaper_wf_mode_max) ||
231 (wf->du > (uint8_t)k_ra8_epaper_wf_mode_max) ||
232 (wf->gc16 > (uint8_t)k_ra8_epaper_wf_mode_max) ||
233 (wf->a2 > (uint8_t)k_ra8_epaper_wf_mode_max)) {
235 }
236 return k_ra8_ok;
237}
238
240{
241 RA8_CHECK_NULL_PTR(cfg, s_tag, "validate_cfg: cfg null");
242 if ((cfg->bus.xfer8 == nullptr) || (cfg->panel_width == 0U) || (cfg->panel_height == 0U) ||
243 (cfg->panel_width > (uint16_t)k_ra8_epaper_geom_panel_max_dim) ||
246 }
248}
249
251 const ra8_epaper_cfg_t* cfg)
252{
253 if ((info == nullptr) || (cfg == nullptr)) {
254 return false;
255 }
256 return (info->panel_width == cfg->panel_width) && (info->panel_height == cfg->panel_height);
257}
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
IT8951 e-paper controller SPI driver – public API.
ra8_epaper_pixel_format_t
Source pixel depth for a ra8_epaper_load_image transfer.
Definition ra8_epaper.h:180
@ k_ra8_epaper_pf_1bpp
1 bpp bi-level, 8 px per byte (A2).
Definition ra8_epaper.h:181
@ k_ra8_epaper_pf_4bpp
4 bpp, 2 px per byte – preferred.
Definition ra8_epaper.h:183
@ k_ra8_epaper_pf_2bpp
2 bpp, 4 px per byte.
Definition ra8_epaper.h:182
@ k_ra8_epaper_pf_8bpp
8 bpp, one byte per pixel.
Definition ra8_epaper.h:184
@ k_ra8_epaper_wf_mode_max
Highest valid LUT mode number.
Definition ra8_epaper.h:206
@ k_ra8_epaper_align_1bpp_px
4-byte (32 px) X/W grid for 1 bpp.
Definition ra8_epaper.h:205
ra8_epaper_bpp_t
Bit depth of each ra8_epaper_pixel_format_t.
@ k_ra8_epaper_bpp_4
k_ra8_epaper_pf_4bpp.
@ k_ra8_epaper_bpp_8
k_ra8_epaper_pf_8bpp.
@ k_ra8_epaper_bpp_1
k_ra8_epaper_pf_1bpp.
@ k_ra8_epaper_bpp_2
k_ra8_epaper_pf_2bpp.
ra8_err_t ra8_epaper_align_area(ra8_epaper_area_t *area, ra8_epaper_pixel_format_t pf, uint16_t panel_width)
Grow area outward onto the alignment grid its depth requires.
ra8_epaper_geom_const_t
Packing arithmetic constants (no magic numbers).
@ k_ra8_epaper_geom_panel_max_dim
Sanity ceiling on cfg dims.
@ k_ra8_epaper_geom_bits_per_byte
Row-packing denominator.
ra8_err_t ra8_epaper_validate_cfg(const ra8_epaper_cfg_t *cfg)
Validate a panel descriptor without touching any hardware.
static ra8_err_t internal_ra8_epaper_validate_waveform(const ra8_epaper_waveform_cfg_t *wf)
Validate the caller's waveform map against the LUT mode range.
static const char *const s_lut_m641
LUT-version token identifying the 6 inch / 6 inch HD waveform set.
bool ra8_epaper_area_is_aligned(const ra8_epaper_area_t *area, ra8_epaper_pixel_format_t pf)
Report whether area satisfies the depth's X/width alignment.
ra8_epaper_lut_mode_t
Waveform LUT mode numbers the vendor documents.
@ k_ra8_epaper_lut_gc16
GC16 on every documented LUT.
@ k_ra8_epaper_lut_a2_m641
A2 on the M641 LUT.
@ k_ra8_epaper_lut_init
INIT on every documented LUT.
@ k_ra8_epaper_lut_a2_gen
A2 on the vendor generic LUT.
@ k_ra8_epaper_lut_du
DU on every documented LUT.
ra8_err_t ra8_epaper_waveform_cfg_for_lut(const char *lut_version, ra8_epaper_waveform_cfg_t *out_cfg)
Fill a waveform map from a controller-reported LUT version.
uint8_t ra8_epaper_bits_per_pixel(ra8_epaper_pixel_format_t pf)
Bits per pixel carried by a ra8_epaper_pixel_format_t.
bool ra8_epaper_geometry_agrees(const ra8_epaper_dev_info_t *info, const ra8_epaper_cfg_t *cfg)
Report whether reported panel geometry matches the descriptor.
ra8_err_t ra8_epaper_image_bytes(const ra8_epaper_area_t *area, ra8_epaper_pixel_format_t pf, size_t *out_bytes)
Bytes a packed source buffer needs for area at depth pf.
Error Code Definitions for ra8-firmware.
@ 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_invalid_size
Invalid size parameter (too large, too small, or misaligned).
Definition ra8_err.h:167
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Rectangle descriptor (top-left + size) used by load + display.
Definition ra8_epaper.h:317
uint16_t x
Top-left X in panel coords (0 = left).
Definition ra8_epaper.h:318
uint16_t height
Height in pixels.
Definition ra8_epaper.h:321
uint16_t width
Width in pixels.
Definition ra8_epaper.h:320
Configuration descriptor for ra8_epaper_init.
Definition ra8_epaper.h:304
uint16_t panel_height
Native panel height in pixels.
Definition ra8_epaper.h:310
uint16_t panel_width
Native panel width in pixels.
Definition ra8_epaper.h:309
ra8_epaper_waveform_cfg_t waveform
Panel's LUT waveform mode numbers.
Definition ra8_epaper.h:306
ra8_spi_bus_ops_t bus
Injected SPI transfer seam (app-bound).
Definition ra8_epaper.h:305
Decoded GET_DEV_INFO (0x0302) response.
Definition ra8_epaper.h:247
uint16_t panel_width
Reported panel width (px).
Definition ra8_epaper.h:248
uint16_t panel_height
Reported panel height (px).
Definition ra8_epaper.h:249
Per-panel map from ra8_epaper_waveform_t onto LUT mode numbers.
Definition ra8_epaper.h:148
uint8_t init
LUT mode number for INIT (flush to white).
Definition ra8_epaper.h:149
uint8_t du
LUT mode number for DU (direct update).
Definition ra8_epaper.h:150
uint8_t a2
LUT mode number for A2 (bi-level, fastest).
Definition ra8_epaper.h:152
uint8_t gc16
LUT mode number for GC16 (16-grey quality).
Definition ra8_epaper.h:151
ra8_err_t(* xfer8)(void *ctx, uint8_t tx, uint8_t *rx)
Full-duplex single-byte exchange on the bound bus.