From 08a371062d0f5e2397d17b7a1402869295872f48 Mon Sep 17 00:00:00 2001 From: finga Date: Sun, 20 Mar 2022 14:27:13 +0100 Subject: [PATCH] fw-rust: Refactor init function of the LCD Use an array for the init sequence commands and iterate over it. --- firmware/rust/src/lcd.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/firmware/rust/src/lcd.rs b/firmware/rust/src/lcd.rs index 55b8f86..2d89a1d 100644 --- a/firmware/rust/src/lcd.rs +++ b/firmware/rust/src/lcd.rs @@ -35,20 +35,26 @@ impl Lcd { // TODO: Try to reduce delay to a minimum delay.delay_ms(1_u8); - block!(self.spi.send(0x40)).unwrap(); // (6) Set Scroll Line: Display start line 0 - block!(self.spi.send(0xA1)).unwrap(); // (13) Set SEG direction: SEG reverse - block!(self.spi.send(0xC0)).unwrap(); // (14) Set COM direction: Normal COM0 - COM63 - // block!(spi.send(0xA4)).unwrap(); // (10) Set All Pixel On: Disable -> Set All Pixel to ON */ - block!(self.spi.send(0xA6)).unwrap(); // (11) Set Inverse Display: Display inverse off - block!(self.spi.send(0xA2)).unwrap(); // (17) Set LCD Bias Ratio: Set Bias 1/9 (Duty 1/65) - block!(self.spi.send(0x2F)).unwrap(); // (5) Set Power Control: Booster, Regulator and Follower on - block!(self.spi.send(0x27)).unwrap(); // (8) Set VLCD Resistor Ratio: Set Contrast - // block!(spi.send(0xEE)).unwrap(); // (18) Reset Cursor Update Mode - block!(self.spi.send(0x81)).unwrap(); // (9) Set Electronic Volume: Set Contrast - block!(self.spi.send(contrast)).unwrap(); // (9) Set Electronic Volume: Set Contrast - // block!(spi.send(0xFA)).unwrap(); // (25) Set Adv. Program Control 0: Set Temperature compensation curve to -0.11%/°C - // block!(spi.send(0x90)).unwrap(); // (25) Set Adv. Program Control 0: Set Temperature compensation curve to -0.11%/°C - block!(self.spi.send(0xAF)).unwrap(); // (12) Set Display Enable: Display on + let init_sequence = [ + 0x40, // (6) Set Scroll Line: Display start line 0 + 0xA1, // (13) Set SEG direction: SEG reverse + 0xC0, // (14) Set COM direction: Normal COM0 - COM63 + // 0xA4, // (10) Set All Pixel On: Disable -> Set All Pixel to ON + 0xA6, // (11) Set Inverse Display: Display inverse off + 0xA2, // (17) Set LCD Bias Ratio: Set Bias 1/9 (Duty 1/65) + 0x2F, // (5) Set Power Control: Booster, Regulator and Follower on + 0x27, // (8) Set VLCD Resistor Ratio: Set Contrast + 0xEE, // (18) Reset Cursor Update Mode + 0x81, // (9) Set Electronic Volume: Set Contrast + contrast, // (9) Set Electronic Volume: Set Contrast + // 0xFA, // (25) Set Adv. Program Control 0: Set Temperature compensation curve to -0.11%/°C + // 0x90, // (25) Set Adv. Program Control 0: Set Temperature compensation curve to -0.11%/°C + 0xAF, // (12) Set Display Enable: Display on + ]; + + 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);