pub struct FilterParameters { /* private fields */ }Expand description
Filter parameters (order, OSR and input width) for a filter.
Implementations§
Source§impl FilterParameters
impl FilterParameters
Sourcepub fn new(order: FilterOrder, iosr: u16) -> Self
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.
Sourcepub fn try_new(order: FilterOrder, iosr: u16) -> Result<Self, Error>
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.
Sourcepub fn new_for_width(order: FilterOrder, iosr: u16, width: InputWidth) -> Self
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.
Sourcepub fn try_new_for_width(
order: FilterOrder,
iosr: u16,
width: InputWidth,
) -> Result<Self, Error>
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.
Sourcepub fn new_ignore_gain_ceiling(
order: FilterOrder,
iosr: u16,
) -> Result<Self, Error>
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.
Sourcepub fn total_gain(&self) -> u32
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.
Sourcepub fn total_gain_wide(&self) -> u128
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.
Sourcepub fn recommended_shift(&self) -> u8
pub fn recommended_shift(&self) -> u8
Recommended right-shift to achieve i24-fullscale results
Trait Implementations§
Source§impl Clone for FilterParameters
impl Clone for FilterParameters
Source§fn clone(&self) -> FilterParameters
fn clone(&self) -> FilterParameters
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more