Skip to content

Commit

Permalink
chore: ch32v0 timer pwm demo
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed May 5, 2024
1 parent 9e2f445 commit 1382d67
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions examples/ch32v003/src/bin/pwm.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 1382d67

Please sign in to comment.