diff --git a/README.md b/README.md index 4656b6d..7c92096 100644 --- a/README.md +++ b/README.md @@ -25,16 +25,16 @@ Keypoints: Currently, supported chips are listed in `Cargo.toml` as feature flags, others should work if you are careful as most peripherals are similar enough. -| Family | Status | Embassy | RCC | GPIO | UART* | SPI* | I2C | ADC | Timer(PWM) | EXTI* | RNG | DMA* | Delay | -|--------|--------|---------|-----|------|-------|-----|-----|-----|------------|-------|-----|-------|-------| -| V2/V3 | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | -| V1 | | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | ✅ | -| V0 | | | ✅ | ✅ | ✅ | ✅ | ✅ | ❓ | ❓ | | | | ✅ | -| X0 | | ✅ | ✅ | ✅ | ✅ | ✅ | | ✅ | ✅ | ✅ | | ✅ | | -| L0 | TODO | | | | | | | | | | | | | -| CH641 | TODO | | | | | | | | | | | | | -| CH643 | TODO | | | | | | | | | | | | | -| CH645 | TODO | | | | | | | | | | | | | +| Family | Status | Embassy | RCC | GPIO | UART*| SPI*| I2C | ADC | Timer(PWM) | EXTI*| RTC | DMA*| Delay | Others | +|--------|--------|---------|-----|------|------|-----|-----|-----|------------|------|-----|-----|-------| ------ | +| V2/V3 | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | ✅ | | RNG | +| V1 | | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | ✅ | | +| V0 | | | ✅ | ✅ | ✅ | ✅ | ✅ | ❓ | ✅ | | | | ✅ | | +| X0 | | ✅ | ✅ | ✅ | ✅ | ✅ | | ✅ | ✅ | ✅ | | ✅ | | | +| L0 | TODO | | | | | | | | | | | | | | +| CH641 | TODO | | | | | | | | | | | | | | +| CH643 | TODO | | | | | | | | | | | | | | +| CH645 | TODO | | | | | | | | | | | | | | - ✅ : Expected to work - ❓ : Not tested diff --git a/examples/ch32v003/src/bin/pwm.rs b/examples/ch32v003/src/bin/pwm.rs new file mode 100644 index 0000000..95a23ae --- /dev/null +++ b/examples/ch32v003/src/bin/pwm.rs @@ -0,0 +1,44 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use hal::delay::Delay; +use hal::println; +use hal::time::Hertz; +use hal::timer::low_level::CountingMode; +use hal::timer::simple_pwm::{PwmPin, SimplePwm}; +use {ch32_hal as hal, panic_halt as _}; + +#[qingke_rt::entry] +fn main() -> ! { + hal::debug::SDIPrint::enable(); + let p = hal::init(Default::default()); + + let pin = PwmPin::new_ch3::<3>(p.PD6); + let mut pwm = SimplePwm::new( + p.TIM2, + None, + None, + Some(pin), + None, + Hertz::khz(1), + CountingMode::default(), + ); + let ch = hal::timer::Channel::Ch3; + + let max_duty = pwm.get_max_duty(); + println!("max duty: {}", max_duty); + pwm.set_duty(ch, 2000); + pwm.enable(ch); + + loop { + for i in 0..100 { + pwm.set_duty(ch, i * 80); + Delay.delay_ms(1_0); + } + for i in (0..100).rev() { + pwm.set_duty(ch, i * 80); + Delay.delay_ms(1_0); + } + } +}