pub fn with_frequency(target_freq: Rate) -> Result<Self, FrequencyError> {
        let clocks = Clocks::get();
        cfg_if::cfg_if! {
            if #[cfg(esp32)] {
                let source_clock = clocks.pwm_clock;
            } else if #[cfg(esp32c6)] {
                let source_clock = clocks.crypto_clock;
            } else if #[cfg(esp32s3)] {
                let source_clock = clocks.crypto_pwm_clock;
            } else if #[cfg(esp32h2)] {
                let source_clock = clocks.xtal_clock;
            }
        }

        if target_freq.as_hz() == 0 || target_freq > source_clock {
            return Err(FrequencyError);
        }

        let prescaler = source_clock / target_freq - 1;
        if prescaler > u8::MAX as u32 {
            return Err(FrequencyError);
        }

        Ok(Self::with_prescaler(prescaler as u8))
    }
Get a clock configuration with the given frequency.

### Note:
This will try to select an appropriate prescaler for the
[`PeripheralClockConfig::with_prescaler`] method.
If the calculated prescaler is not in the range `0..u8::MAX`
[`FrequencyError`] will be returned.

With standard system clock configurations the input clock to the MCPWM
peripheral is `160 MHz`.

Only divisors of the input clock (`160 Mhz / 1`, `160 Mhz / 2`, ...,
`160 Mhz / 256`) are representable exactly. Other target frequencies
will be rounded up to the next divisor.
esp-hal/src/mcpwm/mod.rs