Merge Mask and Bitset, remove Bitset
There isn't as much value as I thought in making the distinction.
This commit is contained in:
parent
c486e1b7a9
commit
61c62ad0ed
|
@ -73,7 +73,7 @@ fn generate_cores_mod_rs(mcus: &[Mcu]) -> Result<(), io::Error> {
|
||||||
fn write_core_module(mcu: &Mcu, w: &mut Write) -> Result<(), io::Error> {
|
fn write_core_module(mcu: &Mcu, w: &mut Write) -> Result<(), io::Error> {
|
||||||
writeln!(w, "//! Core for {}.", mcu.device.name)?;
|
writeln!(w, "//! Core for {}.", mcu.device.name)?;
|
||||||
writeln!(w)?;
|
writeln!(w)?;
|
||||||
writeln!(w, "use {{Mask, Bitset, Register}};")?;
|
writeln!(w, "use {{Mask, Register}};")?;
|
||||||
writeln!(w, "use modules;")?;
|
writeln!(w, "use modules;")?;
|
||||||
writeln!(w)?;
|
writeln!(w)?;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub fn write_registers(mcu: &Mcu, w: &mut Write) -> Result<(), io::Error> {
|
||||||
writeln!(w, "impl {} {{", register.name)?;
|
writeln!(w, "impl {} {{", register.name)?;
|
||||||
for bitfield in register.bitfields.iter() {
|
for bitfield in register.bitfields.iter() {
|
||||||
// Create a mask for the whole bitset.
|
// Create a mask for the whole bitset.
|
||||||
writeln!(w, " pub const {}: Bitset<Self> = Bitset::new(0x{:x});", bitfield.name, bitfield.mask)?;
|
writeln!(w, " pub const {}: Mask<Self> = Mask::new(0x{:x});", bitfield.name, bitfield.mask)?;
|
||||||
|
|
||||||
// We create masks for the individual bits in the field if there
|
// We create masks for the individual bits in the field if there
|
||||||
// is more than one bit in the field.
|
// is more than one bit in the field.
|
||||||
|
@ -186,7 +186,7 @@ pub fn write_timers(mcu: &Mcu, w: &mut Write) -> Result<(), io::Error> {
|
||||||
writeln!(w, " const WGM0: Mask<Self::ControlA> = Self::ControlA::WGM00;")?;
|
writeln!(w, " const WGM0: Mask<Self::ControlA> = Self::ControlA::WGM00;")?;
|
||||||
writeln!(w, " const WGM1: Mask<Self::ControlA> = Self::ControlA::WGM01;")?;
|
writeln!(w, " const WGM1: Mask<Self::ControlA> = Self::ControlA::WGM01;")?;
|
||||||
writeln!(w, " const WGM2: Mask<Self::ControlB> = Self::ControlB::WGM020;")?;
|
writeln!(w, " const WGM2: Mask<Self::ControlB> = Self::ControlB::WGM020;")?;
|
||||||
writeln!(w, " const OCIEA: Bitset<Self::InterruptMask> = Self::InterruptMask::OCIE0A;")?;
|
writeln!(w, " const OCIEA: Mask<Self::InterruptMask> = Self::InterruptMask::OCIE0A;")?;
|
||||||
writeln!(w, "}}")?;
|
writeln!(w, "}}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ pub fn write_timers(mcu: &Mcu, w: &mut Write) -> Result<(), io::Error> {
|
||||||
writeln!(w, " const WGM1: Mask<Self::ControlA> = Self::ControlA::WGM11;")?;
|
writeln!(w, " const WGM1: Mask<Self::ControlA> = Self::ControlA::WGM11;")?;
|
||||||
writeln!(w, " const WGM2: Mask<Self::ControlB> = Self::ControlB::WGM10;")?;
|
writeln!(w, " const WGM2: Mask<Self::ControlB> = Self::ControlB::WGM10;")?;
|
||||||
writeln!(w, " const WGM3: Mask<Self::ControlB> = Self::ControlB::WGM11;")?;
|
writeln!(w, " const WGM3: Mask<Self::ControlB> = Self::ControlB::WGM11;")?;
|
||||||
writeln!(w, " const OCIEA: Bitset<Self::InterruptMask> = Self::InterruptMask::OCIE1A;")?;
|
writeln!(w, " const OCIEA: Mask<Self::InterruptMask> = Self::InterruptMask::OCIE1A;")?;
|
||||||
writeln!(w, "}}")?;
|
writeln!(w, "}}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
pub use self::register::{Bitset, Mask, Register, RegisterValue};
|
pub use self::register::{Mask, Register, RegisterValue};
|
||||||
pub use self::pin::{DataDirection, Pin};
|
pub use self::pin::{DataDirection, Pin};
|
||||||
|
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use {Bitset, Mask, Register};
|
use {Mask, Register};
|
||||||
use core::marker;
|
use core::marker;
|
||||||
|
|
||||||
/// A 16-bit timer.
|
/// A 16-bit timer.
|
||||||
|
@ -50,7 +50,7 @@ pub trait Timer16 : Sized {
|
||||||
const WGM2: Mask<Self::ControlB>;
|
const WGM2: Mask<Self::ControlB>;
|
||||||
const WGM3: Mask<Self::ControlB>;
|
const WGM3: Mask<Self::ControlB>;
|
||||||
|
|
||||||
const OCIEA: Bitset<Self::InterruptMask>;
|
const OCIEA: Mask<Self::InterruptMask>;
|
||||||
|
|
||||||
fn setup() -> Timer16Setup<Self> { Timer16Setup::new() }
|
fn setup() -> Timer16Setup<Self> { Timer16Setup::new() }
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ impl<T: Timer16> Timer16Setup<T> {
|
||||||
T::CompareA::write(v);
|
T::CompareA::write(v);
|
||||||
|
|
||||||
// Enable compare interrupt
|
// Enable compare interrupt
|
||||||
T::OCIEA.set_all();
|
T::InterruptMask::set(T::OCIEA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use {Bitset, Mask, Register};
|
use {Mask, Register};
|
||||||
use core::marker;
|
use core::marker;
|
||||||
|
|
||||||
/// A 8-bit timer.
|
/// A 8-bit timer.
|
||||||
|
@ -44,7 +44,7 @@ pub trait Timer8 : Sized {
|
||||||
const WGM1: Mask<Self::ControlA>;
|
const WGM1: Mask<Self::ControlA>;
|
||||||
const WGM2: Mask<Self::ControlB>;
|
const WGM2: Mask<Self::ControlB>;
|
||||||
|
|
||||||
const OCIEA: Bitset<Self::InterruptMask>;
|
const OCIEA: Mask<Self::InterruptMask>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ClockSource {
|
pub enum ClockSource {
|
||||||
|
@ -176,7 +176,7 @@ impl<T: Timer8> Timer8Setup<T> {
|
||||||
T::CompareA::write(v);
|
T::CompareA::write(v);
|
||||||
|
|
||||||
// Enable compare interrupt
|
// Enable compare interrupt
|
||||||
T::OCIEA.set_all();
|
T::InterruptMask::set(T::OCIEA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,13 +128,6 @@ pub trait Register : Sized {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A register bitmask.
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct Bitset<R: Register> {
|
|
||||||
mask: R::T,
|
|
||||||
_phantom: marker::PhantomData<R>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A register bitmask.
|
/// A register bitmask.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct Mask<R: Register> {
|
pub struct Mask<R: Register> {
|
||||||
|
@ -142,41 +135,6 @@ pub struct Mask<R: Register> {
|
||||||
_phantom: marker::PhantomData<R>,
|
_phantom: marker::PhantomData<R>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> Bitset<R> where R: Register {
|
|
||||||
/// Creates a new register mask.
|
|
||||||
pub const fn new(mask: R::T) -> Self {
|
|
||||||
Bitset { mask, _phantom: marker::PhantomData }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the mask in the register.
|
|
||||||
///
|
|
||||||
/// This is equivalent to `r |= mask`.
|
|
||||||
pub fn set_all(self) {
|
|
||||||
R::set_raw(self.mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clears the mask from the register.
|
|
||||||
///
|
|
||||||
/// This is equivalent to `r &= !mask`.
|
|
||||||
pub fn unset_all(self) {
|
|
||||||
R::unset_raw(self.mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Toggles the masked bits in the register.
|
|
||||||
///
|
|
||||||
/// This is equivalent to `r ^= mask`.
|
|
||||||
pub fn toggle_all(self) {
|
|
||||||
R::toggle_raw(self.mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if the mask is clear.
|
|
||||||
///
|
|
||||||
/// This is equivalent to `(r & mask) == 0`.
|
|
||||||
pub fn is_clear(self) -> bool {
|
|
||||||
R::is_clear_raw(self.mask)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<R> Mask<R> where R: Register {
|
impl<R> Mask<R> where R: Register {
|
||||||
/// Creates a new register mask.
|
/// Creates a new register mask.
|
||||||
pub const fn new(mask: R::T) -> Self {
|
pub const fn new(mask: R::T) -> Self {
|
||||||
|
|
Loading…
Reference in New Issue