~ruther/avr-device

ref: f77864dc9935b6cc402024373ec2e645d1d0cbcf avr-device/src/lib.rs -rw-r--r-- 2.5 KiB
f77864dc — Rahix hack: Make sure you cannot build for more than one chip 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! This crate contains register definitions for
#![cfg_attr(feature = "atmega1280", doc = "**atmega1280**.")]
#![cfg_attr(feature = "atmega8", doc = "**atmega8**.")]
#![cfg_attr(feature = "atmega328p", doc = "**atmega328p**.")]
#![cfg_attr(feature = "atmega32u4", doc = "**atmega32u4**.")]
#![cfg_attr(feature = "attiny85", doc = "**attiny85**.")]
//! Which chip the crate is built for depends on the feature flag used.
//!
//! The following chips are available (using feature flags of the same name):
//! * `atmega1280`
//! * `atmega8`
//! * `atmega328p`
//! * `atmega32u4`
//! * `attiny85`
#![no_std]
#![feature(asm)]

#[allow(non_camel_case_types, unused_attributes)]
mod devices;

pub mod interrupt;

cfg_if::cfg_if! {
    if #[cfg(feature= "atmega1280")] {
        pub use crate::devices::atmega1280::*;
    } else if #[cfg(feature = "atmega8")] {
        pub use crate::devices::atmega8::*;
    } else if #[cfg(feature = "atmega328p")] {
        pub use crate::devices::atmega328p::*;
    } else if #[cfg(feature = "atmega32u4")] {
        pub use crate::devices::atmega32u4::*;
    } else if #[cfg(feature = "attiny85")] {
        pub use crate::devices::attiny85::*;
    } else {
        compile_error!("You need to select a chip as a feature!");
    }
}

// TODO: Find a better way to do this
#[cfg(any(
    all(feature = "atmega1280", any(
        feature = "atmega8",
        feature = "atmega328p",
        feature = "atmega32u4",
        feature = "attiny85",
    )),
    all(feature = "atmega8", any(
        feature = "atmega1280",
        feature = "atmega328p",
        feature = "atmega32u4",
        feature = "attiny85",
    )),
    all(feature = "atmega328p", any(
        feature = "atmega1280",
        feature = "atmega8",
        feature = "atmega32u4",
        feature = "attiny85",
    )),
    all(feature = "atmega32u4", any(
        feature = "atmega1280",
        feature = "atmega8",
        feature = "atmega329p",
        feature = "attiny85",
    )),
))]
compile_error!("You cannot select multiple chips at once!");

#[cfg(any(
    feature = "atmega1280",
    feature = "atmega8",
    feature = "atmega328p",
    feature = "atmega32u4",
    feature = "attiny85",
))]
impl Peripherals {
    /// Returns all the peripherals *once*
    #[inline]
    pub fn take() -> Option<Self> {
        interrupt::free(|_| {
            if unsafe { DEVICE_PERIPHERALS } {
                None
            } else {
                Some(unsafe { Peripherals::steal() })
            }
        })
    }
}
Do not follow this link