diff --git a/firmware/rust/Cargo.lock b/firmware/rust/Cargo.lock index ecc84d6..cb6f692 100644 --- a/firmware/rust/Cargo.lock +++ b/firmware/rust/Cargo.lock @@ -35,7 +35,11 @@ dependencies = [ [[package]] name = "avr-eeprom" version = "0.1.0-dev" -source = "git+https://git.onders.org/finga/avr-eeprom-rs.git?branch=main#d7653567fb2f7ca7bf5100a44c233015a6e03e51" +source = "git+https://git.onders.org/finga/avr-eeprom-rs.git?branch=main#0177da7268e91fa3c0cf545150589b2e33aa2101" +dependencies = [ + "avr-device", + "nb 1.0.0", +] [[package]] name = "avr-hal-generic" diff --git a/firmware/rust/src/main.rs b/firmware/rust/src/main.rs index 8f8feff..d16b397 100644 --- a/firmware/rust/src/main.rs +++ b/firmware/rust/src/main.rs @@ -10,7 +10,7 @@ use atmega_hal::{ Peripherals, }; use avr_device::interrupt; -use avr_eeprom::eeprom; +use avr_eeprom::{eeprom, Eeprom}; use embedded_hal::{ blocking::delay::DelayMs, spi::{FullDuplex, Mode, Phase, Polarity}, @@ -138,31 +138,12 @@ fn main() -> ! { // Get peripherals, pins, eeprom and delay let dp = Peripherals::take().unwrap(); let pins = pins!(dp); - let eeprom = dp.EEPROM; + let eeprom = Eeprom::new(dp.EEPROM); let mut delay = Delay::::new(); - // TODO: Wait for completion of previous write - // Write address into eeprom address register - eeprom - .eear - .write(|w| unsafe { w.bits(CONTRAST.ptr() as u16) }); - // Start to read from eeprom by setting EERE - eeprom.eecr.write(|w| w.eere().set_bit()); - // Return data from eeprom data register - let _contrast = eeprom.eedr.read().bits(); - - // TODO: Remove delay when waiting for completion of revious write is done - delay.delay_ms(1_u8); - - // TODO: Wait for completion of previous write - // Write address into eeprom address register - eeprom - .eear - .write(|w| unsafe { w.bits(BACKLIGHT.ptr() as u16) }); - // Start to read from eeprom by setting EERE - eeprom.eecr.write(|w| w.eere().set_bit()); - // Return data from eeprom data register - let _backlight = eeprom.eedr.read().bits(); + // Get contrast and backlight from EEPROM + let contrast = eeprom.read_value(&CONTRAST); + let backlight = eeprom.read_value(&BACKLIGHT); // Init display backlight let tc0 = dp.TC0; @@ -177,8 +158,7 @@ fn main() -> ! { w }); tc0.ocr0a.write(|w| unsafe { w.bits(255) }); - // TODO: Use EEPROM - tc0.ocr0b.write(|w| unsafe { w.bits(0) }); + tc0.ocr0b.write(|w| unsafe { w.bits(backlight) }); pins.pd5.into_output(); // Init SPI @@ -215,7 +195,7 @@ fn main() -> ! { block!(spi.send(0x2F)).unwrap(); // (5) Set Power Control: Booster, Regulator and Follower on block!(spi.send(0x27)).unwrap(); // (8) Set VLCD Resistor Ratio: Set Contrast block!(spi.send(0x81)).unwrap(); // (9) Set Electronic Volume: Set Contrast - block!(spi.send(0x08)).unwrap(); // (9) Set Electronic Volume: Set Contrast // TODO: Use EEPROM + block!(spi.send(contrast)).unwrap(); // (9) Set Electronic Volume: Set Contrast block!(spi.send(0xAF)).unwrap(); // (12) Set Display Enable: Display on // Draw splash screen