|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
E-reader UI chrome – on-screen keyboard, battery nag, input polling. More...
#include <stddef.h>#include <stdint.h>#include <string.h>#include "er_pageturn.h"#include "ereader_ui_steps.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_display_pal.h"#include "ra8_err.h"#include "ra8_gfx.h"#include "ra8_gfx_font.h"#include "ra8_i3c.h"#include "ra8_keyboard.h"#include "ra8_port_constants.h"#include "ra8_port_utils.h"#include "ra8_touch.h"#include "ra8_ui.h"#include "ra8_widget.h"Go to the source code of this file.
Enumerations | |
| enum | er_kbd_render_t : int32_t { k_er_kbd_glyph_w = 8 , k_er_kbd_glyph_h = 16 , k_er_kbd_qlabel = 72 , k_er_kbd_gap = 6 , k_er_kbd_radius = 10 , k_er_kbd_shadow_dy = 3 , k_er_kbd_lab_max = 8 , k_er_ico_aw = 11 , k_er_ico_atop = 12 , k_er_ico_abot = 2 , k_er_ico_sw = 3 , k_er_ico_sbot = 11 , k_er_ico_dw = 14 , k_er_ico_dh = 9 , k_er_ico_dx = 5 , k_er_ico_dxo = 4 , k_er_ico_rw = 11 , k_er_ico_rh = 10 , k_er_ico_rah = 6 } |
| Keyboard chrome metrics (8x16 glyphs + keys). More... | |
| enum | er_kbd_color_t : uint32_t { k_er_kbd_bg = 0xCCCCCCU , k_er_kbd_keylt = 0xFFFFFFU , k_er_kbd_keydk = 0xAAAAAAU , k_er_kbd_keysh = 0x909090U } |
| Apple-style grayscale keyboard palette. More... | |
Functions | |
| static const char * | er_kbd_label (uint8_t idx, char *s) |
Text label for key idx (SPACE / 123-ABC, or live-case char in s). | |
| static void | er_round_rect (int32_t x, int32_t y, int32_t w, int32_t h, uint32_t c) |
| Filled rounded rect (rect cross + four corner discs). | |
| static void | er_tri_up (int32_t cx, int32_t ay, int32_t by, int32_t hw, uint32_t c) |
Filled upward triangle from apex row ay to base row by (scanlines). | |
| static void | er_icon_shift (int32_t cx, int32_t cy, uint32_t c) |
| SHIFT glyph: an up-arrow (filled arrowhead over a narrow stem). | |
| static void | er_icon_delete (int32_t cx, int32_t cy, uint32_t c) |
| BACKSPACE glyph: a left-pointing pentagon outline with an X inside. | |
| static void | er_icon_return (int32_t cx, int32_t cy, uint32_t c) |
| RETURN glyph: a carriage-return arrow (tail down, shaft left, arrowhead). | |
| static bool | er_key_is_special (ra8_kbd_key_kind_t kind) |
| True for keys drawn dark (SHIFT / BACKSPACE / 123-ABC / RETURN). | |
| static void | er_draw_key_label (uint8_t idx, int32_t kx, int32_t ky, int32_t kw, int32_t kh, uint32_t fill) |
Draw the text label of key idx centred in the key body. | |
| static void | er_draw_key (uint8_t idx) |
Draw key idx Apple-style: a shadowed rounded key + glyph icon / label. | |
| static void | er_kbd_search_render (ra8_widget_t *w) |
| Search-field band widget: the "Search:" label + the query / hint. | |
| static void | er_kbd_keys_render (ra8_widget_t *w) |
| Keyboard band widget: gray backdrop + the laid-out keys + tap targets. | |
| void | er_render_keyboard (void) |
| Render the on-screen keyboard screen + collect its key targets. | |
| static bool | er_fg_read (uint8_t reg, uint8_t *out) |
| Best-effort read of one fuel-gauge register on the touch IIC_B bus. | |
| static bool | er_read_battery (uint8_t *soc, bool *charging) |
| Read SOC + charge direction from the fuel gauge; false if absent (NAK). | |
| static void | er_append_pct (char *buf, uint32_t cap, uint32_t *pos, uint8_t v) |
Append "<v>%" (v in 0..255) to buf at *pos, bounded + NUL-terminated. | |
| static void | er_append_str (char *buf, uint32_t cap, uint32_t *pos, const char *s) |
Append NUL-terminated s to buf at *pos, bounded + NUL-terminated. | |
| static bool | er_nag_hit (int32_t x, int32_t y) |
| True iff (x,y) lands on the low-battery banner rect. | |
| void | er_nag_render (ra8_widget_t *w) |
| Nag banner overlay widget: a centered low-battery toast over the screen. | |
| static bool | er_handle_reading_tap (int32_t x, int32_t y) |
| Handle a tap while the Reading view is on top. | |
| static bool | er_handle_keyboard_tap (int32_t x, int32_t y) |
| Route a tap on the keyboard screen: type a key, or commit on ENTER. | |
| static bool | er_handle_tap (int32_t x, int32_t y) |
| Route a tap to a navigation action for the current screen. | |
| void | er_poll_touch (void) |
| Poll the touch controller and dispatch a tap on a fresh press. | |
| static bool | er_sw_pressed (ra8_port_pin_t pin) |
| Read a user switch (active-low); true == pressed. | |
| void | er_poll_buttons (void) |
| Poll SW1/SW2 and turn a page on a fresh press (#78). | |
| void | er_poll_battery (void) |
| Implementation of er_poll_battery() – the clear-the-banner glue. | |
Variables | |
| static const ra8_widget_vtable_t | k_er_kbd_search_vt = {.render = er_kbd_search_render} |
| Vtables for the keyboard search-field / keys band widgets. | |
| static const ra8_widget_vtable_t | k_er_kbd_keys_vt = {.render = er_kbd_keys_render} |
| static const char | k_er_nag_low_msg [] = "Low battery " |
| Nag banner messages (the SOC percent + dismiss hint follow at render). | |
| static const char | k_er_nag_crit_msg [] = "Battery critical " |
| static const char | k_er_nag_hint [] = " (tap to dismiss)" |
| Trailing hint so the banner says how to close itself. | |
| static bool | s_was_touching |
| Debounce: true while a contact is held, to fire once per tap. | |
| static bool | s_was_sw1 |
| Debounce: true while SW1/SW2 are held, to fire once per press. | |
| static bool | s_was_sw2 |
E-reader UI chrome – on-screen keyboard, battery nag, input polling.
Split out of ereader_ui/main.c to keep every translation unit under the repository's 1000-line cap (a pure code move). This unit owns the Apple-style on-screen keyboard rendering (rounded keys, vector SHIFT / BACKSPACE / RETURN glyph icons, search-field band), the optional Settings stub, the low-battery nag-banner overlay and its fuel-gauge polling, and the per-frame input dispatch (touch taps and SW1/SW2 page-turn buttons). The composited chrome is byte-identical to the pre-split monolith.
Definition in file ereader_ui_input.c.
| enum er_kbd_color_t : uint32_t |
Apple-style grayscale keyboard palette.
| Enumerator | |
|---|---|
| k_er_kbd_bg | Keyboard background. |
| k_er_kbd_keylt | Light (letter/space) key. |
| k_er_kbd_keydk | Dark (special) key. |
| k_er_kbd_keysh | Key drop shadow. |
Definition at line 70 of file ereader_ui_input.c.
| enum er_kbd_render_t : int32_t |
Keyboard chrome metrics (8x16 glyphs + keys).
Definition at line 46 of file ereader_ui_input.c.
|
static |
Append "<v>%" (v in 0..255) to buf at *pos, bounded + NUL-terminated.
Definition at line 330 of file ereader_ui_input.c.
References k_er_nag_dec_max, and k_er_nag_dec_ten.
Referenced by er_nag_render().
|
static |
Append NUL-terminated s to buf at *pos, bounded + NUL-terminated.
Definition at line 355 of file ereader_ui_input.c.
References k_er_nag_line_max.
Referenced by er_nag_render().
|
static |
Draw key idx Apple-style: a shadowed rounded key + glyph icon / label.
SHIFT / BACKSPACE / RETURN render as vector glyph icons; every other key (letters, digits, symbols, SPACE, 123/#+=/ABC) renders its text label. An armed one-shot SHIFT inverts the SHIFT key (white body) like iOS.
Definition at line 188 of file ereader_ui_input.c.
References er_draw_key_label(), er_icon_delete(), er_icon_return(), er_icon_shift(), er_key_is_special(), er_round_rect(), ra8_ui_rect_t::h, k_er_ink, k_er_kbd_gap, k_er_kbd_keydk, k_er_kbd_keylt, k_er_kbd_keysh, k_er_kbd_shadow_dy, k_ra8_kbd_key_backspace, k_ra8_kbd_key_enter, k_ra8_kbd_key_shift, s_kb, ra8_ui_rect_t::w, ra8_ui_rect_t::x, and ra8_ui_rect_t::y.
Referenced by er_kbd_keys_render().
|
static |
Draw the text label of key idx centred in the key body.
Definition at line 172 of file ereader_ui_input.c.
References er_kbd_label(), k_er_ink, k_er_kbd_glyph_h, k_er_kbd_glyph_w, k_er_kbd_lab_max, ra8_gfx_font_8x16, ra8_gfx_text_out(), and strlen().
Referenced by er_draw_key().
|
static |
Best-effort read of one fuel-gauge register on the touch IIC_B bus.
Definition at line 297 of file ereader_ui_input.c.
References k_er_fg_addr, k_er_touch_channel, k_ra8_ok, ra8_i3c_read(), and ra8_i3c_write().
Referenced by er_read_battery().
|
static |
Route a tap on the keyboard screen: type a key, or commit on ENTER.
| [in] | x | Tap X (panel pixels). |
| [in] | y | Tap Y (panel pixels). |
Definition at line 460 of file ereader_ui_input.c.
References k_er_act_key_base, k_er_act_none, k_er_screen_library, k_ra8_ok, ra8_kbd_apply(), ra8_ui_hit_test(), ra8_ui_nav_pop(), s_kb, s_nav, s_query, s_target_count, and s_targets.
Referenced by er_handle_tap().
|
static |
Handle a tap while the Reading view is on top.
In priority order: the back-region (return from a link jump, else pop to the Library), an in-content <a> link (er_reading_link_tap), then a left/right page-turn. Split out of er_handle_tap() to keep each within the cognitive-complexity budget.
| [in] | x | Tap X (panel pixels). |
| [in] | y | Tap Y (panel pixels). |
| true | Re-render required. |
| false | Tap hit nothing actionable. |
Definition at line 426 of file ereader_ui_input.c.
References er_apply_pageturn(), er_reading_link_tap(), er_tap_to_dir(), k_er_back_w, k_er_statusbar_h, k_ra8_ok, ra8_ui_nav_pop(), ra8_ui_rect_contains(), s_chapter_idx, s_fb, s_loc_back, s_loc_back_count, s_nav, and s_reading_page.
Referenced by er_handle_tap().
|
static |
Route a tap to a navigation action for the current screen.
| [in] | x | Tap X (panel pixels). |
| [in] | y | Tap Y (panel pixels). |
| true | Navigation stack changed. |
| false | Tap hit nothing actionable. |
Definition at line 496 of file ereader_ui_input.c.
References er_handle_keyboard_tap(), er_handle_reading_tap(), er_nag_hit(), k_display_event_chapter, k_display_event_open, k_er_act_none, k_er_act_open_book, k_er_act_search, k_er_act_settings, k_er_screen_keyboard, k_er_screen_library, k_er_screen_reading, k_er_screen_settings, k_ra8_batt_nag_none, k_ra8_ok, ra8_kbd_text_init(), ra8_ui_hit_test(), ra8_ui_nav_pop(), ra8_ui_nav_push(), ra8_ui_nav_top(), s_batt_nag, s_chapter_idx, s_loc_back_count, s_nag_region_only, s_nav, s_pending_event, s_query, s_reading_page, s_target_count, and s_targets.
Referenced by er_poll_touch().
|
static |
BACKSPACE glyph: a left-pointing pentagon outline with an X inside.
Definition at line 137 of file ereader_ui_input.c.
References k_er_ico_dh, k_er_ico_dw, k_er_ico_dx, k_er_ico_dxo, and ra8_gfx_line().
Referenced by er_draw_key().
|
static |
RETURN glyph: a carriage-return arrow (tail down, shaft left, arrowhead).
Definition at line 154 of file ereader_ui_input.c.
References k_er_ico_rah, k_er_ico_rh, k_er_ico_rw, and ra8_gfx_line().
Referenced by er_draw_key().
|
static |
SHIFT glyph: an up-arrow (filled arrowhead over a narrow stem).
Definition at line 125 of file ereader_ui_input.c.
References er_tri_up(), k_er_ico_abot, k_er_ico_atop, k_er_ico_aw, k_er_ico_sbot, k_er_ico_sw, and ra8_gfx_rect().
Referenced by er_draw_key().
|
static |
Keyboard band widget: gray backdrop + the laid-out keys + tap targets.
Definition at line 232 of file ereader_ui_input.c.
References er_draw_key(), k_er_act_key_base, k_er_kbd_bg, k_er_max_targets, k_er_pad_ui, k_er_statusbar_h, k_er_toolbar_h, ra8_gfx_rect(), ra8_kbd_layout_init(), s_fb, s_kb, s_target_count, and s_targets.
|
static |
Text label for key idx (SPACE / 123-ABC, or live-case char in s).
Definition at line 82 of file ereader_ui_input.c.
References k_ra8_kbd_key_layer, k_ra8_kbd_key_space, k_ra8_kbd_layer_numbers, k_ra8_kbd_layer_symbols, ra8_kbd_key_glyph(), and s_kb.
Referenced by er_draw_key_label().
|
static |
Search-field band widget: the "Search:" label + the query / hint.
Definition at line 222 of file ereader_ui_input.c.
References er_text_left(), k_er_ink, k_er_ink_muted, k_er_kbd_qlabel, k_er_pad_ui, k_er_search_hint, k_er_statusbar_h, k_er_text_pad, and s_query.
|
static |
True for keys drawn dark (SHIFT / BACKSPACE / 123-ABC / RETURN).
Definition at line 165 of file ereader_ui_input.c.
References k_ra8_kbd_key_char, and k_ra8_kbd_key_space.
Referenced by er_draw_key().
|
static |
True iff (x,y) lands on the low-battery banner rect.
Definition at line 367 of file ereader_ui_input.c.
References k_er_nag_h, k_er_nag_margin, k_er_nag_top, and s_fb.
Referenced by er_handle_tap().
| void er_nag_render | ( | ra8_widget_t * | w | ) |
Nag banner overlay widget: a centered low-battery toast over the screen.
| [in,out] | w | Widget instance (unused; the banner reads file-scope state). |
Definition at line 375 of file ereader_ui_input.c.
References er_append_pct(), er_append_str(), k_er_ink, k_er_nag_crit_bg, k_er_nag_crit_msg, k_er_nag_h, k_er_nag_hint, k_er_nag_line_max, k_er_nag_low_bg, k_er_nag_low_msg, k_er_nag_margin, k_er_nag_text, k_er_nag_text_dx, k_er_nag_text_dy, k_er_nag_top, k_ra8_batt_nag_critical, k_ra8_batt_nag_none, ra8_gfx_font_8x16, ra8_gfx_rect(), ra8_gfx_text_out(), s_batt_nag, s_batt_soc, and s_fb.
| void er_poll_battery | ( | void | ) |
Implementation of er_poll_battery() – the clear-the-banner glue.
Poll the fuel gauge, fold it into the nag policy, and toggle the banner.
Definition at line 626 of file ereader_ui_input.c.
References er_flush_event(), er_read_battery(), er_render_nag_region(), k_display_event_chapter, k_er_batt_every, k_ra8_batt_low_pct, k_ra8_batt_nag_none, k_ra8_batt_rearm_margin, k_ra8_ok, ra8_batt_update(), s_batt_mon, s_batt_nag, and s_batt_soc.
Referenced by main().
| void er_poll_buttons | ( | void | ) |
Poll SW1/SW2 and turn a page on a fresh press (#78).
Definition at line 589 of file ereader_ui_input.c.
References er_apply_pageturn(), er_buttons_to_dir(), er_flush_event(), er_render_current(), er_sw_pressed(), k_er_screen_library, k_er_screen_reading, k_ra8_board_sw1, k_ra8_board_sw2, k_ra8_pin_none, ra8_board_sw_pin(), ra8_ui_nav_top(), s_nav, s_pending_event, s_was_sw1, and s_was_sw2.
Referenced by main().
| void er_poll_touch | ( | void | ) |
Poll the touch controller and dispatch a tap on a fresh press.
Definition at line 558 of file ereader_ui_input.c.
References er_flush_event(), er_handle_tap(), er_render_current(), er_render_nag_region(), k_er_touch_max_points, k_ra8_ok, ra8_touch_read(), s_nag_region_only, s_pending_event, s_was_touching, ra8_touch_point_t::x, and ra8_touch_point_t::y.
Referenced by main().
|
static |
Read SOC + charge direction from the fuel gauge; false if absent (NAK).
Definition at line 311 of file ereader_ui_input.c.
References er_fg_read(), k_er_fg_reg_crate, k_er_fg_reg_soc, and k_er_fg_sign.
Referenced by er_poll_battery().
| void er_render_keyboard | ( | void | ) |
Render the on-screen keyboard screen + collect its key targets.
Definition at line 267 of file ereader_ui_input.c.
References k_er_kbd_keys_vt, k_er_kbd_search_vt, k_er_paper, k_er_statusbar_h, k_er_toolbar_h, k_ra8_widget_axis_col, k_ra8_widget_refresh_quality, ra8_gfx_clear(), ra8_widget_invalidate(), ra8_widget_layout_stack(), ra8_widget_render_dirty(), and s_fb.
Referenced by er_app_render().
|
static |
Filled rounded rect (rect cross + four corner discs).
Definition at line 103 of file ereader_ui_input.c.
References k_er_kbd_radius, ra8_gfx_circle(), and ra8_gfx_rect().
Referenced by er_draw_key().
|
static |
Read a user switch (active-low); true == pressed.
Definition at line 580 of file ereader_ui_input.c.
References k_ra8_level_high, k_ra8_level_low, k_ra8_ok, pin, and ra8_gpio_read().
Referenced by er_poll_buttons().
|
static |
Filled upward triangle from apex row ay to base row by (scanlines).
Definition at line 115 of file ereader_ui_input.c.
References ra8_gfx_line().
Referenced by er_icon_shift().
|
static |
Definition at line 265 of file ereader_ui_input.c.
Referenced by er_render_keyboard().
|
static |
Vtables for the keyboard search-field / keys band widgets.
Definition at line 264 of file ereader_ui_input.c.
Referenced by er_render_keyboard().
|
static |
Definition at line 292 of file ereader_ui_input.c.
Referenced by er_nag_render().
|
static |
Trailing hint so the banner says how to close itself.
Definition at line 294 of file ereader_ui_input.c.
Referenced by er_nag_render().
|
static |
Nag banner messages (the SOC percent + dismiss hint follow at render).
Definition at line 291 of file ereader_ui_input.c.
Referenced by er_nag_render().
|
static |
Debounce: true while SW1/SW2 are held, to fire once per press.
Definition at line 555 of file ereader_ui_input.c.
|
static |
Definition at line 556 of file ereader_ui_input.c.
|
static |
Debounce: true while a contact is held, to fire once per tap.
Definition at line 552 of file ereader_ui_input.c.