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

Pure page-turn + input-region decisions for the e-reader (#78). More...

#include <stdint.h>
Include dependency graph for er_pageturn.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  er_dir_t : int8_t {
  k_er_dir_prev = -1 ,
  k_er_dir_none = 0 ,
  k_er_dir_next = 1
}
 Page-turn direction produced by an input decision. More...
enum  er_pageturn_const_t : uint32_t {
  k_er_pt_thirds = 3U ,
  k_er_page_last = 0xFFFFFFFFU
}
 Constants for the page-turn decisions (no magic numbers). More...

Functions

static er_dir_t er_tap_to_dir (int32_t x, int32_t width)
 Decide a page-turn direction from a touch X coordinate (edge taps).
static er_dir_t er_buttons_to_dir (bool sw1_pressed, bool sw2_pressed)
 Decide a page-turn direction from the two user-button states.
static bool er_pageturn_step (uint32_t chapter, uint32_t page, uint32_t pages, uint32_t ch_count, er_dir_t dir, uint32_t *out_chap, uint32_t *out_page, bool *out_crossed)
 Advance/retreat the reading location by one page, crossing chapters.

Detailed Description

Pure page-turn + input-region decisions for the e-reader (#78).

The reading view turns pages from two inputs – touch edge taps and the two user buttons – and crosses chapter boundaries. The DECISIONS (which way a tap or button means, how a turn advances across pages and chapters, where it clamps) are factored into the small pure functions here so they are unit- and MC/DC-testable without the GLCDC / touch / GPIO stack. main.c calls them and applies the result to its file-scope reading-location state; the host test apps/board/stand_alone/ereader/tests/src/test_ereader_pageturn.c exercises them directly.

Header-only static inline (no TU to link): both the app and the test include it and get their own copies. Pure logic – no MMIO, no heap, no globals.

[Ring 7 / App] {World: NS}

Since
0.1.0

Definition in file er_pageturn.h.

Enumeration Type Documentation

◆ er_dir_t

enum er_dir_t : int8_t

Page-turn direction produced by an input decision.

Since
0.1.0
Enumerator
k_er_dir_prev 

Go to the previous page.

k_er_dir_none 

No page turn.

k_er_dir_next 

Go to the next page.

Definition at line 34 of file er_pageturn.h.

◆ er_pageturn_const_t

enum er_pageturn_const_t : uint32_t

Constants for the page-turn decisions (no magic numbers).

Since
0.1.0
Enumerator
k_er_pt_thirds 

Screen split into thirds for edge taps.

k_er_page_last 

Sentinel: "last page of this chapter".

Definition at line 45 of file er_pageturn.h.

Function Documentation

◆ er_buttons_to_dir()

er_dir_t er_buttons_to_dir ( bool sw1_pressed,
bool sw2_pressed )
inlinestatic

Decide a page-turn direction from the two user-button states.

SW1 = previous page, SW2 = next page. If both are pressed, previous wins (deterministic). Inputs are the logical "pressed" states (the caller maps the active-low GPIO levels to booleans).

Parameters
[in]sw1_pressedtrue if SW1 (P009) is held.
[in]sw2_pressedtrue if SW2 (P008) is held.
Returns
k_er_dir_prev, k_er_dir_next, or k_er_dir_none.
Precondition
The booleans reflect a fresh (edge-triggered) press.
Caller has already debounced / edge-detected.
Postcondition
The return value is one of the three er_dir_t members.
Note
Pure; not stateful.
Since
0.1.0

Definition at line 98 of file er_pageturn.h.

References k_er_dir_next, k_er_dir_none, and k_er_dir_prev.

Referenced by er_poll_buttons().

◆ er_pageturn_step()

bool er_pageturn_step ( uint32_t chapter,
uint32_t page,
uint32_t pages,
uint32_t ch_count,
er_dir_t dir,
uint32_t * out_chap,
uint32_t * out_page,
bool * out_crossed )
inlinestatic

Advance/retreat the reading location by one page, crossing chapters.

Within a chapter, moves page by one in dir. At a chapter edge it crosses: NEXT past the last page goes to page 0 of the next chapter; PREV before page 0 goes to k_er_page_last of the previous chapter (the caller's render clamps that sentinel to the real last page once the new chapter is laid out, since the page count is not known here). Clamps at the book ends (no change). A cross is reported in out_crossed so the caller can pick a clean chapter-boundary refresh.

Parameters
[in]chapterCurrent chapter index.
[in]pageCurrent page within chapter.
[in]pagesPage count of chapter (>= 1).
[in]ch_countNumber of chapters in the spine (>= 1).
[in]direr_dir_t direction.
[out]out_chapReceives the new chapter index.
[out]out_pageReceives the new page (or k_er_page_last on PREV cross).
[out]out_crossedReceives true iff a chapter boundary was crossed.
Returns
true iff the location changed (caller re-renders); false at a book end or k_er_dir_none.
Precondition
pages >= 1 and ch_count >= 1.
All out-params are non-null.
Postcondition
On true, (out_chap, out_page) is the new location.
On false, the out-params are still written to the unchanged location.
Note
Pure; not stateful.
Since
0.1.0
MC/DC:
Documented and exercised in apps/board/stand_alone/ereader/tests/src/test_ereader_pageturn.c.

Definition at line 141 of file er_pageturn.h.

References k_er_dir_next, k_er_dir_prev, and k_er_page_last.

Referenced by er_apply_pageturn().

◆ er_tap_to_dir()

er_dir_t er_tap_to_dir ( int32_t x,
int32_t width )
inlinestatic

Decide a page-turn direction from a touch X coordinate (edge taps).

Right third of the screen = next page, left third = previous, and the middle third is neutral (reserved for in-content links / future menus). The boundaries use integer thirds of width.

Parameters
[in]xTap X in panel pixels.
[in]widthPanel width in pixels (> 0).
Returns
k_er_dir_next (right third), k_er_dir_prev (left third), or k_er_dir_none (middle third, or width == 0).
Precondition
width is the live framebuffer width.
x is a panel-space coordinate.
Postcondition
The return value is one of the three er_dir_t members.
Note
Pure; not stateful.
Since
0.1.0

Definition at line 67 of file er_pageturn.h.

References k_er_dir_next, k_er_dir_none, k_er_dir_prev, and k_er_pt_thirds.

Referenced by er_handle_reading_tap().