avr_device/
lib.rs

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