From b34b2810dbee02cf5fd6136654f5ff2ce3028718 Mon Sep 17 00:00:00 2001 From: finga Date: Tue, 8 Mar 2022 14:42:04 +0100 Subject: [PATCH] fw-rust: Handle data residing in the EEPROM --- firmware/rust/Makefile.toml | 14 +++++++++++++- firmware/rust/src/main.rs | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/firmware/rust/Makefile.toml b/firmware/rust/Makefile.toml index 166b05a..59d36fa 100644 --- a/firmware/rust/Makefile.toml +++ b/firmware/rust/Makefile.toml @@ -12,7 +12,7 @@ command = "avr-size" args = ["--format=avr", "--mcu=${MCU}", "target/avr-atmega328p/debug/clock-generator.elf"] [tasks.copy_flash] -description = "Copy the flash" +description = "Extract the flash" dependencies = ["build"] command = "avr-objcopy" args = ["-O", "ihex", "-j", ".text", "-j", ".data", "target/avr-atmega328p/debug/clock-generator.elf", "target/avr-atmega328p/debug/clock-generator.hex"] @@ -23,6 +23,18 @@ dependencies = ["copy_flash", "size"] command = "avrdude" args = ["-p", "${MCU}", "-c", "${PROGRAMMER}", "-U", "flash:w:target/avr-atmega328p/debug/clock-generator.hex:a"] +[tasks.copy_eeprom] +description = "Extract the EEPROM" +dependencies = ["build"] +command = "avr-objcopy" +args = ["--change-section-lma", ".eeprom=0", "-O", "ihex", "-j", ".eeprom", "target/avr-atmega328p/debug/clock-generator.elf", "target/avr-atmega328p/debug/clock-generator.eep"] + +[tasks.eeprom] +description = "Flash the eeprom" +dependencies = ["copy_eeprom", "size"] +command = "avrdude" +args = ["-p", "${MCU}", "-c", "${PROGRAMMER}", "-U", "eeprom:w:target/avr-atmega328p/debug/clock-generator.eep:a"] + [tasks.fuses] description = "Burn the fuses" command = "avrdude" diff --git a/firmware/rust/src/main.rs b/firmware/rust/src/main.rs index 431bdd9..8b9338d 100644 --- a/firmware/rust/src/main.rs +++ b/firmware/rust/src/main.rs @@ -16,6 +16,14 @@ use embedded_hal::{ use nb::block; use panic_halt as _; +#[used] +#[link_section = ".eeprom"] +static CONTRAST: u8 = 8; + +#[used] +#[link_section = ".eeprom"] +static BACKLIGHT: u8 = 1; + // TODO: Use https://github.com/rust-lang/rust/issues/85077 when stabilized static SACRED_CHAO: [[u8; 40]; 5] = [ [ @@ -64,11 +72,35 @@ static ONDERS_ORG: [[u8; 48]; 2] = [ #[atmega_hal::entry] fn main() -> ! { interrupt::free(|_cs| { - // Get peripherals, pins and delay + // Get peripherals, pins, eeprom and delay let dp = Peripherals::take().unwrap(); let pins = pins!(dp); + let eeprom = 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 as *const u8 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 as *const u8 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(); + // Init display backlight let tc0 = dp.TC0; tc0.tccr0a.write(|w| {