Skip to content

Commit

Permalink
remove some erroneous whitespace, O -> OFFSET, more inline const exprs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdinAck committed Aug 25, 2024
1 parent 9f47dea commit 21eab92
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/cordic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub mod types {
/// Configure the resource to be represented
/// by this type-state.
#[inline]
fn set<const O: u8>(w: crate::stm32::cordic::csr::ARGSIZE_W<O>) {
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::ARGSIZE_W<OFFSET>) {
w.variant(Self::RAW);
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ pub mod types {
/// Configure the resource to be represented
/// by this type-state.
#[inline]
fn set<const O: u8>(w: crate::stm32::cordic::csr::RESSIZE_W<O>) {
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::RESSIZE_W<OFFSET>) {
w.variant(Self::RAW);
}
}
Expand Down Expand Up @@ -225,19 +225,23 @@ pub mod func {
type Raw = crate::stm32::cordic::csr::NARGS_A;

pub(crate) trait State<T> {
fn set<const O: u8>(w: crate::stm32::cordic::csr::NARGS_W<O>);
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::NARGS_W<OFFSET>);
}

impl<Arg, Count> State<Arg> for NReg<Arg, Count>
where
Arg: types::arg::State,
Count: data_count::Property<Arg>,
{
fn set<const O: u8>(w: crate::stm32::cordic::csr::NARGS_W<O>) {
w.variant(match (Arg::RAW, Count::COUNT) {
(types::arg::Raw::Bits32, data_count::Count::Two) => Raw::Num2,
(_, _) => Raw::Num1,
});
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::NARGS_W<OFFSET>) {
w.variant(
const {
match (Arg::RAW, Count::COUNT) {
(types::arg::Raw::Bits32, data_count::Count::Two) => Raw::Num2,
(_, _) => Raw::Num1,
}
},
);
}
}
}
Expand All @@ -248,19 +252,23 @@ pub mod func {
type Raw = crate::stm32::cordic::csr::NRES_A;

pub(crate) trait State<T> {
fn set<const O: u8>(w: crate::stm32::cordic::csr::NRES_W<O>);
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::NRES_W<OFFSET>);
}

impl<Res, Count> State<Res> for NReg<Res, Count>
where
Res: types::res::State,
Count: data_count::Property<Res>,
{
fn set<const O: u8>(w: crate::stm32::cordic::csr::NRES_W<O>) {
w.variant(match (Res::RAW, Count::COUNT) {
(types::res::Raw::Bits32, data_count::Count::Two) => Raw::Num2,
(_, _) => Raw::Num1,
});
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::NRES_W<OFFSET>) {
w.variant(
const {
match (Res::RAW, Count::COUNT) {
(types::res::Raw::Bits32, data_count::Count::Two) => Raw::Num2,
(_, _) => Raw::Num1,
}
},
);
}
}
}
Expand All @@ -279,7 +287,7 @@ pub mod func {
/// Configure the resource to be represented
/// by this type-state.
#[inline]
fn set<const O: u8>(w: crate::stm32::cordic::csr::SCALE_W<O>) {
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::SCALE_W<OFFSET>) {
w.bits(<Self as State>::RAW);
}
}
Expand Down Expand Up @@ -458,7 +466,7 @@ pub mod func {
/// Configure the resource to be represented
/// by this type-state.
#[inline]
fn set<const O: u8>(w: crate::stm32::cordic::csr::FUNC_W<O>) {
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::FUNC_W<OFFSET>) {
w.variant(Self::RAW);
}
}
Expand Down Expand Up @@ -510,7 +518,6 @@ pub mod func {
/// Arctangent of x.
///
/// This function can be scaled by 0-7.
pub struct ATan<Scale: scale::State> {
_scale: PhantomData<Scale>,
}
Expand All @@ -525,14 +532,12 @@ pub mod func {
/// Natural logarithm of x.
///
/// This function can be scaled by 1-4.
pub struct Ln<Scale: scale::State> {
_scale: PhantomData<Scale>,
}
/// Square root of x.
///
/// This function can be scaled by 0-2.
pub struct Sqrt<Scale: scale::State> {
_scale: PhantomData<Scale>,
}
Expand Down Expand Up @@ -656,7 +661,7 @@ pub mod prec {

/// Configure the resource to be represented
/// by this type-state.
fn set<const O: u8>(w: crate::stm32::cordic::csr::PRECISION_W<O>);
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::PRECISION_W<OFFSET>);
}

/// 4 iterations.
Expand Down Expand Up @@ -697,7 +702,7 @@ pub mod prec {
const BITS: u8 = $BITS;

#[inline]
fn set<const O: u8>(w: crate::stm32::cordic::csr::PRECISION_W<O>) {
fn set<const OFFSET: u8>(w: crate::stm32::cordic::csr::PRECISION_W<OFFSET>) {
// SAFETY: reliant on valid type-state
// implementations.
unsafe { w.bits(<Self as State>::BITS) };
Expand Down

0 comments on commit 21eab92

Please sign in to comment.