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

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"
Include dependency graph for main.c:

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_ts_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.

Detailed Description

Viewable page-turn comic reader – baked CBZ decoded to the 1024x600 GLCDC panel, tap-zone navigation (ra8_emulator / emulator-viewable).

Tag
[Ring 7 / App] {World: NS}

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:

  • the current page image, aspect-fit to the content region;
  • a top status bar (title, Page N of M, battery percent);
  • a bottom progress bar (filled fraction = read position).

Navigation is discrete tap zones (ra8_emulator --click / --touch-seq / window taps – never a swipe/drag, which the GT911 model does not provide):

  • tap the RIGHT third -> next page;
  • tap the LEFT third -> previous page;
  • tap the CENTER-top -> toggle the chrome bands.

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

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ cm_color_t

enum cm_color_t : uint32_t

Reader palette (0x00RRGGBB, packed to RGB565 by ra8_gfx).

Enumerator
k_cm_col_letterbox 

Dark fill behind an aspect-fit page.

k_cm_col_bar_bg 

Status / progress band fill.

k_cm_col_bar_fg 

Primary band text.

k_cm_col_bar_muted 

Secondary band text.

k_cm_col_track 

Progress-track (unfilled).

k_cm_col_fill 

Progress-fill (accent).

Definition at line 95 of file main.c.

◆ cm_fb_dim_t

enum cm_fb_dim_t : uint16_t

Panel framebuffer dimensions, sourced from the BSP panel descriptor.

Enumerator
k_cm_fb_w 

Framebuffer width (pixels).

k_cm_fb_h 

Framebuffer height (pixels).

Definition at line 69 of file main.c.

◆ cm_layout_t

enum cm_layout_t : uint16_t

Chrome-band and pacing metrics (pixels / milliseconds).

Enumerator
k_cm_settle_ms 

PLL / SDRAM / panel power-on settle.

k_cm_frame_ms 

Input-poll period (ms).

k_cm_led_every 

Heartbeat-LED toggle sub-cadence.

k_cm_statusbar_h 

Top status-bar band height.

k_cm_progress_h 

Bottom progress band height.

k_cm_text_pad 

Text inset inside a band.

k_cm_glyph_h 

Bundled 8x16 font cell height.

k_cm_glyph_w 

Bundled 8x16 font cell width.

k_cm_track_inset 

Progress-track inset from the band edge.

k_cm_track_h 

Progress-track thickness.

Definition at line 78 of file main.c.

◆ cm_reader_cfg_t

enum cm_reader_cfg_t : uint32_t

Reader capacities, demo battery level, and hash constants.

Enumerator
k_cm_uart_baud 

SCI8 console baud.

k_cm_arena_bytes 

SDRAM PNG-decode scratch.

k_cm_page_cap 

Comic page-index capacity.

k_cm_name_cap 

Comic name-arena bytes.

k_cm_pagebuf 

Encoded page-image scratch.

k_cm_batt_pct 

Demo battery percent.

k_cm_fnv_offset 

FNV-1a-32 offset basis.

k_cm_fnv_prime 

FNV-1a-32 prime.

k_cm_hex_nibbles 

Hex digits in a 32-bit value.

k_cm_nibble_bits 

Bits per hex nibble.

k_cm_nibble_mask 

Low-nibble mask.

k_cm_dec_ten 

Decimal base / digit split.

k_cm_pos_cap 

"Page N of M" scratch size.

k_cm_batt_cap 

"NN%" scratch size.

Definition at line 108 of file main.c.

◆ cm_touch_bus_cfg_t

enum cm_touch_bus_cfg_t : uint32_t

Clocking for the app-owned GT911 I2C bus.

Enumerator
k_cm_touch_bus_hz 

Fast-mode I2C clock.

k_cm_touch_pclka_hz 

IIC_B clock-source rate.

Definition at line 157 of file main.c.

◆ cm_touch_cfg_t

enum cm_touch_cfg_t : uint8_t

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

Enumerator
k_cm_touch_max_points 

One contact = one tap.

Definition at line 149 of file main.c.

◆ cm_zone_div_t

enum cm_zone_div_t : uint8_t

Tap-zone divisors (thirds / halves of the panel).

Enumerator
k_cm_thirds 

Left / center / right column split.

k_cm_halves 

Top / bottom split for the center.

Definition at line 140 of file main.c.

◆ cm_zone_t

enum cm_zone_t : uint8_t

Tap-zone classification of a panel touch.

Enumerator
k_cm_zone_none 

No actionable zone.

k_cm_zone_prev 

Left third -> previous page.

k_cm_zone_next 

Right third -> next page.

k_cm_zone_chrome 

Center-top -> toggle chrome.

Definition at line 129 of file main.c.

Function Documentation

◆ cm_append()

void cm_append ( char * dst,
uint32_t cap,
uint32_t * cursor,
const char * src )
static

Append a NUL-terminated string into a bounded buffer at *cursor.

Parameters
[in,out]dstDestination buffer (NUL-terminated on return).
[in]capCapacity of dst in bytes.
[in,out]cursorCurrent write offset; advanced past the copy.
[in]srcSource string (NUL-terminated).
Precondition
dst holds cap writable bytes and *cursor < cap.
src is a valid NUL-terminated string.
Postcondition
dst[*cursor] == '\0' and *cursor <= cap - 1.
No write occurs past cap - 1.
Note
Not thread-safe on a shared buffer.
Since
0.1.0

Definition at line 439 of file main.c.

Referenced by cm_draw_status_bar().

◆ cm_bringup_clocks()

void cm_bringup_clocks ( void )
static

Bring up clocks, MSTP, SysTick, the console, and both board LEDs.

Precondition
Reset_Handler ran .data/.bss init; IRQs are globally disabled.
ra8_cgc_init has not yet run.
Postcondition
Clocks, MSTP, ra8_time, console, and LEDs are initialised.
Global IRQs are enabled.
Note
Single-shot; not thread-safe. Halts on any failure.
Since
0.1.0

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

◆ cm_bringup_panel()

void cm_bringup_panel ( void )
static

Bring up SDRAM + the GLCDC panel and bind ra8_gfx to the framebuffer.

Precondition
cm_bringup_clocks has run; IRQs are enabled.
s_framebuffer is reachable in SDRAM.
Postcondition
SDRAM is up and the GLCDC scans out s_framebuffer.
s_display is non-NULL and ra8_gfx draws into the panel.
Note
Single-shot; not thread-safe. Halts on any failure.
Since
0.1.0

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

◆ cm_bringup_touch()

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

Precondition
cm_bringup_clocks has run (IIC_B clock + MSTP up).
None.
Postcondition
On success the GT911 is configured for polled reads.
On failure touch input is simply unavailable (no panic).
Note
Single-shot; not thread-safe.
Since
0.1.0

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

◆ cm_draw_page()

bool cm_draw_page ( void )
static

Decode the current page and aspect-fit it into the content region.

Returns
Whether the page decoded and blitted.
Return values
trues_page was drawn into the content box.
falseExtract or decode failed (box left as letterbox).
Precondition
ra8_gfx is bound; s_comic is open; s_page < s_page_count.
The content region has been cleared to the letterbox colour.
Postcondition
On true the page image occupies the content region.
s_img_arena is reset to empty on every return.
Note
Not thread-safe.
Since
0.1.0

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

◆ cm_draw_progress_bar()

void cm_draw_progress_bar ( void )
static

Draw the bottom progress bar (filled fraction = read position).

Precondition
ra8_gfx is bound; s_page_count >= 1.
s_page < s_page_count.
Postcondition
The progress band holds the track + accent fill.
No reader state is mutated.
Note
Not thread-safe.
Since
0.1.0

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

◆ cm_draw_status_bar()

void cm_draw_status_bar ( void )
static

Draw the top status bar: title, Page N of M, battery percent.

Precondition
ra8_gfx is bound; s_page_count >= 1.
s_page < s_page_count.
Postcondition
The status band holds the title / position / battery text.
No reader state is mutated.
Note
Not thread-safe.
Since
0.1.0

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

◆ cm_framebuffer_hash()

uint32_t cm_framebuffer_hash ( void )
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().

◆ cm_handle_tap()

bool cm_handle_tap ( int32_t x,
int32_t y )
static

Apply a tap: turn a page or toggle the chrome.

Parameters
[in]xPanel X of the tap.
[in]yPanel Y of the tap.
Returns
Whether the tap changed what is shown (caller must re-render).
Return values
trueA page turned or the chrome toggled.
falseThe tap was a no-op (already at an end, or dead zone).
Precondition
s_comic is open; s_page_count >= 1.
0 <= x < k_cm_fb_w and 0 <= y < k_cm_fb_h.
Postcondition
On true s_page or s_chrome_on reflects the tap.
On false no state is mutated.
Note
Not thread-safe.
Since
0.1.0

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

◆ cm_open_comic()

bool cm_open_comic ( void )
static

Open the baked CBZ once and cache its page count.

Returns
Whether the archive opened with at least one page.
Return values
trues_comic is open and s_page_count is set (>= 1).
falseThe archive failed to open.
Precondition
k_comic_cbz holds k_comic_cbz_len readable bytes.
s_comic is zero-initialised.
Postcondition
On true the reader stays open for the app lifetime.
On false s_comic is left in the unopened state.
Note
Not thread-safe.
Since
0.1.0

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

◆ cm_panic_halt()

void cm_panic_halt ( void )
static

Halt forever with the red board LED on (fatal init error).

Returns
Never returns.
Precondition
None.
None.
Postcondition
Function never returns; CPU parked in WFI.
Red LED is on.
Note
IRQ-safe.
Since
0.1.0

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

◆ cm_poll_touch()

void cm_poll_touch ( void )
static

Poll the GT911 once and dispatch a tap on a fresh press.

Precondition
ra8_gfx bound; s_display valid; s_comic open.
None.
Postcondition
On a fresh press that changes state, the panel is re-rendered + flushed.
s_was_touching tracks the contact state.
Note
Not thread-safe.
Since
0.1.0

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

◆ cm_present()

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

◆ cm_print()

void cm_print ( const uint8_t * msg,
uint32_t len )
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().

◆ cm_print_banner()

void cm_print_banner ( void )
static

Print the deterministic boot banner (page-1 framebuffer hash).

Precondition
cm_render + cm_present have drawn page 1 to the framebuffer.
The console is initialised.
Postcondition
One banner line is emitted over SCI8.
No reader state is mutated.
Note
Not thread-safe.
Since
0.1.0

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

◆ cm_print_hex()

void cm_print_hex ( uint32_t value)
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().

◆ cm_print_uint()

void cm_print_uint ( uint32_t value)
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().

◆ cm_read()

size_t cm_read ( void * ctx,
uint64_t off,
void * buf,
size_t len )
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().

◆ cm_render()

void cm_render ( void )
static

Render the whole reader screen: letterbox, page, and optional chrome.

Precondition
ra8_gfx is bound; s_comic is open.
s_page < s_page_count.
Postcondition
The framebuffer holds the current page (+ chrome when enabled).
No navigation state is mutated.
Note
Not thread-safe.
Since
0.1.0

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

◆ cm_utoa()

uint32_t cm_utoa ( uint32_t value,
char * buf,
uint32_t cap )
static

Format a small unsigned into a caller ASCII buffer, NUL-terminated.

Parameters
[in]valueValue to format (0 .. 9999999999).
[out]bufDestination (>= 2 bytes, holds the digits + NUL).
[in]capCapacity of buf in bytes (>= 2).
Returns
The number of digit characters written (excluding the NUL).
Return values
countDigits emitted (>= 1).
Precondition
buf holds cap writable bytes.
cap >= 2.
Postcondition
buf is NUL-terminated within cap.
The return value equals the digit length.
Note
Pure formatting helper; not thread-safe on shared buffers.
Since
0.1.0

Definition at line 403 of file main.c.

References k_cm_dec_ten.

Referenced by cm_draw_status_bar().

◆ cm_zone_at()

cm_zone_t cm_zone_at ( int32_t x,
int32_t y )
static

Classify a panel touch into a navigation zone.

Parameters
[in]xPanel X (0 .. width-1).
[in]yPanel Y (0 .. height-1).
Returns
The cm_zone_t the coordinate falls in.
Return values
k_cm_zone_prevLeft third.
k_cm_zone_nextRight third.
k_cm_zone_chromeCenter column, top half.
k_cm_zone_noneCenter column, bottom half.
Precondition
0 <= x < k_cm_fb_w.
0 <= y < k_cm_fb_h.
Postcondition
No state is mutated (pure).
Exactly one zone is returned.
Note
Pure; thread-safe.
Since
0.1.0

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

◆ main()

void main ( void )

App entry: bring up the panel, open the comic, render + poll taps.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler copied .data and zeroed .bss.
SystemInit set VTOR / FPU / priority grouping.
Postcondition
The reader loop runs forever, redrawing on each tap.
A page-1 banner is emitted once after the first render.
Since
0.1.0

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

RA8_BOARD_PANEL_FRAMEBUFFER ( s_framebuffer )

References s_framebuffer.

Variable Documentation

◆ k_cm_display_cfg

const display_cfg_t k_cm_display_cfg
static
Initial value:
= {
.framebuffer = s_framebuffer,
.framebuffer_bytes = sizeof(s_framebuffer),
.width_px = (uint16_t)k_cm_fb_w,
.height_px = (uint16_t)k_cm_fb_h,
.panel_timing = &s_ra8_panel_ek_ra8d2_timing,
}
static uint16_t s_framebuffer[(size_t) k_panel_height_px *(size_t) k_panel_width_px]
1024x600 RGB565 framebuffer in external SDRAM (GLCDC scans this).
Definition main.c:67
@ k_cm_fb_h
Framebuffer height (pixels).
Definition main.c:71
@ k_cm_fb_w
Framebuffer width (pixels).
Definition main.c:70
@ k_display_pixfmt_rgb565
16 bpp, 5/6/5 packed.
const display_backend_iface_t k_display_backend_lcd_ra8_glcdc
LCD backend vtable – pass its address through display_cfg_t.iface to drive the EK-RA8D2 panel.
static const ra8_glcdc_timing_t s_ra8_panel_ek_ra8d2_timing
EK-RA8D2 ER-TFT070-6 RGB timing for ra8_glcdc_init / the LCD backend.

Display PAL config – LCD/GLCDC backend over the SDRAM buffer.

Passed into display_init to bring up the 1024x600 panel.

Note
Immutable; references s_framebuffer.
Warning
The framebuffer must out-live the PAL handle.
Since
0.1.0

Definition at line 523 of file main.c.

Referenced by cm_bringup_panel().

◆ k_cm_msg_boot

const uint8_t k_cm_msg_boot[] = "ereader-comic: boot\r\n"
static

Console boot banner literal (SCI8).

Definition at line 300 of file main.c.

Referenced by main().

◆ k_cm_msg_cerr

const uint8_t k_cm_msg_cerr[] = "ereader-comic: FAIL comic\r\n"
static

Console comic-open failure literal (SCI8).

Definition at line 302 of file main.c.

Referenced by main().

◆ k_cm_msg_colon

const uint8_t k_cm_msg_colon[] = ":"
static

Banner numeric-field separator (SCI8).

Definition at line 314 of file main.c.

Referenced by cm_print_banner().

◆ k_cm_msg_dim

const uint8_t k_cm_msg_dim[] = " "
static

Banner dimension separator (SCI8).

Definition at line 306 of file main.c.

Referenced by cm_print_banner().

◆ k_cm_msg_ok

const uint8_t k_cm_msg_ok[] = " ok\r\n"
static

Banner trailer (SCI8).

Definition at line 316 of file main.c.

Referenced by cm_print_banner().

◆ k_cm_msg_page

const uint8_t k_cm_msg_page[] = " page=1 crc="
static

Banner page + crc separator (SCI8).

Definition at line 310 of file main.c.

Referenced by cm_print_banner().

◆ k_cm_msg_pre

const uint8_t k_cm_msg_pre[] = "ereader-comic: pages="
static

Deterministic banner prefix (SCI8).

Definition at line 304 of file main.c.

Referenced by cm_print_banner().

◆ k_cm_msg_tiled

const uint8_t k_cm_msg_tiled[] = " tiled="
static

Banner oversized-page tile self-check field prefix (SCI8, #344).

Definition at line 312 of file main.c.

Referenced by cm_print_banner().

◆ k_cm_msg_x

const uint8_t k_cm_msg_x[] = "x"
static

Banner width-height separator (SCI8).

Definition at line 308 of file main.c.

Referenced by cm_print_banner().

◆ k_cm_pos_infix

const char k_cm_pos_infix[] = " of "
static

" of " status-bar infix.

Definition at line 297 of file main.c.

Referenced by cm_draw_status_bar().

◆ k_cm_pos_prefix

const char k_cm_pos_prefix[] = "Page "
static

"Page " status-bar prefix.

Definition at line 295 of file main.c.

Referenced by cm_draw_status_bar().

◆ k_cm_title

const char k_cm_title[] = "COMIC READER"
static

Reader title shown in the status bar.

Definition at line 293 of file main.c.

Referenced by cm_draw_status_bar().

◆ s_chrome_on

bool s_chrome_on = true
static

Whether the status / progress chrome bands are drawn.

Toggled by a center-top tap.

Note
Defaults to shown.
Warning
Not thread-safe.
Since
0.1.0

Definition at line 270 of file main.c.

Referenced by cm_handle_tap(), and cm_render().

◆ s_comic

comic_t s_comic
static

The open comic reader, kept open for the app lifetime.

Populated by comic_open; never closed while running.

Note
File-scope (large; not on the stack).
Warning
Single-threaded access only.
Since
0.1.0

Definition at line 200 of file main.c.

◆ s_display

display_handle_t* s_display = nullptr
static

Display PAL handle returned by display_init.

All PAL flushes take this handle.

Note
NULL until cm_bringup_panel succeeds.
Warning
Dereferenced only after a successful init.
Since
0.1.0

Definition at line 230 of file main.c.

◆ s_fb

display_fb_t s_fb
static

Mutable copy of the framebuffer descriptor (populated at boot).

Mirrors the backend-reported geometry for ra8_gfx binding.

Note
Written once during bring-up.
Warning
Read-only after cm_bringup_panel.
Since
0.1.0

Definition at line 240 of file main.c.

◆ s_img_arena

uint8_t s_img_arena[k_cm_arena_bytes]
static

Zero-heap bump arena in SDRAM backing the PNG page decode.

Reset on every ra8_img_decode_blit call (decode-on-demand).

Note
Single-threaded reader; not reentrant.
Warning
Sized for one near-panel page decode at a time.
Since
0.1.0

Definition at line 180 of file main.c.

Referenced by cm_draw_page(), ec_render_cover_or_halt(), ef_decode_and_hash(), and main().

◆ s_loop_ticks

uint32_t s_loop_ticks = 0U
static

Free-running main-loop counter (HIL liveness / LED sub-cadence).

Increments once per loop iteration.

Note
Wraps at 2^32.
Warning
Not thread-safe.
Since
0.1.0

Definition at line 290 of file main.c.

Referenced by main().

◆ s_names

char s_names[k_cm_name_cap]
static

Caller name arena handed to comic_open.

Backs the sorted page-name index.

Note
Bounded by k_cm_name_cap.
Warning
Do not resize while the comic is open.
Since
0.1.0

Definition at line 220 of file main.c.

◆ s_page

uint32_t s_page = 0U
static

Current page index (0-based) shown on the panel.

Mutated by tap navigation; drives the page decode + chrome.

Note
Always < s_page_count.
Warning
Not thread-safe.
Since
0.1.0

Definition at line 250 of file main.c.

◆ s_page_count

uint32_t s_page_count = 1U
static

Total page count parsed from the archive (>= 1).

Cached from comic_page_count at open.

Note
Immutable after cm_open_comic.
Warning
Read-only after open.
Since
0.1.0

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

◆ s_pagebuf

uint8_t s_pagebuf[k_cm_pagebuf]
static

One page's extracted encoded image bytes (SDRAM scratch).

Overwritten by comic_page_read on each turn.

Note
Holds one page at a time.
Warning
Reused across page turns.
Since
0.1.0

Definition at line 190 of file main.c.

◆ s_pages

comic_page_t s_pages[k_cm_page_cap]
static

Caller page-index storage handed to comic_open.

Out-lives s_comic and every read from it.

Note
Bounded by k_cm_page_cap.
Warning
Do not resize while the comic is open.
Since
0.1.0

Definition at line 210 of file main.c.

◆ s_src

cm_src_t s_src
static

Archive source bound into comic_open (lives for the run).

The read callback cm_read dereferences it every extract.

Note
File-scope so it out-lives the open comic.
Warning
Read-only after cm_open_comic.
Since
0.1.0

Definition at line 335 of file main.c.

◆ s_tiled

cm_tiled_result_t s_tiled
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.

Note
File-scope so the banner helper can read it.
Warning
Written only during boot.
Since
0.1.0

Definition at line 346 of file main.c.

Referenced by cm_print_banner(), and main().

◆ s_was_touching

bool s_was_touching = false
static

Debounce: true while a contact is held (fire once per press).

Edge-detects a fresh press in cm_poll_touch.

Note
Not thread-safe.
Warning
Reset only by the poll path.
Since
0.1.0

Definition at line 280 of file main.c.

Referenced by cm_poll_touch(), and er_poll_touch().