ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_epaper_devinfo.c
Go to the documentation of this file.
1
32
33#include <stddef.h>
34#include <stdint.h>
35
36#include "ra8_attributes.h"
37#include "ra8_check.h"
38#include "ra8_epaper.h"
39#include "ra8_err.h"
40
45static const char* const s_tag = "EPAPER";
46
59
77
99static void internal_ra8_epaper_unpack_ver_word(uint16_t word, char* dst)
100{
101 const uint8_t hi =
102 (uint8_t)((word >> (uint16_t)k_ra8_epaper_di_byte_shift) & (uint16_t)k_ra8_epaper_di_byte_mask);
103 const uint8_t lo = (uint8_t)(word & (uint16_t)k_ra8_epaper_di_byte_mask);
104 const bool hi_p =
105 (hi >= (uint8_t)k_ra8_epaper_di_ascii_min) && (hi < (uint8_t)k_ra8_epaper_di_ascii_max);
106 const bool lo_p =
107 (lo >= (uint8_t)k_ra8_epaper_di_ascii_min) && (lo < (uint8_t)k_ra8_epaper_di_ascii_max);
108 /* Cast the whole conditional, not each arm: the usual arithmetic
109 * conversions give the ternary type `int`, so casting only the value arm
110 * still leaves an implicit int -> char narrowing at the assignment. Both
111 * arms are bounded by the printable-ASCII test above (0x20 .. 0x7E), so
112 * every value is representable in a signed char. */
113 dst[0] = (char)(hi_p ? hi : 0U);
114 dst[1] = (char)(lo_p ? lo : 0U);
115}
116
138static void
140{
141 if (idx == (uint32_t)k_ra8_epaper_di_idx_width) {
142 out->panel_width = word;
143 } else if (idx == (uint32_t)k_ra8_epaper_di_idx_height) {
144 out->panel_height = word;
145 } else if (idx == (uint32_t)k_ra8_epaper_di_idx_buf_lo) {
146 out->image_buf_base |= (uint32_t)word;
147 } else if (idx == (uint32_t)k_ra8_epaper_di_idx_buf_hi) {
148 out->image_buf_base |= ((uint32_t)word << (uint32_t)k_ra8_epaper_di_word_shift);
149 } else if (idx < (uint32_t)k_ra8_epaper_di_idx_lut) {
150 const uint32_t off =
151 (idx - (uint32_t)k_ra8_epaper_di_idx_fw) * (uint32_t)k_ra8_epaper_di_ver_per_word;
153 } else {
154 const uint32_t off =
155 (idx - (uint32_t)k_ra8_epaper_di_idx_lut) * (uint32_t)k_ra8_epaper_di_ver_per_word;
157 }
158}
159
160[[nodiscard]] ra8_err_t
161ra8_epaper_decode_dev_info(const uint16_t* words, size_t count, ra8_epaper_dev_info_t* out_info)
162{
163 RA8_CHECK_NULL_PTR(words, s_tag, "decode_dev_info: words null");
164 RA8_CHECK_NULL_PTR(out_info, s_tag, "decode_dev_info: out null");
165 if (count < (size_t)k_ra8_epaper_di_idx_end) {
166 ra8_log_error(s_tag, "decode_dev_info: short response");
168 }
169
170 *out_info = (ra8_epaper_dev_info_t){};
171 for (uint32_t i = 0U; i < (uint32_t)k_ra8_epaper_di_idx_end; i++) {
172 internal_ra8_epaper_decode_dev_word(i, words[i], out_info);
173 }
174 /* The version fields are one char longer than the packed data, so the
175 * terminator lands past the last decoded char and can never be
176 * overwritten by the loop above. */
177 out_info->fw_version[k_ra8_epaper_ver_chars] = '\0';
178 out_info->lut_version[k_ra8_epaper_ver_chars] = '\0';
179 return k_ra8_ok;
180}
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.
@ k_ra8_epaper_ver_chars
Chars in a FW / LUT version string.
Definition ra8_epaper.h:214
ra8_epaper_devinfo_const_t
Word-unpacking constants (no magic numbers).
@ k_ra8_epaper_di_ascii_min
Lowest printable ASCII.
@ k_ra8_epaper_di_byte_shift
Bits per byte.
@ k_ra8_epaper_di_word_shift
Bits per 16-bit word.
@ k_ra8_epaper_di_byte_mask
Low-byte extraction mask.
@ k_ra8_epaper_di_ver_per_word
Version chars per word.
@ k_ra8_epaper_di_ascii_max
One past printable ASCII.
static void internal_ra8_epaper_unpack_ver_word(uint16_t word, char *dst)
Unpack one 16-bit version word into two ASCII chars.
static void internal_ra8_epaper_decode_dev_word(uint32_t idx, uint16_t word, ra8_epaper_dev_info_t *out)
Fold one GET_DEV_INFO word into the decoded info block.
ra8_err_t ra8_epaper_decode_dev_info(const uint16_t *words, size_t count, ra8_epaper_dev_info_t *out_info)
Decode a raw GET_DEV_INFO word block into a device-info struct.
ra8_epaper_devinfo_idx_t
Word offsets inside the 20-word GET_DEV_INFO response.
@ k_ra8_epaper_di_idx_height
Panel height.
@ k_ra8_epaper_di_idx_width
Panel width.
@ k_ra8_epaper_di_idx_fw
First firmware-version word.
@ k_ra8_epaper_di_idx_buf_lo
Image-buffer base, low half.
@ k_ra8_epaper_di_idx_lut
First LUT-version word.
@ k_ra8_epaper_di_idx_end
One past the last decoded word.
@ k_ra8_epaper_di_idx_buf_hi
Image-buffer base, high half.
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
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
#define ra8_log_error(tag, message)
RA8 log error.
Definition ra8_log.h:335
Decoded GET_DEV_INFO (0x0302) response.
Definition ra8_epaper.h:247
uint32_t image_buf_base
Controller frame-RAM base.
Definition ra8_epaper.h:250
char fw_version[k_ra8_epaper_ver_chars+1U]
Firmware version, NUL-term.
Definition ra8_epaper.h:251
char lut_version[k_ra8_epaper_ver_chars+1U]
LUT version, NUL-terminated.
Definition ra8_epaper.h:252
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