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

Viewable continuous vertical-scroll (longstrip / manhwa) reader (#289). More...

#include <stddef.h>
#include <stdint.h>
#include "jof.h"
#include "longstrip.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_check.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_io_i2c_bus.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_panel.h"
#include "ra8_panel_timing.h"
#include "ra8_sdramc.h"
#include "ra8_tile_cache.h"
#include "ra8_time.h"
#include "ra8_touch.h"
Include dependency graph for main.c:

Go to the source code of this file.

Data Structures

struct  ls_paint_ctx_t
 Geometry the procedural band painter needs (tile-cache decode ctx). More...

Enumerations

enum  ls_geom_t : uint16_t {
  k_ls_view_w = k_panel_width_px ,
  k_ls_view_h = k_panel_height_px ,
  k_ls_band_h = 280U ,
  k_ls_bands = 16U ,
  k_ls_status_h = 40U ,
  k_ls_rail_w = 12U ,
  k_ls_text_pad = 16U ,
  k_ls_glyph_w = 8U ,
  k_ls_glyph_h = 16U ,
  k_ls_settle_ms = 500U ,
  k_ls_frame_ms = 20U ,
  k_ls_led_every = 16U
}
 Panel, chrome and strip geometry in pixels. More...
enum  ls_size_t : uint32_t {
  k_ls_canvas_w = (uint32_t)k_panel_width_px ,
  k_ls_canvas_h = (uint32_t)k_ls_bands * (uint32_t)k_ls_band_h ,
  k_ls_bpp = 3U ,
  k_ls_band_bytes = (uint32_t)k_panel_width_px * (uint32_t)k_ls_band_h * 3U ,
  k_ls_cells = 6U ,
  k_ls_buckets = 16U ,
  k_ls_image_id = 1U ,
  k_ls_scroll_page
}
 32-bit strip + cache + scroll magnitudes. More...
enum  ls_atlas_t : uint32_t {
  k_ls_hdr_bytes = 32U ,
  k_ls_ftr_bytes = 16U ,
  k_ls_idx_entry = 8U ,
  k_ls_ftr_magic_off = 12U ,
  k_ls_atlas_total ,
  k_ls_byte_mask = 0xFFU ,
  k_ls_shift_8 = 8U ,
  k_ls_shift_16 = 16U ,
  k_ls_shift_24 = 24U
}
 JOF metadata-only atlas layout (procedural bands -> no pixel region). More...
enum  ls_paint_t : uint32_t {
  k_ls_grad_lo = 55U ,
  k_ls_grad_span = 45U ,
  k_ls_pct_full = 100U ,
  k_ls_seam_h = 6U ,
  k_ls_seam_level = 0xF0U ,
  k_ls_palette_size = 16U
}
 Procedural band-painter constants. More...
enum  ls_zone_t : uint16_t {
  k_ls_zone_top = (uint16_t)(k_panel_height_px / 3U) ,
  k_ls_zone_mid = (uint16_t)((k_panel_height_px * 2U) / 3U)
}
 Vertical tap-zone thresholds (thirds of the panel), pixels. More...
enum  ls_color_t : uint32_t {
  k_ls_col_bg = 0x0A0A12U ,
  k_ls_col_status_bg = 0x101826U ,
  k_ls_col_text = 0xF0F4FFU ,
  k_ls_col_text_dim = 0x8FA0C0U ,
  k_ls_col_rail_bg = 0x263042U ,
  k_ls_col_rail_thumb = 0xF5C542U
}
 Chrome palette, 0x00RRGGBB. More...
enum  ls_rail_t : int32_t { k_ls_rail_min_thumb = 32 }
 Scroll-rail thumb geometry, pixels. More...
enum  ls_console_t : uint32_t {
  k_ls_uart_baud = 115200U ,
  k_ls_fnv_offset = 2166136261U ,
  k_ls_fnv_prime = 16777619U ,
  k_ls_hex_nibbles = 8U ,
  k_ls_nibble_bits = 4U ,
  k_ls_nibble_mask = 0x0FU ,
  k_ls_dec_ten = 10U ,
  k_ls_dec_digits = 10U
}
 Console baud + FNV-1a-32 + decimal/hex print knobs. More...
enum  ls_touch_cfg_t : uint8_t { k_ls_touch_max_points = 1U }
 GT911 touch-controller wiring (IIC_B channel 0, polled). More...

Functions

static void ls_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void ls_print_hex (uint32_t value)
 Print a 32-bit value as 8 upper-case hex digits.
static void ls_print_uint (uint32_t value)
 Print a small unsigned integer in decimal on the console.
static const char * ls_utoa (char *buf, uint32_t value)
 Format an unsigned integer as a NUL-terminated ASCII decimal string.
static void app_panic_halt (void)
 Halt forever with the red board LED on (visual sign of fatal init).
static void app_bringup_clocks (void)
 Bring up clocks, MSTP, SysTick, the SCI8 console and both LEDs.
static void app_bringup_panel (void)
 Bring up external SDRAM + the GLCDC panel, then cache the FB.
static void app_bringup_gfx (void)
 Bind ra8_gfx to the panel framebuffer.
static void app_bringup_touch (void)
 Open the GT911 touch controller (best-effort, polled; non-fatal).
static void ls_put_u16 (uint8_t *p, uint16_t v)
 Write a little-endian u16 at p.
static void ls_put_u32 (uint8_t *p, uint32_t v)
 Write a little-endian u32 at p.
static uint32_t ls_build_atlas (void)
 Build the metadata-only JOF band-tile atlas; return its byte length.
static uint8_t ls_scale_u8 (uint8_t v, uint32_t pct)
 Scale an 8-bit channel by a 0..100 percentage (saturating at 255).
static void ls_row_color (uint32_t base, uint32_t r, uint32_t th, uint8_t *rgb)
 Compute the RGB888 colour of one strip row inside a band.
static ra8_err_t ls_band_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: paint band key->tile_y procedurally.
static ra8_err_t ls_blit (void *ctx, const uint8_t *pixels, uint16_t src_w, uint16_t src_h, uint8_t bpp, int32_t dst_x, int32_t dst_y)
 Longstrip blit sink -> ra8_gfx software blit (RGB888 -> RGB565).
static void ls_open_strip (uint32_t total)
 Wire the memstore/painter/cache and open the strip; halt on failure.
static int32_t ls_text (int32_t x, int32_t y, const char *str, uint32_t color)
 Draw a text run in the bundled font; return the next x column.
static void ls_draw_status (void)
 Draw the status bar overlay: wordmark + band + scroll-position text.
static void ls_draw_rail (void)
 Draw the right-edge scroll rail overlay (track + proportional thumb).
static void ls_redraw (void)
 Repaint the whole panel: strip bands, then the chrome overlays.
static void ls_present (void)
 Present the framebuffer to the panel (clean full refresh).
static uint32_t ls_hash_fb (void)
 Fold an FNV-1a-32 over the whole panel framebuffer.
static void ls_emit_banner (void)
 Emit the deterministic boot banner (bands, viewport, scroll, FB CRC).
static void ls_apply_nav (int32_t delta, bool toggle)
 Apply one navigation action, redrawing + presenting if state changed.
static void ls_handle_tap (int32_t y)
 Map a tap Y coordinate to a navigation action (tap-zone hit-test).
static void ls_poll_touch (void)
 Poll the touch controller; dispatch one tap per delivered GT911 frame.
static void ls_poll_buttons (void)
 Poll SW1/SW2 and page up/down on a fresh press (button fallback).
void main (void)
 App entry: bring up the panel, build the strip, run the reader loop.

Variables

static const char *const s_tag = "ereader_longstrip"
 Component tag for RA8_CHECK_* log lines.
static const uint32_t k_ls_palette [k_ls_palette_size]
 Vivid 16-hue band palette (0x00RRGGBB) – distinct so scroll is obvious.
static uint16_t s_framebuffer [(size_t) k_ls_view_h *(size_t) k_ls_view_w]
 RGB565 panel framebuffer in external SDRAM, AXI-burst aligned.
static uint8_t s_cells [(size_t) k_ls_cells *(size_t) k_ls_band_bytes]
 Tile-cache cell storage in SDRAM (one decoded band per cell).
static uint8_t s_atlas [k_ls_atlas_total]
 Metadata-only JOF atlas backing (header + index + footer).
static ra8_tile_key_t s_keys [(size_t) k_ls_cells]
 Cache key storage.
static ra8_tile_dims_t s_dims [(size_t) k_ls_cells]
 Cache dim storage.
static ra8_keycache_cell_t s_meta [(size_t) k_ls_cells]
 Cache link metadata.
static int32_t s_buckets [(size_t) k_ls_buckets]
 Cache hash buckets.
static jof_memstore_t s_store
 Atlas backing-read seam.
static ra8_tile_cache_t s_cache
 Band cache (procedural decode).
static longstrip_t s_strip
 Opened longstrip scroll state.
static ls_paint_ctx_t s_paint
 Painter context bound as the tile cache's decode ctx.
static const display_cfg_t k_ls_display_cfg
 Display-PAL config: LCD/GLCDC backend over the SDRAM framebuffer.
static display_handle_ts_display = nullptr
 PAL handle returned by display_init.
static display_fb_t s_fb
 Mutable copy of the FB descriptor populated at boot.
static bool s_chrome = true
 True while the status bar + scroll rail chrome is shown.
static uint16_t s_last_skipped = 0U
 Skipped-band count from the last render (must stay 0: #289 contract).
static bool s_was_sw1 = false
 Edge-detect: was SW1 held on the previous button poll.
static bool s_was_sw2 = false
 Edge-detect: was SW2 held on the previous button poll.
volatile uint32_t g_ls_loop_ticks = 0U
 Free-running main-loop counter – HIL/liveness probe symbol.
volatile uint32_t g_ls_scroll_y = 0U
 Current scroll position (px) mirrored for --dump-sym telemetry.
volatile uint32_t g_ls_redraws = 0U
 Count of full redraws since boot – render-progress telemetry.
volatile uint32_t g_ls_frame_crc = 0U
 FNV-1a-32 over the panel FB at the boot banner (render fingerprint).
static const uint8_t k_msg_boot [] = "ereader-longstrip: boot\r\n"
 Boot / banner literals (SCI8).
static const uint8_t k_msg_pre [] = "ereader-longstrip: bands="
static const uint8_t k_msg_view [] = " view="
static const uint8_t k_msg_x [] = "x"
static const uint8_t k_msg_scroll [] = " scroll="
static const uint8_t k_msg_crc [] = " crc="
static const uint8_t k_msg_eol [] = "\r\n"

Detailed Description

Viewable continuous vertical-scroll (longstrip / manhwa) reader (#289).

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

The #289 continuous vertical-scroll engine (longstrip) made VIEWABLE on the stock EK-RA8D2 1024x600 GLCDC panel: the headless sibling scrolled a strip into a 160x120 scratch buffer and printed a CRC; this app binds the engine's band-composite blit sink to the LIVE panel framebuffer, so ra8_emulator's --view window (or a --ppm capture) shows the reader screen.

Pipeline: boot clocks/MSTP/SysTick/console/LEDs, bring up external SDRAM + the 1024x600 RGB565 GLCDC panel via ra8_display_pal (k_display_backend_lcd_ra8_glcdc), bind ra8_gfx to the panel FB, then build a tall colourful strip as a JOF band-tile atlas (jof, one full-width band column). Only the atlas header + index + footer are materialised (~176 bytes); each band's pixels are painted PROCEDURALLY on a cache miss (a vivid palette hue + a top->bottom brightness gradient + a white seam stripe at every band edge, so scrolling is obviously visible), which keeps boot instant and needs no multi-megabyte pixel buffer while still exercising the real streaming path: bands page through a deliberately small ra8_tile_cache (fewer cells than bands, so the LRU must evict – the #147 bounded-memory property) and longstrip_render composites the visible range into the panel FB through ra8_gfx_blit.

Navigation is discrete-tap only (the ra8_emulator GT911 model has no swipe/drag gesture, so this app needs zero ra8_emulator change): a tap in the BOTTOM third pages down, the TOP third pages up, the CENTRE third toggles the chrome (status bar + scroll rail); SW1/SW2 page down/up as a button fallback. A deterministic boot banner (band count, viewport, initial scroll, FNV-1a-32 over the panel FB) is emitted over SCI8 so the headless EIL / smoke gate still asserts a stable render, and g_ls_loop_ticks feeds the jlink liveness probe.

See also
longstrip.h The continuous vertical-scroll engine this drives.
Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ ls_atlas_t

enum ls_atlas_t : uint32_t

JOF metadata-only atlas layout (procedural bands -> no pixel region).

jof_parse reads only the header + footer and validates index_off + tiles*8 + 16 == total, never the pixel bytes, so the index is placed immediately after the header and the whole atlas is just header + index + footer. Band pixels are synthesised on demand by ls_band_decode, so no pixel region is stored.

Since
0.1.0
Enumerator
k_ls_hdr_bytes 

JOF header length.

k_ls_ftr_bytes 

JOF footer length.

k_ls_idx_entry 

Index-entry length (offset + len).

k_ls_ftr_magic_off 

Footer "JOFE" magic offset.

k_ls_atlas_total 

176-byte atlas length.

k_ls_byte_mask 

Low-byte mask.

k_ls_shift_8 

One-byte shift.

k_ls_shift_16 

Two-byte shift.

k_ls_shift_24 

Three-byte shift.

Definition at line 128 of file main.c.

◆ ls_color_t

enum ls_color_t : uint32_t

Chrome palette, 0x00RRGGBB.

Since
0.1.0
Enumerator
k_ls_col_bg 

Content backdrop (behind bands).

k_ls_col_status_bg 

Status-bar fill.

k_ls_col_text 

Status-bar primary text.

k_ls_col_text_dim 

Status-bar secondary text.

k_ls_col_rail_bg 

Scroll-rail track.

k_ls_col_rail_thumb 

Scroll-rail thumb (amber).

Definition at line 170 of file main.c.

◆ ls_console_t

enum ls_console_t : uint32_t

Console baud + FNV-1a-32 + decimal/hex print knobs.

Since
0.1.0
Enumerator
k_ls_uart_baud 

SCI8 console baud.

k_ls_fnv_offset 

FNV-1a-32 offset basis.

k_ls_fnv_prime 

FNV-1a-32 prime.

k_ls_hex_nibbles 

Hex digits in a 32-bit value.

k_ls_nibble_bits 

Bits per hex nibble.

k_ls_nibble_mask 

Low-nibble mask.

k_ls_dec_ten 

Decimal base / hex split.

k_ls_dec_digits 

Max decimal digits (u32).

Definition at line 193 of file main.c.

◆ ls_geom_t

enum ls_geom_t : uint16_t

Panel, chrome and strip geometry in pixels.

The viewport is the whole panel; the status bar and scroll rail are chrome OVERLAYS drawn on top of the strip, so toggling them off lets the strip fill the full 1024x600 panel.

Since
0.1.0
Enumerator
k_ls_view_w 

Viewport / strip width (== panel).

k_ls_view_h 

Viewport / strip-window height.

k_ls_band_h 

One band (JOF tile) height, pixels.

k_ls_bands 

Bands in the strip (16 palette hues).

k_ls_status_h 

Status-bar overlay band height.

k_ls_rail_w 

Scroll-rail overlay width, pixels.

k_ls_text_pad 

Status-bar left text inset.

k_ls_glyph_w 

Bundled font cell width.

k_ls_glyph_h 

Bundled font cell height.

k_ls_settle_ms 

PLL / SDRAM / panel-POR settle.

k_ls_frame_ms 

Input-poll period (ms).

k_ls_led_every 

Toggle heartbeat LED every Nth frame.

Definition at line 84 of file main.c.

◆ ls_paint_t

enum ls_paint_t : uint32_t

Procedural band-painter constants.

Since
0.1.0
Enumerator
k_ls_grad_lo 

Band-top brightness (percent of the hue).

k_ls_grad_span 

Top->bottom brightness gain (percent).

k_ls_pct_full 

Percentage denominator.

k_ls_seam_h 

White seam-stripe rows at each band top.

k_ls_seam_level 

Seam-stripe grey level (near white).

k_ls_palette_size 

Entries in the vivid band palette.

Definition at line 146 of file main.c.

◆ ls_rail_t

enum ls_rail_t : int32_t

Scroll-rail thumb geometry, pixels.

Since
0.1.0
Enumerator
k_ls_rail_min_thumb 

Minimum thumb height so it stays grabbable.

Definition at line 184 of file main.c.

◆ ls_size_t

enum ls_size_t : uint32_t

32-bit strip + cache + scroll magnitudes.

Since
0.1.0
Enumerator
k_ls_canvas_w 

Strip width, pixels.

k_ls_canvas_h 

4480 px.

k_ls_bpp 

RGB888 strip pixels.

k_ls_band_bytes 

One band payload, bytes.

k_ls_cells 

Tile-cache cells (< 16 bands -> LRU eviction).

k_ls_buckets 

Tile-cache hash buckets.

k_ls_image_id 

Tile-cache key namespace for this strip.

k_ls_scroll_page 

Page-scroll step (~90% of a viewport), pixels.

Definition at line 104 of file main.c.

◆ ls_touch_cfg_t

enum ls_touch_cfg_t : uint8_t

GT911 touch-controller wiring (IIC_B channel 0, polled).

ra8_emulator feeds --click / --touch-seq / window taps through this same ra8_touch -> I2C -> GT911 path unchanged.

Since
0.1.0
Enumerator
k_ls_touch_max_points 

One contact = one tap.

Definition at line 212 of file main.c.

◆ ls_zone_t

enum ls_zone_t : uint16_t

Vertical tap-zone thresholds (thirds of the panel), pixels.

Since
0.1.0
Enumerator
k_ls_zone_top 

y < this: up.

k_ls_zone_mid 

< this: chrome.

Definition at line 160 of file main.c.

Function Documentation

◆ app_bringup_clocks()

void app_bringup_clocks ( void )
static

◆ app_bringup_gfx()

void app_bringup_gfx ( void )
static

Bind ra8_gfx to the panel framebuffer.

Definition at line 452 of file main.c.

References app_panic_halt(), k_ra8_gfx_format_rgb565, k_ra8_ok, ra8_gfx_init(), and s_fb.

Referenced by main().

◆ app_bringup_panel()

void app_bringup_panel ( void )
static

Bring up external SDRAM + the GLCDC panel, then cache the FB.

Definition at line 437 of file main.c.

References app_panic_halt(), display_get_framebuffer(), display_init(), k_ls_display_cfg, k_ls_settle_ms, k_ra8_ok, ra8_delay_ms(), ra8_sdramc_init(), s_display, and s_fb.

Referenced by main().

◆ app_bringup_touch()

void app_bringup_touch ( void )
static

Open the GT911 touch controller (best-effort, polled; non-fatal).

Definition at line 461 of file main.c.

References k_ls_touch_max_points, k_ra8_touch_irq_pin_unset, and ra8_board_touch_open().

Referenced by main().

◆ app_panic_halt()

void app_panic_halt ( void )
static

Halt forever with the red board LED on (visual sign of fatal init).

Definition at line 405 of file main.c.

References k_ra8_board_led_red, and ra8_board_led_on().

Referenced by app_bringup_clocks(), app_bringup_display(), app_bringup_gfx(), app_bringup_panel(), and ls_open_strip().

◆ ls_apply_nav()

void ls_apply_nav ( int32_t delta,
bool toggle )
static

Apply one navigation action, redrawing + presenting if state changed.

Parameters
[in]deltaScroll delta (px, +down/-up); ignored when toggle is set.
[in]toggleTrue to toggle the chrome overlay instead of scrolling.
Note
Not thread-safe.
Since
0.1.0

Definition at line 841 of file main.c.

References longstrip_scroll_by(), ls_present(), ls_redraw(), s_chrome, and s_strip.

Referenced by ls_handle_tap(), and ls_poll_buttons().

◆ ls_band_decode()

ra8_err_t ls_band_decode ( void * ctx,
const ra8_tile_key_t * key,
uint8_t * cell,
uint32_t cell_bytes,
uint16_t * out_w,
uint16_t * out_h )
static

Tile-cache decode-on-miss: paint band key->tile_y procedurally.

Parameters
[in]ctxA ls_paint_ctx_t*.
[in]keyBand to paint (tile_y = band index).
[out]cellDestination cell pixels.
[in]cell_bytesCell capacity in bytes.
[out]out_wReceives the band width, pixels.
[out]out_hReceives the band height, pixels (clamped for the last).
Returns
ra8_err_t
Return values
k_ra8_okBand painted into cell.
k_ra8_err_null_ptrA required pointer is NULL.
k_ra8_err_out_of_rangeThe band payload exceeds cell_bytes.
Note
Not thread-safe.
Since
0.1.0

Definition at line 602 of file main.c.

References ls_paint_ctx_t::band_h, ls_paint_ctx_t::bpp, ls_paint_ctx_t::canvas_h, k_ls_bpp, k_ls_palette, k_ls_palette_size, k_ra8_err_out_of_range, k_ra8_ok, ls_row_color(), RA8_CHECK_NULL_PTR, s_tag, ra8_tile_key_t::tile_y, and ls_paint_ctx_t::width.

Referenced by ls_open_strip().

◆ ls_blit()

ra8_err_t ls_blit ( void * ctx,
const uint8_t * pixels,
uint16_t src_w,
uint16_t src_h,
uint8_t bpp,
int32_t dst_x,
int32_t dst_y )
static

Longstrip blit sink -> ra8_gfx software blit (RGB888 -> RGB565).

Parameters
[in]ctxUnused sink context.
[in]pixelsDecoded band pixels (RGB888, row-major).
[in]src_wBand width, pixels.
[in]src_hBand height, pixels.
[in]bppBytes per pixel (unused: strip is RGB888).
[in]dst_xDestination left in the framebuffer.
[in]dst_yDestination top in the framebuffer (may be negative).
Returns
k_ra8_ok on success; k_ra8_err_null_ptr if pixels is NULL.
Note
Not thread-safe.
Since
0.1.0

Definition at line 701 of file main.c.

References k_ra8_gfx_format_rgb888, RA8_CHECK_NULL_PTR, ra8_gfx_blit(), and s_tag.

Referenced by ls_open_strip().

◆ ls_build_atlas()

uint32_t ls_build_atlas ( void )
static

Build the metadata-only JOF band-tile atlas; return its byte length.

Emits only the header, the tile index (immediately after the header, so there is no pixel region) and the footer. jof_parse validates index_off + tiles*8 + 16 == total and never reads the pixel bytes, so the strip parses with band pixels supplied later by ls_band_decode.

Returns
The atlas length in bytes (k_ls_atlas_total).
Note
Not thread-safe (mutates s_atlas).
Since
0.1.0

Definition at line 503 of file main.c.

References k_jof_codec_raw, k_ls_atlas_total, k_ls_band_h, k_ls_bands, k_ls_bpp, k_ls_canvas_h, k_ls_canvas_w, k_ls_ftr_magic_off, k_ls_hdr_bytes, k_ls_idx_entry, ls_put_u16(), ls_put_u32(), and s_atlas.

Referenced by main().

◆ ls_draw_rail()

void ls_draw_rail ( void )
static

Draw the right-edge scroll rail overlay (track + proportional thumb).

Definition at line 757 of file main.c.

References k_ls_canvas_h, k_ls_col_rail_bg, k_ls_col_rail_thumb, k_ls_rail_min_thumb, k_ls_rail_w, k_ls_view_h, k_ls_view_w, ra8_gfx_rect(), and s_strip.

Referenced by ls_redraw().

◆ ls_draw_status()

void ls_draw_status ( void )
static

Draw the status bar overlay: wordmark + band + scroll-position text.

Definition at line 728 of file main.c.

References k_ls_bands, k_ls_col_status_bg, k_ls_col_text, k_ls_col_text_dim, k_ls_dec_digits, k_ls_glyph_h, k_ls_pct_full, k_ls_status_h, k_ls_text_pad, k_ls_view_w, ls_text(), ls_utoa(), ra8_gfx_rect(), s_last_skipped, and s_strip.

Referenced by ls_redraw().

◆ ls_emit_banner()

void ls_emit_banner ( void )
static

Emit the deterministic boot banner (bands, viewport, scroll, FB CRC).

Definition at line 813 of file main.c.

References g_ls_frame_crc, k_ls_bands, k_ls_view_h, k_ls_view_w, k_msg_crc, k_msg_eol, k_msg_pre, k_msg_scroll, k_msg_view, k_msg_x, ls_hash_fb(), ls_print(), ls_print_hex(), ls_print_uint(), and s_strip.

Referenced by main().

◆ ls_handle_tap()

void ls_handle_tap ( int32_t y)
static

Map a tap Y coordinate to a navigation action (tap-zone hit-test).

Parameters
[in]yPanel Y coordinate of the contact (pixels).
Note
Bottom third pages down, top third pages up, centre toggles chrome.
Since
0.1.0

Definition at line 862 of file main.c.

References k_ls_scroll_page, k_ls_zone_mid, k_ls_zone_top, and ls_apply_nav().

Referenced by ls_poll_touch().

◆ ls_hash_fb()

uint32_t ls_hash_fb ( void )
static

Fold an FNV-1a-32 over the whole panel framebuffer.

Definition at line 801 of file main.c.

References k_ls_fnv_offset, k_ls_fnv_prime, and s_framebuffer.

Referenced by ls_emit_banner().

◆ ls_open_strip()

void ls_open_strip ( uint32_t total)
static

◆ ls_poll_buttons()

void ls_poll_buttons ( void )
static

Poll SW1/SW2 and page up/down on a fresh press (button fallback).

Definition at line 899 of file main.c.

References k_ls_scroll_page, k_ra8_board_sw1, k_ra8_board_sw2, k_ra8_board_sw_pressed, k_ra8_ok, ls_apply_nav(), ra8_board_sw_read(), s_was_sw1, and s_was_sw2.

Referenced by main().

◆ ls_poll_touch()

void ls_poll_touch ( void )
static

Poll the touch controller; dispatch one tap per delivered GT911 frame.

Each drained GT911 frame is treated as one discrete tap. The GT911 reports a fresh "ready" frame on every poll while a contact is present (and ra8_emulator serves one queued --touch-seq tap per read with no interposed release), so a rising-edge gate would collapse a whole tap sequence into a single action; acting per delivered frame makes each queued tap page independently. There is no swipe/drag model, so navigation stays purely discrete-tap.

Note
Not thread-safe.
Since
0.1.0

Definition at line 886 of file main.c.

References k_ls_touch_max_points, k_ra8_ok, ls_handle_tap(), ra8_touch_read(), and ra8_touch_point_t::y.

Referenced by main().

◆ ls_present()

void ls_present ( void )
static

Present the framebuffer to the panel (clean full refresh).

Definition at line 795 of file main.c.

References display_flush(), display_full_rect(), k_display_refresh_quality, and s_display.

Referenced by ls_apply_nav(), and main().

◆ ls_print()

void ls_print ( const uint8_t * msg,
uint32_t len )
static

Emit a byte run on the SCI8 console.

Definition at line 336 of file main.c.

References ra8_board_uart_console_write().

Referenced by ls_emit_banner(), ls_print_hex(), ls_print_uint(), and main().

◆ ls_print_hex()

void ls_print_hex ( uint32_t value)
static

Print a 32-bit value as 8 upper-case hex digits.

Definition at line 342 of file main.c.

References k_ls_dec_ten, k_ls_hex_nibbles, k_ls_nibble_bits, k_ls_nibble_mask, and ls_print().

Referenced by ls_emit_banner().

◆ ls_print_uint()

void ls_print_uint ( uint32_t value)
static

Print a small unsigned integer in decimal on the console.

Definition at line 354 of file main.c.

References k_ls_dec_digits, k_ls_dec_ten, and ls_print().

Referenced by ls_emit_banner().

◆ ls_put_u16()

void ls_put_u16 ( uint8_t * p,
uint16_t v )
static

Write a little-endian u16 at p.

Definition at line 476 of file main.c.

References k_ls_byte_mask, and k_ls_shift_8.

Referenced by ls_build_atlas().

◆ ls_put_u32()

void ls_put_u32 ( uint8_t * p,
uint32_t v )
static

Write a little-endian u32 at p.

Definition at line 483 of file main.c.

References k_ls_byte_mask, k_ls_shift_16, k_ls_shift_24, and k_ls_shift_8.

Referenced by ls_build_atlas().

◆ ls_redraw()

void ls_redraw ( void )
static

Repaint the whole panel: strip bands, then the chrome overlays.

Definition at line 779 of file main.c.

References g_ls_redraws, g_ls_scroll_y, k_ls_col_bg, longstrip_render(), ls_draw_rail(), ls_draw_status(), ra8_gfx_clear(), ra8_gfx_reset_clip(), s_chrome, s_last_skipped, s_strip, and longstrip_render_stats_t::skipped.

Referenced by ls_apply_nav(), and main().

◆ ls_row_color()

void ls_row_color ( uint32_t base,
uint32_t r,
uint32_t th,
uint8_t * rgb )
static

Compute the RGB888 colour of one strip row inside a band.

Rows in the seam stripe (r < k_ls_seam_h) are a bright neutral so band boundaries read as crisp lines; the rest is the band's palette hue on a top(dim)->bottom(full) brightness gradient, so vertical motion is visible even within one hue.

Parameters
[in]baseBand base colour (0x00RRGGBB).
[in]rRow index within the band.
[in]thBand height in rows (>= 1).
[out]rgbReceives the row's R,G,B bytes (3 bytes).
Note
Pure over its inputs.
Since
0.1.0

Definition at line 569 of file main.c.

References k_ls_byte_mask, k_ls_grad_lo, k_ls_grad_span, k_ls_seam_h, k_ls_seam_level, k_ls_shift_16, k_ls_shift_8, and ls_scale_u8().

Referenced by ls_band_decode().

◆ ls_scale_u8()

uint8_t ls_scale_u8 ( uint8_t v,
uint32_t pct )
static

Scale an 8-bit channel by a 0..100 percentage (saturating at 255).

Definition at line 550 of file main.c.

References k_ls_pct_full.

Referenced by ls_row_color().

◆ ls_text()

int32_t ls_text ( int32_t x,
int32_t y,
const char * str,
uint32_t color )
static

Draw a text run in the bundled font; return the next x column.

Definition at line 716 of file main.c.

References k_ls_col_status_bg, k_ra8_ok, ra8_gfx_font_8x16, ra8_gfx_text_out(), and ra8_gfx_text_size().

Referenced by ls_draw_status().

◆ ls_utoa()

const char * ls_utoa ( char * buf,
uint32_t value )
static

Format an unsigned integer as a NUL-terminated ASCII decimal string.

Parameters
[out]bufDestination (at least k_ls_dec_digits + 1 bytes).
[in]valueValue to format.
Returns
buf.
Since
0.1.0

Definition at line 379 of file main.c.

References k_ls_dec_digits, and k_ls_dec_ten.

Referenced by ls_draw_status().

◆ main()

void main ( void )

App entry: bring up the panel, build the strip, run the reader loop.

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 panel shows the reader screen and the input loop runs forever.
Since
0.1.0

Definition at line 930 of file main.c.

References app_bringup_clocks(), app_bringup_gfx(), app_bringup_panel(), app_bringup_touch(), g_ls_loop_ticks, k_ls_frame_ms, k_ls_led_every, k_msg_boot, k_ra8_board_led_blue, k_ra8_board_sw1, k_ra8_board_sw2, ls_build_atlas(), ls_emit_banner(), ls_open_strip(), ls_poll_buttons(), ls_poll_touch(), ls_present(), ls_print(), ls_redraw(), ra8_board_led_toggle(), ra8_board_sw_init(), and ra8_delay_ms().

Variable Documentation

◆ g_ls_frame_crc

volatile uint32_t g_ls_frame_crc = 0U

FNV-1a-32 over the panel FB at the boot banner (render fingerprint).

Definition at line 319 of file main.c.

Referenced by ls_emit_banner().

◆ g_ls_loop_ticks

volatile uint32_t g_ls_loop_ticks = 0U

Free-running main-loop counter – HIL/liveness probe symbol.

Definition at line 313 of file main.c.

Referenced by main().

◆ g_ls_redraws

volatile uint32_t g_ls_redraws = 0U

Count of full redraws since boot – render-progress telemetry.

Definition at line 317 of file main.c.

Referenced by ls_redraw().

◆ g_ls_scroll_y

volatile uint32_t g_ls_scroll_y = 0U

Current scroll position (px) mirrored for --dump-sym telemetry.

Definition at line 315 of file main.c.

Referenced by ls_redraw().

◆ k_ls_display_cfg

const display_cfg_t k_ls_display_cfg
static
Initial value:
= {
.framebuffer = s_framebuffer,
.framebuffer_bytes = sizeof(s_framebuffer),
.width_px = (uint16_t)k_ls_view_w,
.height_px = (uint16_t)k_ls_view_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_ls_view_w
Viewport / strip width (== panel).
Definition main.c:85
@ k_ls_view_h
Viewport / strip-window height.
Definition main.c:86
@ 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 framebuffer.

Definition at line 289 of file main.c.

Referenced by app_bringup_panel().

◆ k_ls_palette

const uint32_t k_ls_palette[k_ls_palette_size]
static
Initial value:
= {
0xE6194BU,
0xF58231U,
0xFFE119U,
0xBFEF45U,
0x3CB44BU,
0x42D4F4U,
0x4363D8U,
0x911EB4U,
0xF032E6U,
0xFABEBEU,
0x469990U,
0x9A6324U,
0x800000U,
0x808000U,
0x000075U,
0xA9A9A9U,
}

Vivid 16-hue band palette (0x00RRGGBB) – distinct so scroll is obvious.

Note
Read-only; indexed by band % k_ls_palette_size.
Since
0.1.0

Definition at line 229 of file main.c.

Referenced by ls_band_decode().

◆ k_msg_boot

const uint8_t k_msg_boot[] = "ereader-longstrip: boot\r\n"
static

Boot / banner literals (SCI8).

Definition at line 322 of file main.c.

◆ k_msg_crc

const uint8_t k_msg_crc[] = " crc="
static

Definition at line 327 of file main.c.

◆ k_msg_eol

const uint8_t k_msg_eol[] = "\r\n"
static

Definition at line 328 of file main.c.

Referenced by iic_print_banner(), imp_panic(), imp_run(), imp_walk_book(), ls_emit_banner(), and main().

◆ k_msg_pre

const uint8_t k_msg_pre[] = "ereader-longstrip: bands="
static

Definition at line 323 of file main.c.

◆ k_msg_scroll

const uint8_t k_msg_scroll[] = " scroll="
static

Definition at line 326 of file main.c.

Referenced by ls_emit_banner().

◆ k_msg_view

const uint8_t k_msg_view[] = " view="
static

Definition at line 324 of file main.c.

Referenced by ls_emit_banner(), and mg_print_banner().

◆ k_msg_x

const uint8_t k_msg_x[] = "x"
static

Definition at line 325 of file main.c.

◆ s_atlas

uint8_t s_atlas[k_ls_atlas_total]
static

Metadata-only JOF atlas backing (header + index + footer).

Definition at line 262 of file main.c.

Referenced by ls_build_atlas(), and ls_open_strip().

◆ s_buckets

int32_t s_buckets[(size_t) k_ls_buckets]
static

Cache hash buckets.

Definition at line 267 of file main.c.

Referenced by ez_setup_scene(), ls_open_strip(), and mg_setup_cache().

◆ s_cache

ra8_tile_cache_t s_cache
static

Band cache (procedural decode).

Definition at line 270 of file main.c.

Referenced by ls_open_strip(), main(), and mg_setup_cache().

◆ s_cells

uint8_t s_cells[(size_t) k_ls_cells *(size_t) k_ls_band_bytes]
static

Tile-cache cell storage in SDRAM (one decoded band per cell).

Definition at line 259 of file main.c.

Referenced by ls_open_strip().

◆ s_chrome

bool s_chrome = true
static

True while the status bar + scroll rail chrome is shown.

Definition at line 304 of file main.c.

Referenced by ls_apply_nav(), ls_redraw(), and wd_state_init().

◆ s_dims

ra8_tile_dims_t s_dims[(size_t) k_ls_cells]
static

Cache dim storage.

Definition at line 265 of file main.c.

Referenced by ez_setup_scene(), ls_open_strip(), and mg_setup_cache().

◆ s_display

display_handle_t* s_display = nullptr
static

PAL handle returned by display_init.

Definition at line 300 of file main.c.

◆ s_fb

display_fb_t s_fb
static

Mutable copy of the FB descriptor populated at boot.

Definition at line 302 of file main.c.

◆ s_framebuffer

uint16_t s_framebuffer[(size_t) k_ls_view_h *(size_t) k_ls_view_w]
static

RGB565 panel framebuffer in external SDRAM, AXI-burst aligned.

Warning
Scanned out continuously by the GLCDC; write only through ra8_gfx.
Since
0.1.0

Definition at line 255 of file main.c.

◆ s_keys

ra8_tile_key_t s_keys[(size_t) k_ls_cells]
static

Cache key storage.

Definition at line 264 of file main.c.

Referenced by ez_setup_scene(), ls_open_strip(), and mg_setup_cache().

◆ s_last_skipped

uint16_t s_last_skipped = 0U
static

Skipped-band count from the last render (must stay 0: #289 contract).

Definition at line 306 of file main.c.

Referenced by ls_draw_status(), and ls_redraw().

◆ s_meta

ra8_keycache_cell_t s_meta[(size_t) k_ls_cells]
static

Cache link metadata.

Definition at line 266 of file main.c.

Referenced by ez_setup_scene(), ls_open_strip(), and mg_setup_cache().

◆ s_paint

ls_paint_ctx_t s_paint
static

Painter context bound as the tile cache's decode ctx.

Definition at line 286 of file main.c.

Referenced by ls_open_strip().

◆ s_store

jof_memstore_t s_store
static

Atlas backing-read seam.

Definition at line 269 of file main.c.

Referenced by ls_open_strip(), mg_build_atlas(), and mg_setup_cache().

◆ s_strip

longstrip_t s_strip
static

Opened longstrip scroll state.

Definition at line 271 of file main.c.

Referenced by ez_setup_scene(), ls_apply_nav(), ls_draw_rail(), ls_draw_status(), ls_emit_banner(), ls_open_strip(), and ls_redraw().

◆ s_tag

const char* const s_tag = "ereader_longstrip"
static

Component tag for RA8_CHECK_* log lines.

Definition at line 222 of file main.c.

◆ s_was_sw1

bool s_was_sw1 = false
static

Edge-detect: was SW1 held on the previous button poll.

Definition at line 308 of file main.c.

Referenced by er_poll_buttons(), ls_poll_buttons(), and wd_poll_buttons().

◆ s_was_sw2

bool s_was_sw2 = false
static

Edge-detect: was SW2 held on the previous button poll.

Definition at line 310 of file main.c.

Referenced by er_poll_buttons(), ls_poll_buttons(), and wd_poll_buttons().