atmega_hal/
lib.rs

1#![no_std]
2
3//! `atmega-hal`
4//! =============
5//! Common HAL (hardware abstraction layer) for ATmega* microcontrollers.
6//!
7//! **Note**: This version of the documentation was built for
8#![cfg_attr(feature = "atmega48p", doc = "**ATmega48P**.")]
9#![cfg_attr(feature = "atmega16", doc = "**ATmega16**.")]
10#![cfg_attr(feature = "atmega164pa", doc = "**ATmega164PA**.")]
11#![cfg_attr(feature = "atmega168", doc = "**ATmega168**.")]
12#![cfg_attr(feature = "atmega328p", doc = "**ATmega328P**.")]
13#![cfg_attr(feature = "atmega328pb", doc = "**ATmega328PB**.")]
14#![cfg_attr(feature = "atmega32a", doc = "**ATmega32a**.")]
15#![cfg_attr(feature = "atmega32u4", doc = "**ATmega32U4**.")]
16#![cfg_attr(feature = "atmega2560", doc = "**ATmega2560**.")]
17#![cfg_attr(feature = "atmega128a", doc = "**ATmega128A**.")]
18#![cfg_attr(feature = "atmega1280", doc = "**ATmega1280**.")]
19#![cfg_attr(feature = "atmega1284p", doc = "**ATmega1284P**.")]
20#![cfg_attr(feature = "atmega8", doc = "**ATmega8**.")]
21#![cfg_attr(feature = "atmega88p", doc = "**ATmega88P**.")]
22//! This means that only items which are available for this MCU are visible.  If you are using
23//! a different chip, try building the documentation locally with:
24//!
25//! ```text
26//! cargo doc --features <your-mcu> --open
27//! ```
28
29#[cfg(all(
30    not(feature = "device-selected"),
31    not(feature = "disable-device-selection-error")
32))]
33compile_error!(
34    "This crate requires you to specify your target chip as a feature.
35
36    Please select one of the following
37
38    * atmega48p
39    * atmega16
40    * atmega164pa
41    * atmega168
42    * atmega328p
43    * atmega328pb
44    * atmega32u4
45    * atmega128a
46    * atmega1280
47    * atmega2560
48    * atmega1284p
49    * atmega8
50    * atmega88p
51    "
52);
53
54/// Reexport of `atmega1280` from `avr-device`
55///
56#[cfg(feature = "atmega1280")]
57pub use avr_device::atmega1280 as pac;
58/// Reexport of `atmega1284p` from `avr-device`
59///
60#[cfg(feature = "atmega1284p")]
61pub use avr_device::atmega1284p as pac;
62/// Reexport of `atmega128a` from `avr-device`
63///
64#[cfg(feature = "atmega128a")]
65pub use avr_device::atmega128a as pac;
66/// Reexport of `atmega16` from `avr-device`
67///
68#[cfg(feature = "atmega16")]
69pub use avr_device::atmega16 as pac;
70/// Reexport of `atmega164pa` from `avr-device`
71///
72#[cfg(feature = "atmega164pa")]
73pub use avr_device::atmega164pa as pac;
74/// Reexport of `atmega168` from `avr-device`
75///
76#[cfg(feature = "atmega168")]
77pub use avr_device::atmega168 as pac;
78/// Reexport of `atmega2560` from `avr-device`
79///
80#[cfg(feature = "atmega2560")]
81pub use avr_device::atmega2560 as pac;
82/// Reexport of `atmega328p` from `avr-device`
83///
84#[cfg(feature = "atmega328p")]
85pub use avr_device::atmega328p as pac;
86/// Reexport of `atmega328pb` from `avr-device`
87///
88#[cfg(feature = "atmega328pb")]
89pub use avr_device::atmega328pb as pac;
90/// Reexport of `atmega32a` from `avr-device`
91///
92#[cfg(feature = "atmega32a")]
93pub use avr_device::atmega32a as pac;
94/// Reexport of `atmega32u4` from `avr-device`
95///
96#[cfg(feature = "atmega32u4")]
97pub use avr_device::atmega32u4 as pac;
98/// Reexport of `atmega48p` from `avr-device`
99///
100#[cfg(feature = "atmega48p")]
101pub use avr_device::atmega48p as pac;
102/// Reexport of `atmega8` from `avr-device`
103///
104#[cfg(feature = "atmega8")]
105pub use avr_device::atmega8 as pac;
106/// Reexport of `atmega88p` from `avr-device`
107///
108#[cfg(feature = "atmega88p")]
109pub use avr_device::atmega88p as pac;
110
111/// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html).
112#[cfg(feature = "rt")]
113pub use avr_device::entry;
114
115/// Reexport of the [`avr_device`](https://docs.rs/avr-device) crate.
116///
117/// This makes items such as `avr_device::interrupt` available without depending
118/// on `avr-device` directly and keeping its version in sync manually.
119pub use avr_device;
120
121#[cfg(feature = "device-selected")]
122pub use pac::Peripherals;
123
124pub use avr_hal_generic::clock;
125pub use avr_hal_generic::delay;
126pub use avr_hal_generic::prelude;
127
128#[cfg(feature = "device-selected")]
129pub mod adc;
130#[cfg(feature = "device-selected")]
131pub use adc::Adc;
132
133#[cfg(feature = "device-selected")]
134pub mod i2c;
135#[cfg(feature = "device-selected")]
136pub use i2c::I2c;
137
138#[cfg(feature = "device-selected")]
139pub mod spi;
140#[cfg(feature = "device-selected")]
141pub use spi::Spi;
142
143#[cfg(feature = "device-selected")]
144pub mod port;
145#[cfg(feature = "device-selected")]
146pub use port::Pins;
147
148#[cfg(feature = "device-selected")]
149pub mod simple_pwm;
150
151#[cfg(feature = "device-selected")]
152pub mod usart;
153#[cfg(feature = "device-selected")]
154pub use usart::Usart;
155
156#[cfg(feature = "device-selected")]
157pub mod wdt;
158#[cfg(feature = "device-selected")]
159pub use wdt::Wdt;
160
161#[cfg(feature = "device-selected")]
162pub mod eeprom;
163#[cfg(feature = "device-selected")]
164pub use eeprom::Eeprom;
165
166pub struct Atmega;
167
168#[cfg(any(
169    feature = "atmega48p",
170    feature = "atmega88p",
171    feature = "atmega168",
172    feature = "atmega328p"
173))]
174#[macro_export]
175macro_rules! pins {
176    ($p:expr) => {
177        $crate::Pins::new($p.PORTB, $p.PORTC, $p.PORTD)
178    };
179}
180#[cfg(any(feature = "atmega16", feature = "atmega164pa"))]
181#[macro_export]
182macro_rules! pins {
183    ($p:expr) => {
184        $crate::Pins::new($p.PORTA, $p.PORTB, $p.PORTC, $p.PORTD)
185    };
186}
187#[cfg(feature = "atmega328pb")]
188#[macro_export]
189macro_rules! pins {
190    ($p:expr) => {
191        $crate::Pins::new($p.PORTB, $p.PORTC, $p.PORTD, $p.PORTE)
192    };
193}
194#[cfg(feature = "atmega32u4")]
195#[macro_export]
196macro_rules! pins {
197    ($p:expr) => {
198        $crate::Pins::new($p.PORTB, $p.PORTC, $p.PORTD, $p.PORTE, $p.PORTF)
199    };
200}
201
202#[cfg(any(feature = "atmega128a"))]
203#[macro_export]
204macro_rules! pins {
205    ($p:expr) => {
206        $crate::Pins::new(
207            $p.PORTA, $p.PORTB, $p.PORTC, $p.PORTD, $p.PORTE, $p.PORTF, $p.PORTG,
208        )
209    };
210}
211
212#[cfg(any(feature = "atmega1280", feature = "atmega2560"))]
213#[macro_export]
214macro_rules! pins {
215    ($p:expr) => {
216        $crate::Pins::new(
217            $p.PORTA, $p.PORTB, $p.PORTC, $p.PORTD, $p.PORTE, $p.PORTF, $p.PORTG, $p.PORTH,
218            $p.PORTJ, $p.PORTK, $p.PORTL,
219        )
220    };
221}
222
223#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
224#[macro_export]
225macro_rules! pins {
226    ($p:expr) => {
227        $crate::Pins::new($p.PORTA, $p.PORTB, $p.PORTC, $p.PORTD)
228    };
229}
230
231#[cfg(any(feature = "atmega8"))]
232#[macro_export]
233macro_rules! pins {
234    ($p:expr) => {
235        $crate::Pins::new($p.PORTB, $p.PORTC, $p.PORTD)
236    };
237}