fw-rust: Start to use the avr-eeprom crate
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Start to use the avr-eeprom crate to handle values residing inside the EEPROM.
This commit is contained in:
parent
b34b2810db
commit
8b9d21a012
3 changed files with 14 additions and 9 deletions
6
firmware/rust/Cargo.lock
generated
6
firmware/rust/Cargo.lock
generated
|
@ -32,6 +32,11 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "avr-eeprom"
|
||||||
|
version = "0.1.0-dev"
|
||||||
|
source = "git+https://git.onders.org/finga/avr-eeprom-rs.git?branch=main#d7653567fb2f7ca7bf5100a44c233015a6e03e51"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "avr-hal-generic"
|
name = "avr-hal-generic"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -67,6 +72,7 @@ version = "0.1.0-dev"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atmega-hal",
|
"atmega-hal",
|
||||||
"avr-device",
|
"avr-device",
|
||||||
|
"avr-eeprom",
|
||||||
"embedded-hal",
|
"embedded-hal",
|
||||||
"nb 1.0.0",
|
"nb 1.0.0",
|
||||||
"panic-halt",
|
"panic-halt",
|
||||||
|
|
|
@ -15,6 +15,7 @@ panic-halt = "0.2"
|
||||||
nb = "1.0"
|
nb = "1.0"
|
||||||
embedded-hal = "0.2"
|
embedded-hal = "0.2"
|
||||||
avr-device = { version = "0.3", features = ["atmega328p"] }
|
avr-device = { version = "0.3", features = ["atmega328p"] }
|
||||||
|
avr-eeprom = { git = "https://git.onders.org/finga/avr-eeprom-rs.git", branch = "main" }
|
||||||
|
|
||||||
[dependencies.atmega-hal]
|
[dependencies.atmega-hal]
|
||||||
git = "https://github.com/rahix/avr-hal"
|
git = "https://github.com/rahix/avr-hal"
|
||||||
|
|
|
@ -9,6 +9,7 @@ use atmega_hal::{
|
||||||
Peripherals,
|
Peripherals,
|
||||||
};
|
};
|
||||||
use avr_device::interrupt;
|
use avr_device::interrupt;
|
||||||
|
use avr_eeprom::eeprom;
|
||||||
use embedded_hal::{
|
use embedded_hal::{
|
||||||
blocking::delay::DelayMs,
|
blocking::delay::DelayMs,
|
||||||
spi::{FullDuplex, Mode, Phase, Polarity},
|
spi::{FullDuplex, Mode, Phase, Polarity},
|
||||||
|
@ -16,13 +17,10 @@ use embedded_hal::{
|
||||||
use nb::block;
|
use nb::block;
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
|
|
||||||
#[used]
|
eeprom! {
|
||||||
#[link_section = ".eeprom"]
|
static eeprom CONTRAST: u8 = 8;
|
||||||
static CONTRAST: u8 = 8;
|
static eeprom BACKLIGHT: u8 = 1;
|
||||||
|
}
|
||||||
#[used]
|
|
||||||
#[link_section = ".eeprom"]
|
|
||||||
static BACKLIGHT: u8 = 1;
|
|
||||||
|
|
||||||
// TODO: Use https://github.com/rust-lang/rust/issues/85077 when stabilized
|
// TODO: Use https://github.com/rust-lang/rust/issues/85077 when stabilized
|
||||||
static SACRED_CHAO: [[u8; 40]; 5] = [
|
static SACRED_CHAO: [[u8; 40]; 5] = [
|
||||||
|
@ -82,7 +80,7 @@ fn main() -> ! {
|
||||||
// Write address into eeprom address register
|
// Write address into eeprom address register
|
||||||
eeprom
|
eeprom
|
||||||
.eear
|
.eear
|
||||||
.write(|w| unsafe { w.bits(&CONTRAST as *const u8 as u16) });
|
.write(|w| unsafe { w.bits(CONTRAST.ptr() as u16) });
|
||||||
// Start to read from eeprom by setting EERE
|
// Start to read from eeprom by setting EERE
|
||||||
eeprom.eecr.write(|w| w.eere().set_bit());
|
eeprom.eecr.write(|w| w.eere().set_bit());
|
||||||
// Return data from eeprom data register
|
// Return data from eeprom data register
|
||||||
|
@ -95,7 +93,7 @@ fn main() -> ! {
|
||||||
// Write address into eeprom address register
|
// Write address into eeprom address register
|
||||||
eeprom
|
eeprom
|
||||||
.eear
|
.eear
|
||||||
.write(|w| unsafe { w.bits(&BACKLIGHT as *const u8 as u16) });
|
.write(|w| unsafe { w.bits(BACKLIGHT.ptr() as u16) });
|
||||||
// Start to read from eeprom by setting EERE
|
// Start to read from eeprom by setting EERE
|
||||||
eeprom.eecr.write(|w| w.eere().set_bit());
|
eeprom.eecr.write(|w| w.eere().set_bit());
|
||||||
// Return data from eeprom data register
|
// Return data from eeprom data register
|
||||||
|
|
Loading…
Reference in a new issue