#![cfg_attr(not(test), no_std)]
#![warn(missing_docs)]
#[macro_use]
extern crate uom;
pub(crate) mod fmt;
pub(crate) mod counters;
pub mod protocol_layer;
pub mod sink;
pub mod timers;
#[cfg(test)]
pub mod dummy;
pub mod units {
ISQ!(
uom::si,
u32,
(millimeter, kilogram, second, milliampere, kelvin, mole, candela)
);
}
pub mod _50milliamperes_mod {
unit! {
system: uom::si;
quantity: uom::si::electric_current;
@_50milliamperes: 0.05; "_50mA", "_50milliamps", "_50milliamps";
}
}
pub mod _50millivolts_mod {
unit! {
system: uom::si;
quantity: uom::si::electric_potential;
@_50millivolts: 0.05; "_50mV", "_50millivolts", "_50millivolts";
}
}
pub mod _20millivolts_mod {
unit! {
system: uom::si;
quantity: uom::si::electric_potential;
@_20millivolts: 0.02; "_20mV", "_20millivolts", "_20millivolts";
}
}
pub mod _25millivolts_mod {
unit! {
system: uom::si;
quantity: uom::si::electric_potential;
@_25millivolts: 0.025; "_25mV", "_25millivolts", "_25millivolts";
}
}
pub mod _250milliwatts_mod {
unit! {
system: uom::si;
quantity: uom::si::power;
@_250milliwatts: 0.25; "_250mW", "_250milliwatts", "_250milliwatts";
}
}
use core::fmt::Debug;
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PowerRole {
Source,
Sink,
}
impl From<bool> for PowerRole {
fn from(value: bool) -> Self {
match value {
false => Self::Sink,
true => Self::Source,
}
}
}
impl From<PowerRole> for bool {
fn from(role: PowerRole) -> bool {
match role {
PowerRole::Sink => false,
PowerRole::Source => true,
}
}
}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DataRole {
Ufp,
Dfp,
}
impl From<bool> for DataRole {
fn from(value: bool) -> Self {
match value {
false => Self::Ufp,
true => Self::Dfp,
}
}
}
impl From<DataRole> for bool {
fn from(role: DataRole) -> bool {
match role {
DataRole::Ufp => false,
DataRole::Dfp => true,
}
}
}
#[cfg(test)]
mod tests {
use uom::si::electric_current::milliampere;
use uom::si::electric_potential::millivolt;
use crate::_20millivolts_mod::_20millivolts;
use crate::units;
#[test]
fn test_units() {
let current = units::ElectricCurrent::new::<milliampere>(123);
let potential = units::ElectricPotential::new::<millivolt>(4560);
assert_eq!(current.get::<milliampere>(), 123);
assert_eq!(potential.get::<millivolt>(), 4560);
assert_eq!(potential.get::<_20millivolts>(), 228);
}
}