initial commit of heartbeat on ch32v
This commit is contained in:
commit
faa1622857
10 changed files with 750 additions and 0 deletions
45
ch32v-insert-coin/src/main.rs
Normal file
45
ch32v-insert-coin/src/main.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
use hal::delay::Delay;
|
||||
use hal::gpio::{AnyPin, Level, Output, Pin};
|
||||
use {ch32_hal as hal};
|
||||
|
||||
|
||||
fn blink(pin: AnyPin, interval_ms: u64) {
|
||||
let mut led = Output::new(pin, Level::Low, Default::default());
|
||||
|
||||
let mut delay = Delay;
|
||||
|
||||
loop {
|
||||
let hb_count = 3;
|
||||
let hb_period_ms = 1000;
|
||||
for _ in 0..hb_count {
|
||||
led.set_low();
|
||||
delay.delay_ms((interval_ms/2) as u32);
|
||||
led.set_high();
|
||||
delay.delay_ms((interval_ms/2) as u32);
|
||||
}
|
||||
delay.delay_ms((hb_period_ms - (interval_ms * hb_count)) as u32);
|
||||
}
|
||||
}
|
||||
|
||||
#[qingke_rt::entry]
|
||||
fn main() -> ! {
|
||||
let mut config = hal::Config::default();
|
||||
config.rcc = hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSE;
|
||||
let p = hal::init(config);
|
||||
|
||||
let mut delay = Delay;
|
||||
|
||||
blink(p.PD6.degrade(), 100);
|
||||
loop{};
|
||||
}
|
||||
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue