ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ereader_ui_steps.h File Reference

E-reader UI chrome – shared contract between main.c and the per-aspect helper translation units (screens + input). More...

#include <stddef.h>
#include <stdint.h>
#include "er_pageturn.h"
#include "ra8_app.h"
#include "ra8_batt.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_box.h"
#include "ra8_display_pal.h"
#include "ra8_display_pal_policy.h"
#include "ra8_keyboard.h"
#include "ra8_panel.h"
#include "ra8_panel_timing.h"
#include "ra8_port_constants.h"
#include "ra8_ui.h"
#include "ra8_widget.h"
#include "reflow.h"
Include dependency graph for ereader_ui_steps.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  er_book_t
 One library entry: title, author, reading progress percent. More...
struct  er_chapter_t
 One mock-spine chapter: its XHTML, length, and resolving href. More...
struct  er_loc_t
 A reading location (chapter + page) for the navigation back-stack. More...

Enumerations

enum  er_fb_dim_t : uint16_t {
  k_er_fb_w = k_panel_width_px ,
  k_er_fb_h = k_panel_height_px
}
 Framebuffer dimensions, sourced from the BSP panel descriptor. More...
enum  er_fb_misc_t : uint16_t {
  k_er_settle_ms = 500U ,
  k_er_frame_ms = 25U ,
  k_er_led_every = 16U
}
 Framebuffer byte-math and pacing constants. More...
enum  er_color_t : uint32_t {
  k_er_paper = 0xFFFFFFU ,
  k_er_ink = 0x000000U ,
  k_er_ink_muted = 0x555555U ,
  k_er_rule = 0xAAAAAAU ,
  k_er_rule_soft = 0xCCCCCCU ,
  k_er_fill = 0xDDDDDDU ,
  k_er_fill_deep = 0x888888U
}
 PAPYR 16-level grayscale ramp, semantic roles (0xRRGGBB). More...
enum  er_layout_t : uint16_t {
  k_er_statusbar_h = 64U ,
  k_er_footer_h = 56U ,
  k_er_nav_h = 88U ,
  k_er_toolbar_h = 72U ,
  k_er_margin_x = 64U ,
  k_er_pad_ui = 32U ,
  k_er_body_gap = 24U ,
  k_er_line_h = 26U ,
  k_er_glyph_w = 8U ,
  k_er_glyph_h = 16U ,
  k_er_text_inset_y = 24U ,
  k_er_text_pad = 6U ,
  k_er_hair = 1U ,
  k_er_border_w = 2U ,
  k_er_progress_h = 6U ,
  k_er_progress_gap = 12U ,
  k_er_blank_lines = 2U ,
  k_er_grid_cols = 2U ,
  k_er_grid_gap = 28U ,
  k_er_tile_gap = 8U ,
  k_er_card_label_h = 20U ,
  k_er_card_bar_h = 8U ,
  k_er_count_w = 200U
}
 Shared chrome layout metrics (8 px grid), pixels. More...
enum  er_progress_t : uint16_t {
  k_er_page_current = 12U ,
  k_er_page_total = 248U ,
  k_er_pct_full = 100U
}
 Reading-position + percentage constants. More...
enum  er_node_cap_t : uint16_t { k_er_max_nodes = 64U }
 Box-tree node-storage capacity. More...
enum  er_screen_t : uint16_t {
  k_er_screen_library = 1U ,
  k_er_screen_reading = 2U ,
  k_er_screen_keyboard = 3U ,
  k_er_screen_settings = 4U
}
 Screen ids for the ra8_ui navigation stack. More...
enum  er_action_t : uint16_t {
  k_er_act_none = 0U ,
  k_er_act_open_book = 1U ,
  k_er_act_nav = 2U ,
  k_er_act_search = 3U ,
  k_er_act_settings = 4U ,
  k_er_act_key_base = 100U
}
 Tap-target action ids (carried on box nodes as their tag). More...
enum  er_touch_cfg_t : uint8_t {
  k_er_touch_channel = (uint8_t)k_ra8_board_touch_i3c_channel ,
  k_er_touch_max_points = 1U
}
 GT911 touch-controller wiring on the EK-RA8D2 carrier. More...
enum  er_fg_cfg_t : uint8_t {
  k_er_fg_addr = 0x36U ,
  k_er_fg_reg_soc = 0x04U ,
  k_er_fg_reg_crate = 0x16U ,
  k_er_fg_sign = 0x80U
}
 MAX17048-class fuel gauge wiring (shares the touch IIC_B bus). More...
enum  er_nag_cfg_t : int32_t {
  k_er_nag_h = 72 ,
  k_er_nag_margin = 24 ,
  k_er_nag_top = 96 ,
  k_er_nag_text_dx = 28 ,
  k_er_nag_text_dy = 28 ,
  k_er_nag_dec_max = 4 ,
  k_er_nag_dec_ten = 10 ,
  k_er_nag_line_max = 48 ,
  k_er_batt_every = 40
}
 Low-battery nag-banner geometry. More...
enum  er_nag_color_t : uint32_t {
  k_er_nag_low_bg = 0x555555U ,
  k_er_nag_crit_bg = 0x000000U ,
  k_er_nag_text = 0xFFFFFFU
}
 Nag-banner palette (grayscale e-ink). More...
enum  er_hit_cap_t : uint16_t {
  k_er_max_targets = 32U ,
  k_er_back_w = 240U ,
  k_er_page_back_cap = 16U
}
 Tap-target table capacity and Reading back-affordance size. More...
enum  er_reflow_cfg_t : uint32_t {
  k_er_font_cap = 512U * 1024U ,
  k_er_font_min = 16U ,
  k_er_reflow_px = 22U ,
  k_er_spi_chan = 0U ,
  k_er_reflow_ink = 0xFF101010U ,
  k_er_reflow_link = 0xFF2A52BEU ,
  k_er_img_arena = 2U * 1024U * 1024U ,
  k_er_glyph_cell_px = 64U ,
  k_er_glyph_cell_bytes = k_er_glyph_cell_px * k_er_glyph_cell_px ,
  k_er_glyph_cells = 256U ,
  k_er_glyph_buckets = 512U
}
 SD-font load + reflow body-render tunables (no magic numbers). More...
enum  er_reflow_sentinel_t : uint32_t { k_er_chapter_none = 0xFFFFFFFFU }
 "No chapter cached" sentinel. More...
enum  er_nav_count_t : uint16_t {
  k_er_nav_count = 4U ,
  k_er_nav_idx_setting = 3U
}
 Bottom-nav destination count. More...
enum  er_book_count_t : uint16_t { k_er_book_count = 6U }
 Number of demo books. More...
enum  er_body_count_t : uint16_t { k_er_body_line_count = 10U }
 Number of pre-wrapped body lines. More...
enum  er_spine_count_t : uint16_t { k_er_spine_count = 2U }
 Number of chapters in the mock spine. More...

Functions

void er_text_left (int32_t x, int32_t y, const char *str, uint32_t color)
 Draw a left-anchored text run in the bundled font.
void er_text_right (int32_t right, int32_t y, const char *str, uint32_t color)
 Draw a right-anchored text run ending at column right.
void er_render_library (void)
 Render the full Library screen.
void er_render_reading (void)
 Render the full Reading screen (status bar, body, footer).
bool er_apply_pageturn (er_dir_t dir)
 Apply a page turn to the reading location (touch + button shared path).
bool er_reading_link_tap (int32_t x, int32_t y)
 Follow an in-content <a> tap in the Reading body (#110).
void er_push_loc (void)
 Push the current (chapter, page) on the back-stack, capacity permitting.
uint32_t er_spine_count (void)
 Number of chapters in the (mock) spine.
void er_render_keyboard (void)
 Render the on-screen keyboard screen + collect its key targets.
void er_nag_render (ra8_widget_t *w)
 Nag banner overlay widget: a centered low-battery toast over the screen.
void er_poll_touch (void)
 Poll the touch controller and dispatch a tap on a fresh press.
void er_poll_buttons (void)
 Poll SW1/SW2 and turn a page on a fresh press (#78).
void er_poll_battery (void)
 Poll the fuel gauge, fold it into the nag policy, and toggle the banner.
void er_render_current (void)
 Render whichever screen is on top of the navigation stack.
void er_render_nag_region (void)
 Repaint only the low-battery banner rect (dirty-region update).
void er_flush_event (display_turn_event_t event)
 Flush the panel for a refresh event through the cadence policy (#78).

Variables

const char k_er_wordmark [6]
 Wordmark / status text.
const char k_er_lib_heading []
 Library heading text.
const char k_er_status_right []
 Status-bar right text.
const char k_er_search_hint []
 Search placeholder.
const char k_er_count_text []
 Book-count chip text.
const char k_er_book_title []
 Reading title text.
const char k_er_page_label []
 Reading page label.
const char k_er_chapter []
 Bitmap-fallback heading.
const char *const k_er_nav_items []
 Bottom-nav destinations (Library / Store / Notes / Settings).
const er_book_t k_er_books []
 Demo shelf (public-domain works).
const char *const k_er_body_lines []
 Reading-view body paragraph lines (pre-wrapped for the font).
const er_chapter_t k_er_spine []
 Two-chapter mock spine for in-content cross-chapter navigation (#110).
display_fb_t s_fb
 Mutable copy of the FB descriptor.
ra8_ui_target_t s_targets []
 Tap targets for the current screen.
uint16_t s_target_count
 Tap targets currently populated.
ra8_kbd_layout_t s_kb
 On-screen keyboard grid.
ra8_kbd_text_t s_query
 Live search query.
uint32_t s_chapter_idx
 Reading chapter index.
uint32_t s_reading_page
 Reading current reflow page.
uint32_t s_reading_pages
 Reading total reflow pages (>= 1).
reflow_t s_reflow_engine
 reflow engine for the body.
bool s_reflow_open
 True while the engine holds a layout.
uint32_t s_reflow_chapter
 Chapter laid out (cache key).
int32_t s_reflow_w
 Body width the layout used.
int32_t s_reflow_h
 Body height the layout used.
uint8_t s_font_buf []
 Font blob read off the SD card.
uint32_t s_font_len
 Bytes of font read off the card.
bool s_have_font
 True once an SD font is loaded.
uint8_t s_img_arena_buf []
 Image-decode bump arena in SDRAM.
er_loc_t s_loc_back []
 Reading back-stack for link jumps.
uint32_t s_loc_back_count
 Entries used in s_loc_back.
ra8_ui_nav_t s_nav
 Navigation stack (active screen).
ra8_batt_nag_t s_batt_nag
 Nag currently shown over the chrome.
uint8_t s_batt_soc
 Last fuel-gauge SOC percent.
ra8_batt_monitor_t s_batt_mon
 Low-battery nag policy state.
bool s_nag_region_only
 True when a tap only toggled the nag.
display_turn_event_t s_pending_event
 Pending refresh event for next flush.
volatile uint32_t g_er_cur_page
 SWD / --dump-sym telemetry for the headless page-turn HIL (#78).
volatile uint32_t g_er_turns
 Count of page turns applied since boot.
volatile uint32_t g_er_last_hint
 Last display_refresh_hint_t flushed.

Detailed Description

E-reader UI chrome – shared contract between main.c and the per-aspect helper translation units (screens + input).

Tag
[Ring 6 / APP] {World: S}

ereader_ui/main.c was split into cohesive translation units to keep every source file under the repository's 1000-line cap. This header is the seam between them: it owns the compile-time typed-enum configuration, the small shared structs, the extern declarations of the mutable file-scope state and read-only data tables that main.c defines (single definition site), and the prototypes of the helper functions moved out of main.c. The split is a pure code move; the composited chrome is byte-identical.

Translation units sharing this contract:

  • main.c boot, app framework, screen dispatch, main loop.
  • ereader_ui_screens.c Library + Reading rendering + in-content nav.
  • ereader_ui_input.c keyboard rendering, battery nag, tap + button polling.
Since
0.1.0

Definition in file ereader_ui_steps.h.

Enumeration Type Documentation

◆ er_action_t

enum er_action_t : uint16_t

Tap-target action ids (carried on box nodes as their tag).

Keyboard key taps use the contiguous block k_er_act_key_base .. k_er_act_key_base + 28 so the dispatcher recovers the key index by subtraction; nothing else may occupy that range.

Enumerator
k_er_act_none 

Not a tap target.

k_er_act_open_book 

Library card -> open the reading view.

k_er_act_nav 

Bottom-nav destination (stay in lib).

k_er_act_search 

Toolbar Search -> open the keyboard.

k_er_act_settings 

Bottom-nav Settings -> Settings app.

k_er_act_key_base 

Keyboard key i -> base + i.

Definition at line 154 of file ereader_ui_steps.h.

◆ er_body_count_t

enum er_body_count_t : uint16_t

Number of pre-wrapped body lines.

Enumerator
k_er_body_line_count 

Number of pre-wrapped body lines.

Definition at line 328 of file ereader_ui_steps.h.

◆ er_book_count_t

enum er_book_count_t : uint16_t

Number of demo books.

Enumerator
k_er_book_count 

Number of demo books.

Definition at line 318 of file ereader_ui_steps.h.

◆ er_color_t

enum er_color_t : uint32_t

PAPYR 16-level grayscale ramp, semantic roles (0xRRGGBB).

Enumerator
k_er_paper 

Page background (g15).

k_er_ink 

Primary text / glyphs (g0).

k_er_ink_muted 

Secondary text / metadata (g5).

k_er_rule 

Hairline dividers (g10).

k_er_rule_soft 

Faintest hairlines / track (g12).

k_er_fill 

Flat fills / covers (g13).

k_er_fill_deep 

Heavier fill / progress (g8).

Definition at line 76 of file ereader_ui_steps.h.

◆ er_fb_dim_t

enum er_fb_dim_t : uint16_t

Framebuffer dimensions, sourced from the BSP panel descriptor.

Enumerator
k_er_fb_w 

Framebuffer width (pixels).

k_er_fb_h 

Framebuffer height (pixels).

Definition at line 57 of file ereader_ui_steps.h.

◆ er_fb_misc_t

enum er_fb_misc_t : uint16_t

Framebuffer byte-math and pacing constants.

Enumerator
k_er_settle_ms 

PLL / SDRAM / panel-POR settle.

k_er_frame_ms 

Input poll period (ms): touch / button cadence.

k_er_led_every 

Toggle the heartbeat LED every Nth frame.

Definition at line 66 of file ereader_ui_steps.h.

◆ er_fg_cfg_t

enum er_fg_cfg_t : uint8_t

MAX17048-class fuel gauge wiring (shares the touch IIC_B bus).

The fuel gauge sits at 7-bit 0x36 on the same IIC_B channel 0 the GT911 touch already brought up, so the battery is read with raw ra8_i3c register reads (no second bus init). ra8_emulator models this gauge and drives its SOC / CRATE from the on-screen battery slider.

Enumerator
k_er_fg_addr 

Fuel gauge 7-bit I2C address.

k_er_fg_reg_soc 

SOC register (high byte = percent).

k_er_fg_reg_crate 

CRATE register (sign = charge dir).

k_er_fg_sign 

CRATE high-byte sign bit (discharge).

Definition at line 188 of file ereader_ui_steps.h.

◆ er_hit_cap_t

enum er_hit_cap_t : uint16_t

Tap-target table capacity and Reading back-affordance size.

Enumerator
k_er_max_targets 

Max collected tap targets.

k_er_back_w 

Reading back-region width (px).

k_er_page_back_cap 

Footnote-jump back-stack depth.

Definition at line 222 of file ereader_ui_steps.h.

◆ er_layout_t

enum er_layout_t : uint16_t

Shared chrome layout metrics (8 px grid), pixels.

Enumerator
k_er_statusbar_h 

Top status-bar band height.

k_er_footer_h 

Reading footer band height.

k_er_nav_h 

Library bottom-nav band height.

k_er_toolbar_h 

Library toolbar band height.

k_er_margin_x 

Reading left/right margin.

k_er_pad_ui 

Side padding for bands / grid.

k_er_body_gap 

Gap between band and body text.

k_er_line_h 

Body line advance.

k_er_glyph_w 

Bundled font cell width.

k_er_glyph_h 

Bundled font cell height.

k_er_text_inset_y 

16 px text centred in a 64 px band.

k_er_text_pad 

Inset for text inside a box.

k_er_hair 

Hairline weight.

k_er_border_w 

Card / control border weight.

k_er_progress_h 

Reading-progress bar height.

k_er_progress_gap 

Gap above the reading progress bar.

k_er_blank_lines 

Blank advance after the heading.

k_er_grid_cols 

Library grid column count.

k_er_grid_gap 

Library grid gap.

k_er_tile_gap 

Gap between a card's stacked parts.

k_er_card_label_h 

Card title / author row height.

k_er_card_bar_h 

Card progress-bar height.

k_er_count_w 

Toolbar "N books" chip width.

Definition at line 90 of file ereader_ui_steps.h.

◆ er_nag_cfg_t

enum er_nag_cfg_t : int32_t

Low-battery nag-banner geometry.

Enumerator
k_er_nag_h 

Banner height (px).

k_er_nag_margin 

Banner inset from the screen sides.

k_er_nag_top 

Banner top y (clear of the status bar).

k_er_nag_text_dx 

Text inset from the banner left.

k_er_nag_text_dy 

Text inset from the banner top.

k_er_nag_dec_max 

Scratch for a "NNN%" decimal tail.

k_er_nag_dec_ten 

Decimal base.

k_er_nag_line_max 

Banner text buffer size (bounds copy).

k_er_batt_every 

Poll the gauge every Nth frame (~1/s).

Definition at line 199 of file ereader_ui_steps.h.

◆ er_nag_color_t

enum er_nag_color_t : uint32_t

Nag-banner palette (grayscale e-ink).

Enumerator
k_er_nag_low_bg 

Low-battery banner fill (g5).

k_er_nag_crit_bg 

Critical banner fill (g0 ink).

k_er_nag_text 

Banner text (paper on the fill).

Definition at line 212 of file ereader_ui_steps.h.

◆ er_nav_count_t

enum er_nav_count_t : uint16_t

Bottom-nav destination count.

Enumerator
k_er_nav_count 

Number of bottom-nav destinations.

k_er_nav_idx_setting 

Index of the "Settings" nav item.

Definition at line 307 of file ereader_ui_steps.h.

◆ er_node_cap_t

enum er_node_cap_t : uint16_t

Box-tree node-storage capacity.

Enumerator
k_er_max_nodes 

Upper bound on chrome box nodes.

Definition at line 130 of file ereader_ui_steps.h.

◆ er_progress_t

enum er_progress_t : uint16_t

Reading-position + percentage constants.

Enumerator
k_er_page_current 

Reading current page (1-based).

k_er_page_total 

Reading total pages.

k_er_pct_full 

Percent denominator.

Definition at line 120 of file ereader_ui_steps.h.

◆ er_reflow_cfg_t

enum er_reflow_cfg_t : uint32_t

SD-font load + reflow body-render tunables (no magic numbers).

Enumerator
k_er_font_cap 

Max font read off the card (bytes).

k_er_font_min 

Smallest plausible font blob (bytes).

k_er_reflow_px 

Body type size (pixels).

k_er_spi_chan 

Pmod2 / J25 = SCI0 Simple-SPI.

k_er_reflow_ink 

Body text colour (near-black ARGB).

k_er_reflow_link 

Anchor colour (cerulean ARGB).

k_er_img_arena 

SDRAM image-decode scratch.

k_er_glyph_cell_px 

Cell edge, px (>= body).

k_er_glyph_cell_bytes 

Bytes per cell.

k_er_glyph_cells 

Glyph-cache budget.

k_er_glyph_buckets 

Glyph-cache hash buckets.

Definition at line 262 of file ereader_ui_steps.h.

◆ er_reflow_sentinel_t

enum er_reflow_sentinel_t : uint32_t

"No chapter cached" sentinel.

Enumerator
k_er_chapter_none 

s_reflow_chapter when nothing is laid out.

Definition at line 280 of file ereader_ui_steps.h.

◆ er_screen_t

enum er_screen_t : uint16_t

Screen ids for the ra8_ui navigation stack.

Enumerator
k_er_screen_library 

Library / home grid.

k_er_screen_reading 

Reading view.

k_er_screen_keyboard 

On-screen keyboard (search entry).

k_er_screen_settings 

Settings (optional app, #if RA8_APP_SETTINGS).

Definition at line 138 of file ereader_ui_steps.h.

◆ er_spine_count_t

enum er_spine_count_t : uint16_t

Number of chapters in the mock spine.

Enumerator
k_er_spine_count 

Number of chapters in k_er_spine.

Definition at line 338 of file ereader_ui_steps.h.

◆ er_touch_cfg_t

enum er_touch_cfg_t : uint8_t

GT911 touch-controller wiring on the EK-RA8D2 carrier.

ra8_board_touch_open brings the GT911 up on the board's own channel, at the board's address and rate, against the live PCLKA – so only the contact cap is an app choice. The channel is still named here because the fuel gauge shares that bus and is read with raw ra8_i3c calls; its value is the board's, not a second declaration of it.

Enumerator
k_er_touch_channel 

The board's GT911 bus.

k_er_touch_max_points 

One contact = one tap.

Definition at line 174 of file ereader_ui_steps.h.

Function Documentation

◆ er_apply_pageturn()

bool er_apply_pageturn ( er_dir_t dir)

Apply a page turn to the reading location (touch + button shared path).

Parameters
[in]dirDirection (k_er_dir_prev / k_er_dir_next / k_er_dir_none).
Returns
true iff the reading location changed (caller must re-render).
Return values
trueA page turn was applied.
falseNo turn (book end, or k_er_dir_none).
Precondition
The Reading view is active and a chapter is laid out (s_reading_pages).
s_chapter_idx / s_reading_page are the visible location.
Postcondition
On true the location advanced and s_pending_event reflects the kind.
On false no state changed.
Note
Not thread-safe.
Since
0.1.0

Definition at line 888 of file ereader_ui_screens.c.

References er_pageturn_step(), er_spine_count(), g_er_turns, k_display_event_chapter, k_display_event_turn, s_chapter_idx, s_pending_event, s_reading_page, and s_reading_pages.

Referenced by er_handle_reading_tap(), and er_poll_buttons().

◆ er_flush_event()

void er_flush_event ( display_turn_event_t event)

Flush the panel for a refresh event through the cadence policy (#78).

Parameters
[in]eventThe page-transition that occurred (open / turn / chapter).
Precondition
s_policy was initialised and s_display is valid.
s_fb describes the bound framebuffer.
Postcondition
One panel flush is issued; g_er_last_hint / g_er_cur_page are current.
Note
Not thread-safe; the reader UI is single-threaded.
Since
0.1.0

Definition at line 623 of file main.c.

References display_flush(), display_full_rect(), display_policy_decide(), display_policy_full_rect(), g_er_cur_page, g_er_last_hint, display_policy_decision_t::hint, k_display_refresh_quality, k_ra8_ok, s_display, s_fb, s_policy, and s_reading_page.

Referenced by er_poll_battery(), er_poll_buttons(), er_poll_touch(), and main().

◆ er_nag_render()

void er_nag_render ( ra8_widget_t * w)

Nag banner overlay widget: a centered low-battery toast over the screen.

Parameters
[in,out]wWidget instance (unused; the banner reads file-scope state).
Precondition
ra8_gfx is bound; s_fb reflects the framebuffer geometry.
None.
Postcondition
On an active nag the banner rect + text is drawn; else nothing.
No navigation state mutated.
Note
Not thread-safe.
Since
0.1.0

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.

◆ er_poll_battery()

void er_poll_battery ( void )

Poll the fuel gauge, fold it into the nag policy, and toggle the banner.

Precondition
app_bringup_touch brought up IIC_B channel 0 (shared with the gauge).
s_batt_mon was initialised by ra8_batt_monitor_init.
Postcondition
On a banner state change the chrome is re-rendered + flushed.
s_batt_nag reflects the banner shown.
Note
Not thread-safe.
Since
0.1.0

Poll the fuel gauge, fold it into the nag policy, and toggle the banner.

MC/DC:
Decision: (s_batt_nag != k_ra8_batt_nag_none) && (chg || (soc > recover)) (3 conditions: banner-active, charging, soc-recovered). The ra8_batt policy's own edge / re-arm decisions are MC/DC-tested in tests/misc/src/test_ra8_batt.c; this clear-the-banner glue is exercised by the ra8_emulator battery-slider gate (dragging below 20/10 percent raises the banner; back up or toggling charge clears it) rather than a host unit test, per the hw_pending board-demo convention (no host test, like smbus_demo).

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().

◆ er_poll_buttons()

void er_poll_buttons ( void )

Poll SW1/SW2 and turn a page on a fresh press (#78).

Precondition
The switch pins were configured as inputs (::app_bringup_buttons).
s_display / s_fb are valid.
Postcondition
On a fresh press that turns a page, the new page is shown and flushed.
s_was_sw1 / s_was_sw2 track the held state.
Note
Not thread-safe.
Since
0.1.0

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().

◆ er_poll_touch()

void er_poll_touch ( void )

Poll the touch controller and dispatch a tap on a fresh press.

Precondition
ra8_gfx bound; s_nav initialised; s_display valid.
None.
Postcondition
On a press that changes the screen, the new screen is shown.
s_was_touching tracks the contact state.
Note
Not thread-safe.
Since
0.1.0

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().

◆ er_push_loc()

void er_push_loc ( void )

Push the current (chapter, page) on the back-stack, capacity permitting.

Precondition
s_chapter_idx / s_reading_page are the visible location.
None.
Postcondition
On free capacity the location is appended to s_loc_back.
s_loc_back_count is bounded by k_er_page_back_cap.
Note
Not thread-safe.
Since
0.1.0

Definition at line 874 of file ereader_ui_screens.c.

References k_er_page_back_cap, s_chapter_idx, s_loc_back, s_loc_back_count, and s_reading_page.

Referenced by er_nav_chapter(), and er_nav_fragment().

◆ er_reading_link_tap()

bool er_reading_link_tap ( int32_t x,
int32_t y )

Follow an in-content <a> tap in the Reading body (#110).

Parameters
[in]xTap X (panel pixels).
[in]yTap Y (panel pixels).
Returns
true iff the tap followed a link and changed the reading location.
Return values
trueA link was followed; chapter/page updated.
falseNo link hit, or an unresolved / external target.
Precondition
The Reading body was laid out (link rects reflect the chapter).
s_reading_page is the visible page.
Postcondition
On true the reading location changed and the old one is on s_loc_back.
Note
Not thread-safe.
Since
0.1.0

Definition at line 960 of file ereader_ui_screens.c.

References er_nav_chapter(), er_nav_fragment(), k_er_body_gap, k_er_margin_x, k_er_statusbar_h, k_ra8_ok, k_reflow_href_chapter, k_reflow_href_chapter_fragment, k_reflow_href_empty, k_reflow_href_fragment, reflow_hit_test_link(), reflow_href_split(), s_reading_page, and s_reflow_engine.

Referenced by er_handle_reading_tap().

◆ er_render_current()

void er_render_current ( void )

Render whichever screen is on top of the navigation stack.

Precondition
ra8_gfx is bound; s_nav initialised.
None.
Postcondition
The framebuffer holds the current screen.
No navigation state mutated beyond focusing the active app.
Note
Not thread-safe.
Since
0.1.0

Definition at line 585 of file main.c.

References k_er_nag_vt, k_er_screen_library, k_ra8_batt_nag_none, ra8_app_launch(), ra8_app_render(), ra8_ui_nav_top(), ra8_widget_render_dirty(), s_app_reg, s_batt_nag, and s_nav.

Referenced by er_poll_buttons(), er_poll_touch(), er_render_nag_region(), and main().

◆ er_render_keyboard()

void er_render_keyboard ( void )

Render the on-screen keyboard screen + collect its key targets.

Precondition
ra8_gfx is bound; s_fb reflects the framebuffer geometry.
None.
Postcondition
The framebuffer holds the keyboard; s_kb + s_targets set.
Note
Not thread-safe.
Since
0.1.0

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().

◆ er_render_library()

void er_render_library ( void )

Render the full Library screen.

Precondition
ra8_gfx is bound; s_fb reflects the framebuffer geometry.
None.
Postcondition
The framebuffer holds the Library screen; s_targets set.
Caller flushes the panel to make it visible.
Note
Not thread-safe.
Since
0.1.0

Definition at line 545 of file ereader_ui_screens.c.

References ra8_box_tree_t::count, er_build_library(), er_collect_targets(), k_er_lib_body_vt, k_er_lib_sb_vt, k_er_paper, k_er_statusbar_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(), s_fb, and s_lib_node_count.

Referenced by er_app_render().

◆ er_render_nag_region()

void er_render_nag_region ( void )

Repaint only the low-battery banner rect (dirty-region update).

Precondition
ra8_gfx is bound; s_nav initialised.
None.
Postcondition
Only the banner rect is repainted (full repaint if clip unavailable).
No navigation state mutated.
Note
Not thread-safe.
Since
0.1.0

Definition at line 602 of file main.c.

References er_render_current(), k_er_nag_h, k_er_nag_margin, k_er_nag_top, k_er_nag_vt, k_er_screen_library, k_ra8_batt_nag_none, k_ra8_ok, ra8_app_launch(), ra8_app_render(), ra8_gfx_reset_clip(), ra8_gfx_set_clip(), ra8_ui_nav_top(), ra8_widget_render_dirty(), s_app_reg, s_batt_nag, s_fb, and s_nav.

Referenced by er_poll_battery(), and er_poll_touch().

◆ er_render_reading()

void er_render_reading ( void )

Render the full Reading screen (status bar, body, footer).

Precondition
ra8_gfx is bound; s_fb reflects the framebuffer geometry.
None.
Postcondition
The framebuffer holds the Reading screen.
Caller flushes the panel to make it visible.
Note
Not thread-safe.
Since
0.1.0

Definition at line 848 of file ereader_ui_screens.c.

References k_er_footer_h, k_er_paper, k_er_read_body_vt, k_er_read_footer_vt, k_er_read_sb_vt, k_er_statusbar_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().

◆ er_spine_count()

uint32_t er_spine_count ( void )

Number of chapters in the (mock) spine.

Returns
Chapter count of k_er_spine.
Return values
countThe number of spine chapters.
Precondition
k_er_spine is a valid table.
None.
Postcondition
No state mutated.
Returned value is >= 1.
Note
Pure.
Since
0.1.0

Definition at line 883 of file ereader_ui_screens.c.

References k_er_spine_count.

Referenced by er_apply_pageturn(), and er_nav_chapter().

◆ er_text_left()

void er_text_left ( int32_t x,
int32_t y,
const char * str,
uint32_t color )

Draw a left-anchored text run in the bundled font.

Parameters
[in]xLeft pixel column.
[in]yTop pixel row.
[in]strASCII string (NUL-terminated).
[in]colorForeground colour (0xRRGGBB); background is paper.
Precondition
ra8_gfx is bound; str is non-NULL ASCII 0x20..0x7E.
None.
Postcondition
The run is blitted (clipped if needed).
Glyph cells are backed with paper-white.
Note
Not thread-safe.
Since
0.1.0

Definition at line 129 of file ereader_ui_screens.c.

References k_er_paper, ra8_gfx_font_8x16, and ra8_gfx_text_out().

Referenced by er_draw_reading_body(), er_kbd_search_render(), er_read_footer_render(), er_read_sb_render(), er_render_boxnodes(), and er_text_right().

◆ er_text_right()

void er_text_right ( int32_t right,
int32_t y,
const char * str,
uint32_t color )

Draw a right-anchored text run ending at column right.

Parameters
[in]rightRight pixel column the run ends at.
[in]yTop pixel row.
[in]strASCII string (NUL-terminated).
[in]colorForeground colour (0xRRGGBB); background is paper.
Precondition
ra8_gfx is bound; str is non-NULL ASCII 0x20..0x7E.
None.
Postcondition
The run is right-aligned to end near right.
Glyph cells are backed with paper-white.
Note
Not thread-safe.
Since
0.1.0

Definition at line 134 of file ereader_ui_screens.c.

References er_text_left(), k_ra8_ok, ra8_gfx_font_8x16, and ra8_gfx_text_size().

Referenced by er_lib_sb_render(), er_read_footer_render(), and er_read_sb_render().

Variable Documentation

◆ g_er_cur_page

volatile uint32_t g_er_cur_page
extern

SWD / --dump-sym telemetry for the headless page-turn HIL (#78).

Current reading page after the last turn.

Definition at line 254 of file main.c.

Referenced by er_flush_event().

◆ g_er_last_hint

volatile uint32_t g_er_last_hint
extern

Last display_refresh_hint_t flushed.

Definition at line 256 of file main.c.

Referenced by er_flush_event().

◆ g_er_turns

volatile uint32_t g_er_turns
extern

Count of page turns applied since boot.

Definition at line 255 of file main.c.

Referenced by er_apply_pageturn().

◆ k_er_body_lines

const char* const k_er_body_lines[]
extern

Reading-view body paragraph lines (pre-wrapped for the font).

Definition at line 110 of file main.c.

Referenced by er_draw_reading_body().

◆ k_er_book_title

const char k_er_book_title[]
extern

Reading title text.

Definition at line 86 of file main.c.

Referenced by er_read_footer_render(), and er_read_sb_render().

◆ k_er_books

const er_book_t k_er_books[]
extern

Demo shelf (public-domain works).

Definition at line 96 of file main.c.

Referenced by er_build_library().

◆ k_er_chapter

const char k_er_chapter[]
extern

Bitmap-fallback heading.

Definition at line 88 of file main.c.

Referenced by er_draw_reading_body().

◆ k_er_count_text

const char k_er_count_text[]
extern

Book-count chip text.

Definition at line 85 of file main.c.

Referenced by er_build_toolbar().

◆ k_er_lib_heading

const char k_er_lib_heading[]
extern

Library heading text.

Definition at line 82 of file main.c.

Referenced by er_build_library().

◆ k_er_nav_items

const char* const k_er_nav_items[]
extern

Bottom-nav destinations (Library / Store / Notes / Settings).

Bottom-nav destinations (Library / Store / Notes / Settings).

Definition at line 91 of file main.c.

Referenced by er_build_nav().

◆ k_er_page_label

const char k_er_page_label[]
extern

Reading page label.

Definition at line 87 of file main.c.

Referenced by er_read_footer_render().

◆ k_er_search_hint

const char k_er_search_hint[]
extern

Search placeholder.

Definition at line 84 of file main.c.

Referenced by er_build_toolbar(), and er_kbd_search_render().

◆ k_er_spine

const er_chapter_t k_er_spine[]
extern

Two-chapter mock spine for in-content cross-chapter navigation (#110).

Definition at line 164 of file main.c.

Referenced by er_nav_chapter(), and er_reflow_relayout().

◆ k_er_status_right

const char k_er_status_right[]
extern

Status-bar right text.

Definition at line 83 of file main.c.

Referenced by er_lib_sb_render(), and er_read_sb_render().

◆ k_er_wordmark

const char k_er_wordmark[6]
extern

Wordmark / status text.

Complete bound so er_read_sb_render can take sizeof to advance past it (a static_assert in main.c pins the size).

Definition at line 80 of file main.c.

Referenced by er_read_sb_render().

◆ s_batt_mon

ra8_batt_monitor_t s_batt_mon
extern

Low-battery nag policy state.

Low-battery nag policy state.

Definition at line 235 of file main.c.

Referenced by er_poll_battery(), and main().

◆ s_batt_nag

ra8_batt_nag_t s_batt_nag
extern

Nag currently shown over the chrome.

Nag currently shown over the chrome.

Definition at line 237 of file main.c.

Referenced by er_handle_tap(), er_nag_render(), er_poll_battery(), er_render_current(), and er_render_nag_region().

◆ s_batt_soc

uint8_t s_batt_soc
extern

Last fuel-gauge SOC percent.

Last fuel-gauge SOC percent.

Definition at line 239 of file main.c.

Referenced by er_nag_render(), and er_poll_battery().

◆ s_chapter_idx

uint32_t s_chapter_idx
extern

Reading chapter index.

Reading chapter index.

Definition at line 178 of file main.c.

Referenced by er_apply_pageturn(), er_draw_reading_body_reflow(), er_handle_reading_tap(), er_handle_tap(), er_nav_chapter(), er_push_loc(), and er_reflow_relayout().

◆ s_fb

display_fb_t s_fb
extern

Mutable copy of the FB descriptor.

Mutable copy of the FB descriptor.

Definition at line 211 of file main.c.

◆ s_font_buf

uint8_t s_font_buf[]
extern

Font blob read off the SD card.

Font blob read off the SD card.

Definition at line 271 of file main.c.

◆ s_font_len

uint32_t s_font_len
extern

Bytes of font read off the card.

Bytes of font read off the card.

Definition at line 288 of file main.c.

Referenced by er_draw_reading_body_reflow(), and er_try_load_font().

◆ s_have_font

bool s_have_font
extern

True once an SD font is loaded.

True once an SD font is loaded.

Definition at line 291 of file main.c.

Referenced by er_draw_reading_body_reflow(), and er_try_load_font().

◆ s_img_arena_buf

uint8_t s_img_arena_buf[]
extern

Image-decode bump arena in SDRAM.

Image-decode bump arena in SDRAM.

Definition at line 274 of file main.c.

Referenced by er_reflow_relayout().

◆ s_kb

ra8_kbd_layout_t s_kb
extern

On-screen keyboard grid.

On-screen keyboard grid.

Definition at line 223 of file main.c.

Referenced by er_draw_key(), er_handle_keyboard_tap(), er_kbd_keys_render(), er_kbd_label(), kb_key_of(), kb_key_of_kind(), kb_tap(), and main().

◆ s_loc_back

er_loc_t s_loc_back[]
extern

Reading back-stack for link jumps.

Reading back-stack for link jumps.

Definition at line 265 of file main.c.

Referenced by er_handle_reading_tap(), and er_push_loc().

◆ s_loc_back_count

uint32_t s_loc_back_count
extern

Entries used in s_loc_back.

Entries used in s_loc_back.

Definition at line 268 of file main.c.

Referenced by er_handle_reading_tap(), er_handle_tap(), and er_push_loc().

◆ s_nag_region_only

bool s_nag_region_only
extern

True when a tap only toggled the nag.

True when a tap only toggled the nag.

Definition at line 241 of file main.c.

Referenced by er_handle_tap(), and er_poll_touch().

◆ s_nav

ra8_ui_nav_t s_nav
extern

Navigation stack (active screen).

Navigation stack (active screen).

Definition at line 214 of file main.c.

◆ s_pending_event

display_turn_event_t s_pending_event
extern

Pending refresh event for next flush.

Pending refresh event for next flush.

Defaults to a clean chapter-boundary refresh for any screen change; a same-chapter page turn lowers it to k_display_event_turn.

Definition at line 251 of file main.c.

Referenced by er_apply_pageturn(), er_handle_tap(), er_poll_buttons(), and er_poll_touch().

◆ s_query

ra8_kbd_text_t s_query
extern

Live search query.

Live search query.

Definition at line 226 of file main.c.

Referenced by er_book_matches(), er_handle_keyboard_tap(), er_handle_tap(), and er_kbd_search_render().

◆ s_reading_page

uint32_t s_reading_page
extern

◆ s_reading_pages

uint32_t s_reading_pages
extern

Reading total reflow pages (>= 1).

Reading total reflow pages (>= 1).

Definition at line 232 of file main.c.

Referenced by er_apply_pageturn(), er_draw_reading_body_reflow(), er_read_footer_render(), and er_reflow_relayout().

◆ s_reflow_chapter

uint32_t s_reflow_chapter
extern

Chapter laid out (cache key).

Chapter laid out (cache key).

Definition at line 282 of file main.c.

Referenced by er_draw_reading_body_reflow(), and er_reflow_relayout().

◆ s_reflow_engine

reflow_t s_reflow_engine
extern

reflow engine for the body.

reflow engine for the body.

Definition at line 277 of file main.c.

Referenced by er_bind_glyph_atlas(), er_draw_reading_body_reflow(), er_nav_chapter(), er_nav_fragment(), er_reading_link_tap(), and er_reflow_relayout().

◆ s_reflow_h

int32_t s_reflow_h
extern

Body height the layout used.

See also
s_reflow_w

Definition at line 285 of file main.c.

Referenced by er_draw_reading_body_reflow(), and er_reflow_relayout().

◆ s_reflow_open

bool s_reflow_open
extern

True while the engine holds a layout.

True while the engine holds a layout.

Definition at line 280 of file main.c.

Referenced by er_draw_reading_body_reflow(), and er_reflow_relayout().

◆ s_reflow_w

int32_t s_reflow_w
extern

Body width the layout used.

Body width the layout used.

Definition at line 284 of file main.c.

Referenced by er_draw_reading_body_reflow(), and er_reflow_relayout().

◆ s_target_count

uint16_t s_target_count
extern

Tap targets currently populated.

Tap targets currently populated.

Definition at line 220 of file main.c.

Referenced by er_collect_targets(), er_handle_keyboard_tap(), er_handle_tap(), and er_kbd_keys_render().

◆ s_targets

ra8_ui_target_t s_targets[]
extern

Tap targets for the current screen.

Tap targets for the current screen.

Definition at line 217 of file main.c.

Referenced by er_collect_targets(), er_handle_keyboard_tap(), er_handle_tap(), and er_kbd_keys_render().