Skip to main content

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