avr_device/devices/atmega328p/
mod.rs1#![doc = "Peripheral access API for ATMEGA328P microcontrollers (generated using svd2rust v0.28.0 ( ))\n\nYou can find an overview of the generated API [here].\n\nAPI features to be included in the [next]
2svd2rust release can be generated by cloning the svd2rust [repository], checking out the above commit, and running `cargo doc --open`.\n\n[here]: https://docs.rs/svd2rust/0.28.0/svd2rust/#peripheral-api\n[next]: https://github.com/rust-embedded/svd2rust/blob/master/CHANGELOG.md#unreleased\n[repository]: https://github.com/rust-embedded/svd2rust"]
3use core::marker::PhantomData;
4use core::ops::Deref;
5#[doc = r"Number available in the NVIC for configuring priority"]
6pub const NVIC_PRIO_BITS: u8 = 4;
7#[doc(hidden)]
8pub mod interrupt;
9pub use self::interrupt::Interrupt;
10#[doc = "Analog Comparator"]
11pub struct AC {
12 _marker: PhantomData<*const ()>,
13}
14unsafe impl Send for AC {}
15impl AC {
16 #[doc = r"Pointer to the register block"]
17 pub const PTR: *const ac::RegisterBlock = 0x50 as *const _;
18 #[doc = r"Return the pointer to the register block"]
19 #[inline(always)]
20 pub const fn ptr() -> *const ac::RegisterBlock {
21 Self::PTR
22 }
23}
24impl Deref for AC {
25 type Target = ac::RegisterBlock;
26 #[inline(always)]
27 fn deref(&self) -> &Self::Target {
28 unsafe { &*Self::PTR }
29 }
30}
31impl core::fmt::Debug for AC {
32 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
33 f.debug_struct("AC").finish()
34 }
35}
36#[doc = "Analog Comparator"]
37pub mod ac;
38#[doc = "Analog-to-Digital Converter"]
39pub struct ADC {
40 _marker: PhantomData<*const ()>,
41}
42unsafe impl Send for ADC {}
43impl ADC {
44 #[doc = r"Pointer to the register block"]
45 pub const PTR: *const adc::RegisterBlock = 0x78 as *const _;
46 #[doc = r"Return the pointer to the register block"]
47 #[inline(always)]
48 pub const fn ptr() -> *const adc::RegisterBlock {
49 Self::PTR
50 }
51}
52impl Deref for ADC {
53 type Target = adc::RegisterBlock;
54 #[inline(always)]
55 fn deref(&self) -> &Self::Target {
56 unsafe { &*Self::PTR }
57 }
58}
59impl core::fmt::Debug for ADC {
60 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
61 f.debug_struct("ADC").finish()
62 }
63}
64#[doc = "Analog-to-Digital Converter"]
65pub mod adc;
66#[doc = "CPU Registers"]
67pub struct CPU {
68 _marker: PhantomData<*const ()>,
69}
70unsafe impl Send for CPU {}
71impl CPU {
72 #[doc = r"Pointer to the register block"]
73 pub const PTR: *const cpu::RegisterBlock = 0x3e as *const _;
74 #[doc = r"Return the pointer to the register block"]
75 #[inline(always)]
76 pub const fn ptr() -> *const cpu::RegisterBlock {
77 Self::PTR
78 }
79}
80impl Deref for CPU {
81 type Target = cpu::RegisterBlock;
82 #[inline(always)]
83 fn deref(&self) -> &Self::Target {
84 unsafe { &*Self::PTR }
85 }
86}
87impl core::fmt::Debug for CPU {
88 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
89 f.debug_struct("CPU").finish()
90 }
91}
92#[doc = "CPU Registers"]
93pub mod cpu;
94#[doc = "EEPROM"]
95pub struct EEPROM {
96 _marker: PhantomData<*const ()>,
97}
98unsafe impl Send for EEPROM {}
99impl EEPROM {
100 #[doc = r"Pointer to the register block"]
101 pub const PTR: *const eeprom::RegisterBlock = 0x3f as *const _;
102 #[doc = r"Return the pointer to the register block"]
103 #[inline(always)]
104 pub const fn ptr() -> *const eeprom::RegisterBlock {
105 Self::PTR
106 }
107}
108impl Deref for EEPROM {
109 type Target = eeprom::RegisterBlock;
110 #[inline(always)]
111 fn deref(&self) -> &Self::Target {
112 unsafe { &*Self::PTR }
113 }
114}
115impl core::fmt::Debug for EEPROM {
116 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
117 f.debug_struct("EEPROM").finish()
118 }
119}
120#[doc = "EEPROM"]
121pub mod eeprom;
122#[doc = "External Interrupts"]
123pub struct EXINT {
124 _marker: PhantomData<*const ()>,
125}
126unsafe impl Send for EXINT {}
127impl EXINT {
128 #[doc = r"Pointer to the register block"]
129 pub const PTR: *const exint::RegisterBlock = 0x3b as *const _;
130 #[doc = r"Return the pointer to the register block"]
131 #[inline(always)]
132 pub const fn ptr() -> *const exint::RegisterBlock {
133 Self::PTR
134 }
135}
136impl Deref for EXINT {
137 type Target = exint::RegisterBlock;
138 #[inline(always)]
139 fn deref(&self) -> &Self::Target {
140 unsafe { &*Self::PTR }
141 }
142}
143impl core::fmt::Debug for EXINT {
144 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
145 f.debug_struct("EXINT").finish()
146 }
147}
148#[doc = "External Interrupts"]
149pub mod exint;
150#[doc = "Fuses"]
151pub struct FUSE {
152 _marker: PhantomData<*const ()>,
153}
154unsafe impl Send for FUSE {}
155impl FUSE {
156 #[doc = r"Pointer to the register block"]
157 pub const PTR: *const fuse::RegisterBlock = 0 as *const _;
158 #[doc = r"Return the pointer to the register block"]
159 #[inline(always)]
160 pub const fn ptr() -> *const fuse::RegisterBlock {
161 Self::PTR
162 }
163}
164impl Deref for FUSE {
165 type Target = fuse::RegisterBlock;
166 #[inline(always)]
167 fn deref(&self) -> &Self::Target {
168 unsafe { &*Self::PTR }
169 }
170}
171impl core::fmt::Debug for FUSE {
172 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
173 f.debug_struct("FUSE").finish()
174 }
175}
176#[doc = "Fuses"]
177pub mod fuse;
178#[doc = "Lockbits"]
179pub struct LOCKBIT {
180 _marker: PhantomData<*const ()>,
181}
182unsafe impl Send for LOCKBIT {}
183impl LOCKBIT {
184 #[doc = r"Pointer to the register block"]
185 pub const PTR: *const lockbit::RegisterBlock = 0 as *const _;
186 #[doc = r"Return the pointer to the register block"]
187 #[inline(always)]
188 pub const fn ptr() -> *const lockbit::RegisterBlock {
189 Self::PTR
190 }
191}
192impl Deref for LOCKBIT {
193 type Target = lockbit::RegisterBlock;
194 #[inline(always)]
195 fn deref(&self) -> &Self::Target {
196 unsafe { &*Self::PTR }
197 }
198}
199impl core::fmt::Debug for LOCKBIT {
200 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
201 f.debug_struct("LOCKBIT").finish()
202 }
203}
204#[doc = "Lockbits"]
205pub mod lockbit;
206#[doc = "I/O Port"]
207pub struct PORTB {
208 _marker: PhantomData<*const ()>,
209}
210unsafe impl Send for PORTB {}
211impl PORTB {
212 #[doc = r"Pointer to the register block"]
213 pub const PTR: *const portb::RegisterBlock = 0x23 as *const _;
214 #[doc = r"Return the pointer to the register block"]
215 #[inline(always)]
216 pub const fn ptr() -> *const portb::RegisterBlock {
217 Self::PTR
218 }
219}
220impl Deref for PORTB {
221 type Target = portb::RegisterBlock;
222 #[inline(always)]
223 fn deref(&self) -> &Self::Target {
224 unsafe { &*Self::PTR }
225 }
226}
227impl core::fmt::Debug for PORTB {
228 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
229 f.debug_struct("PORTB").finish()
230 }
231}
232#[doc = "I/O Port"]
233pub mod portb;
234#[doc = "I/O Port"]
235pub struct PORTC {
236 _marker: PhantomData<*const ()>,
237}
238unsafe impl Send for PORTC {}
239impl PORTC {
240 #[doc = r"Pointer to the register block"]
241 pub const PTR: *const portc::RegisterBlock = 0x26 as *const _;
242 #[doc = r"Return the pointer to the register block"]
243 #[inline(always)]
244 pub const fn ptr() -> *const portc::RegisterBlock {
245 Self::PTR
246 }
247}
248impl Deref for PORTC {
249 type Target = portc::RegisterBlock;
250 #[inline(always)]
251 fn deref(&self) -> &Self::Target {
252 unsafe { &*Self::PTR }
253 }
254}
255impl core::fmt::Debug for PORTC {
256 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
257 f.debug_struct("PORTC").finish()
258 }
259}
260#[doc = "I/O Port"]
261pub mod portc;
262#[doc = "I/O Port"]
263pub struct PORTD {
264 _marker: PhantomData<*const ()>,
265}
266unsafe impl Send for PORTD {}
267impl PORTD {
268 #[doc = r"Pointer to the register block"]
269 pub const PTR: *const portd::RegisterBlock = 0x29 as *const _;
270 #[doc = r"Return the pointer to the register block"]
271 #[inline(always)]
272 pub const fn ptr() -> *const portd::RegisterBlock {
273 Self::PTR
274 }
275}
276impl Deref for PORTD {
277 type Target = portd::RegisterBlock;
278 #[inline(always)]
279 fn deref(&self) -> &Self::Target {
280 unsafe { &*Self::PTR }
281 }
282}
283impl core::fmt::Debug for PORTD {
284 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
285 f.debug_struct("PORTD").finish()
286 }
287}
288#[doc = "I/O Port"]
289pub mod portd;
290#[doc = "Serial Peripheral Interface"]
291pub struct SPI {
292 _marker: PhantomData<*const ()>,
293}
294unsafe impl Send for SPI {}
295impl SPI {
296 #[doc = r"Pointer to the register block"]
297 pub const PTR: *const spi::RegisterBlock = 0x4c as *const _;
298 #[doc = r"Return the pointer to the register block"]
299 #[inline(always)]
300 pub const fn ptr() -> *const spi::RegisterBlock {
301 Self::PTR
302 }
303}
304impl Deref for SPI {
305 type Target = spi::RegisterBlock;
306 #[inline(always)]
307 fn deref(&self) -> &Self::Target {
308 unsafe { &*Self::PTR }
309 }
310}
311impl core::fmt::Debug for SPI {
312 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
313 f.debug_struct("SPI").finish()
314 }
315}
316#[doc = "Serial Peripheral Interface"]
317pub mod spi;
318#[doc = "Timer/Counter, 8-bit"]
319pub struct TC0 {
320 _marker: PhantomData<*const ()>,
321}
322unsafe impl Send for TC0 {}
323impl TC0 {
324 #[doc = r"Pointer to the register block"]
325 pub const PTR: *const tc0::RegisterBlock = 0x35 as *const _;
326 #[doc = r"Return the pointer to the register block"]
327 #[inline(always)]
328 pub const fn ptr() -> *const tc0::RegisterBlock {
329 Self::PTR
330 }
331}
332impl Deref for TC0 {
333 type Target = tc0::RegisterBlock;
334 #[inline(always)]
335 fn deref(&self) -> &Self::Target {
336 unsafe { &*Self::PTR }
337 }
338}
339impl core::fmt::Debug for TC0 {
340 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
341 f.debug_struct("TC0").finish()
342 }
343}
344#[doc = "Timer/Counter, 8-bit"]
345pub mod tc0;
346#[doc = "Timer/Counter, 16-bit"]
347pub struct TC1 {
348 _marker: PhantomData<*const ()>,
349}
350unsafe impl Send for TC1 {}
351impl TC1 {
352 #[doc = r"Pointer to the register block"]
353 pub const PTR: *const tc1::RegisterBlock = 0x36 as *const _;
354 #[doc = r"Return the pointer to the register block"]
355 #[inline(always)]
356 pub const fn ptr() -> *const tc1::RegisterBlock {
357 Self::PTR
358 }
359}
360impl Deref for TC1 {
361 type Target = tc1::RegisterBlock;
362 #[inline(always)]
363 fn deref(&self) -> &Self::Target {
364 unsafe { &*Self::PTR }
365 }
366}
367impl core::fmt::Debug for TC1 {
368 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
369 f.debug_struct("TC1").finish()
370 }
371}
372#[doc = "Timer/Counter, 16-bit"]
373pub mod tc1;
374#[doc = "Timer/Counter, 8-bit Async"]
375pub struct TC2 {
376 _marker: PhantomData<*const ()>,
377}
378unsafe impl Send for TC2 {}
379impl TC2 {
380 #[doc = r"Pointer to the register block"]
381 pub const PTR: *const tc2::RegisterBlock = 0x37 as *const _;
382 #[doc = r"Return the pointer to the register block"]
383 #[inline(always)]
384 pub const fn ptr() -> *const tc2::RegisterBlock {
385 Self::PTR
386 }
387}
388impl Deref for TC2 {
389 type Target = tc2::RegisterBlock;
390 #[inline(always)]
391 fn deref(&self) -> &Self::Target {
392 unsafe { &*Self::PTR }
393 }
394}
395impl core::fmt::Debug for TC2 {
396 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
397 f.debug_struct("TC2").finish()
398 }
399}
400#[doc = "Timer/Counter, 8-bit Async"]
401pub mod tc2;
402#[doc = "Two Wire Serial Interface"]
403pub struct TWI {
404 _marker: PhantomData<*const ()>,
405}
406unsafe impl Send for TWI {}
407impl TWI {
408 #[doc = r"Pointer to the register block"]
409 pub const PTR: *const twi::RegisterBlock = 0xb8 as *const _;
410 #[doc = r"Return the pointer to the register block"]
411 #[inline(always)]
412 pub const fn ptr() -> *const twi::RegisterBlock {
413 Self::PTR
414 }
415}
416impl Deref for TWI {
417 type Target = twi::RegisterBlock;
418 #[inline(always)]
419 fn deref(&self) -> &Self::Target {
420 unsafe { &*Self::PTR }
421 }
422}
423impl core::fmt::Debug for TWI {
424 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
425 f.debug_struct("TWI").finish()
426 }
427}
428#[doc = "Two Wire Serial Interface"]
429pub mod twi;
430#[doc = "USART"]
431pub struct USART0 {
432 _marker: PhantomData<*const ()>,
433}
434unsafe impl Send for USART0 {}
435impl USART0 {
436 #[doc = r"Pointer to the register block"]
437 pub const PTR: *const usart0::RegisterBlock = 0xc0 as *const _;
438 #[doc = r"Return the pointer to the register block"]
439 #[inline(always)]
440 pub const fn ptr() -> *const usart0::RegisterBlock {
441 Self::PTR
442 }
443}
444impl Deref for USART0 {
445 type Target = usart0::RegisterBlock;
446 #[inline(always)]
447 fn deref(&self) -> &Self::Target {
448 unsafe { &*Self::PTR }
449 }
450}
451impl core::fmt::Debug for USART0 {
452 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
453 f.debug_struct("USART0").finish()
454 }
455}
456#[doc = "USART"]
457pub mod usart0;
458#[doc = "Watchdog Timer"]
459pub struct WDT {
460 _marker: PhantomData<*const ()>,
461}
462unsafe impl Send for WDT {}
463impl WDT {
464 #[doc = r"Pointer to the register block"]
465 pub const PTR: *const wdt::RegisterBlock = 0x60 as *const _;
466 #[doc = r"Return the pointer to the register block"]
467 #[inline(always)]
468 pub const fn ptr() -> *const wdt::RegisterBlock {
469 Self::PTR
470 }
471}
472impl Deref for WDT {
473 type Target = wdt::RegisterBlock;
474 #[inline(always)]
475 fn deref(&self) -> &Self::Target {
476 unsafe { &*Self::PTR }
477 }
478}
479impl core::fmt::Debug for WDT {
480 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
481 f.debug_struct("WDT").finish()
482 }
483}
484#[doc = "Watchdog Timer"]
485pub mod wdt;
486use crate::devices::DEVICE_PERIPHERALS;
487#[doc = r" All the peripherals."]
488#[allow(non_snake_case)]
489pub struct Peripherals {
490 #[doc = "AC"]
491 pub AC: AC,
492 #[doc = "ADC"]
493 pub ADC: ADC,
494 #[doc = "CPU"]
495 pub CPU: CPU,
496 #[doc = "EEPROM"]
497 pub EEPROM: EEPROM,
498 #[doc = "EXINT"]
499 pub EXINT: EXINT,
500 #[doc = "FUSE"]
501 pub FUSE: FUSE,
502 #[doc = "LOCKBIT"]
503 pub LOCKBIT: LOCKBIT,
504 #[doc = "PORTB"]
505 pub PORTB: PORTB,
506 #[doc = "PORTC"]
507 pub PORTC: PORTC,
508 #[doc = "PORTD"]
509 pub PORTD: PORTD,
510 #[doc = "SPI"]
511 pub SPI: SPI,
512 #[doc = "TC0"]
513 pub TC0: TC0,
514 #[doc = "TC1"]
515 pub TC1: TC1,
516 #[doc = "TC2"]
517 pub TC2: TC2,
518 #[doc = "TWI"]
519 pub TWI: TWI,
520 #[doc = "USART0"]
521 pub USART0: USART0,
522 #[doc = "WDT"]
523 pub WDT: WDT,
524}
525impl Peripherals {
526 #[doc = r" Returns all the peripherals *once*."]
527 #[inline]
528 pub fn take() -> Option<Self> {
529 crate::interrupt::free(|_| {
530 if unsafe { DEVICE_PERIPHERALS } {
531 return None;
532 }
533 Some(unsafe { Peripherals::steal() })
534 })
535 }
536 #[doc = r" Unchecked version of `Peripherals::take`."]
537 #[doc = r""]
538 #[doc = r" # Safety"]
539 #[doc = r""]
540 #[doc = r" Each of the returned peripherals must be used at most once."]
541 #[inline]
542 pub unsafe fn steal() -> Self {
543 DEVICE_PERIPHERALS = true;
544 Peripherals {
545 AC: AC {
546 _marker: PhantomData,
547 },
548 ADC: ADC {
549 _marker: PhantomData,
550 },
551 CPU: CPU {
552 _marker: PhantomData,
553 },
554 EEPROM: EEPROM {
555 _marker: PhantomData,
556 },
557 EXINT: EXINT {
558 _marker: PhantomData,
559 },
560 FUSE: FUSE {
561 _marker: PhantomData,
562 },
563 LOCKBIT: LOCKBIT {
564 _marker: PhantomData,
565 },
566 PORTB: PORTB {
567 _marker: PhantomData,
568 },
569 PORTC: PORTC {
570 _marker: PhantomData,
571 },
572 PORTD: PORTD {
573 _marker: PhantomData,
574 },
575 SPI: SPI {
576 _marker: PhantomData,
577 },
578 TC0: TC0 {
579 _marker: PhantomData,
580 },
581 TC1: TC1 {
582 _marker: PhantomData,
583 },
584 TC2: TC2 {
585 _marker: PhantomData,
586 },
587 TWI: TWI {
588 _marker: PhantomData,
589 },
590 USART0: USART0 {
591 _marker: PhantomData,
592 },
593 WDT: WDT {
594 _marker: PhantomData,
595 },
596 }
597 }
598}