* Remove the chip-specific HAL packages * Update some doc comments which were missed, fix build script for ESP32/S2 * Refactor/update `esp-hal-procmacros` * Create the `examples` package, add back all of the previously existing examples * Use `xtask` automation package for checking examples and documentation in CI * Combine the `rt-riscv` and `rt-xtensa` features into a single `rt` feature * Bump MSRV to 1.76.0 (shocking!) * Re-document the features for the HAL * No need to re-export the `riscv` package like this * Make clippy happy, improve CI clippy checks * Update `CHANGELOG.md` * riscv: zero bss Co-authored-by: Björn Quentin <bjoernQ@users.noreply.github.com> * Address a number of review comments * Correct pin number in `hello_rgb` example for ESP32-C3 * Address the remaining review comments * More small tweaks/improvements * Fix RMT examples (#11) * Fix RMT examples * Remove logger-init * Make I2S examples work on ESP32 (#12) * Make I2S examples work on ESP32 * Remove logger init * Fix the direct-vectoring examples on all RISCV chips (#10) * Update GPIOs for some examples... * Embassy timer example fixes (#13) * Switch to generic queue instead of integrated for all examples * changelog * Update GPIO in another example, make `rustfmt` happy * Fix ESP32-S2 PSRAM * Avoid UART0 and SPI flash pins (#15) * Avoid UART0 and SPI flash pins * Fix spi_eh1_device_loopback for non-ESP32 * Update examples/src/bin/gpio_interrupt.rs Co-authored-by: Juraj Sadel <jurajsadel@gmail.com> --------- Co-authored-by: Juraj Sadel <jurajsadel@gmail.com> --------- Co-authored-by: Scott Mabin <scott@mabez.dev> Co-authored-by: Björn Quentin <bjoernQ@users.noreply.github.com> Co-authored-by: bjoernQ <bjoern.quentin@mobile-j.de> Co-authored-by: Juraj Sadel <jurajsadel@gmail.com>
56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
//! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty
|
|
//! signal at 20 kHz.
|
|
//!
|
|
//! The signal will be output to the pin assigned to `pin`. (GPIO0)
|
|
|
|
//% CHIPS: esp32 esp32c6 esp32h2 esp32s3
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use esp_backtrace as _;
|
|
use esp_hal::{
|
|
clock::ClockControl,
|
|
gpio::IO,
|
|
mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM},
|
|
peripherals::Peripherals,
|
|
prelude::*,
|
|
};
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let peripherals = Peripherals::take();
|
|
let system = peripherals.SYSTEM.split();
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
let pin = io.pins.gpio0;
|
|
|
|
// initialize peripheral
|
|
#[cfg(feature = "esp32h2")]
|
|
let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40u32.MHz()).unwrap();
|
|
#[cfg(not(feature = "esp32h2"))]
|
|
let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32u32.MHz()).unwrap();
|
|
|
|
let mut mcpwm = MCPWM::new(peripherals.MCPWM0, clock_cfg);
|
|
|
|
// connect operator0 to timer0
|
|
mcpwm.operator0.set_timer(&mcpwm.timer0);
|
|
// connect operator0 to pin
|
|
let mut pwm_pin = mcpwm
|
|
.operator0
|
|
.with_pin_a(pin, PwmPinConfig::UP_ACTIVE_HIGH);
|
|
|
|
// start timer with timestamp values in the range of 0..=99 and a frequency of
|
|
// 20 kHz
|
|
let timer_clock_cfg = clock_cfg
|
|
.timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz())
|
|
.unwrap();
|
|
mcpwm.timer0.start(timer_clock_cfg);
|
|
|
|
// pin will be high 50% of the time
|
|
pwm_pin.set_timestamp(50);
|
|
|
|
loop {}
|
|
}
|