43typedef enum : uint8_t {
57typedef enum : uint8_t {
70typedef enum : uint32_t {
144 uint32_t w = (uint32_t)src[0];
171 (void)
memcpy(&out, &f,
sizeof(out));
194 (void)
memcpy(&out, &w,
sizeof(out));
220 for (
size_t i = 0U; i < len; i++) {
221 crc ^= (uint32_t)data[i];
223 const uint32_t mask = (uint32_t)0U - (crc & 1U);
257 const float abs_det = (det < 0.0F) ? -det : det;
376 for (uint8_t i = 0U; i < n; i++) {
377 const float xi = (float)raw[i].x;
378 const float yi = (float)raw[i].y;
379 const float ui = (float)screen[i].x;
380 const float vi = (float)screen[i].y;
400 if ((raw ==
nullptr) || (screen ==
nullptr) || (out_mtx ==
nullptr)) {
410 const float fn = (float)n;
411 const float norm_mat[9] = {
422 const float rhs_u[3] = {s.
Sxu, s.
Syu, s.
Su};
423 const float rhs_v[3] = {s.
Sxv, s.
Syv, s.
Sv};
425 float sol_u[3] = {0.0F, 0.0F, 0.0F};
426 float sol_v[3] = {0.0F, 0.0F, 0.0F};
432 if (!ok_u || !ok_v) {
436 out_mtx->
a = sol_u[0];
437 out_mtx->
b = sol_u[1];
438 out_mtx->
c = sol_u[2];
439 out_mtx->
d = sol_v[0];
440 out_mtx->
e = sol_v[1];
441 out_mtx->
f = sol_v[2];
452 if ((cfg ==
nullptr) || (out_matrix ==
nullptr)) {
461 const uint32_t margin_total = (uint32_t)cfg->
inset_px * 2U;
469 const int32_t ins = (int32_t)cfg->
inset_px;
474 {w - 1 - ins, h - 1 - ins},
508 uint16_t screen_width,
509 uint16_t screen_height,
512 if ((matrix ==
nullptr) || (out_screen ==
nullptr)) {
515 if ((screen_width == 0U) || (screen_height == 0U)) {
519 const float xf = (float)raw.
x;
520 const float yf = (float)raw.
y;
521 const float u = (matrix->
a * xf) + (matrix->
b * yf) + matrix->
c;
522 const float v = (matrix->
d * xf) + (matrix->
e * yf) + matrix->
f;
540 if ((matrix ==
nullptr) || (dst ==
nullptr)) {
556 const float coeffs[6] = {
564 for (uint8_t i = 0U; i < 6U; i++) {
578 if ((src ==
nullptr) || (out_matrix ==
nullptr)) {
602 if (want_crc != have_crc) {
606 float coeffs[6] = {0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F};
607 for (uint8_t i = 0U; i < 6U; i++) {
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_crc_mismatch
CRC mismatch detected on received data.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
@ 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.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
ra8_err_t ra8_touch_cal_compute(const ra8_touch_cal_point_t *raw, const ra8_touch_cal_point_t *screen, uint8_t n, ra8_touch_cal_matrix_t *out_mtx)
Compute an affine transform from N target/sample pairs.
static const float s_round_bias
Round-to-nearest bias for float->int conversion.
affine_coeff_idx_t
Affine calibration coefficient indices (a..f).
ra8_err_t ra8_touch_cal_save(const ra8_touch_cal_matrix_t *matrix, uint8_t *dst, size_t dst_size)
Serialise a calibration matrix to a fixed-size byte blob.
static const float s_min_det
Floor for |det| below which the normal equations are treated as singular.
ra8_err_t ra8_touch_cal_load(const uint8_t *src, size_t src_size, ra8_touch_cal_matrix_t *out_matrix)
Deserialise a calibration matrix from a byte blob.
static float internal_u32_to_float(uint32_t w)
Bitwise reinterpret a uint32_t as a float.
mat3_idx_t
Row-major flat indices of a 3x3 matrix (a[r*3+c]).
static int32_t internal_clip32(int32_t v, int32_t lo, int32_t hi)
Clip a value to [lo, hi].
static void internal_solve3(const float a[k_m3_len], const float b[3], float x[3], bool *ok)
Solve a 3x3 system A * x = b via Cramer's rule.
internal_const_t
Module-private numeric constants (no magic numbers).
@ k_internal_crc32_init
IEEE 802.3 CRC seed.
@ k_internal_byte_shift_16
Shift to byte 2.
@ k_internal_bits_per_byte
Bits in one byte.
@ k_internal_byte_shift_8
Shift to byte 1.
@ k_internal_centre_div
Halve to get panel centre.
@ k_internal_byte_shift_24
Shift to byte 3.
@ k_internal_crc32_poly
IEEE 802.3 reversed polynomial.
@ k_internal_byte_mask
8-bit mask for byte extracts.
ra8_err_t ra8_touch_cal_apply(ra8_touch_cal_point_t raw, const ra8_touch_cal_matrix_t *matrix, uint16_t screen_width, uint16_t screen_height, ra8_touch_cal_point_t *out_screen)
Apply a calibration matrix to a single raw touch sample.
static uint32_t internal_crc32(const uint8_t *data, size_t len)
Compute the IEEE 802.3 CRC32 of a byte range.
static uint32_t internal_unpack_le32(const uint8_t *src)
Unpack a 32-bit little-endian word from a byte buffer.
static void internal_pack_le32(uint8_t *dst, uint32_t word)
Pack a 32-bit little-endian word into a byte buffer.
static void internal_accumulate_sums(const ra8_touch_cal_point_t *raw, const ra8_touch_cal_point_t *screen, uint8_t n, internal_lsq_sums_t *s)
Accumulate the 11 least-squares sums over n sample pairs.
ra8_err_t ra8_touch_cal_run(const ra8_touch_cal_run_cfg_t *cfg, ra8_touch_cal_matrix_t *out_matrix)
Drive the on-screen calibration sequence and produce a matrix.
static uint32_t internal_float_to_u32(float f)
Bitwise reinterpret a float as a uint32_t.
Resistive/capacitive touch-screen calibration utility.
@ k_ra8_touch_cal_blob_size
Bytes in ra8_touch_cal_save.
@ k_ra8_touch_cal_min_targets
Floor for a unique solve.
@ k_ra8_touch_cal_n_targets
4 corners + centre.
@ k_ra8_touch_cal_max_targets
Ceiling for the fit.
@ k_ra8_touch_cal_storage_version
On-disk format version.
@ k_ra8_touch_cal_magic_b3
'L'
@ k_ra8_touch_cal_magic_b0
'T'
@ k_ra8_touch_cal_magic_b2
'A'
@ k_ra8_touch_cal_magic_b1
'C'
@ k_ra8_touch_cal_off_reserved
Offset of 3 reserved zero bytes.
@ k_ra8_touch_cal_off_magic
Offset of 'TCAL' magic.
@ k_ra8_touch_cal_off_version
Offset of version byte.
@ k_ra8_touch_cal_off_crc32
Offset of the CRC32 trailer.
@ k_ra8_touch_cal_off_coeffs
Offset of the 6-float coeff array.
Accumulated least-squares sums driving the calibration solve.
float Syu
Sum of raw y * screen x.
float Sxu
Sum of raw x * screen x.
float Sxv
Sum of raw x * screen y.
float Syv
Sum of raw y * screen y.
2-D affine transform screen = [a b; d e] * raw + [c; f].
float e
Row 1, column 1: raw-Y gain on screen-Y.
float b
Row 0, column 1: raw-Y gain on screen-X.
float d
Row 1, column 0: raw-X gain on screen-Y.
float f
Row 1 offset: screen-Y bias.
float a
Row 0, column 0: raw-X gain on screen-X.
float c
Row 0 offset: screen-X bias.
One (x, y) integer coordinate pair.
int32_t y
Vertical coordinate.
int32_t x
Horizontal coordinate.
Configuration for ra8_touch_cal_run.
ra8_touch_cal_read_raw_fn_t read_raw
Raw sample reader.
ra8_touch_cal_draw_target_fn_t draw_target
Cross-hair painter.
void * draw_ctx
Forwarded to painter.
uint16_t inset_px
Margin from panel edge to corner targets.
uint16_t screen_height
Panel height, pixels.
void * read_ctx
Forwarded to reader.
uint16_t screen_width
Panel width, pixels.