attiny_hal/
eeprom.rs

1//! EEPROM
2//!
3//! # Example
4//!
5//! For full source code, please refer to the ATmega EEPROM example:
6//! [`atmega2560-eeprom.rs`](https://github.com/Rahix/avr-hal/blob/main/examples/atmega2560/src/bin/atmega2560-eeprom.rs)
7//!
8//! ```
9//! const BOOT_COUNT_OFFSET: u16 = 0;
10//!
11//! let dp = attiny_hal::Peripherals::take().unwrap();
12//! let mut eeprom = Eeprom::new(dp.EEPROM);
13//!
14//! let mut boot_count = eeprom.read_byte(BOOT_COUNT_OFFSET);
15//! boot_count = boot_count.wrapping_add(1);
16//! eeprom.write_byte(BOOT_COUNT_OFFSET, boot_count);
17//!
18//! ufmt::uwriteln!(&mut serial, "Boot count: {}", boot_count).unwrap();
19//! ```
20
21pub use avr_hal_generic::eeprom::{EepromOps, OutOfBoundsError};
22
23pub type Eeprom = avr_hal_generic::eeprom::Eeprom<crate::Attiny, crate::pac::EEPROM>;
24
25#[cfg(feature = "attiny2313")]
26avr_hal_generic::impl_eeprom_attiny! {
27    hal: crate::Attiny,
28    peripheral: crate::pac::EEPROM,
29    capacity: 128,
30    addr_width: u8,
31    set_address: |peripheral, address| {
32        peripheral.eear.write(|w| w.bits(address));
33    },
34}
35
36#[cfg(any(feature = "attiny167", feature = "attiny85"))]
37avr_hal_generic::impl_eeprom_attiny! {
38    hal: crate::Attiny,
39    peripheral: crate::pac::EEPROM,
40    capacity: 512,
41    addr_width: u16,
42    set_address: |peripheral, address| {
43        peripheral.eear.write(|w| w.bits(address));
44    },
45}
46
47#[cfg(feature = "attiny88")]
48avr_hal_generic::impl_eeprom_attiny! {
49    hal: crate::Attiny,
50    peripheral: crate::pac::EEPROM,
51    capacity: 64,
52    addr_width: u8,
53    set_address: |peripheral, address| {
54        peripheral.eearl.write(|w| w.bits(address));
55    },
56}