ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
er_pageturn.h
Go to the documentation of this file.
1
24
25#pragma once
26
27#include <stdint.h>
28
34typedef enum : int8_t {
38} er_dir_t;
39
45typedef enum : uint32_t {
47 k_er_page_last = 0xFFFFFFFFU,
49
67static inline er_dir_t er_tap_to_dir(int32_t x, int32_t width)
68{
69 if (width <= 0) {
70 return k_er_dir_none;
71 }
72 const int32_t third = width / (int32_t)k_er_pt_thirds;
73 if (x >= (width - third)) {
74 return k_er_dir_next;
75 }
76 if (x < third) {
77 return k_er_dir_prev;
78 }
79 return k_er_dir_none;
80}
81
98static inline er_dir_t er_buttons_to_dir(bool sw1_pressed, bool sw2_pressed)
99{
100 if (sw1_pressed) {
101 return k_er_dir_prev;
102 }
103 if (sw2_pressed) {
104 return k_er_dir_next;
105 }
106 return k_er_dir_none;
107}
108
141static inline bool er_pageturn_step(uint32_t chapter,
142 uint32_t page,
143 uint32_t pages,
144 uint32_t ch_count,
145 er_dir_t dir,
146 uint32_t* out_chap,
147 uint32_t* out_page,
148 bool* out_crossed)
149{
150 *out_chap = chapter;
151 *out_page = page;
152 *out_crossed = false;
153 if (dir == k_er_dir_next) {
154 if ((page + 1U) < pages) {
155 *out_page = page + 1U;
156 return true;
157 }
158 if ((chapter + 1U) < ch_count) {
159 *out_chap = chapter + 1U;
160 *out_page = 0U;
161 *out_crossed = true;
162 return true;
163 }
164 return false;
165 }
166 if (dir == k_er_dir_prev) {
167 if (page > 0U) {
168 *out_page = page - 1U;
169 return true;
170 }
171 if (chapter > 0U) {
172 *out_chap = chapter - 1U;
173 *out_page = (uint32_t)k_er_page_last;
174 *out_crossed = true;
175 return true;
176 }
177 return false;
178 }
179 return false;
180}
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.
Definition er_pageturn.h:98
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.
er_pageturn_const_t
Constants for the page-turn decisions (no magic numbers).
Definition er_pageturn.h:45
@ k_er_page_last
Sentinel: "last page of this chapter".
Definition er_pageturn.h:47
@ k_er_pt_thirds
Screen split into thirds for edge taps.
Definition er_pageturn.h:46
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).
Definition er_pageturn.h:67
er_dir_t
Page-turn direction produced by an input decision.
Definition er_pageturn.h:34
@ k_er_dir_none
No page turn.
Definition er_pageturn.h:36
@ k_er_dir_prev
Go to the previous page.
Definition er_pageturn.h:35
@ k_er_dir_next
Go to the next page.
Definition er_pageturn.h:37