|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Viewable page-turn comic reader – baked CBZ decoded to the 1024x600 GLCDC panel, tap-zone navigation (ra8_emulator / emulator-viewable). More...
#include <stddef.h>#include <stdint.h>#include <string.h>#include "cm_tiled_check.h"#include "comic.h"#include "comic_pages_fixture.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_board_ek_ra8d2_touch.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_display_pal.h"#include "ra8_display_pal_lcd.h"#include "ra8_err.h"#include "ra8_gfx.h"#include "ra8_gfx_font.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_panel.h"#include "ra8_panel_timing.h"#include "ra8_sdramc.h"#include "ra8_time.h"#include "ra8_touch.h"#include "reflow_image.h"Go to the source code of this file.
Data Structures | |
| struct | cm_src_t |
| Resident-buffer backing for the reader's seek+read callback. More... | |
Enumerations | |
| enum | cm_fb_dim_t : uint16_t { k_cm_fb_w = k_panel_width_px , k_cm_fb_h = k_panel_height_px } |
| Panel framebuffer dimensions, sourced from the BSP panel descriptor. More... | |
| enum | cm_layout_t : uint16_t { k_cm_settle_ms = 500U , k_cm_frame_ms = 25U , k_cm_led_every = 16U , k_cm_statusbar_h = 56U , k_cm_progress_h = 40U , k_cm_text_pad = 20U , k_cm_glyph_h = 16U , k_cm_glyph_w = 8U , k_cm_track_inset = 10U , k_cm_track_h = 12U } |
| Chrome-band and pacing metrics (pixels / milliseconds). More... | |
| enum | cm_color_t : uint32_t { k_cm_col_letterbox = 0x0C0C10U , k_cm_col_bar_bg = 0x1C1C24U , k_cm_col_bar_fg = 0xF0F0F0U , k_cm_col_bar_muted = 0x9098A8U , k_cm_col_track = 0x39414FU , k_cm_col_fill = 0x4C8BF5U } |
| Reader palette (0x00RRGGBB, packed to RGB565 by ra8_gfx). More... | |
| enum | cm_reader_cfg_t : uint32_t { k_cm_uart_baud = 115200U , k_cm_arena_bytes = 2U * 1024U * 1024U , k_cm_page_cap = 8U , k_cm_name_cap = 256U , k_cm_pagebuf = 64U * 1024U , k_cm_batt_pct = 87U , k_cm_fnv_offset = 2166136261U , k_cm_fnv_prime = 16777619U , k_cm_hex_nibbles = 8U , k_cm_nibble_bits = 4U , k_cm_nibble_mask = 0x0FU , k_cm_dec_ten = 10U , k_cm_pos_cap = 24U , k_cm_batt_cap = 8U } |
| Reader capacities, demo battery level, and hash constants. More... | |
| enum | cm_zone_t : uint8_t { k_cm_zone_none = 0U , k_cm_zone_prev = 1U , k_cm_zone_next = 2U , k_cm_zone_chrome = 3U } |
| Tap-zone classification of a panel touch. More... | |
| enum | cm_zone_div_t : uint8_t { k_cm_thirds = 3U , k_cm_halves = 2U } |
| Tap-zone divisors (thirds / halves of the panel). More... | |
| enum | cm_touch_cfg_t : uint8_t { k_cm_touch_max_points = 1U } |
| GT911 touch-controller wiring on the EK-RA8D2 carrier. More... | |
| enum | cm_touch_bus_cfg_t : uint32_t { k_cm_touch_bus_hz = 400000U , k_cm_touch_pclka_hz = 60000000U } |
| Clocking for the app-owned GT911 I2C bus. More... | |
Functions | |
| RA8_BOARD_PANEL_FRAMEBUFFER (s_framebuffer) | |
| static void | cm_print (const uint8_t *msg, uint32_t len) |
| Emit a byte run on the SCI8 console. | |
| static void | cm_print_hex (uint32_t value) |
| Print a 32-bit value as 8 upper-case hex digits. | |
| static void | cm_print_uint (uint32_t value) |
| Print a small unsigned integer in decimal. | |
| static uint32_t | cm_utoa (uint32_t value, char *buf, uint32_t cap) |
| Format a small unsigned into a caller ASCII buffer, NUL-terminated. | |
| static void | cm_append (char *dst, uint32_t cap, uint32_t *cursor, const char *src) |
Append a NUL-terminated string into a bounded buffer at *cursor. | |
| static uint32_t | cm_framebuffer_hash (void) |
| FNV-1a-32 over the whole panel framebuffer (deterministic banner). | |
| static void | cm_panic_halt (void) |
| Halt forever with the red board LED on (fatal init error). | |
| static void | cm_bringup_clocks (void) |
| Bring up clocks, MSTP, SysTick, the console, and both board LEDs. | |
| static void | cm_bringup_panel (void) |
| Bring up SDRAM + the GLCDC panel and bind ra8_gfx to the framebuffer. | |
| static void | cm_bringup_touch (void) |
| Open the GT911 touch controller (best-effort, polled). | |
| static size_t | cm_read (void *ctx, uint64_t off, void *buf, size_t len) |
| Read callback over the resident archive buffer. | |
| static bool | cm_open_comic (void) |
| Open the baked CBZ once and cache its page count. | |
| static bool | cm_draw_page (void) |
| Decode the current page and aspect-fit it into the content region. | |
| static void | cm_draw_status_bar (void) |
| Draw the top status bar: title, Page N of M, battery percent. | |
| static void | cm_draw_progress_bar (void) |
| Draw the bottom progress bar (filled fraction = read position). | |
| static void | cm_render (void) |
| Render the whole reader screen: letterbox, page, and optional chrome. | |
| static void | cm_present (void) |
| Flush the whole panel so the GLCDC scans out the new frame. | |
| static cm_zone_t | cm_zone_at (int32_t x, int32_t y) |
| Classify a panel touch into a navigation zone. | |
| static bool | cm_handle_tap (int32_t x, int32_t y) |
| Apply a tap: turn a page or toggle the chrome. | |
| static void | cm_poll_touch (void) |
| Poll the GT911 once and dispatch a tap on a fresh press. | |
| static void | cm_print_banner (void) |
| Print the deterministic boot banner (page-1 framebuffer hash). | |
| void | main (void) |
| App entry: bring up the panel, open the comic, render + poll taps. | |
Variables | |
| static uint8_t | s_img_arena [k_cm_arena_bytes] |
| Zero-heap bump arena in SDRAM backing the PNG page decode. | |
| static uint8_t | s_pagebuf [k_cm_pagebuf] |
| One page's extracted encoded image bytes (SDRAM scratch). | |
| static comic_t | s_comic |
| The open comic reader, kept open for the app lifetime. | |
| static comic_page_t | s_pages [k_cm_page_cap] |
| Caller page-index storage handed to comic_open. | |
| static char | s_names [k_cm_name_cap] |
| Caller name arena handed to comic_open. | |
| static display_handle_t * | s_display = nullptr |
| Display PAL handle returned by display_init. | |
| static display_fb_t | s_fb |
| Mutable copy of the framebuffer descriptor (populated at boot). | |
| static uint32_t | s_page = 0U |
| Current page index (0-based) shown on the panel. | |
| static uint32_t | s_page_count = 1U |
| Total page count parsed from the archive (>= 1). | |
| static bool | s_chrome_on = true |
| Whether the status / progress chrome bands are drawn. | |
| static bool | s_was_touching = false |
| Debounce: true while a contact is held (fire once per press). | |
| static uint32_t | s_loop_ticks = 0U |
| Free-running main-loop counter (HIL liveness / LED sub-cadence). | |
| static const char | k_cm_title [] = "COMIC READER" |
| Reader title shown in the status bar. | |
| static const char | k_cm_pos_prefix [] = "Page " |
| "Page " status-bar prefix. | |
| static const char | k_cm_pos_infix [] = " of " |
| " of " status-bar infix. | |
| static const uint8_t | k_cm_msg_boot [] = "ereader-comic: boot\r\n" |
| Console boot banner literal (SCI8). | |
| static const uint8_t | k_cm_msg_cerr [] = "ereader-comic: FAIL comic\r\n" |
| Console comic-open failure literal (SCI8). | |
| static const uint8_t | k_cm_msg_pre [] = "ereader-comic: pages=" |
| Deterministic banner prefix (SCI8). | |
| static const uint8_t | k_cm_msg_dim [] = " " |
| Banner dimension separator (SCI8). | |
| static const uint8_t | k_cm_msg_x [] = "x" |
| Banner width-height separator (SCI8). | |
| static const uint8_t | k_cm_msg_page [] = " page=1 crc=" |
| Banner page + crc separator (SCI8). | |
| static const uint8_t | k_cm_msg_tiled [] = " tiled=" |
| Banner oversized-page tile self-check field prefix (SCI8, #344). | |
| static const uint8_t | k_cm_msg_colon [] = ":" |
| Banner numeric-field separator (SCI8). | |
| static const uint8_t | k_cm_msg_ok [] = " ok\r\n" |
| Banner trailer (SCI8). | |
| static cm_src_t | s_src |
| Archive source bound into comic_open (lives for the run). | |
| static cm_tiled_result_t | s_tiled |
| Result of the #344 oversized-page tile self-check. | |
| static const display_cfg_t | k_cm_display_cfg |
| Display PAL config – LCD/GLCDC backend over the SDRAM buffer. | |
Viewable page-turn comic reader – baked CBZ decoded to the 1024x600 GLCDC panel, tap-zone navigation (ra8_emulator / emulator-viewable).
Demo A of the e-reader GUI plan: a real, viewable comic reader. Boot brings up clocks / MSTP / SysTick, external SDRAM, and the GLCDC panel through ra8_display_pal (k_display_backend_lcd_ra8_glcdc); the 1024x600 RGB565 framebuffer lives in SDRAM and ra8_gfx draws into it. A baked multi-page CBZ (k_comic_cbz, generated by scripts/gen/gen_comic_fixture.py) is opened once through comic_open; each page is decoded on demand with comic_page_read + ra8_img_decode_blit (aspect-fit into the content region between the chrome bands).
Screens drawn to the panel:
Navigation is discrete tap zones (ra8_emulator --click / --touch-seq / window taps – never a swipe/drag, which the GT911 model does not provide):
A deterministic banner is printed once over the SCI8 console after the first render so the headless EIL gate still asserts a fixed framebuffer hash:
ereader-comic: pages=<N> <W>x<H> page=1 crc=<8hex> ok
Definition in file main.c.
| enum cm_color_t : uint32_t |
Reader palette (0x00RRGGBB, packed to RGB565 by ra8_gfx).
| enum cm_fb_dim_t : uint16_t |
| enum cm_layout_t : uint16_t |
Chrome-band and pacing metrics (pixels / milliseconds).
| enum cm_reader_cfg_t : uint32_t |
Reader capacities, demo battery level, and hash constants.
| enum cm_touch_bus_cfg_t : uint32_t |
| enum cm_touch_cfg_t : uint8_t |
| enum cm_zone_div_t : uint8_t |
| enum cm_zone_t : uint8_t |
|
static |
Append a NUL-terminated string into a bounded buffer at *cursor.
| [in,out] | dst | Destination buffer (NUL-terminated on return). |
| [in] | cap | Capacity of dst in bytes. |
| [in,out] | cursor | Current write offset; advanced past the copy. |
| [in] | src | Source string (NUL-terminated). |
dst holds cap writable bytes and *cursor < cap. src is a valid NUL-terminated string. dst[*cursor] == '\0' and *cursor <= cap - 1. cap - 1. Definition at line 439 of file main.c.
Referenced by cm_draw_status_bar().
|
static |
Bring up clocks, MSTP, SysTick, the console, and both board LEDs.
Definition at line 493 of file main.c.
References cm_panic_halt(), k_cm_uart_baud, k_ra8_board_led_blue, k_ra8_board_led_red, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_isr_globals_enable(), ra8_mstp_init(), and ra8_time_init().
Referenced by main().
|
static |
Bring up SDRAM + the GLCDC panel and bind ra8_gfx to the framebuffer.
Definition at line 542 of file main.c.
References cm_panic_halt(), display_get_framebuffer(), display_init(), k_cm_display_cfg, k_cm_settle_ms, k_ra8_gfx_format_rgb565, k_ra8_ok, ra8_delay_ms(), ra8_gfx_init(), ra8_sdramc_init(), s_display, and s_fb.
Referenced by main().
|
static |
Open the GT911 touch controller (best-effort, polled).
Brings up IIC_B in I2C-compat mode, binds it through the ra8_io facade into the driver seam, then opens the driver. Emulator runs / boards without a GT911 simply leave touch unavailable (non-fatal).
Definition at line 572 of file main.c.
References k_cm_touch_max_points, k_ra8_touch_irq_pin_unset, and ra8_board_touch_open().
Referenced by main().
|
static |
Decode the current page and aspect-fit it into the content region.
| true | s_page was drawn into the content box. |
| false | Extract or decode failed (box left as letterbox). |
Definition at line 644 of file main.c.
References comic_page_read(), k_cm_arena_bytes, k_cm_fb_h, k_cm_fb_w, k_cm_progress_h, k_cm_statusbar_h, k_ra8_ok, ra8_img_decode_blit(), s_comic, s_img_arena, s_page, and s_pagebuf.
Referenced by cm_render().
|
static |
Draw the bottom progress bar (filled fraction = read position).
Definition at line 730 of file main.c.
References k_cm_col_bar_bg, k_cm_col_fill, k_cm_col_track, k_cm_fb_h, k_cm_fb_w, k_cm_progress_h, k_cm_track_h, k_cm_track_inset, ra8_gfx_rect(), s_page, and s_page_count.
Referenced by cm_render().
|
static |
Draw the top status bar: title, Page N of M, battery percent.
Definition at line 673 of file main.c.
References cm_append(), cm_utoa(), k_cm_batt_cap, k_cm_batt_pct, k_cm_col_bar_bg, k_cm_col_bar_fg, k_cm_col_bar_muted, k_cm_dec_ten, k_cm_fb_w, k_cm_glyph_h, k_cm_glyph_w, k_cm_pos_cap, k_cm_pos_infix, k_cm_pos_prefix, k_cm_statusbar_h, k_cm_text_pad, k_cm_title, ra8_gfx_font_8x16, ra8_gfx_rect(), ra8_gfx_text_out(), s_page, and s_page_count.
Referenced by cm_render().
|
static |
FNV-1a-32 over the whole panel framebuffer (deterministic banner).
Definition at line 451 of file main.c.
References k_cm_fnv_offset, k_cm_fnv_prime, and s_framebuffer.
Referenced by cm_print_banner().
|
static |
Apply a tap: turn a page or toggle the chrome.
| [in] | x | Panel X of the tap. |
| [in] | y | Panel Y of the tap. |
| true | A page turned or the chrome toggled. |
| false | The tap was a no-op (already at an end, or dead zone). |
x < k_cm_fb_w and 0 <= y < k_cm_fb_h. Definition at line 822 of file main.c.
References cm_zone_at(), k_cm_zone_chrome, k_cm_zone_next, k_cm_zone_none, k_cm_zone_prev, s_chrome_on, s_page, and s_page_count.
Referenced by cm_poll_touch().
|
static |
Open the baked CBZ once and cache its page count.
| true | s_comic is open and s_page_count is set (>= 1). |
| false | The archive failed to open. |
Definition at line 610 of file main.c.
References cm_read(), comic_open(), comic_page_count(), k_cm_page_cap, k_comic_cbz, k_comic_cbz_len, k_ra8_ok, s_comic, s_names, s_page_count, s_pages, and s_src.
Referenced by main().
|
static |
Halt forever with the red board LED on (fatal init error).
Definition at line 476 of file main.c.
References k_ra8_board_led_red, and ra8_board_led_on().
Referenced by cm_bringup_clocks(), cm_bringup_panel(), and main().
|
static |
Poll the GT911 once and dispatch a tap on a fresh press.
Definition at line 855 of file main.c.
References cm_handle_tap(), cm_present(), cm_render(), k_cm_touch_max_points, k_ra8_ok, ra8_touch_read(), s_was_touching, ra8_touch_point_t::x, and ra8_touch_point_t::y.
Referenced by main().
|
static |
Flush the whole panel so the GLCDC scans out the new frame.
Definition at line 768 of file main.c.
References display_flush(), display_full_rect(), k_display_refresh_quality, and s_display.
Referenced by cm_poll_touch(), and main().
|
static |
Emit a byte run on the SCI8 console.
Definition at line 353 of file main.c.
References ra8_board_uart_console_write().
Referenced by cm_print_banner(), cm_print_hex(), cm_print_uint(), and main().
|
static |
Print the deterministic boot banner (page-1 framebuffer hash).
Definition at line 881 of file main.c.
References cm_framebuffer_hash(), cm_print(), cm_print_hex(), cm_print_uint(), k_cm_fb_h, k_cm_fb_w, k_cm_msg_colon, k_cm_msg_dim, k_cm_msg_ok, k_cm_msg_page, k_cm_msg_pre, k_cm_msg_tiled, k_cm_msg_x, s_page_count, and s_tiled.
Referenced by main().
|
static |
Print a 32-bit value as 8 upper-case hex digits.
Definition at line 359 of file main.c.
References cm_print(), k_cm_dec_ten, k_cm_hex_nibbles, k_cm_nibble_bits, and k_cm_nibble_mask.
Referenced by cm_print_banner().
|
static |
Print a small unsigned integer in decimal.
Definition at line 371 of file main.c.
References cm_print(), and k_cm_dec_ten.
Referenced by cm_print_banner().
|
static |
Read callback over the resident archive buffer.
Definition at line 586 of file main.c.
References cm_src_t::d, memcpy(), and cm_src_t::n.
Referenced by cm_open_comic().
|
static |
Render the whole reader screen: letterbox, page, and optional chrome.
Definition at line 757 of file main.c.
References cm_draw_page(), cm_draw_progress_bar(), cm_draw_status_bar(), k_cm_col_letterbox, ra8_gfx_clear(), and s_chrome_on.
Referenced by cm_poll_touch(), and main().
|
static |
Format a small unsigned into a caller ASCII buffer, NUL-terminated.
| [in] | value | Value to format (0 .. 9999999999). |
| [out] | buf | Destination (>= 2 bytes, holds the digits + NUL). |
| [in] | cap | Capacity of buf in bytes (>= 2). |
| count | Digits emitted (>= 1). |
buf holds cap writable bytes. cap >= 2. buf is NUL-terminated within cap. Definition at line 403 of file main.c.
References k_cm_dec_ten.
Referenced by cm_draw_status_bar().
|
static |
Classify a panel touch into a navigation zone.
| [in] | x | Panel X (0 .. width-1). |
| [in] | y | Panel Y (0 .. height-1). |
| k_cm_zone_prev | Left third. |
| k_cm_zone_next | Right third. |
| k_cm_zone_chrome | Center column, top half. |
| k_cm_zone_none | Center column, bottom half. |
Definition at line 793 of file main.c.
References k_cm_fb_h, k_cm_fb_w, k_cm_halves, k_cm_thirds, k_cm_zone_chrome, k_cm_zone_next, k_cm_zone_none, and k_cm_zone_prev.
Referenced by cm_handle_tap().
| void main | ( | void | ) |
App entry: bring up the panel, open the comic, render + poll taps.
The application entry point Reset_Handler hands control to.
Definition at line 910 of file main.c.
References cm_bringup_clocks(), cm_bringup_panel(), cm_bringup_touch(), cm_comic_tiled_selfcheck(), cm_open_comic(), cm_panic_halt(), cm_poll_touch(), cm_present(), cm_print(), cm_print_banner(), cm_render(), k_cm_frame_ms, k_cm_led_every, k_cm_msg_boot, k_cm_msg_cerr, k_ra8_board_led_blue, ra8_board_led_toggle(), ra8_delay_ms(), s_loop_ticks, and s_tiled.
| RA8_BOARD_PANEL_FRAMEBUFFER | ( | s_framebuffer | ) |
References s_framebuffer.
|
static |
Display PAL config – LCD/GLCDC backend over the SDRAM buffer.
Passed into display_init to bring up the 1024x600 panel.
Definition at line 523 of file main.c.
Referenced by cm_bringup_panel().
|
static |
|
static |
|
static |
Banner numeric-field separator (SCI8).
Definition at line 314 of file main.c.
Referenced by cm_print_banner().
|
static |
Banner dimension separator (SCI8).
Definition at line 306 of file main.c.
Referenced by cm_print_banner().
|
static |
|
static |
Banner page + crc separator (SCI8).
Definition at line 310 of file main.c.
Referenced by cm_print_banner().
|
static |
Deterministic banner prefix (SCI8).
Definition at line 304 of file main.c.
Referenced by cm_print_banner().
|
static |
Banner oversized-page tile self-check field prefix (SCI8, #344).
Definition at line 312 of file main.c.
Referenced by cm_print_banner().
|
static |
Banner width-height separator (SCI8).
Definition at line 308 of file main.c.
Referenced by cm_print_banner().
|
static |
|
static |
"Page " status-bar prefix.
Definition at line 295 of file main.c.
Referenced by cm_draw_status_bar().
|
static |
Reader title shown in the status bar.
Definition at line 293 of file main.c.
Referenced by cm_draw_status_bar().
|
static |
Whether the status / progress chrome bands are drawn.
Toggled by a center-top tap.
Definition at line 270 of file main.c.
Referenced by cm_handle_tap(), and cm_render().
|
static |
The open comic reader, kept open for the app lifetime.
Populated by comic_open; never closed while running.
|
static |
Display PAL handle returned by display_init.
All PAL flushes take this handle.
|
static |
Mutable copy of the framebuffer descriptor (populated at boot).
Mirrors the backend-reported geometry for ra8_gfx binding.
|
static |
Zero-heap bump arena in SDRAM backing the PNG page decode.
Reset on every ra8_img_decode_blit call (decode-on-demand).
Definition at line 180 of file main.c.
Referenced by cm_draw_page(), ec_render_cover_or_halt(), ef_decode_and_hash(), and main().
|
static |
|
static |
Caller name arena handed to comic_open.
Backs the sorted page-name index.
|
static |
Current page index (0-based) shown on the panel.
Mutated by tap navigation; drives the page decode + chrome.
|
static |
Total page count parsed from the archive (>= 1).
Cached from comic_page_count at open.
Definition at line 260 of file main.c.
Referenced by cm_draw_progress_bar(), cm_draw_status_bar(), cm_handle_tap(), cm_open_comic(), and cm_print_banner().
|
static |
One page's extracted encoded image bytes (SDRAM scratch).
Overwritten by comic_page_read on each turn.
|
static |
Caller page-index storage handed to comic_open.
Out-lives s_comic and every read from it.
|
static |
Archive source bound into comic_open (lives for the run).
The read callback cm_read dereferences it every extract.
|
static |
Result of the #344 oversized-page tile self-check.
Populated once in main (before the banner) by cm_comic_tiled_selfcheck; read by cm_print_banner.
Definition at line 346 of file main.c.
Referenced by cm_print_banner(), and main().
|
static |
Debounce: true while a contact is held (fire once per press).
Edge-detects a fresh press in cm_poll_touch.
Definition at line 280 of file main.c.
Referenced by cm_poll_touch(), and er_poll_touch().