use crate::config::InputPull;
use crate::description::PinLevel;
use serde::{Deserialize, Serialize};
#[cfg(not(feature = "std"))]
use core::clone::Clone;
#[cfg(not(feature = "std"))]
use core::cmp::PartialEq;
#[cfg(not(feature = "std"))]
use core::fmt::Debug;
#[cfg(not(feature = "std"))]
use core::marker::Copy;
#[cfg(not(feature = "std"))]
use core::option::Option;
#[cfg(not(feature = "std"))]
use core::prelude::rust_2024::derive;
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
#[allow(clippy::upper_case_acronyms)]
pub enum PinFunction {
Input(Option<InputPull>),
Output(Option<PinLevel>),
}
#[cfg(feature = "std")]
impl std::fmt::Display for PinFunction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let full = format!("{self:?}");
write!(f, "{}", full.split_once('(').unwrap_or((&full, "")).0)
}
}
#[cfg(all(test, feature = "std"))]
mod test {
use crate::config::InputPull::{PullDown, PullUp};
use crate::pin_function::PinFunction;
#[test]
fn display_pin_function() {
let functions = vec![
PinFunction::Output(None),
PinFunction::Output(Some(true)),
PinFunction::Output(Some(false)),
PinFunction::Input(None),
PinFunction::Input(Some(PullUp)),
PinFunction::Input(Some(PullDown)),
];
for function in functions {
println!("{function}");
}
}
}