use crate::ral::{self, ccm::CCM};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
Pll3Sw = 0,
Osc = 1,
Pll2Bypass = 2,
}
#[inline(always)]
pub fn set_selection(ccm: &mut CCM, selection: Selection) {
ral::modify_reg!(ral::ccm, ccm, CBCMR, PERIPH_CLK2_SEL: selection as u32);
crate::ccm::wait_handshake(ccm);
}
#[inline(always)]
pub fn selection(ccm: &CCM) -> Selection {
let raw = ral::read_reg!(ral::ccm, ccm, CBCMR, PERIPH_CLK2_SEL);
match raw {
0 => Selection::Pll3Sw,
1 => Selection::Osc,
2 => Selection::Pll2Bypass,
_ => unreachable!(),
}
}