avr_device/
lib.rs

1//! This crate contains register definitions for
2
3#![cfg_attr(feature = "at90usb1286", doc = "**at90usb1286**,")]
4#![cfg_attr(feature = "atmega1280", doc = "**atmega1280**,")]
5#![cfg_attr(feature = "atmega1284p", doc = "**atmega1284p**,")]
6#![cfg_attr(feature = "atmega128a", doc = "**atmega128a**,")]
7#![cfg_attr(feature = "atmega128rfa1", doc = "**atmega128rfa1**,")]
8#![cfg_attr(feature = "atmega16", doc = "**atmega16**,")]
9#![cfg_attr(feature = "atmega164pa", doc = "**atmega164pa**,")]
10#![cfg_attr(feature = "atmega168", doc = "**atmega168**,")]
11#![cfg_attr(feature = "atmega16u2", doc = "**atmega16u2**,")]
12#![cfg_attr(feature = "atmega2560", doc = "**atmega2560**,")]
13#![cfg_attr(feature = "atmega8", doc = "**atmega8**,")]
14#![cfg_attr(feature = "atmega8u2", doc = "**atmega8u2**,")]
15#![cfg_attr(feature = "atmega324pa", doc = "**atmega324pa**,")]
16#![cfg_attr(feature = "atmega328p", doc = "**atmega328p**,")]
17#![cfg_attr(feature = "atmega328pb", doc = "**atmega328pb**,")]
18#![cfg_attr(feature = "atmega32a", doc = "**atmega32a**,")]
19#![cfg_attr(feature = "atmega32u2", doc = "**atmega32u2**,")]
20#![cfg_attr(feature = "atmega32u4", doc = "**atmega32u4**,")]
21#![cfg_attr(feature = "atmega3208", doc = "**atmega3208**,")]
22#![cfg_attr(feature = "atmega3209", doc = "**atmega3209**,")]
23#![cfg_attr(feature = "atmega4808", doc = "**atmega4808**,")]
24#![cfg_attr(feature = "atmega4809", doc = "**atmega4809**,")]
25#![cfg_attr(feature = "atmega48p", doc = "**atmega48p**,")]
26#![cfg_attr(feature = "atmega64", doc = "**atmega64**,")]
27#![cfg_attr(feature = "atmega644", doc = "**atmega644**,")]
28#![cfg_attr(feature = "atmega88p", doc = "**atmega88p**,")]
29#![cfg_attr(feature = "attiny13a", doc = "**attiny13a**,")]
30#![cfg_attr(feature = "attiny167", doc = "**attiny167**,")]
31#![cfg_attr(feature = "attiny1614", doc = "**attiny1614**,")]
32#![cfg_attr(feature = "attiny202", doc = "**attiny202**,")]
33#![cfg_attr(feature = "attiny212", doc = "**attiny212**,")]
34#![cfg_attr(feature = "attiny214", doc = "**attiny214**,")]
35#![cfg_attr(feature = "attiny2313", doc = "**attiny2313**,")]
36#![cfg_attr(feature = "attiny2313a", doc = "**attiny2313a**,")]
37#![cfg_attr(feature = "attiny26", doc = "**attiny26**,")]
38#![cfg_attr(feature = "attiny402", doc = "**attiny402**,")]
39#![cfg_attr(feature = "attiny404", doc = "**attiny404**,")]
40#![cfg_attr(feature = "attiny412", doc = "**attiny412**,")]
41#![cfg_attr(feature = "attiny414", doc = "**attiny414**,")]
42#![cfg_attr(feature = "attiny416", doc = "**attiny416**,")]
43#![cfg_attr(feature = "attiny44a", doc = "**attiny44a**,")]
44#![cfg_attr(feature = "attiny816", doc = "**attiny816**,")]
45#![cfg_attr(feature = "attiny828", doc = "**attiny828**,")]
46#![cfg_attr(feature = "attiny84", doc = "**attiny84**,")]
47#![cfg_attr(feature = "attiny841", doc = "**attiny841**,")]
48#![cfg_attr(feature = "attiny84a", doc = "**attiny84a**,")]
49#![cfg_attr(feature = "attiny85", doc = "**attiny85**,")]
50#![cfg_attr(feature = "attiny861", doc = "**attiny861**,")]
51#![cfg_attr(feature = "attiny88", doc = "**attiny88**,")]
52#![cfg_attr(feature = "avr64du32", doc = "**avr64du32**,")]
53#![cfg_attr(feature = "avr64du28", doc = "**avr64du28**,")]
54//! and a few things which apply to AVR microcontrollers generally.
55//!
56#![cfg_attr(
57    feature = "docsrs",
58    doc = "**Warning**: The doc-build here on docs.rs is only for a subset of supported chips.  Please build documentation locally if your MCU's registers are not documented here.\n\n"
59)]
60//! Which chips the crate is built for depends on the feature flag used.
61//! The following chips are available (using feature flags of the same name):
62//! `at90usb1286`,
63//! `atmega1280`,
64//! `atmega1284p`,
65//! `atmega128a`,
66//! `atmega128rfa1`,
67//! `atmega16`,
68//! `atmega164pa`,
69//! `atmega168`,
70//! `atmega16u2`,
71//! `atmega2560`,
72//! `atmega8`,
73//! `atmega8u2`,
74//! `atmega324pa`
75//! `atmega328p`,
76//! `atmega328pb`,
77//! `atmega32a`
78//! `atmega32u2`,
79//! `atmega32u4`,
80//! `atmega3208`,
81//! `atmega3209`,
82//! `atmega4808`,
83//! `atmega4809`,
84//! `atmega48p`,
85//! `atmega64`,
86//! `atmega644`,
87//! `atmega88p`,
88//! `attiny13a`,
89//! `attiny167`,
90//! `attiny1614`,
91//! `attiny202`,
92//! `attiny212`,
93//! `attiny214`,
94//! `attiny2313`,
95//! `attiny2313a`,
96//! `attiny26`,
97//! `attiny402`,
98//! `attiny404`,
99//! `attiny412`,
100//! `attiny414`,
101//! `attiny416`,
102//! `attiny44a`,
103//! `attiny816`,
104//! `attiny828`,
105//! `attiny84`,
106//! `attiny841`,
107//! `attiny84a`,
108//! `attiny85`,
109//! `attiny861`,
110//! `attiny88`,
111//! `avr64du32`,
112//! `avr64du28`,
113//!
114//! # How to use this crate?
115//!
116//! In most cases you probably don't want to use this crate directly.
117//!
118//! This is a low level peripheral access crate (PAC).
119//! There are more high level crates, like `avr-hal`, that implement a more convenient
120//! and higher level API built ontop of `avr-device`.
121//! However, sometimes it's required to operate on bare device register level.
122//! That's what this crate is for.
123//!
124//! ## Main program entry point
125//!
126//! ```
127//! #[avr_device::entry] // requires avr_device's rt feature.
128//! fn main() -> ! {
129//!     loop {
130//!         // Your code here.
131//!     }
132//! }
133//! ```
134//!
135//! ## Get access to the device peripherals
136//!
137//! ```ignore
138//! // To get access to the Peripherals struct, use this *once*:
139//! let dp = avr_device::atmega328p::Peripherals::take().unwrap();
140//! ```
141//!
142//! ## Example: Digital I/O port access
143//!
144//! ```ignore
145//! // Configure bit 5 of port B as output:
146//! dp.PORTB.ddrb.write(|w| w.pb5().set_bit());
147//! // Clear bit 5 of port B:
148//! dp.PORTB.portb.write(|w| w.pb5().clear_bit());
149//! // Set bit 5 of port B:
150//! dp.PORTB.portb.write(|w| w.pb5().set_bit());
151//!
152//! // Configure bit 6 of port B as input with pullup:
153//! dp.PORTB.ddrb.write(|w| w.pb6().clear_bit());
154//! dp.PORTB.portb.write(|w| w.pb6().set_bit());
155//! // Read bit 6 of pin B:
156//! let _mybit = dp.PORTB.pinb.read().pb6().bit_is_set();
157//! // Read bit 6 and write to bit 5 of port B:
158//! dp.PORTB.portb.modify(|r, w| w.pb6().bit(r.pb5().bit_is_set()))
159//! ```
160//!
161//! ## Example: Other peripheral register access
162//!
163//! Other peripheral register accesses are similar to I/O port access.
164//! Please read the documentation of the `struct R` and `struct W`
165//! for the register of interest.
166//!
167//! e.g. [crate::atmega328p::spi::spcr::W]
168//!
169//! ```ignore
170//! // Set SPE in SPCR (Enable SPI):
171//! dp.SPI.spcr.write(|w| w.spe().set_bit());
172//! ```
173//!
174//! # Crate feature flags
175//!
176//! * Device selection: To enable your device, select the crate feature that matches your device.
177//!   For a full list of supported devices, see the list at the beginning of this documentation.
178//! * To enable the crate's runtime environment, use the `rt` feature.
179//! * To enable `ufmt` formatting (e.g. `uDebug`), use the `ufmt` feature.
180
181#![no_std]
182#![cfg_attr(target_arch = "avr", feature(asm_experimental_arch))] // for experimental AVR asm! macro.
183
184pub mod asm;
185pub mod interrupt;
186
187#[allow(unused_imports)]
188use generic::*;
189#[doc = r"Common register and bit access and modify traits"]
190pub mod generic;
191
192/// Attribute to declare an interrupt service routine
193///
194/// ```
195/// #[avr_device::interrupt(atmega32u4)]
196/// fn INT6() {
197///     // ...
198/// }
199/// ```
200///
201/// # Constraints
202/// - The name of the function must be the name of an interrupt.  Each chip's
203///   module has a `Interrupt` enum defining the available names.
204/// - The attribute needs the chip-name to correctly map the interrupt to its
205///   vector.  This is an unfortunate requirement of the current crate
206///   architecture and might change in the future.
207/// - The function must have a signature of `[unsafe] fn() [-> !]`.
208/// - This macro requires the avr-device `rt` crate feature.
209#[cfg(feature = "rt")]
210pub use avr_device_macros::interrupt;
211
212/// Attribute to declare the entry point of the program
213///
214/// Exactly one entry point must be declared in the entire dependency tree.
215///
216/// ```
217/// #[avr_device::entry]
218/// fn main() -> ! {
219///     loop {
220///         // ...
221///     }
222/// }
223/// ```
224///
225/// # Constraints
226/// - The entry function must have a signature of `[unsafe] fn() -> !`.
227/// - This macro requires the avr-device `rt` crate feature.
228#[cfg(feature = "rt")]
229pub use avr_device_macros::entry;
230
231#[cfg(not(feature = "device-selected"))]
232compile_error!(
233    "This crate requires you to specify your target chip as a feature.
234
235    Please select one of the following:
236    * atmega1280
237    * atmega1284p
238    * atmega128a
239    * atmega128rfa1
240    * atmega16
241    * atmega164pa
242    * atmega168
243    * atmega16u2
244    * atmega2560
245    * atmega324pa
246    * atmega328p
247    * atmega328pb
248    * atmega32a
249    * atmega32u2
250    * atmega32u4
251    * atmega3208
252    * atmega3209
253    * atmega4808
254    * atmega4809
255    * atmega48p
256    * atmega64
257    * atmega644
258    * atmega8
259    * atmega8u2
260    * atmega88p
261    * attiny13a
262    * attiny167
263    * attiny1614
264    * attiny202
265    * attiny212
266    * attiny214
267    * attiny2313
268    * attiny2313a
269    * attiny26
270    * attiny402
271    * attiny412
272    * attiny414
273    * attiny416
274    * attiny44a
275    * attiny816
276    * attiny828
277    * attiny84
278    * attiny841
279    * attiny84a
280    * attiny85
281    * attiny861
282    * attiny88
283    * avr64du32
284    * avr64du28
285    "
286);
287
288#[allow(non_camel_case_types, unused_attributes, unreachable_patterns)]
289mod devices;
290
291#[cfg(feature = "at90usb1286")]
292pub use crate::devices::at90usb1286;
293#[cfg(feature = "atmega1280")]
294pub use crate::devices::atmega1280;
295#[cfg(feature = "atmega1284p")]
296pub use crate::devices::atmega1284p;
297#[cfg(feature = "atmega128a")]
298pub use crate::devices::atmega128a;
299#[cfg(feature = "atmega128rfa1")]
300pub use crate::devices::atmega128rfa1;
301#[cfg(feature = "atmega16")]
302pub use crate::devices::atmega16;
303#[cfg(feature = "atmega164pa")]
304pub use crate::devices::atmega164pa;
305#[cfg(feature = "atmega168")]
306pub use crate::devices::atmega168;
307#[cfg(feature = "atmega16u2")]
308pub use crate::devices::atmega16u2;
309#[cfg(feature = "atmega2560")]
310pub use crate::devices::atmega2560;
311#[cfg(feature = "atmega324pa")]
312pub use crate::devices::atmega324pa;
313#[cfg(feature = "atmega328p")]
314pub use crate::devices::atmega328p;
315#[cfg(feature = "atmega328pb")]
316pub use crate::devices::atmega328pb;
317#[cfg(feature = "atmega32a")]
318pub use crate::devices::atmega32a;
319#[cfg(feature = "atmega32u2")]
320pub use crate::devices::atmega32u2;
321#[cfg(feature = "atmega32u4")]
322pub use crate::devices::atmega32u4;
323#[cfg(feature = "atmega3208")]
324pub use crate::devices::atmega3208;
325#[cfg(feature = "atmega3209")]
326pub use crate::devices::atmega3209;
327#[cfg(feature = "atmega4808")]
328pub use crate::devices::atmega4808;
329#[cfg(feature = "atmega4809")]
330pub use crate::devices::atmega4809;
331#[cfg(feature = "atmega48p")]
332pub use crate::devices::atmega48p;
333#[cfg(feature = "atmega64")]
334pub use crate::devices::atmega64;
335#[cfg(feature = "atmega644")]
336pub use crate::devices::atmega644;
337#[cfg(feature = "atmega8")]
338pub use crate::devices::atmega8;
339#[cfg(feature = "atmega88p")]
340pub use crate::devices::atmega88p;
341#[cfg(feature = "atmega8u2")]
342pub use crate::devices::atmega8u2;
343#[cfg(feature = "attiny13a")]
344pub use crate::devices::attiny13a;
345#[cfg(feature = "attiny1614")]
346pub use crate::devices::attiny1614;
347#[cfg(feature = "attiny167")]
348pub use crate::devices::attiny167;
349#[cfg(feature = "attiny202")]
350pub use crate::devices::attiny202;
351#[cfg(feature = "attiny212")]
352pub use crate::devices::attiny212;
353#[cfg(feature = "attiny214")]
354pub use crate::devices::attiny214;
355#[cfg(feature = "attiny2313")]
356pub use crate::devices::attiny2313;
357#[cfg(feature = "attiny2313a")]
358pub use crate::devices::attiny2313a;
359#[cfg(feature = "attiny26")]
360pub use crate::devices::attiny26;
361#[cfg(feature = "attiny402")]
362pub use crate::devices::attiny402;
363#[cfg(feature = "attiny404")]
364pub use crate::devices::attiny404;
365#[cfg(feature = "attiny412")]
366pub use crate::devices::attiny412;
367#[cfg(feature = "attiny414")]
368pub use crate::devices::attiny414;
369#[cfg(feature = "attiny416")]
370pub use crate::devices::attiny416;
371#[cfg(feature = "attiny44a")]
372pub use crate::devices::attiny44a;
373#[cfg(feature = "attiny816")]
374pub use crate::devices::attiny816;
375#[cfg(feature = "attiny828")]
376pub use crate::devices::attiny828;
377#[cfg(feature = "attiny84")]
378pub use crate::devices::attiny84;
379#[cfg(feature = "attiny841")]
380pub use crate::devices::attiny841;
381#[cfg(feature = "attiny84a")]
382pub use crate::devices::attiny84a;
383#[cfg(feature = "attiny85")]
384pub use crate::devices::attiny85;
385#[cfg(feature = "attiny861")]
386pub use crate::devices::attiny861;
387#[cfg(feature = "attiny88")]
388pub use crate::devices::attiny88;
389#[cfg(feature = "avr64du28")]
390pub use crate::devices::avr64du28;
391#[cfg(feature = "avr64du32")]
392pub use crate::devices::avr64du32;