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: u8Fine fractional multiplier (×1/65536). 8-bit field.
sdm1: u8Mid fractional multiplier (×1/256). 8-bit field.
sdm2: u8Integer-part multiplier (added to fixed +4). 6-bit field
(apll_write_mask(7, 5, 0, sdm2)).
o_div: u8Output divider field. Final divisor is 2 * (o_div + 2). 5-bit
field (apll_write_mask(4, 4, 0, o_div)).
Implementations§
Source§impl ApllCoefficients
impl ApllCoefficients
Sourcepub const fn for_xtal(xtal: XtalFreq) -> Self
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):
| XTAL | sdm2 | sdm1 | sdm0 | o_div | Computed fout |
|---|---|---|---|---|---|
| 26 MHz | 11 | 98 | 118 | 2 | 50.0000 MHz |
| 32 MHz | 8 | 128 | 0 | 2 | 50.0000 MHz |
| 40 MHz | 6 | 0 | 0 | 2 | 50.0000 MHz |
Trait Implementations§
Source§impl Clone for ApllCoefficients
impl Clone for ApllCoefficients
Source§fn clone(&self) -> ApllCoefficients
fn clone(&self) -> ApllCoefficients
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ApllCoefficients
impl Debug for ApllCoefficients
Source§impl PartialEq for ApllCoefficients
impl PartialEq for ApllCoefficients
Source§fn eq(&self, other: &ApllCoefficients) -> bool
fn eq(&self, other: &ApllCoefficients) -> bool
self and other values to be equal, and is used by ==.