|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
On-screen keyboard widget – iOS-style layers + shift. More...
#include "ra8_keyboard.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_ui.h"Go to the source code of this file.
Enumerations | |
| enum | kbd_geom_t : int32_t { k_kbd_hu_div = 20 , k_kbd_key_hu = 2 , k_kbd_wide_hu = 3 , k_kbd_inset_hu = 1 , k_kbd_act_hu = 4 , k_kbd_space_hu = 12 , k_kbd_top_keys = 10 , k_kbd_mid_keys = 9 , k_kbd_r2_lett = 7 , k_kbd_punct_n = 5 , k_kbd_punct_hu0 = 5 , k_kbd_sym1_n = 7 , k_kbd_sym1_hu0 = 3 , k_kbd_row1 = 1 , k_kbd_row2 = 2 , k_kbd_row3 = 3 } |
| Row geometry in 20ths of the width ("half-units"), iOS proportions. More... | |
Functions | |
| static void | internal_add (ra8_kbd_layout_t *kb, int32_t x, int32_t w, int32_t y, int32_t h, char lo, char hi, ra8_kbd_key_kind_t kind, uint8_t aux) |
| Append one key descriptor to the layout, bounded by k_ra8_kbd_max_keys. | |
| static int32_t | internal_hx (const ra8_ui_rect_t *f, int32_t hu) |
| Compute the pixel X coordinate for a given half-unit offset within a frame. | |
| static void | internal_place (ra8_kbd_layout_t *kb, const char *lo, const char *hi, int32_t n, int32_t hu0, const ra8_ui_rect_t *f, int32_t y, int32_t rh) |
Place n character keys, each k_kbd_key_hu (2) half-units wide, starting from half-unit offset hu0. | |
| static void | internal_span (ra8_kbd_layout_t *kb, int32_t a, int32_t b, const ra8_ui_rect_t *f, int32_t y, int32_t rh, ra8_kbd_key_kind_t kind, uint8_t aux) |
Append one special key that spans half-units [a, b). | |
| static void | internal_row_punct (ra8_kbd_layout_t *kb, const ra8_ui_rect_t *f, int32_t y, int32_t rh, uint8_t tog_aux) |
| Build row 2 for the numbers or symbols layer: layer-toggle, punctuation, backspace. | |
| static void | internal_row_bottom (ra8_kbd_layout_t *kb, const ra8_ui_rect_t *f, int32_t y, int32_t rh, uint8_t left_aux) |
| Build the bottom row: a layer-toggle key, SPACE, and RETURN. | |
| static void | internal_build_letters (ra8_kbd_layout_t *kb, const ra8_ui_rect_t *f, int32_t rh) |
| Build the letters layer (QWERTY / SHIFT / 123 bottom-row toggle). | |
| static void | internal_build_numbers (ra8_kbd_layout_t *kb, const ra8_ui_rect_t *f, int32_t rh) |
| Build the numbers layer (digits, common symbols; #+= toggles to symbols). | |
| static void | internal_build_symbols (ra8_kbd_layout_t *kb, const ra8_ui_rect_t *f, int32_t rh) |
| Build the symbols layer (brackets, math operators; 123 toggles to numbers). | |
| static void | internal_build_layer (ra8_kbd_layout_t *kb) |
| Rebuild the key grid for the active layer stored in kb->layer. | |
| ra8_err_t | ra8_kbd_layout_init (ra8_kbd_layout_t *kb, const ra8_ui_rect_t *frame) |
Lay the letters layer into frame; clear SHIFT. | |
| uint8_t | ra8_kbd_hit (const ra8_kbd_layout_t *kb, int32_t px, int32_t py) |
| Map a tap to a key index. | |
| char | ra8_kbd_key_glyph (const ra8_kbd_layout_t *kb, uint8_t key_idx) |
| Effective character a char key emits given the live SHIFT state. | |
| ra8_err_t | ra8_kbd_text_init (ra8_kbd_text_t *t) |
| Reset a text buffer to empty / uncommitted. | |
| static void | internal_append (ra8_kbd_text_t *t, char ch) |
Append character ch to the text buffer if capacity allows. | |
| ra8_err_t | ra8_kbd_apply (ra8_kbd_text_t *t, ra8_kbd_layout_t *kb, uint8_t key_idx) |
Apply key key_idx to the text buffer, SHIFT, and active layer. | |
Variables | |
| static const char * | s_tag = "KBD" |
| Log tag for this module. | |
| static const char | s_l_r0_lo [] = "qwertyuiop" |
| static const char | s_l_r0_hi [] = "QWERTYUIOP" |
| static const char | s_l_r1_lo [] = "asdfghjkl" |
| static const char | s_l_r1_hi [] = "ASDFGHJKL" |
| static const char | s_l_r2_lo [] = "zxcvbnm" |
| static const char | s_l_r2_hi [] = "ZXCVBNM" |
| static const char | s_n_r0 [] = "1234567890" |
| static const char | s_n_r1 [] = "-/:;()$&@\"" |
| static const char | s_s_r0 [] = "[]{}#%^*+=" |
| static const char | s_s_r1 [] = "<>\\_`|~" |
| static const char | s_punct [] = ".,?!'" |
On-screen keyboard widget – iOS-style layers + shift.
Builds bounded letter, number, and symbol layouts, performs hit testing, and applies key actions to caller-owned text state without heap use.
Definition in file ra8_keyboard.c.
| enum kbd_geom_t : int32_t |
Row geometry in 20ths of the width ("half-units"), iOS proportions.
Definition at line 30 of file ra8_keyboard.c.
|
static |
Append one key descriptor to the layout, bounded by k_ra8_kbd_max_keys.
Writes a single ra8_kbd_key_t entry into kb->keys[kb->count] and increments kb->count. If the layout is already at capacity (kb->count >= k_ra8_kbd_max_keys) the call is silently discarded so callers do not need to perform their own bounds check.
| [in,out] | kb | Layout being built; count is incremented on success. |
| [in] | x | Left edge of the key rectangle in screen pixels. |
| [in] | w | Width of the key rectangle in screen pixels. |
| [in] | y | Top edge of the key rectangle in screen pixels. |
| [in] | h | Height of the key rectangle in screen pixels. |
| [in] | lo | Character produced when shift is inactive (0 for special keys). |
| [in] | hi | Character produced when shift is active (0 for special keys). |
| [in] | kind | Key kind tag (char, space, backspace, shift, enter, layer). |
| [in] | aux | Auxiliary data; for k_ra8_kbd_key_layer this is the target layer index, otherwise 0. |
Definition at line 100 of file ra8_keyboard.c.
References ra8_kbd_key_t::aux, ra8_kbd_key_t::ch_lower, ra8_kbd_key_t::ch_upper, ra8_kbd_layout_t::count, ra8_ui_rect_t::h, k_ra8_kbd_max_keys, ra8_kbd_layout_t::keys, ra8_kbd_key_t::kind, RA8_INTERNAL, ra8_kbd_key_t::rect, ra8_ui_rect_t::w, ra8_ui_rect_t::x, and ra8_ui_rect_t::y.
Referenced by internal_layout(), internal_place(), and internal_span().
|
static |
Append character ch to the text buffer if capacity allows.
Checks whether t->len is strictly less than (k_ra8_kbd_text_max - 1) to preserve room for the NUL terminator. If there is space, writes ch at t->buf[t->len], increments t->len, and writes '\0' at the new t->len position. If the buffer is full the call is silently discarded so callers do not need to guard against overflow.
| [in,out] | t | Text buffer to append to; len and buf are modified on success. |
| [in] | ch | Character to append (must not be '\0'). |
Definition at line 632 of file ra8_keyboard.c.
References ra8_kbd_text_t::buf, k_ra8_kbd_text_max, ra8_kbd_text_t::len, and RA8_INTERNAL.
Referenced by priv_fmt_host_spool_open(), ra8_fmt_jof_convert_stream(), and ra8_kbd_apply().
|
static |
Rebuild the key grid for the active layer stored in kb->layer.
Resets kb->count to zero, computes the uniform row height as kb->frame.h / k_ra8_kbd_rows, then dispatches to the appropriate layer builder:
| [in,out] | kb | Layout to rebuild; kb->layer and kb->frame must be valid. kb->count is reset to 0 and then repopulated. |
kb.Definition at line 543 of file ra8_keyboard.c.
References ra8_kbd_layout_t::count, ra8_kbd_layout_t::frame, ra8_ui_rect_t::h, internal_build_letters(), internal_build_numbers(), internal_build_symbols(), k_ra8_kbd_layer_numbers, k_ra8_kbd_layer_symbols, k_ra8_kbd_rows, ra8_kbd_layout_t::layer, and RA8_INTERNAL.
Referenced by ra8_kbd_apply(), and ra8_kbd_layout_init().
|
static |
Build the letters layer (QWERTY / SHIFT / 123 bottom-row toggle).
Populates four rows into kb:
rh parameter is used as the uniform row height; f->y is the top of row 0 and subsequent rows are offset by multiples of rh.| [in,out] | kb | Layout being built; all letter-layer keys are appended. |
| [in] | f | Bounding rectangle of the keyboard widget. |
| [in] | rh | Row height in pixels (f->h / k_ra8_kbd_rows). |
Definition at line 397 of file ra8_keyboard.c.
References internal_place(), internal_row_bottom(), internal_span(), k_kbd_hu_div, k_kbd_inset_hu, k_kbd_mid_keys, k_kbd_r2_lett, k_kbd_row2, k_kbd_row3, k_kbd_top_keys, k_kbd_wide_hu, k_ra8_kbd_key_backspace, k_ra8_kbd_key_shift, k_ra8_kbd_layer_numbers, s_l_r0_hi, s_l_r0_lo, s_l_r1_hi, s_l_r1_lo, s_l_r2_hi, s_l_r2_lo, and ra8_ui_rect_t::y.
Referenced by internal_build_layer().
|
static |
Build the numbers layer (digits, common symbols; #+= toggles to symbols).
Populates four rows into kb:
| [in,out] | kb | Layout being built; all numbers-layer keys are appended. |
| [in] | f | Bounding rectangle of the keyboard widget. |
| [in] | rh | Row height in pixels (f->h / k_ra8_kbd_rows). |
Definition at line 459 of file ra8_keyboard.c.
References internal_place(), internal_row_bottom(), internal_row_punct(), k_kbd_row2, k_kbd_row3, k_kbd_top_keys, k_ra8_kbd_layer_letters, k_ra8_kbd_layer_symbols, s_n_r0, s_n_r1, and ra8_ui_rect_t::y.
Referenced by internal_build_layer().
|
static |
Build the symbols layer (brackets, math operators; 123 toggles to numbers).
Populates four rows into kb:
| [in,out] | kb | Layout being built; all symbols-layer keys are appended. |
| [in] | f | Bounding rectangle of the keyboard widget. |
| [in] | rh | Row height in pixels (f->h / k_ra8_kbd_rows). |
Definition at line 498 of file ra8_keyboard.c.
References internal_place(), internal_row_bottom(), internal_row_punct(), k_kbd_row2, k_kbd_row3, k_kbd_sym1_hu0, k_kbd_sym1_n, k_kbd_top_keys, k_ra8_kbd_layer_letters, k_ra8_kbd_layer_numbers, s_s_r0, s_s_r1, and ra8_ui_rect_t::y.
Referenced by internal_build_layer().
|
static |
Compute the pixel X coordinate for a given half-unit offset within a frame.
Maps a half-unit index hu to an absolute horizontal pixel position using the formula: f->x + (f->w * hu) / k_kbd_hu_div. The division is integer (truncating), matching the iOS-style proportional key layout where the full frame width is divided into k_kbd_hu_div (20) equal slots.
| [in] | f | Bounding rectangle of the keyboard widget; x and w are used. |
| [in] | hu | Half-unit index in the range [0, k_kbd_hu_div]. |
| (f->x | + (f->w * hu) / k_kbd_hu_div) Computed X coordinate. |
Definition at line 150 of file ra8_keyboard.c.
References k_kbd_hu_div, RA8_INTERNAL, ra8_ui_rect_t::w, and ra8_ui_rect_t::x.
Referenced by internal_place(), and internal_span().
|
static |
Place n character keys, each k_kbd_key_hu (2) half-units wide, starting from half-unit offset hu0.
Iterates over indices 0..n-1 and calls internal_add() for each character in the lo string. The left edge of key i is at half-unit (hu0 + i*2) and the right edge at half-unit (hu0 + (i+1)*2), with actual pixel positions resolved via internal_hx(). When hi is nullptr the upper-case glyph is set equal to the lower-case glyph (used for layers without a shift effect).
| [in,out] | kb | Layout being built; keys are appended via internal_add(). |
| [in] | lo | Null-terminated string of lower-case glyphs; must have at least n characters. |
| [in] | hi | Null-terminated string of upper-case glyphs with at least n characters, or nullptr if shift has no effect. |
| [in] | n | Number of character keys to place. |
| [in] | hu0 | Starting half-unit offset within f. |
| [in] | f | Bounding rectangle of the keyboard widget. |
| [in] | y | Top pixel coordinate of the key row. |
| [in] | rh | Row height in pixels. |
n elements. Definition at line 189 of file ra8_keyboard.c.
References internal_add(), internal_hx(), k_kbd_key_hu, k_ra8_kbd_key_char, and RA8_INTERNAL.
Referenced by internal_build_letters(), internal_build_numbers(), internal_build_symbols(), and internal_row_punct().
|
static |
Build the bottom row: a layer-toggle key, SPACE, and RETURN.
Lays out three groups from left to right across the full frame width:
left_aux (the layer index to switch to).left_aux.| [in,out] | kb | Layout being built; keys are appended via internal_span(). |
| [in] | f | Bounding rectangle of the keyboard widget. |
| [in] | y | Top pixel coordinate of the row. |
| [in] | rh | Row height in pixels. |
| [in] | left_aux | Target layer index stored in the left layer-toggle key's aux field. |
Definition at line 343 of file ra8_keyboard.c.
References internal_span(), k_kbd_act_hu, k_kbd_hu_div, k_kbd_space_hu, k_ra8_kbd_key_enter, k_ra8_kbd_key_layer, k_ra8_kbd_key_space, and RA8_INTERNAL.
Referenced by internal_build_letters(), internal_build_numbers(), and internal_build_symbols().
|
static |
Build row 2 for the numbers or symbols layer: layer-toggle, punctuation, backspace.
Lays out three groups from left to right across the full frame width:
tog_aux (the layer to switch to on press).tog_aux.| [in,out] | kb | Layout being built; keys are appended via internal_span() and internal_place(). |
| [in] | f | Bounding rectangle of the keyboard widget. |
| [in] | y | Top pixel coordinate of the row. |
| [in] | rh | Row height in pixels. |
| [in] | tog_aux | Target layer index stored in the layer-toggle key's aux field (k_ra8_kbd_layer_symbols or k_ra8_kbd_layer_numbers). |
Definition at line 292 of file ra8_keyboard.c.
References internal_place(), internal_span(), k_kbd_act_hu, k_kbd_hu_div, k_kbd_punct_hu0, k_kbd_punct_n, k_ra8_kbd_key_backspace, k_ra8_kbd_key_layer, RA8_INTERNAL, and s_punct.
Referenced by internal_build_numbers(), and internal_build_symbols().
|
static |
Append one special key that spans half-units [a, b).
Computes the pixel left edge from half-unit a and the pixel width as internal_hx(f, b) - internal_hx(f, a), then delegates to internal_add() with zero glyph characters. Used for shift, backspace, space, enter, and layer- toggle keys which span more than the standard 2-half-unit width.
| [in,out] | kb | Layout being built; one key is appended via internal_add(). |
| [in] | a | First half-unit of the key span (inclusive). |
| [in] | b | Last half-unit of the key span (exclusive). |
| [in] | f | Bounding rectangle of the keyboard widget. |
| [in] | y | Top pixel coordinate of the key row. |
| [in] | rh | Row height in pixels. |
| [in] | kind | Key kind (shift, backspace, space, enter, or layer). |
| [in] | aux | Auxiliary data; for k_ra8_kbd_key_layer this is the target layer index, otherwise 0. |
Definition at line 244 of file ra8_keyboard.c.
References internal_add(), internal_hx(), and RA8_INTERNAL.
Referenced by internal_build_letters(), internal_row_bottom(), and internal_row_punct().
|
nodiscard |
Apply key key_idx to the text buffer, SHIFT, and active layer.
A char/space appends (shift-correct) and clears one-shot SHIFT; SHIFT toggles kb->shift; a layer key swaps the layer (re-laying the grid in place); backspace deletes; RETURN sets committed. Out-of-range / capacity edges are no-ops (still k_ra8_ok).
| [in,out] | t | Text buffer. |
| [in,out] | kb | Laid-out grid (SHIFT / layer / keys may change). |
| [in] | key_idx | Key index from ra8_kbd_hit. |
| k_ra8_ok | Applied (possibly a no-op at a capacity edge). |
| k_ra8_err_null_ptr | t or kb is NULL. |
t, kb non-NULL. key_idx is a hit index or k_ra8_kbd_no_hit (no-op). t / kb. Definition at line 641 of file ra8_keyboard.c.
References ra8_kbd_key_t::aux, ra8_kbd_text_t::buf, ra8_kbd_key_t::ch_lower, ra8_kbd_key_t::ch_upper, ra8_kbd_text_t::committed, ra8_kbd_layout_t::count, internal_append(), internal_build_layer(), k_ra8_kbd_key_backspace, k_ra8_kbd_key_char, k_ra8_kbd_key_enter, k_ra8_kbd_key_layer, k_ra8_kbd_key_shift, k_ra8_kbd_key_space, k_ra8_ok, ra8_kbd_layout_t::keys, ra8_kbd_key_t::kind, ra8_kbd_layout_t::layer, ra8_kbd_text_t::len, RA8_CHECK_NULL_PTR, s_tag, and ra8_kbd_layout_t::shift.
Referenced by er_handle_keyboard_tap(), and kb_tap().
|
nodiscard |
Map a tap to a key index.
| [in] | kb | Laid-out grid. |
| [in] | px | Tap X (pixels). |
| [in] | py | Tap Y (pixels). |
kb is NULL).kb is laid out (or NULL, handled). Definition at line 571 of file ra8_keyboard.c.
References ra8_kbd_layout_t::count, k_ra8_kbd_no_hit, ra8_kbd_layout_t::keys, ra8_ui_rect_contains(), and ra8_kbd_key_t::rect.
Referenced by kb_tap().
|
nodiscard |
Effective character a char key emits given the live SHIFT state.
| [in] | kb | Laid-out grid (for SHIFT). |
| [in] | key_idx | Key index. |
kb).kb is laid out (or NULL, handled). Definition at line 584 of file ra8_keyboard.c.
References ra8_kbd_key_t::ch_lower, ra8_kbd_key_t::ch_upper, ra8_kbd_layout_t::count, k_ra8_kbd_key_char, ra8_kbd_layout_t::keys, ra8_kbd_key_t::kind, and ra8_kbd_layout_t::shift.
Referenced by er_kbd_label().
|
nodiscard |
Lay the letters layer into frame; clear SHIFT.
| [out] | kb | Receives the laid-out grid (letters layer, SHIFT cleared). |
| [in] | frame | Pixel rectangle to fill (w,h > 0); saved for layer swaps. |
| k_ra8_ok | Grid laid out. |
| k_ra8_err_null_ptr | kb or frame is NULL. |
| k_ra8_err_invalid_arg | frame has non-positive w or h. |
kb, frame non-NULL. frame.kb. Definition at line 556 of file ra8_keyboard.c.
References ra8_kbd_layout_t::frame, ra8_ui_rect_t::h, internal_build_layer(), k_ra8_err_invalid_arg, k_ra8_kbd_layer_letters, k_ra8_ok, ra8_kbd_layout_t::layer, RA8_CHECK_NULL_PTR, s_tag, ra8_kbd_layout_t::shift, and ra8_ui_rect_t::w.
Referenced by er_kbd_keys_render(), and main().
|
nodiscard |
Reset a text buffer to empty / uncommitted.
| [out] | t | Buffer to clear. |
| k_ra8_ok | Cleared. |
| k_ra8_err_null_ptr | t is NULL. |
t non-NULL. t. Definition at line 596 of file ra8_keyboard.c.
References ra8_kbd_text_t::buf, ra8_kbd_text_t::committed, k_ra8_ok, ra8_kbd_text_t::len, RA8_CHECK_NULL_PTR, and s_tag.
Referenced by er_handle_tap(), and main().
|
static |
Definition at line 51 of file ra8_keyboard.c.
Referenced by internal_build_letters().
|
static |
Definition at line 50 of file ra8_keyboard.c.
Referenced by internal_build_letters().
|
static |
Definition at line 53 of file ra8_keyboard.c.
Referenced by internal_build_letters().
|
static |
Definition at line 52 of file ra8_keyboard.c.
Referenced by internal_build_letters().
|
static |
Definition at line 55 of file ra8_keyboard.c.
Referenced by internal_build_letters().
|
static |
Definition at line 54 of file ra8_keyboard.c.
Referenced by internal_build_letters().
|
static |
Definition at line 57 of file ra8_keyboard.c.
Referenced by internal_build_numbers().
|
static |
Definition at line 58 of file ra8_keyboard.c.
Referenced by internal_build_numbers().
|
static |
Definition at line 65 of file ra8_keyboard.c.
Referenced by internal_row_punct().
|
static |
Definition at line 62 of file ra8_keyboard.c.
Referenced by internal_build_symbols().
|
static |
Definition at line 63 of file ra8_keyboard.c.
Referenced by internal_build_symbols().
|
static |
Log tag for this module.
Definition at line 24 of file ra8_keyboard.c.