Skip to main content

ApllCoefficients

Struct ApllCoefficients 

Source
pub struct ApllCoefficients {
    pub sdm0: u8,
    pub sdm1: u8,
    pub sdm2: u8,
    pub o_div: u8,
}
Expand description

SDM coefficients for the ESP32 APLL.

Output frequency formula:

fout = fxtal * (sdm2 + sdm1/256 + sdm0/65536 + 4) / (2 * (o_div + 2))

For each supported on-board crystal, ApllCoefficients::for_xtal returns the coefficients that land on 50 MHz (the RMII reference clock).

Fields§

§sdm0: u8

Fine fractional multiplier (×1/65536). 8-bit field.

§sdm1: u8

Mid fractional multiplier (×1/256). 8-bit field.

§sdm2: u8

Integer-part multiplier (added to fixed +4). 6-bit field (apll_write_mask(7, 5, 0, sdm2)).

§o_div: u8

Output divider field. Final divisor is 2 * (o_div + 2). 5-bit field (apll_write_mask(4, 4, 0, o_div)).

Implementations§

Source§

impl ApllCoefficients

Source

pub const fn for_xtal(xtal: XtalFreq) -> Self

Look up the coefficients that produce a 50 MHz APLL output for the given on-board crystal.

Total: infallible — the input is constrained by XtalFreq, which only enumerates crystals the crate has verified coefficients for (Mhz26 / Mhz32 / Mhz40). Adding support for another crystal therefore takes two concrete edits — extend XtalFreq with the new variant, and add a matching arm here — followed by a host-side unit test asserting the new arm lands on 50 MHz.

Verified results (target 50.000 MHz):

XTALsdm2sdm1sdm0o_divComputed fout
26 MHz1198118250.0000 MHz
32 MHz81280250.0000 MHz
40 MHz600250.0000 MHz

Trait Implementations§

Source§

impl Clone for ApllCoefficients

Source§

fn clone(&self) -> ApllCoefficients

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 ApllCoefficients

Source§

impl Debug for ApllCoefficients

Source§

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

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

impl Eq for ApllCoefficients

Source§

impl PartialEq for ApllCoefficients

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ApllCoefficients

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> 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 = Infallible

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.