atmega_hal/
eeprom.rs

1//! EEPROM
2//!
3//! # Example
4//!
5//! Complete example source code can be found in the repository:
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 = atmega_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::Atmega, crate::pac::EEPROM>;
24
25///////////////////////////////////////////////////////////
26#[cfg(feature = "atmega48p")]
27avr_hal_generic::impl_eeprom_atmega! {
28    hal: crate::Atmega,
29    peripheral: crate::pac::EEPROM,
30    capacity: 256,
31    addr_width: u8,
32    set_address: |peripheral, address| {
33        peripheral.eearl.write(|w| w.bits(address));
34    },
35}
36
37#[cfg(feature = "atmega88p")]
38avr_hal_generic::impl_eeprom_atmega! {
39    hal: crate::Atmega,
40    peripheral: crate::pac::EEPROM,
41    capacity: 512,
42    addr_width: u16,
43    set_address: |peripheral, address| {
44        peripheral.eear.write(|w| w.bits(address));
45    },
46}
47
48#[cfg(any(feature = "atmega168", feature = "atmega164pa"))]
49avr_hal_generic::impl_eeprom_atmega! {
50    hal: crate::Atmega,
51    peripheral: crate::pac::EEPROM,
52    capacity: 512,
53    addr_width: u16,
54    set_address: |peripheral, address| {
55        peripheral.eear.write(|w| w.bits(address));
56    },
57}
58
59#[cfg(any(
60    feature = "atmega328pb",
61    feature = "atmega328p",
62    feature = "atmega32u4"
63))]
64avr_hal_generic::impl_eeprom_atmega! {
65    hal: crate::Atmega,
66    peripheral: crate::pac::EEPROM,
67    capacity: 1024,
68    addr_width: u16,
69    set_address: |peripheral, address| {
70        peripheral.eear.write(|w| w.bits(address));
71    },
72}
73
74#[cfg(any(
75    feature = "atmega2560",
76    feature = "atmega1280",
77    feature = "atmega1284p"
78))]
79avr_hal_generic::impl_eeprom_atmega! {
80    hal: crate::Atmega,
81    peripheral: crate::pac::EEPROM,
82    capacity: 4096,
83    addr_width: u16,
84    set_address: |peripheral, address| {
85        peripheral.eear.write(|w| w.bits(address));
86    },
87}
88
89#[cfg(any(feature = "atmega8", feature = "atmega16"))]
90avr_hal_generic::impl_eeprom_atmega_old! {
91    hal: crate::Atmega,
92    peripheral: crate::pac::EEPROM,
93    capacity: 512,
94    addr_width: u16,
95    set_address: |peripheral, address| {
96        peripheral.eear.write(|w| w.bits(address));
97    },
98}
99
100#[cfg(any(feature = "atmega32a"))]
101avr_hal_generic::impl_eeprom_atmega_old! {
102    hal: crate::Atmega,
103    peripheral: crate::pac::EEPROM,
104    capacity: 1024,
105    addr_width: u16,
106    set_address: |peripheral, address| {
107        peripheral.eear.write(|w| w.bits(address));
108    },
109}
110
111#[cfg(any(feature = "atmega128a",))]
112avr_hal_generic::impl_eeprom_atmega_old! {
113    hal: crate::Atmega,
114    peripheral: crate::pac::EEPROM,
115    capacity: 4096,
116    addr_width: u16,
117    set_address: |peripheral, address| {
118        peripheral.eear.write(|w| w.bits(address));
119    },
120}