From e6bf3e780e0e611eac0a1e430a4df3b0ccda47cb Mon Sep 17 00:00:00 2001 From: finga Date: Thu, 7 Apr 2022 12:13:34 +0200 Subject: [PATCH] fw-rust: Improve control/display toggle times Optimize the control data/display data slope timing. This closes #1. --- firmware/rust/src/lcd.rs | 59 +++++++++--------------------- firmware/rust/src/screen/splash.rs | 14 +++---- 2 files changed, 22 insertions(+), 51 deletions(-) diff --git a/firmware/rust/src/lcd.rs b/firmware/rust/src/lcd.rs index 4d25a18..b088996 100644 --- a/firmware/rust/src/lcd.rs +++ b/firmware/rust/src/lcd.rs @@ -4,7 +4,7 @@ use atmega_hal::{ Spi, }; use core::convert::TryInto; -use embedded_hal::{blocking::delay::DelayMs, spi::FullDuplex}; +use embedded_hal::{blocking::delay::DelayUs, spi::FullDuplex}; use nb::block; use crate::{assets::SYMBOL_TABLE, eeprom, DefaultClock, CONTRAST}; @@ -22,13 +22,7 @@ impl Lcd { } pub fn init(&mut self) { - let mut delay = Delay::::new(); - - // TODO: Test if delay is really needed - delay.delay_ms(1_u8); self.rst.set_high(); - // TODO: Try to reduce delay to a minimum - delay.delay_ms(1_u8); let init_sequence = [ 0x40, // (6) Set Scroll Line: Display start line 0 @@ -47,9 +41,6 @@ impl Lcd { for i in init_sequence.iter() { block!(self.spi.send(*i)).unwrap(); } - - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); } pub fn set_contrast(&mut self, contrast: u8) { @@ -74,16 +65,14 @@ impl Lcd { self.move_cursor(segment, page); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_high(); for _ in 0..width { block!(self.spi.send(data)).unwrap(); } - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_low(); } @@ -101,8 +90,7 @@ impl Lcd { for i in 0..2 { self.move_cursor(segment, page + i); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_high(); block!(self.spi.send(0x00)).unwrap(); @@ -115,8 +103,7 @@ impl Lcd { } block!(self.spi.send(0x00)).unwrap(); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_low(); } } @@ -127,8 +114,7 @@ impl Lcd { for i in 0..2 { self.move_cursor(segment, page + i); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_high(); block!(self.spi.send(0xFF)).unwrap(); @@ -141,8 +127,7 @@ impl Lcd { } block!(self.spi.send(0xFF)).unwrap(); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_low(); } } @@ -160,8 +145,7 @@ impl Lcd { for i in 0..2 { self.move_cursor(segment, page + i); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_high(); block!(self.spi.send(0x00)).unwrap(); @@ -174,8 +158,7 @@ impl Lcd { } block!(self.spi.send(0x00)).unwrap(); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_low(); } } @@ -193,8 +176,7 @@ impl Lcd { for i in 0..2 { self.move_cursor(segment, page + i); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_high(); block!(self.spi.send(0xFF)).unwrap(); @@ -207,8 +189,7 @@ impl Lcd { } block!(self.spi.send(0xFF)).unwrap(); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_low(); } } @@ -227,8 +208,7 @@ impl Lcd { for i in 0..2 { self.move_cursor(segment, page + i); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_high(); block!(self.spi.send(0x00)).unwrap(); @@ -261,8 +241,7 @@ impl Lcd { } block!(self.spi.send(0x00)).unwrap(); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_low(); } } @@ -282,8 +261,7 @@ impl Lcd { for i in 0..2 { self.move_cursor(segment, page + i); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_high(); block!(self.spi.send(0x00)).unwrap(); @@ -334,8 +312,7 @@ impl Lcd { } block!(self.spi.send(0x00)).unwrap(); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_low(); } } @@ -344,16 +321,14 @@ impl Lcd { let mut delay = Delay::::new(); self.move_cursor(segment, page); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_high(); for c in symbol { block!(self.spi.send(*c)).unwrap(); } - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); self.cd.set_low(); } } diff --git a/firmware/rust/src/screen/splash.rs b/firmware/rust/src/screen/splash.rs index 1f95039..4d1342c 100644 --- a/firmware/rust/src/screen/splash.rs +++ b/firmware/rust/src/screen/splash.rs @@ -4,7 +4,7 @@ use crate::{ DefaultClock, }; use atmega_hal::delay::Delay; -use embedded_hal::{blocking::delay::DelayMs, spi::FullDuplex}; +use embedded_hal::{blocking::delay::DelayUs, spi::FullDuplex}; use nb::block; pub struct Splash; @@ -16,32 +16,28 @@ impl Splash { for (i, page) in SACRED_CHAO.iter().enumerate() { lcd.move_cursor(31, 1 + i as u8); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); lcd.cd.set_high(); for segment in page { block!(lcd.spi.send(*segment)).unwrap(); } - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); lcd.cd.set_low(); } for (i, page) in ONDERS_ORG.iter().enumerate() { lcd.move_cursor(27, 6 + i as u8); - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); lcd.cd.set_high(); for segment in page { block!(lcd.spi.send(*segment)).unwrap(); } - // TODO: This delay fixes issues, try find a better solution - delay.delay_ms(1_u8); + delay.delay_us(5_u8); lcd.cd.set_low(); } }