ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ereader_ui_steps.h
Go to the documentation of this file.
1
28
29#pragma once
30
31#include <stddef.h>
32#include <stdint.h>
33
34#include "er_pageturn.h"
35#include "ra8_app.h"
36#include "ra8_batt.h"
37#include "ra8_board_ek_ra8d2.h"
38#include "ra8_box.h"
39#include "ra8_display_pal.h"
41#include "ra8_keyboard.h"
42#include "ra8_panel.h"
43#include "ra8_panel_timing.h"
44#include "ra8_port_constants.h"
45#include "ra8_ui.h"
46#include "ra8_widget.h"
47#include "reflow.h"
48
49/* ===========================================================================
50 * Compile-time configuration -- typed enums per the no-magic-number rule.
51 * =========================================================================== */
52
61
66typedef enum : uint16_t {
71
76typedef enum : uint32_t {
77 k_er_paper = 0xFFFFFFU,
78 k_er_ink = 0x000000U,
79 k_er_ink_muted = 0x555555U,
80 k_er_rule = 0xAAAAAAU,
81 k_er_rule_soft = 0xCCCCCCU,
82 k_er_fill = 0xDDDDDDU,
83 k_er_fill_deep = 0x888888U,
85
115
120typedef enum : uint16_t {
125
130typedef enum : uint16_t {
133
144
162
178
188typedef enum : uint8_t {
189 k_er_fg_addr = 0x36U,
192 k_er_fg_sign = 0x80U,
194
210
212typedef enum : uint32_t {
213 k_er_nag_low_bg = 0x555555U,
214 k_er_nag_crit_bg = 0x000000U,
215 k_er_nag_text = 0xFFFFFFU,
217
222typedef enum : uint16_t {
224 k_er_back_w = 240U,
227
232typedef struct {
233 const char* title;
234 const char* author;
235 uint16_t pct;
236} er_book_t;
237
242typedef struct {
243 const char* xhtml;
244 uint32_t len;
245 const char* href;
246 uint32_t href_len;
248
253typedef struct {
254 uint32_t chapter;
255 uint32_t page;
256} er_loc_t;
257
262typedef enum : uint32_t {
263 k_er_font_cap = 512U * 1024U,
267 k_er_reflow_ink = 0xFF101010U,
268 k_er_reflow_link = 0xFF2A52BEU,
269 k_er_img_arena = 2U * 1024U * 1024U,
270
271 /* Layer-3 glyph atlas (#164): cache rasterised body glyphs in SDRAM so page
272 * turns reuse them instead of re-running stb_truetype every frame. */
278
280typedef enum : uint32_t {
281 k_er_chapter_none = 0xFFFFFFFFU,
283
284/* ===========================================================================
285 * Shared read-only content tables (defined in main.c -- single site).
286 * =========================================================================== */
287
292extern const char k_er_wordmark[6];
293extern const char k_er_lib_heading[];
294extern const char k_er_status_right[];
295extern const char k_er_search_hint[];
296extern const char k_er_count_text[];
297extern const char k_er_book_title[];
298extern const char k_er_page_label[];
299extern const char k_er_chapter[];
300
302extern const char* const k_er_nav_items[];
307typedef enum : uint16_t {
311
313extern const er_book_t k_er_books[];
318typedef enum : uint16_t {
321
323extern const char* const k_er_body_lines[];
328typedef enum : uint16_t {
331
333extern const er_chapter_t k_er_spine[];
338typedef enum : uint16_t {
341
342/* ===========================================================================
343 * Shared mutable file-scope state (defined in main.c -- single site).
344 * =========================================================================== */
345
346extern display_fb_t s_fb;
347extern ra8_ui_target_t s_targets[];
348extern uint16_t s_target_count;
349extern ra8_kbd_layout_t s_kb;
350extern ra8_kbd_text_t s_query;
351extern uint32_t s_chapter_idx;
352extern uint32_t s_reading_page;
353extern uint32_t s_reading_pages;
355extern bool s_reflow_open;
356extern uint32_t s_reflow_chapter;
357extern int32_t s_reflow_w;
358extern int32_t s_reflow_h;
359extern uint8_t s_font_buf[];
360extern uint32_t s_font_len;
361extern bool s_have_font;
362extern uint8_t s_img_arena_buf[];
363extern er_loc_t s_loc_back[];
364extern uint32_t s_loc_back_count;
365extern ra8_ui_nav_t s_nav;
367extern uint8_t s_batt_soc;
369extern bool s_nag_region_only;
371
373extern volatile uint32_t g_er_cur_page;
374extern volatile uint32_t g_er_turns;
375extern volatile uint32_t g_er_last_hint;
376
377/* ===========================================================================
378 * Text helpers (ereader_ui_screens.c) -- shared by every band renderer.
379 * =========================================================================== */
380
397void er_text_left(int32_t x, int32_t y, const char* str, uint32_t color);
398
415void er_text_right(int32_t right, int32_t y, const char* str, uint32_t color);
416
417/* ===========================================================================
418 * Screen rendering + in-content navigation (ereader_ui_screens.c).
419 * =========================================================================== */
420
432void er_render_library(void);
433
445void er_render_reading(void);
446
462
477bool er_reading_link_tap(int32_t x, int32_t y);
478
489void er_push_loc(void);
490
503uint32_t er_spine_count(void);
504
505/* ===========================================================================
506 * Keyboard rendering (ereader_ui_input.c).
507 * =========================================================================== */
508
519void er_render_keyboard(void);
520
521/* ===========================================================================
522 * Battery nag + input polling (ereader_ui_input.c).
523 * =========================================================================== */
524
538
550void er_poll_touch(void);
551
562void er_poll_buttons(void);
563
574void er_poll_battery(void);
575
576/* ===========================================================================
577 * Screen dispatch + panel flush (main.c) -- called from the input helpers.
578 * =========================================================================== */
579
590void er_render_current(void);
591
602void er_render_nag_region(void);
603
Pure page-turn + input-region decisions for the e-reader (#78).
er_dir_t
Page-turn direction produced by an input decision.
Definition er_pageturn.h:34
er_spine_count_t
Number of chapters in the mock spine.
@ k_er_spine_count
Number of chapters in k_er_spine.
bool s_have_font
True once an SD font is loaded.
Definition main.c:291
const char k_er_count_text[]
Book-count chip text.
Definition main.c:85
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.
er_color_t
PAPYR 16-level grayscale ramp, semantic roles (0xRRGGBB).
@ k_er_fill
Flat fills / covers (g13).
@ k_er_fill_deep
Heavier fill / progress (g8).
@ k_er_rule
Hairline dividers (g10).
@ k_er_paper
Page background (g15).
@ k_er_rule_soft
Faintest hairlines / track (g12).
@ k_er_ink
Primary text / glyphs (g0).
@ k_er_ink_muted
Secondary text / metadata (g5).
er_fb_dim_t
Framebuffer dimensions, sourced from the BSP panel descriptor.
@ k_er_fb_w
Framebuffer width (pixels).
@ k_er_fb_h
Framebuffer height (pixels).
void er_poll_buttons(void)
Poll SW1/SW2 and turn a page on a fresh press (#78).
bool s_reflow_open
True while the engine holds a layout.
Definition main.c:280
const char k_er_search_hint[]
Search placeholder.
Definition main.c:84
ra8_ui_target_t s_targets[]
Tap targets for the current screen.
Definition main.c:217
reflow_t s_reflow_engine
reflow engine for the body.
Definition main.c:277
ra8_kbd_layout_t s_kb
On-screen keyboard grid.
Definition main.c:223
ra8_kbd_text_t s_query
Live search query.
Definition main.c:226
er_reflow_cfg_t
SD-font load + reflow body-render tunables (no magic numbers).
@ k_er_img_arena
SDRAM image-decode scratch.
@ k_er_glyph_cells
Glyph-cache budget.
@ k_er_font_min
Smallest plausible font blob (bytes).
@ k_er_font_cap
Max font read off the card (bytes).
@ k_er_spi_chan
Pmod2 / J25 = SCI0 Simple-SPI.
@ k_er_reflow_ink
Body text colour (near-black ARGB).
@ k_er_glyph_cell_px
Cell edge, px (>= body).
@ k_er_glyph_cell_bytes
Bytes per cell.
@ k_er_reflow_link
Anchor colour (cerulean ARGB).
@ k_er_glyph_buckets
Glyph-cache hash buckets.
@ k_er_reflow_px
Body type size (pixels).
const char *const k_er_body_lines[]
Reading-view body paragraph lines (pre-wrapped for the font).
Definition main.c:110
uint32_t s_chapter_idx
Reading chapter index.
Definition main.c:178
uint16_t s_target_count
Tap targets currently populated.
Definition main.c:220
uint32_t s_reflow_chapter
Chapter laid out (cache key).
Definition main.c:282
bool s_nag_region_only
True when a tap only toggled the nag.
Definition main.c:241
er_fg_cfg_t
MAX17048-class fuel gauge wiring (shares the touch IIC_B bus).
@ k_er_fg_reg_crate
CRATE register (sign = charge dir).
@ k_er_fg_addr
Fuel gauge 7-bit I2C address.
@ k_er_fg_sign
CRATE high-byte sign bit (discharge).
@ k_er_fg_reg_soc
SOC register (high byte = percent).
volatile uint32_t g_er_turns
Count of page turns applied since boot.
Definition main.c:255
const char *const k_er_nav_items[]
Bottom-nav destinations (Library / Store / Notes / Settings).
Definition main.c:91
er_hit_cap_t
Tap-target table capacity and Reading back-affordance size.
@ k_er_back_w
Reading back-region width (px).
@ k_er_page_back_cap
Footnote-jump back-stack depth.
@ k_er_max_targets
Max collected tap targets.
const char k_er_page_label[]
Reading page label.
Definition main.c:87
er_layout_t
Shared chrome layout metrics (8 px grid), pixels.
@ k_er_pad_ui
Side padding for bands / grid.
@ k_er_count_w
Toolbar "N books" chip width.
@ k_er_card_label_h
Card title / author row height.
@ k_er_text_inset_y
16 px text centred in a 64 px band.
@ k_er_border_w
Card / control border weight.
@ k_er_text_pad
Inset for text inside a box.
@ k_er_glyph_w
Bundled font cell width.
@ k_er_footer_h
Reading footer band height.
@ k_er_toolbar_h
Library toolbar band height.
@ k_er_card_bar_h
Card progress-bar height.
@ k_er_progress_gap
Gap above the reading progress bar.
@ k_er_nav_h
Library bottom-nav band height.
@ k_er_progress_h
Reading-progress bar height.
@ k_er_line_h
Body line advance.
@ k_er_statusbar_h
Top status-bar band height.
@ k_er_grid_gap
Library grid gap.
@ k_er_tile_gap
Gap between a card's stacked parts.
@ k_er_blank_lines
Blank advance after the heading.
@ k_er_grid_cols
Library grid column count.
@ k_er_margin_x
Reading left/right margin.
@ k_er_body_gap
Gap between band and body text.
@ k_er_hair
Hairline weight.
@ k_er_glyph_h
Bundled font cell height.
er_touch_cfg_t
GT911 touch-controller wiring on the EK-RA8D2 carrier.
@ k_er_touch_channel
The board's GT911 bus.
@ k_er_touch_max_points
One contact = one tap.
display_turn_event_t s_pending_event
Pending refresh event for next flush.
Definition main.c:251
void er_render_reading(void)
Render the full Reading screen (status bar, body, footer).
int32_t s_reflow_w
Body width the layout used.
Definition main.c:284
const char k_er_book_title[]
Reading title text.
Definition main.c:86
uint8_t s_img_arena_buf[]
Image-decode bump arena in SDRAM.
Definition main.c:274
er_progress_t
Reading-position + percentage constants.
@ k_er_page_total
Reading total pages.
@ k_er_pct_full
Percent denominator.
@ k_er_page_current
Reading current page (1-based).
void er_flush_event(display_turn_event_t event)
Flush the panel for a refresh event through the cadence policy (#78).
Definition main.c:623
er_nav_count_t
Bottom-nav destination count.
@ k_er_nav_count
Number of bottom-nav destinations.
@ k_er_nav_idx_setting
Index of the "Settings" nav item.
void er_nag_render(ra8_widget_t *w)
Nag banner overlay widget: a centered low-battery toast over the screen.
ra8_batt_monitor_t s_batt_mon
Low-battery nag policy state.
Definition main.c:235
volatile uint32_t g_er_last_hint
Last display_refresh_hint_t flushed.
Definition main.c:256
er_nag_cfg_t
Low-battery nag-banner geometry.
@ k_er_nag_margin
Banner inset from the screen sides.
@ k_er_nag_h
Banner height (px).
@ k_er_nag_top
Banner top y (clear of the status bar).
@ k_er_nag_dec_max
Scratch for a "NNN%" decimal tail.
@ k_er_nag_text_dy
Text inset from the banner top.
@ k_er_nag_line_max
Banner text buffer size (bounds copy).
@ k_er_nag_text_dx
Text inset from the banner left.
@ k_er_nag_dec_ten
Decimal base.
@ k_er_batt_every
Poll the gauge every Nth frame (~1/s).
const char k_er_status_right[]
Status-bar right text.
Definition main.c:83
int32_t s_reflow_h
Body height the layout used.
Definition main.c:285
uint32_t s_loc_back_count
Entries used in s_loc_back.
Definition main.c:268
er_loc_t s_loc_back[]
Reading back-stack for link jumps.
Definition main.c:265
uint32_t s_reading_pages
Reading total reflow pages (>= 1).
Definition main.c:232
const char k_er_chapter[]
Bitmap-fallback heading.
Definition main.c:88
uint32_t er_spine_count(void)
Number of chapters in the (mock) spine.
ra8_batt_nag_t s_batt_nag
Nag currently shown over the chrome.
Definition main.c:237
const char k_er_wordmark[6]
Wordmark / status text.
Definition main.c:80
uint32_t s_reading_page
Reading current reflow page.
Definition main.c:229
const er_chapter_t k_er_spine[]
Two-chapter mock spine for in-content cross-chapter navigation (#110).
Definition main.c:164
const er_book_t k_er_books[]
Demo shelf (public-domain works).
Definition main.c:96
er_node_cap_t
Box-tree node-storage capacity.
@ k_er_max_nodes
Upper bound on chrome box nodes.
void er_render_current(void)
Render whichever screen is on top of the navigation stack.
Definition main.c:585
void er_push_loc(void)
Push the current (chapter, page) on the back-stack, capacity permitting.
void er_poll_battery(void)
Poll the fuel gauge, fold it into the nag policy, and toggle the banner.
er_action_t
Tap-target action ids (carried on box nodes as their tag).
@ k_er_act_none
Not a tap target.
@ k_er_act_open_book
Library card -> open the reading view.
@ k_er_act_settings
Bottom-nav Settings -> Settings app.
@ k_er_act_search
Toolbar Search -> open the keyboard.
@ k_er_act_nav
Bottom-nav destination (stay in lib).
@ k_er_act_key_base
Keyboard key i -> base + i.
const char k_er_lib_heading[]
Library heading text.
Definition main.c:82
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.
er_book_count_t
Number of demo books.
@ k_er_book_count
Number of demo books.
er_reflow_sentinel_t
"No chapter cached" sentinel.
@ k_er_chapter_none
s_reflow_chapter when nothing is laid out.
bool er_reading_link_tap(int32_t x, int32_t y)
Follow an in-content <a> tap in the Reading body (#110).
er_body_count_t
Number of pre-wrapped body lines.
@ k_er_body_line_count
Number of pre-wrapped body lines.
void er_render_keyboard(void)
Render the on-screen keyboard screen + collect its key targets.
er_screen_t
Screen ids for the ra8_ui navigation stack.
@ k_er_screen_reading
Reading view.
@ k_er_screen_keyboard
On-screen keyboard (search entry).
@ k_er_screen_library
Library / home grid.
@ k_er_screen_settings
Settings (optional app, if RA8_APP_SETTINGS).
bool er_apply_pageturn(er_dir_t dir)
Apply a page turn to the reading location (touch + button shared path).
uint8_t s_batt_soc
Last fuel-gauge SOC percent.
Definition main.c:239
uint32_t s_font_len
Bytes of font read off the card.
Definition main.c:288
void er_render_nag_region(void)
Repaint only the low-battery banner rect (dirty-region update).
Definition main.c:602
void er_poll_touch(void)
Poll the touch controller and dispatch a tap on a fresh press.
er_fb_misc_t
Framebuffer byte-math and pacing constants.
@ 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.
volatile uint32_t g_er_cur_page
SWD / --dump-sym telemetry for the headless page-turn HIL (#78).
Definition main.c:254
er_nag_color_t
Nag-banner palette (grayscale e-ink).
@ k_er_nag_low_bg
Low-battery banner fill (g5).
@ k_er_nag_text
Banner text (paper on the fill).
@ k_er_nag_crit_bg
Critical banner fill (g0 ink).
void er_render_library(void)
Render the full Library screen.
static uint8_t s_font_buf[k_pc_font_cap]
Font blob read off the card.
Definition main.c:197
static display_fb_t s_fb
Definition main.c:203
static ra8_app_nav_t s_nav
Navigation back-stack layered over s_reg.
Definition main.c:236
Zero-heap app framework: lifecycle + static registry + launcher (#146).
Bounded, allocation-free low-battery nag policy.
ra8_batt_nag_t
The low-battery warning a single ra8_batt_update step raises.
Definition ra8_batt.h:54
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
@ k_ra8_board_touch_i3c_channel
IIC_B / I3C channel 0 carries the GT911.
Bounded, allocation-free box-model layout for e-reader chrome.
Display Platform Abstraction Layer for the RA8D2.
Pluggable page-turn refresh-cadence policy for bistable (e-ink) panels.
display_turn_event_t
The page-transition event the policy reacts to.
On-screen keyboard widget – iOS-style layers, shift, hit-test.
Active display-panel descriptor for the EK-RA8D2 (ER-TFT070-6).
@ k_panel_height_px
Native height (pixels).
Definition ra8_panel.h:52
@ k_panel_width_px
Native width (pixels).
Definition ra8_panel.h:51
EK-RA8D2 panel timing as the HAL's ra8_glcdc_timing_t (ER-TFT070-6).
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
Bounded UI interaction core: hit-testing, screen stack, paging.
Zero-heap composable widget layer (dwm-style) over ra8_box + ra8_ui.
HTML / CSS reflow + paginate engine for the ra8d2 ereader.
Framebuffer descriptor returned by display_get_framebuffer.
One library entry: title, author, reading progress percent.
const char * title
Book title.
const char * author
Author.
uint16_t pct
Reading progress (0..100).
One mock-spine chapter: its XHTML, length, and resolving href.
uint32_t len
Length of xhtml (excl.
const char * xhtml
Chapter XHTML body.
const char * href
Manifest href that links to it.
uint32_t href_len
Length of href (excl.
A reading location (chapter + page) for the navigation back-stack.
uint32_t chapter
Spine chapter index.
uint32_t page
Page within chapter.
Caller-owned nag state carried across ra8_batt_update calls.
Definition ra8_batt.h:85
The key grid for the active layer, plus SHIFT / layer / frame state.
The typed query buffer + commit state.
Fixed-depth screen-id stack (caller-owned).
Definition ra8_ui.h:163
One tap target: a rectangle bound to an opaque action id.
Definition ra8_ui.h:83
One widget instance (caller-owned, no allocation).
Reflow / pagination engine state.