Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions app-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod buttons;
/// The storage/display task's command loop, as sequences a host test can drive.
pub mod storage_loop;

pub const SETTINGS_ITEMS: u8 = 7;
pub const SETTINGS_ITEMS: u8 = 8;
pub const MAX_SD_CHAPTERS: usize = 128;
pub const FIRST_SD_BOOK_ID: u32 = 2;

Expand Down Expand Up @@ -135,6 +135,12 @@ pub enum FrontButtons {
PagesLeft,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RefreshQuality {
Normal,
Fast,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RefreshPolicy {
FastOnly,
Expand Down Expand Up @@ -314,6 +320,7 @@ pub struct RenderRequest {
/// sheet, relabel the key rail, and show the wait or its note.
pub library_menu: LibraryMenu,
pub refresh_policy: RefreshPolicy,
pub refresh_quality: RefreshQuality,
pub font_size: FontSize,
pub line_spacing: LineSpacing,
pub font_weight: FontWeight,
Expand Down Expand Up @@ -1322,6 +1329,7 @@ pub enum LibraryEvent {
page_count: u32,
reading_orientation: u8,
refresh_policy: u8,
refresh_quality: u8,
font_size: u8,
line_spacing: u8,
font_weight: u8,
Expand Down Expand Up @@ -1801,6 +1809,7 @@ pub struct PersistedAppState {
pub shell_orientation: u8,
pub reading_orientation: u8,
pub refresh_policy: u8,
pub refresh_quality: u8,
pub font_size: u8,
pub line_spacing: u8,
pub font_weight: u8,
Expand Down Expand Up @@ -1835,6 +1844,7 @@ pub struct ReaderState {
pub orientation: DisplayOrientation,
pub front_buttons: FrontButtons,
pub refresh_policy: RefreshPolicy,
pub refresh_quality: RefreshQuality,
pub font_size: FontSize,
pub line_spacing: LineSpacing,
pub font_weight: FontWeight,
Expand Down Expand Up @@ -1890,6 +1900,7 @@ impl ReaderState {
orientation: DisplayOrientation::PortraitButtonsLeft,
front_buttons: FrontButtons::PagesRight,
refresh_policy: RefreshPolicy::FullOnWake,
refresh_quality: RefreshQuality::Normal,
font_size: FontSize::Medium,
line_spacing: LineSpacing::Normal,
font_weight: FontWeight::Normal,
Expand Down Expand Up @@ -2383,6 +2394,7 @@ impl ReaderState {
page_count,
reading_orientation,
refresh_policy,
refresh_quality,
font_size,
line_spacing,
font_weight,
Expand Down Expand Up @@ -2416,6 +2428,9 @@ impl ReaderState {
if let Some(policy) = refresh_policy_from_u8(refresh_policy) {
self.refresh_policy = policy;
}
if let Some(quality) = refresh_quality_from_u8(refresh_quality) {
self.refresh_quality = quality;
}
if let Some(size) = FontSize::from_u8(font_size) {
self.font_size = size;
}
Expand Down Expand Up @@ -2499,6 +2514,7 @@ impl ReaderState {
reading_sheet: self.reading_sheet,
library_menu: self.library_menu,
refresh_policy: self.refresh_policy,
refresh_quality: self.refresh_quality,
font_size: self.font_size,
line_spacing: self.line_spacing,
font_weight: self.font_weight,
Expand Down Expand Up @@ -2527,6 +2543,7 @@ impl ReaderState {
shell_orientation: DisplayOrientation::PortraitButtonsLeft as u8,
reading_orientation: self.orientation as u8,
refresh_policy: self.refresh_policy as u8,
refresh_quality: self.refresh_quality as u8,
font_size: self.font_size as u8,
line_spacing: self.line_spacing as u8,
font_weight: self.font_weight as u8,
Expand Down Expand Up @@ -2658,6 +2675,14 @@ pub fn refresh_policy_from_u8(value: u8) -> Option<RefreshPolicy> {
}
}

pub fn refresh_quality_from_u8(value: u8) -> Option<RefreshQuality> {
match value {
0 => Some(RefreshQuality::Normal),
1 => Some(RefreshQuality::Fast),
_ => None,
}
}

fn wrap_next(value: u16, len: u16) -> u16 {
if value + 1 >= len {
0
Expand Down Expand Up @@ -2809,6 +2834,12 @@ fn apply_setting(mut state: ReaderState) -> ReaderState {
FrontButtons::PagesLeft => FrontButtons::PagesRight,
};
}
7 => {
state.refresh_quality = match state.refresh_quality {
RefreshQuality::Normal => RefreshQuality::Fast,
RefreshQuality::Fast => RefreshQuality::Normal,
};
}
_ => {}
}
state
Expand Down Expand Up @@ -3501,7 +3532,7 @@ mod tests {
// 16 bytes and the planner's stored request four. Recorded because
// `.bss` trades one-for-one against the main stack region on this
// target, so a struct in a channel is never free.
assert_eq!(core::mem::size_of::<RenderRequest>(), 112);
assert_eq!(core::mem::size_of::<RenderRequest>(), 120);
assert!(
core::mem::size_of::<PersistedAppState>() < core::mem::size_of::<WifiCredentials>(),
"the departing state has outgrown the credentials variant",
Expand Down Expand Up @@ -4000,6 +4031,7 @@ mod tests {
page_count: 0,
reading_orientation: 0,
refresh_policy: 0,
refresh_quality: 0,
font_size: 0,
line_spacing: 0,
font_weight: 0,
Expand Down Expand Up @@ -4846,6 +4878,7 @@ mod tests {
page_count: 0,
reading_orientation: DisplayOrientation::LandscapeButtonsBottom as u8,
refresh_policy: RefreshPolicy::FullOnWake as u8,
refresh_quality: RefreshQuality::Normal as u8,
font_size: FontSize::Medium as u8,
line_spacing: LineSpacing::Normal as u8,
font_weight: FontWeight::Normal as u8,
Expand Down Expand Up @@ -4893,6 +4926,7 @@ mod tests {
page_count: 0,
reading_orientation: DisplayOrientation::LandscapeButtonsBottom as u8,
refresh_policy: RefreshPolicy::FullOnWake as u8,
refresh_quality: RefreshQuality::Normal as u8,
font_size: FontSize::Medium as u8,
line_spacing: LineSpacing::Normal as u8,
font_weight: FontWeight::Normal as u8,
Expand Down Expand Up @@ -4968,9 +5002,23 @@ mod tests {
let state = press(state, Button::Next);
assert_eq!(state.selection, 6);
let state = press(state, Button::Next);
assert_eq!(state.selection, 7);
let state = press(state, Button::Next);
assert_eq!(state.selection, 0, "selection wraps after the last row");
}

#[test]
fn settings_change_key_toggles_refresh_quality() {
let mut state = press(ReaderState::boot(), Button::Next);
state.selection = 7;

let state = press(state, Button::Confirm);
assert_eq!(state.refresh_quality, RefreshQuality::Fast);

let state = press(state, Button::Confirm);
assert_eq!(state.refresh_quality, RefreshQuality::Normal);
}

#[test]
fn settings_change_key_toggles_front_buttons() {
let mut state = press(ReaderState::boot(), Button::Next);
Expand Down Expand Up @@ -5188,6 +5236,7 @@ mod tests {
page_count: 0,
reading_orientation: DisplayOrientation::PortraitButtonsRight as u8,
refresh_policy: RefreshPolicy::FastOnly as u8,
refresh_quality: RefreshQuality::Fast as u8,
font_size: FontSize::Large as u8,
line_spacing: LineSpacing::Compact as u8,
font_weight: FontWeight::Normal as u8,
Expand Down Expand Up @@ -5487,6 +5536,7 @@ mod tests {
shell_orientation: 0,
reading_orientation: 0,
refresh_policy: 0,
refresh_quality: 0,
font_size: 0,
line_spacing: 0,
font_weight: 0,
Expand Down
2 changes: 2 additions & 0 deletions app-core/src/storage_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ impl OpenSequence {
shell_orientation: 0,
reading_orientation: 0,
refresh_policy: 0,
refresh_quality: 0,
font_size: 0,
line_spacing: 0,
font_weight: 0,
Expand Down Expand Up @@ -756,6 +757,7 @@ mod tests {
shell_orientation: 1,
reading_orientation: 2,
refresh_policy: 3,
refresh_quality: 0,
font_size: 4,
line_spacing: 5,
font_weight: 6,
Expand Down
26 changes: 24 additions & 2 deletions display/src/epd/ssd1677.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ pub const fn ram_y_counter(rect: Rect) -> [u8; 2] {
[bottom as u8, (bottom >> 8) as u8]
}

pub const fn update_control_2(mode: RefreshMode, screen_is_on: bool, turn_off: bool) -> u8 {
pub const fn update_control_2(
mode: RefreshMode,
screen_is_on: bool,
turn_off: bool,
fast_du: bool,
) -> u8 {
let mut value = 0;
if !screen_is_on {
value |= 0xC0;
Expand All @@ -140,7 +145,8 @@ pub const fn update_control_2(mode: RefreshMode, screen_is_on: bool, turn_off: b
}
match mode {
RefreshMode::Full => value | 0x34,
RefreshMode::Fast => value | 0x1C,
RefreshMode::Fast if fast_du => value | 0x1C,
RefreshMode::Fast => value | 0x18,
// Load LUT (display mode 1) + display, deliberately without the
// 0x20 load-temperature bit so the FAST_CLEAN_TEMPERATURE override
// written via 0x1A decides which OTP waveform runs.
Expand All @@ -159,3 +165,19 @@ pub const fn update_control_1(mode: RefreshMode) -> [u8; 2] {
pub const fn is_byte_aligned(rect: Rect) -> bool {
rect.x & 7 == 0 && rect.w & 7 == 0 && rect.w > 0 && rect.h > 0 && rect.x < WIDTH as u16
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_update_control_2_fast_du() {
// Fast with fast_du = true uses 0x1C (the DU shortcut).
assert_eq!(update_control_2(RefreshMode::Fast, true, false, true), 0x1C);
// Fast with fast_du = false uses 0x18 (the stock temperature-compensated sequence).
assert_eq!(
update_control_2(RefreshMode::Fast, true, false, false),
0x18
);
}
}
Binary file modified fixtures/golden/landscape-settings-x3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fixtures/golden/landscape-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fixtures/golden/settings-type-x3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fixtures/golden/settings-type.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions fw/src/display_flush/ssd1677.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(crate) async fn flush(
screen_on: bool,
mode: RefreshMode,
prev_staged: bool,
fast_du: bool,
) -> Result<(), PanelError> {
let bw_start = Instant::now();
write_ram(epd, CMD_WRITE_RAM_BW, fb).await?;
Expand Down Expand Up @@ -69,7 +70,7 @@ pub(crate) async fn flush(
.await?;
epd.command(
CMD_DISPLAY_UPDATE_CTRL2,
&[update_control_2(mode, screen_on, false)],
&[update_control_2(mode, screen_on, false, fast_du)],
)
.await?;
epd.command(CMD_MASTER_ACTIVATION, &[]).await?;
Expand Down Expand Up @@ -111,7 +112,7 @@ pub(crate) async fn sleep_panel(epd: &mut Epd) -> Result<(), PanelError> {
);
epd.command(
CMD_DISPLAY_UPDATE_CTRL2,
&[update_control_2(RefreshMode::PowerDown, true, false)],
&[update_control_2(RefreshMode::PowerDown, true, false, false)],
)
.await?;
epd.command(CMD_MASTER_ACTIVATION, &[]).await?;
Expand Down
1 change: 1 addition & 0 deletions fw/src/display_flush/uc8253.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(crate) async fn flush(
_screen_on: bool,
mode: RefreshMode,
prev_staged: bool,
_fast_du: bool,
) -> Result<(), PanelError> {
let plan = flush_plan(mode, SCREEN_POWERED.load(Ordering::Relaxed), prev_staged);
bench_log!(
Expand Down
7 changes: 7 additions & 0 deletions fw/src/tasks/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ pub async fn run(mut epd: Epd, mut sd_cs: Output<'static>, deep_sleep_wake: bool
refresh_planner.screen_on(),
mode,
prev_prestaged,
request.refresh_quality == app_core::RefreshQuality::Fast,
)
.await
.is_ok()
Expand Down Expand Up @@ -692,6 +693,7 @@ pub async fn run(mut epd: Epd, mut sd_cs: Output<'static>, deep_sleep_wake: bool
refresh_planner.screen_on(),
RefreshMode::Full,
prev_prestaged,
false,
)
.await
.is_ok()
Expand Down Expand Up @@ -812,6 +814,7 @@ pub async fn run(mut epd: Epd, mut sd_cs: Output<'static>, deep_sleep_wake: bool
refresh_planner.screen_on(),
mode,
prev_prestaged,
loading_request.refresh_quality == app_core::RefreshQuality::Fast,
)
.await
.is_ok()
Expand Down Expand Up @@ -2035,6 +2038,7 @@ fn record_for_persisted(library: &ReaderStore, state: PersistedAppState) -> AppS
shell_orientation: state.shell_orientation,
reading_orientation: state.reading_orientation,
refresh_policy: state.refresh_policy,
refresh_quality: state.refresh_quality,
font_size: state.font_size,
line_spacing: state.line_spacing,
font_weight: state.font_weight,
Expand Down Expand Up @@ -2135,6 +2139,7 @@ fn restore_saved_state(
page_count,
reading_orientation: record.reading_orientation,
refresh_policy: record.refresh_policy,
refresh_quality: record.refresh_quality,
font_size: record.font_size,
line_spacing: record.line_spacing,
font_weight: record.font_weight,
Expand Down Expand Up @@ -2190,6 +2195,8 @@ fn sleep_request_from_saved_state(
library_menu: app_core::LibraryMenu::None,
refresh_policy: refresh_policy_from_u8(record.refresh_policy)
.unwrap_or(app_core::RefreshPolicy::FullOnWake),
refresh_quality: app_core::refresh_quality_from_u8(record.refresh_quality)
.unwrap_or(app_core::RefreshQuality::Normal),
font_size: display::font::FontSize::from_u8(record.font_size)
.unwrap_or(display::font::FontSize::Medium),
line_spacing: display::font::LineSpacing::from_u8(record.line_spacing)
Expand Down
Loading