fw-rust: Handle data residing in the EEPROM
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
finga 2022-03-08 14:42:04 +01:00
parent 4bc3e84bdd
commit b34b2810db
2 changed files with 46 additions and 2 deletions

View file

@ -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"

View file

@ -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::<MHz8>::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| {