|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Tap-driven pan/zoom viewer over a tiled manga page (ereader_manga). More...
#include <stddef.h>#include <stdint.h>#include "jof.h"#include "ra8_err.h"#include "ra8_tile_cache.h"Go to the source code of this file.
Data Structures | |
| struct | mg_tile_src_t |
| Decode-on-miss context bound into the tile cache (DIP seam). More... | |
| struct | mg_reader_cfg_t |
| Everything mg_reader_init needs to bind a viewer to a page. More... | |
| struct | mg_reader_t |
| Viewer state: the page geometry plus the current viewport + zoom. More... | |
Enumerations | |
| enum | mg_layout_t : uint16_t { k_mg_statusbar_h = 48U , k_mg_pan_step = 256U , k_mg_edge_band = 176U , k_mg_minimap_w = 104U , k_mg_minimap_h = 140U , k_mg_minimap_pad = 14U , k_mg_minimap_in = 2U } |
| Fixed chrome + navigation geometry, in panel/page pixels. More... | |
| enum | mg_zoom_t : uint8_t { k_mg_zoom_full = 0U , k_mg_zoom_fit = 1U } |
| The two zoom states cycled by a centre tap. More... | |
| enum | mg_zone_t : uint8_t { k_mg_zone_none = 0U , k_mg_zone_pan_up = 1U , k_mg_zone_pan_down = 2U , k_mg_zone_pan_left = 3U , k_mg_zone_pan_right = 4U , k_mg_zone_zoom = 5U } |
| The tap-zone a panel coordinate falls in (mg_zone_hit result). More... | |
Functions | |
| ra8_err_t | mg_reader_init (mg_reader_t *r, const mg_reader_cfg_t *cfg) |
| Bind a viewer to a produced atlas and reset it to 1:1 top-left. | |
| mg_zone_t | mg_zone_hit (const mg_reader_t *r, int32_t x, int32_t y) |
| Classify a panel coordinate into its tap-zone. | |
| bool | mg_reader_tap (mg_reader_t *r, int32_t x, int32_t y) |
| Apply a tap: pan or toggle zoom, and report whether state changed. | |
| bool | mg_reader_toggle_zoom (mg_reader_t *r) |
| Toggle the zoom between 1:1 and fit-page (SW-button entry point). | |
| ra8_err_t | mg_reader_render (mg_reader_t *r) |
| Render the current viewport + chrome into the framebuffer. | |
| ra8_err_t | mg_reader_prefetch (mg_reader_t *r) |
| Warm the tiles one step ahead of the last pan (predictive prefetch). | |
| ra8_err_t | mg_reader_status (const mg_reader_t *r, char *buf, uint32_t cap) |
| Format the status-bar string ("MANGA 1:1 x=.. y=.."). | |
| uint32_t | mg_fnv1a (const void *buf, uint32_t len) |
| FNV-1a-32 over a byte buffer (framebuffer render hash for the banner). | |
| ra8_err_t | mg_tile_decode (void *ctx, const ra8_tile_key_t *key, uint8_t *cell, uint32_t cell_bytes, uint16_t *out_w, uint16_t *out_h) |
| Tile-cache decode-on-miss callback: page one atlas tile into a cell. | |
Tap-driven pan/zoom viewer over a tiled manga page (ereader_manga).
The presentation model for the ereader_manga demo: a viewport onto a page far larger than the 1024x600 panel, backed by a JOF tile atlas (jof) paged through a small fixed-budget tile cache (ra8_tile_cache). The reader owns no hardware – it draws into a caller-supplied RGB565 framebuffer through ra8_gfx and reads decoded tiles through the cache – so the identical render runs on the cross-built firmware, under ra8_emulator, and in the host unit test.
Navigation is discrete tap-zones (ra8_emulator's GT911 model has no gestures):
A tile is fetched, blitted, and released one at a time, so a viewport that spans more tiles than the cache has cells forces LRU eviction every frame – the streaming-larger-than-RAM property the tile cache exists for.
Definition in file mg_reader.h.
| enum mg_layout_t : uint16_t |
Fixed chrome + navigation geometry, in panel/page pixels.
The status band and minimap are panel-pixel metrics; the pan step is measured in page pixels (how far one edge tap slides the viewport); the edge band is the panel-pixel thickness of each pan tap-zone.
Definition at line 54 of file mg_reader.h.
| enum mg_zone_t : uint8_t |
The tap-zone a panel coordinate falls in (mg_zone_hit result).
Definition at line 81 of file mg_reader.h.
| enum mg_zoom_t : uint8_t |
The two zoom states cycled by a centre tap.
| Enumerator | |
|---|---|
| k_mg_zoom_full | 1:1 – one page pixel per panel pixel; panned. |
| k_mg_zoom_fit | Fit-page – whole page decimated to the panel. |
Definition at line 70 of file mg_reader.h.
|
nodiscard |
FNV-1a-32 over a byte buffer (framebuffer render hash for the banner).
| [in] | buf | Bytes to hash. |
| [in] | len | Byte count. |
| 2166136261 | The offset basis, when len is 0 (empty digest). |
buf holds len readable bytes (or len is 0). Definition at line 540 of file mg_reader.c.
References k_mg_fnv_offset, and k_mg_fnv_prime.
Referenced by mg_print_banner().
|
nodiscard |
Bind a viewer to a produced atlas and reset it to 1:1 top-left.
| [out] | r | Reader state to populate. |
| [in] | cfg | Framebuffer + cache + parsed atlas geometry. |
| k_ra8_ok | Reader ready; viewport at (0,0), zoom 1:1. |
| k_ra8_err_null_ptr | r, cfg, or a required cfg field NULL. |
| k_ra8_err_invalid_size | cfg geometry is zero / smaller than the fb. |
| k_ra8_err_not_supported | cfg->info->bpp is not 1 (gray8); the blit path reads one byte per pixel, so a colour atlas is rejected rather than mis-rendered. |
cfg->info came from a successful jof_parse. cfg->info->bpp == 1 (gray8); colour atlases are unsupported. cfg->fb covers fb_w * fb_h RGB565 pixels. r is left unbound.Definition at line 619 of file mg_reader.c.
References k_ra8_ok, mg_reader_bind(), mg_reader_check_geometry(), and mg_reader_check_ptrs().
Referenced by main().
|
nodiscard |
Warm the tiles one step ahead of the last pan (predictive prefetch).
Called in the idle window after mg_reader_render presents a panned frame, so the next tiles the viewport will expose are decoded into the cache before the next pan needs them – the image counterpart of the chapter-text read-ahead (book_src_prefetch_chapter). Warms the lead tile row/column in r->last_pan through ra8_tile_cache_prefetch_pan, sizing the budget from the cache's spare capacity (capacity - currently-visible tiles) so a prefetch can never evict an on-screen tile. A no-op when the last action was not a moving pan (last_pan == k_ra8_tile_pan_none – the initial frame, a zoom toggle, a pan clamped at the page edge, or fit-page zoom where a pan is a no-op), or when the cache has no spare capacity. Transparent: warming changes only residency, so the next mg_reader_render is byte-identical.
| [in,out] | r | Bound reader (its last_pan seeds the direction). |
| k_ra8_ok | Prefetch ran (possibly warming zero tiles). |
| k_ra8_err_null_ptr | r or its cache was NULL. |
| k_ra8_err_* | Propagated from ra8_tile_cache_prefetch_pan. |
r was populated by mg_reader_init. r->fb and the viewport state are unchanged.Definition at line 349 of file mg_reader.c.
References mg_reader_t::cache, mg_reader_t::image_id, k_mg_tag, k_ra8_ok, k_ra8_tile_pan_none, mg_reader_t::last_pan, mg_region(), mg_tiles_of_region(), RA8_CHECK_NULL_PTR, ra8_tile_cache_capacity(), ra8_tile_cache_prefetch_pan(), mg_reader_t::tile_cols, and mg_reader_t::tile_rows.
Referenced by mg_poll_touch().
|
nodiscard |
Render the current viewport + chrome into the framebuffer.
Clears the framebuffer, pages every tile overlapping the viewport through the cache (get/blit/put one at a time so a small cache evicts across the frame), packs gray8 to RGB565 with nearest- neighbour decimation at fit-page zoom, then draws the status bar and the minimap overlay.
| [in,out] | r | Bound reader. |
| k_ra8_ok | The framebuffer holds the current view. |
| k_ra8_err_null_ptr | r or its framebuffer was NULL. |
| k_ra8_err_* | Propagated from the tile cache / gfx. |
r was populated by mg_reader_init and ra8_gfx is bound to r->fb. r->fb holds the rendered screen. Definition at line 332 of file mg_reader.c.
References mg_reader_t::fb, k_mg_col_letterbox, k_mg_tag, k_ra8_ok, mg_render_minimap(), mg_render_page(), mg_render_status(), RA8_CHECK_NULL_PTR, and ra8_gfx_clear().
Referenced by main(), and mg_poll_touch().
|
nodiscard |
Format the status-bar string ("MANGA 1:1 x=.. y=..").
| [in] | r | Bound reader. |
| [out] | buf | Destination, NUL-terminated on return. |
| [in] | cap | Capacity of buf (>= 1). |
| k_ra8_ok | The status text was written. |
| k_ra8_err_null_ptr | r or buf was NULL. |
| k_ra8_err_invalid_size | cap was 0. |
r was populated by mg_reader_init. buf holds cap writable bytes. buf is NUL-terminated within cap. Definition at line 522 of file mg_reader.c.
References k_mg_tag, k_mg_zoom_full, k_ra8_err_invalid_size, k_ra8_ok, mg_append_str(), mg_append_uint(), RA8_CHECK_NULL_PTR, mg_reader_t::view_x, mg_reader_t::view_y, and mg_reader_t::zoom.
Referenced by mg_render_status().
|
nodiscard |
Apply a tap: pan or toggle zoom, and report whether state changed.
Maps (x,y) through mg_zone_hit, then mutates the viewport (an edge zone, clamped inside the page) or the zoom (the centre zone). A pan already at the page edge, or a tap on no zone, leaves the state unchanged and returns false so the caller can skip the redraw.
| [in,out] | r | Bound reader. |
| [in] | x | Tap X, panel pixels. |
| [in] | y | Tap Y, panel pixels. |
| true | State changed; the caller should re-render. |
| false | Tap hit nothing actionable (no redraw needed). |
r was populated by mg_reader_init. x and y are panel coordinates. r is byte-for-byte unchanged.Definition at line 461 of file mg_reader.c.
References k_mg_pan_step, k_mg_zone_none, k_mg_zone_pan_down, k_mg_zone_pan_left, k_mg_zone_pan_right, k_mg_zone_pan_up, k_mg_zone_zoom, mg_pan(), mg_reader_toggle_zoom(), and mg_zone_hit().
Referenced by mg_poll_touch().
|
nodiscard |
Toggle the zoom between 1:1 and fit-page (SW-button entry point).
| [in,out] | r | Bound reader. |
| true | The zoom state flipped (the normal case). |
| false | r was NULL (nothing toggled). |
r was populated by mg_reader_init. r->zoom is the other mg_zoom_t member. Definition at line 450 of file mg_reader.c.
References k_mg_zoom_fit, k_mg_zoom_full, k_ra8_tile_pan_none, mg_reader_t::last_pan, mg_clamp(), and mg_reader_t::zoom.
Referenced by mg_reader_tap().
|
nodiscard |
Tile-cache decode-on-miss callback: page one atlas tile into a cell.
Matches ra8_tile_decode_fn. Reads key->tile_x / tile_y and reads that tile out of the atlas through jof_read_tile (raw copy or deflate inflate) into cell, reporting the tile's clamped dimensions.
| [in] | ctx | A mg_tile_src_t* bound at cache init. |
| [in] | key | The tile to decode. |
| [out] | cell | Destination cell (cell_bytes writable). |
| [in] | cell_bytes | Cell capacity in bytes. |
| [out] | out_w | Decoded tile width, pixels. |
| [out] | out_h | Decoded tile height, pixels. |
| k_ra8_ok | Tile decoded into cell. |
| k_ra8_err_null_ptr | A required pointer was NULL. |
| k_ra8_err_* | Propagated from jof_read_tile. |
ctx points at a live mg_tile_src_t. cell holds cell_bytes writable bytes. cell. cell content is unspecified.Definition at line 633 of file mg_reader.c.
References mg_tile_src_t::info, jof_read_tile(), k_mg_tag, mg_tile_src_t::pread, mg_tile_src_t::pread_ctx, RA8_CHECK_NULL_PTR, mg_tile_src_t::scratch, mg_tile_src_t::scratch_cap, ra8_tile_key_t::tile_x, and ra8_tile_key_t::tile_y.
Referenced by mg_setup_cache().
|
nodiscard |
Classify a panel coordinate into its tap-zone.
Pure hit-test with no side effects: the centre rectangle (inside all four edge bands, below the status bar) is the zoom zone; each edge band is its pan zone; the status bar and any gap map to k_mg_zone_none.
| [in] | r | Bound reader (for the framebuffer extent). |
| [in] | x | Tap X, panel pixels. |
| [in] | y | Tap Y, panel pixels. |
(x,y) falls in. | k_mg_zone_none | Status bar / outside the content area. |
| k_mg_zone_pan_* | An edge band. |
| k_mg_zone_zoom | The centre. |
r was populated by mg_reader_init. x and y are panel coordinates. Definition at line 417 of file mg_reader.c.
References mg_reader_t::fb_h, mg_reader_t::fb_w, k_mg_edge_band, k_mg_statusbar_h, k_mg_zone_none, k_mg_zone_pan_down, k_mg_zone_pan_left, k_mg_zone_pan_right, k_mg_zone_pan_up, and k_mg_zone_zoom.
Referenced by mg_reader_tap().