#![no_implicit_prelude]
extern crate core;
use core::clone::Clone;
use core::marker::Copy;
use crate::pac::VREG_AND_CHIP_RESET;
#[repr(u8)]
pub enum Voltage {
Volts0_80 = 0x5u8,
Volts0_85 = 0x6u8,
Volts0_90 = 0x7u8,
Volts0_95 = 0x8u8,
Volts1_00 = 0x9u8,
Volts1_05 = 0xAu8,
Volts1_10 = 0xBu8,
Volts1_15 = 0xCu8,
Volts1_20 = 0xDu8,
Volts1_25 = 0xEu8,
Volts1_30 = 0xFu8,
}
#[inline]
pub fn voltage() -> Voltage {
match unsafe { VREG_AND_CHIP_RESET::steal() }.vreg().read().vsel().bits() {
0x6 => Voltage::Volts0_85,
0x7 => Voltage::Volts0_90,
0x8 => Voltage::Volts0_95,
0x9 => Voltage::Volts1_00,
0xA => Voltage::Volts1_05,
0xB => Voltage::Volts1_10,
0xC => Voltage::Volts1_15,
0xD => Voltage::Volts1_20,
0xE => Voltage::Volts1_25,
0xF => Voltage::Volts1_30,
_ => Voltage::Volts0_80,
}
}
#[inline]
pub fn set_voltage(v: Voltage) {
unsafe { VREG_AND_CHIP_RESET::steal() }
.vreg()
.write(|r| unsafe { r.vsel().bits(v as u8) });
}
impl Copy for Voltage {}
impl Clone for Voltage {
#[inline]
fn clone(&self) -> Voltage {
*self
}
}