Skip to content

Commit

Permalink
demo: adc demo for ch32v003
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed May 5, 2024
1 parent 1382d67 commit 8e7b9da
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ others should work if you are careful as most peripherals are similar enough.
|--------|--------|---------|-----|------|------|-----|-----|-----|------------|------|-----|-----|-------| ------ |
| V2/V3 | |||||||||| || | RNG |
| V1 | | |||||||| | | || |
| V0 | | |||||| || | | || |
| V0 | | |||||| || | | || |
| X0 | |||||| |||| || | |
| L0 | TODO | | | | | | | | | | | | | |
| CH641 | TODO | | | | | | | | | | | | | |
Expand Down
3 changes: 3 additions & 0 deletions examples/ch32v003/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
### nanoCH32V003

Link: [wuxx/nanoCH32V003](https://github.com/wuxx/nanoCH32V003)

- MCU: CH32V003F4U6
- LED: PD6
31 changes: 31 additions & 0 deletions examples/ch32v003/src/bin/adc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]

use hal::delay::Delay;
use hal::gpio::{Level, Output};
use hal::println;
use {ch32_hal as hal, panic_halt as _};

#[qingke_rt::entry]
fn main() -> ! {
hal::debug::SDIPrint::enable();
let mut config = hal::Config::default();
config.rcc = hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSE;
let p = hal::init(config);

let mut delay = Delay;

let mut led = Output::new(p.PD6, Level::Low, Default::default());

let mut adc = hal::adc::Adc::new(p.ADC1, Default::default());
let mut pin = p.PA1;

loop {
led.toggle();
delay.delay_ms(1000);

let val = adc.convert(&mut pin, hal::adc::SampleTime::CYCLES73);
println!("adc: {}", val);
}
}

0 comments on commit 8e7b9da

Please sign in to comment.