39static const char*
const s_tag =
"EPD_CAL";
61#ifdef RA8_BENCH_VCOM_MV
65#ifdef RA8_PRODUCTION_BUILD
66#error "RA8_BENCH_VCOM_MV must not ship -- provision the panel's real VCOM"
79typedef enum : uint16_t {
80 k_ra8_epd_cal_bench_vcom_mv = (uint16_t)(RA8_BENCH_VCOM_MV),
94typedef enum : uint32_t {
103typedef enum : uint8_t {
136 for (
size_t i = 0U; i < len; i++) {
137 crc ^= (uint32_t)data[i];
139 const uint32_t mask = (uint32_t)0U - (crc & 1U);
282 if (store->
read ==
nullptr) {
308 if (limits ==
nullptr) {
311 if ((mv < limits->min_mv) || (mv > limits->
max_mv)) {
365 const uint16_t payload_len =
416 uint16_t panel_mv = 0U;
424 out_result->
vcom_mv = panel_mv;
489#ifdef RA8_BENCH_VCOM_MV
493 ra8_log_warn(
s_tag,
"USING BENCH VCOM FROM RA8_BENCH_VCOM_MV -- NOT FOR SHIPPING");
494 out_result->
vcom_mv = (uint16_t)k_ra8_epd_cal_bench_vcom_mv;
537 uint16_t readback = 0U;
547 if (readback != result->
vcom_mv) {
static const char * s_tag
Logging / check tag.
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.
bool ra8_epd_cal_vcom_in_range(uint16_t mv, const ra8_epd_cal_limits_mv_t *limits)
Range-check a candidate VCOM against a panel's documented window.
ra8_epd_cal_crc_t
IEEE 802.3 CRC-32 parameters.
@ k_ra8_epd_cal_crc_init
CRC seed / final XOR.
@ k_ra8_epd_cal_crc_poly
Reversed IEEE 802.3 poly.
static ra8_err_t internal_ra8_epd_cal_try_panel(const ra8_epd_cal_cfg_t *cfg, ra8_epd_cal_result_t *out_result)
Try the controller's own persisted VCOM (resolution source 1).
static void internal_ra8_epd_cal_pack_le32(uint8_t *dst, uint32_t val)
Store a little-endian 32-bit value.
ra8_err_t ra8_epd_cal_provision(const ra8_epd_cal_cfg_t *cfg, uint16_t vcom_mv)
Write a per-device calibration record to non-volatile storage.
static bool internal_ra8_epd_cal_magic_ok(const uint8_t *src)
Report whether a serialised record carries the 'EVCM' magic.
static uint32_t internal_ra8_epd_cal_crc32(const uint8_t *data, size_t len)
Compute the IEEE 802.3 CRC-32 of a byte span.
ra8_err_t ra8_epd_cal_resolve(const ra8_epd_cal_cfg_t *cfg, ra8_epd_cal_result_t *out_result)
Resolve the VCOM to drive this panel at, or fail safe.
ra8_err_t ra8_epd_cal_deserialize(const uint8_t *src, size_t src_size, ra8_epd_cal_record_t *out_rec)
Parse and integrity-check a serialised record.
static void internal_ra8_epd_cal_pack_le16(uint8_t *dst, uint16_t val)
Store a little-endian 16-bit value.
ra8_epd_cal_bits_t
Byte / word packing constants (no magic numbers).
@ k_ra8_epd_cal_bits_per_byte
CRC inner-loop bound.
@ k_ra8_epd_cal_off_b2
Little-endian byte 2.
@ k_ra8_epd_cal_byte_shift
Bits per byte.
@ k_ra8_epd_cal_off_b1
Little-endian byte 1.
@ k_ra8_epd_cal_off_b0
Little-endian byte 0.
@ k_ra8_epd_cal_byte_mask
Low-byte extraction mask.
@ k_ra8_epd_cal_off_b3
Little-endian byte 3.
ra8_err_t ra8_epd_cal_serialize(const ra8_epd_cal_record_t *rec, uint8_t *dst, size_t dst_size)
Serialise a record into its 32-byte on-flash form.
static ra8_err_t internal_ra8_epd_cal_try_record(const ra8_epd_cal_cfg_t *cfg, ra8_epd_cal_result_t *out_result)
Try the per-device record in storage (resolution source 2).
static uint16_t internal_ra8_epd_cal_unpack_le16(const uint8_t *src)
Load a little-endian 16-bit value.
ra8_err_t ra8_epd_cal_apply(const ra8_epd_cal_cfg_t *cfg, const ra8_epd_cal_result_t *result)
Programme a resolved VCOM onto the controller and confirm it took.
static uint32_t internal_ra8_epd_cal_unpack_le32(const uint8_t *src)
Load a little-endian 32-bit value.
static ra8_err_t internal_ra8_epd_cal_read_record(const ra8_epd_cal_store_t *store, ra8_epd_cal_record_t *out_rec)
Read and validate the per-device record through the store seam.
Per-device e-paper panel calibration (VCOM) – record, storage seam, resolution policy.
bool ra8_epd_cal_vcom_in_range(uint16_t mv, const ra8_epd_cal_limits_mv_t *limits)
Range-check a candidate VCOM against a panel's documented window.
@ k_ra8_epd_cal_blob_size
Serialised record size in bytes.
@ k_ra8_epd_cal_schema_version
Current on-flash schema version.
@ k_ra8_epd_cal_payload_len
Schema-1 payload bytes (vcom_mv).
@ k_ra8_epd_cal_src_panel
Read back from the controller.
@ k_ra8_epd_cal_src_record
From the per-device NV record.
@ k_ra8_epd_cal_src_provisioned
Operator-supplied this boot.
@ k_ra8_epd_cal_src_bench
RA8_BENCH_VCOM_MV; see below.
@ k_ra8_epd_cal_src_none
No trusted value – do NOT drive.
@ k_ra8_epd_cal_magic_b0
'E'
@ k_ra8_epd_cal_magic_b2
'C'
@ k_ra8_epd_cal_magic_b3
'M'
@ k_ra8_epd_cal_magic_b1
'V'
@ k_ra8_epd_cal_off_crc32
CRC-32 trailer, LE32.
@ k_ra8_epd_cal_off_payload_len
Payload length, LE16.
@ k_ra8_epd_cal_off_magic
'EVCM' magic.
@ k_ra8_epd_cal_off_version
Schema version byte.
@ k_ra8_epd_cal_off_vcom_mv
VCOM magnitude, LE16.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ k_ra8_err_crc_mismatch
CRC mismatch detected on received data.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ k_ra8_err_range_check_failed
Value outside range enforced by RA8_CHECK_RANGE / RA8_CHECK_RANGE_TAG.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_warn(tag, message)
RA8 log warn.
#define ra8_log_error(tag, message)
RA8 log error.
Everything ra8_epd_cal_resolve needs.
ra8_epd_cal_store_t store
Per-device record store seam.
bool has_provisioned
Whether the field above is set.
uint16_t provisioned_mv
Operator value for this boot.
ra8_epd_cal_panel_ops_t panel
Controller access seam.
ra8_epd_cal_limits_mv_t limits
Panel's documented VCOM window.
The panel's documented VCOM window, in millivolt magnitudes.
uint16_t min_mv
Lowest accepted VCOM magnitude, millivolts.
uint16_t max_mv
Highest accepted VCOM magnitude, millivolts.
ra8_epd_cal_panel_get_fn_t get
VCOM read seam; may be NULL.
void * ctx
Opaque context for both.
ra8_epd_cal_panel_set_fn_t set
VCOM write seam; may be NULL.
Decoded per-device calibration record.
uint8_t schema_version
Schema the record was written under.
uint16_t vcom_mv
VCOM magnitude in millivolts (e.g.
Outcome of ra8_epd_cal_resolve.
ra8_epd_cal_source_t source
Which authority supplied it.
uint16_t vcom_mv
Resolved VCOM magnitude, millivolts.
Injected non-volatile store for the calibration record.
ra8_epd_cal_nv_read_fn_t read
Record read seam; may be NULL.
void * ctx
Opaque context for both.
ra8_epd_cal_nv_write_fn_t write
Record write seam; may be NULL.