fw-rust: Refactor everything
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Remove avr-eeprom dependency for now and introduce events.
This commit is contained in:
parent
6cd8df515d
commit
fdd1f4636d
9 changed files with 459 additions and 263 deletions
|
@ -4,15 +4,11 @@ use atmega_hal::{
|
|||
port::{mode::Output, Pin, PB0, PB1},
|
||||
Spi,
|
||||
};
|
||||
use avr_device::interrupt;
|
||||
use core::convert::TryInto;
|
||||
use embedded_hal::{blocking::delay::DelayMs, spi::FullDuplex};
|
||||
use nb::block;
|
||||
|
||||
use crate::{
|
||||
assets::SYMBOL_TABLE,
|
||||
screen::{Screen, Screens},
|
||||
};
|
||||
use crate::{assets::SYMBOL_TABLE, eeprom, CONTRAST};
|
||||
|
||||
// TODO: Make `cd` and `rst` pins generic pins
|
||||
pub struct Lcd {
|
||||
|
@ -26,7 +22,7 @@ impl Lcd {
|
|||
Self { spi, cd, rst }
|
||||
}
|
||||
|
||||
pub fn init(&mut self, contrast: u8) {
|
||||
pub fn init(&mut self) {
|
||||
let mut delay = Delay::<MHz8>::new();
|
||||
|
||||
// TODO: Test if delay is really needed
|
||||
|
@ -40,13 +36,13 @@ impl Lcd {
|
|||
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
|
||||
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
|
||||
nb::block!(eeprom::read_byte(&CONTRAST)).unwrap(), // (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
|
||||
|
@ -60,6 +56,13 @@ impl Lcd {
|
|||
delay.delay_ms(1_u8);
|
||||
}
|
||||
|
||||
pub fn set_contrast(&mut self, contrast: u8) {
|
||||
assert!(contrast <= 63);
|
||||
|
||||
block!(self.spi.send(0x81)).unwrap(); // (9) Set Electronic Volume: Set Contrast
|
||||
block!(self.spi.send(contrast)).unwrap(); // (9) Set Electronic Volume: Set Contrast
|
||||
}
|
||||
|
||||
pub fn move_cursor(&mut self, segment: u8, page: u8) {
|
||||
assert!(segment < 102);
|
||||
assert!(page < 8);
|
||||
|
@ -181,21 +184,36 @@ impl Lcd {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn draw(&mut self, screen: &Screens) {
|
||||
interrupt::free(|_cs| {
|
||||
self.fill_area(0, 0, 102, 8, 0x00);
|
||||
pub fn print_u8_inverted(&mut self, segment: u8, page: u8, digits: u8, data: u8) {
|
||||
assert!(digits <= 3);
|
||||
let mut delay = Delay::<MHz8>::new();
|
||||
|
||||
match screen {
|
||||
Screens::Splash(splash) => {
|
||||
splash.draw(self);
|
||||
}
|
||||
Screens::Home(home) => {
|
||||
home.draw(self);
|
||||
}
|
||||
Screens::Setup(setup) => {
|
||||
setup.draw(self);
|
||||
let mut array = [0usize; 3];
|
||||
for (i, item) in array.iter_mut().enumerate() {
|
||||
*item = ((data / 10_u8.pow(i.try_into().unwrap())) % 10).into();
|
||||
}
|
||||
array.reverse();
|
||||
|
||||
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);
|
||||
self.cd.set_high();
|
||||
|
||||
block!(self.spi.send(0xFF)).unwrap();
|
||||
block!(self.spi.send(0xFF)).unwrap();
|
||||
for j in 3 - digits..3 {
|
||||
for segment in SYMBOL_TABLE[array[j as usize]][i as usize] {
|
||||
block!(self.spi.send(!*segment)).unwrap();
|
||||
}
|
||||
block!(self.spi.send(0xFF)).unwrap();
|
||||
}
|
||||
});
|
||||
block!(self.spi.send(0xFF)).unwrap();
|
||||
|
||||
// TODO: This delay fixes issues, try find a better solution
|
||||
delay.delay_ms(1_u8);
|
||||
self.cd.set_low();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue