embassy-stm32

Crates

git

Versions

stm32h7b0zb

Flavors

Skip to main content

FilterParameters

Struct FilterParameters 

Source
pub struct FilterParameters { /* private fields */ }
Expand description

Filter parameters (order, OSR and input width) for a filter.

Implementations§

Source§

impl FilterParameters

Source

pub fn new(order: FilterOrder, iosr: u16) -> Self

Create from FilterOrder (carrying its FOSR) and the actual IOSR value, assuming a 1-bit serial input. Panics if out of range. For a non-panicking variant, use FilterParameters::try_new. For parallel (ADC/DMA) inputs use FilterParameters::new_for_width.

Source

pub fn try_new(order: FilterOrder, iosr: u16) -> Result<Self, Error>

Try to create from the actual OSR value, assuming a 1-bit serial input. See the TRM for valid OSR and IOSR. Filter gain and total gain must each <= 2^31.

Returns Error::InvalidFilterParameters if iosr is outside 1..=256, the filter order’s FOSR is invalid, or the resulting gain exceeds the ceiling.

Source

pub fn new_for_width(order: FilterOrder, iosr: u16, width: InputWidth) -> Self

Create from FilterOrder, IOSR, and the effective input bit-width. Use this for parallel (ADC/DMA) inputs, where the gain ceiling is lower than for serial inputs. Panics if out of range.

Source

pub fn try_new_for_width( order: FilterOrder, iosr: u16, width: InputWidth, ) -> Result<Self, Error>

Try to create from the actual OSR value and the effective input bit-width. Filter gain and total gain must each fit under max_gain for the given width.

Returns Error::InvalidFilterParameters if iosr is outside 1..=256, the filter order’s FOSR is invalid, or the resulting gain exceeds the ceiling for width.

Source

pub fn new_ignore_gain_ceiling( order: FilterOrder, iosr: u16, ) -> Result<Self, Error>

Skips the input-width gain-ceiling check entirely. For callers who have verified their own headroom - e.g. known-small input amplitude, or downstream scaling/offset that keeps the accumulator in range regardless of the nominal filter gain.

Still validates FOSR/IOSR register range and rejects combinations where the gain calculation itself overflows u128 (garbage in, garbage out) - only the “does this fit under the input-width ceiling” check is bypassed.

Because the ceiling is skipped, the resulting gain may exceed u32::MAX. FilterParameters::total_gain truncates silently in that case (as u32) - use FilterParameters::total_gain_wide for a lossless u128 reading, and prefer it when constructing via this method.

Returns Error::InvalidFilterParameters if iosr is outside 1..=256, the filter order’s FOSR is invalid, or the gain computation itself overflows u128.

Source

pub fn total_gain(&self) -> u32

Returns the total gain of this filter parametrization, truncated to u32.

For instances built via new/try_new/new_for_width/ try_new_for_width, the gain is guaranteed <= i32::MAX-derived ceiling and this never truncates.

For instances built via FilterParameters::new_ignore_gain_ceiling, the true gain may exceed u32::MAX and this value silently truncates (as u32) - use FilterParameters::total_gain_wide instead in that case.

Source

pub fn total_gain_wide(&self) -> u128

Returns the total gain of this filter parametrization as a lossless u128, regardless of how the instance was constructed. Prefer this over FilterParameters::total_gain for instances built via FilterParameters::new_ignore_gain_ceiling.

Source

pub fn recommended_shift(&self) -> u8

Recommended right-shift to achieve i24-fullscale results

Trait Implementations§

Source§

impl Clone for FilterParameters

Source§

fn clone(&self) -> FilterParameters

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FilterParameters

Source§

impl Debug for FilterParameters

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for FilterParameters

Source§

impl PartialEq for FilterParameters

Source§

fn eq(&self, other: &FilterParameters) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FilterParameters

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, I> Binding<I, NoHandler<I>> for T
where T: Copy, I: Interrupt,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.