Refactor: Factor out Resolution
This commit is contained in:
59
embassy-stm32/src/adc/resolution.rs
Normal file
59
embassy-stm32/src/adc/resolution.rs
Normal file
@ -0,0 +1,59 @@
|
||||
#[cfg(any(adc_v2, adc_v3, adc_g0))]
|
||||
pub enum Resolution {
|
||||
TwelveBit,
|
||||
TenBit,
|
||||
EightBit,
|
||||
SixBit,
|
||||
}
|
||||
|
||||
#[cfg(adc_v4)]
|
||||
pub enum Resolution {
|
||||
SixteenBit,
|
||||
FourteenBit,
|
||||
TwelveBit,
|
||||
TenBit,
|
||||
EightBit,
|
||||
}
|
||||
|
||||
impl Default for Resolution {
|
||||
fn default() -> Self {
|
||||
#[cfg(any(adc_v2, adc_v3, adc_g0))]
|
||||
{
|
||||
Self::TwelveBit
|
||||
}
|
||||
#[cfg(adc_v4)]
|
||||
{
|
||||
Self::SixteenBit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Resolution {
|
||||
pub(super) fn res(&self) -> crate::pac::adc::vals::Res {
|
||||
match self {
|
||||
#[cfg(adc_v4)]
|
||||
Resolution::SixteenBit => crate::pac::adc::vals::Res::SIXTEENBIT,
|
||||
#[cfg(adc_v4)]
|
||||
Resolution::FourteenBit => crate::pac::adc::vals::Res::FOURTEENBITV,
|
||||
Resolution::TwelveBit => crate::pac::adc::vals::Res::TWELVEBIT,
|
||||
Resolution::TenBit => crate::pac::adc::vals::Res::TENBIT,
|
||||
Resolution::EightBit => crate::pac::adc::vals::Res::EIGHTBIT,
|
||||
#[cfg(any(adc_v2, adc_v3, adc_g0))]
|
||||
Resolution::SixBit => crate::pac::adc::vals::Res::SIXBIT,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_max_count(&self) -> u32 {
|
||||
match self {
|
||||
#[cfg(adc_v4)]
|
||||
Resolution::SixteenBit => (1 << 16) - 1,
|
||||
#[cfg(adc_v4)]
|
||||
Resolution::FourteenBit => (1 << 14) - 1,
|
||||
Resolution::TwelveBit => (1 << 12) - 1,
|
||||
Resolution::TenBit => (1 << 10) - 1,
|
||||
Resolution::EightBit => (1 << 8) - 1,
|
||||
#[cfg(any(adc_v2, adc_v3, adc_g0))]
|
||||
Resolution::SixBit => (1 << 6) - 1,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user