fw-rust: Create a print u8 function for setup
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Create `print_u8()` helper function to print `u8` primitives to
lcd. Refactor contrast and backlight variables to also keep them in a
global `AtomicU8`.
This commit is contained in:
finga 2022-03-19 18:40:18 +01:00
parent c2920ea334
commit 7d8f5f6870
3 changed files with 55 additions and 14 deletions

View file

@ -5,6 +5,7 @@ use atmega_hal::{
Spi,
};
use avr_device::interrupt;
use core::convert::TryInto;
use embedded_hal::{blocking::delay::DelayMs, spi::FullDuplex};
use nb::block;
@ -161,6 +162,39 @@ impl Lcd {
}
}
pub fn print_u8(&mut self, segment: u8, page: u8, digits: u8, data: u8) {
assert!(digits <= 3);
let mut delay = Delay::<MHz8>::new();
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(0x00)).unwrap();
block!(self.spi.send(0x00)).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(0x00)).unwrap();
}
block!(self.spi.send(0x00)).unwrap();
// TODO: This delay fixes issues, try find a better solution
delay.delay_ms(1_u8);
self.cd.set_low();
}
}
pub fn draw(&mut self, screen: &Screens) {
interrupt::free(|_cs| {
self.clear();