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