avr_mcu/current.rs
1//! Utilities for querying information about the microcontroller being targeted.
2
3use load;
4use std::env;
5use Mcu;
6
7/// Gets information about the current microcontroller.
8///
9/// Returns `None` if the target architecture is not AVR.
10///
11/// When targeting AVR, this function will always return `Some(mcu)`.
12pub fn mcu() -> Option<Mcu> {
13 mcu_name().map(|mcu_name| load::microcontroller(&mcu_name))
14}
15
16/// Gets the name of the microcontroller being targeted.
17///
18/// Returns `None` if the target architecture is not AVR.
19///
20/// When targeting AVR, this function will always return `Some(mcu_name)`.
21///
22/// # Example results
23///
24/// * `Some("atmega328")`
25/// * `Some("attiny85")`
26/// * `None`
27pub fn mcu_name() -> Option<String> {
28 target_cpu_fetch::target_cpu().ok().and_then(|o| o)
29}
30
31/// Checks if the current cargo target architecture is AVR.
32pub fn is_compiling_for_avr() -> bool {
33 env::var("CARGO_CFG_TARGET_ARCH") == Ok("avr".to_string())
34}
35