fw-rust: Refactor init function of the LCD
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Use an array for the init sequence commands and iterate over it.
This commit is contained in:
finga 2022-03-20 14:27:13 +01:00
parent 7d8f5f6870
commit 08a371062d

View file

@ -35,20 +35,26 @@ impl Lcd {
// TODO: Try to reduce delay to a minimum // TODO: Try to reduce delay to a minimum
delay.delay_ms(1_u8); delay.delay_ms(1_u8);
block!(self.spi.send(0x40)).unwrap(); // (6) Set Scroll Line: Display start line 0 let init_sequence = [
block!(self.spi.send(0xA1)).unwrap(); // (13) Set SEG direction: SEG reverse 0x40, // (6) Set Scroll Line: Display start line 0
block!(self.spi.send(0xC0)).unwrap(); // (14) Set COM direction: Normal COM0 - COM63 0xA1, // (13) Set SEG direction: SEG reverse
// block!(spi.send(0xA4)).unwrap(); // (10) Set All Pixel On: Disable -> Set All Pixel to ON */ 0xC0, // (14) Set COM direction: Normal COM0 - COM63
block!(self.spi.send(0xA6)).unwrap(); // (11) Set Inverse Display: Display inverse off // 0xA4, // (10) Set All Pixel On: Disable -> Set All Pixel to ON
block!(self.spi.send(0xA2)).unwrap(); // (17) Set LCD Bias Ratio: Set Bias 1/9 (Duty 1/65) 0xA6, // (11) Set Inverse Display: Display inverse off
block!(self.spi.send(0x2F)).unwrap(); // (5) Set Power Control: Booster, Regulator and Follower on 0xA2, // (17) Set LCD Bias Ratio: Set Bias 1/9 (Duty 1/65)
block!(self.spi.send(0x27)).unwrap(); // (8) Set VLCD Resistor Ratio: Set Contrast 0x2F, // (5) Set Power Control: Booster, Regulator and Follower on
// block!(spi.send(0xEE)).unwrap(); // (18) Reset Cursor Update Mode 0x27, // (8) Set VLCD Resistor Ratio: Set Contrast
block!(self.spi.send(0x81)).unwrap(); // (9) Set Electronic Volume: Set Contrast 0xEE, // (18) Reset Cursor Update Mode
block!(self.spi.send(contrast)).unwrap(); // (9) Set Electronic Volume: Set Contrast 0x81, // (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 contrast, // (9) Set Electronic Volume: Set Contrast
// block!(spi.send(0x90)).unwrap(); // (25) Set Adv. Program Control 0: Set Temperature compensation curve to -0.11%/°C // 0xFA, // (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 // 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 // TODO: This delay fixes issues, try find a better solution
delay.delay_ms(1_u8); delay.delay_ms(1_u8);