Implement Timer trait in embedded_hal for Channels in hardware timer#12
Open
longfangsong wants to merge 1 commit intoriscv-rust:masterfrom
Open
Implement Timer trait in embedded_hal for Channels in hardware timer#12longfangsong wants to merge 1 commit intoriscv-rust:masterfrom
Timer trait in embedded_hal for Channels in hardware timer#12longfangsong wants to merge 1 commit intoriscv-rust:masterfrom
Conversation
Contributor
Author
|
Use example: #![allow(warnings)]
#![no_std]
#![no_main]
use core::mem;
use core::sync::atomic::{compiler_fence, Ordering};
use k210_hal::fpioa;
use k210_hal::pac;
use k210_hal::pac::{sysctl, SYSCTL, TIMER0};
use k210_hal::prelude::*;
use k210_hal::stdout::Stdout;
use k210_hal::timer::Timer0;
use panic_halt as _;
#[riscv_rt::entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();
let mut sysctl = p.SYSCTL.constrain();
// Prepare pins for UARTHS
let fpioa = p.FPIOA.split(&mut sysctl.apb0);
let _io5 = fpioa.io5.into_function(fpioa::UARTHS_TX);
// Configure clocks (TODO)
let clocks = sysctl.clocks();
// Configure UART
let serial = p.UARTHS.configure(115_200.bps(), &clocks);
let (mut tx, _) = serial.split();
// todo: new stdout design (simple Write impl?)
let mut stdout = Stdout(&mut tx);
let mut timer0 = sysctl.timer0;
timer0.set_frequency(1.khz());
let mut timer = Timer0::new(&p.TIMER0, 0, &mut timer0, &mut sysctl.apb0);
loop {
for _ in 0..60 {
timer
.try_start(1.hz())
.unwrap_or_else(|_| writeln!(stdout, "Start failed").unwrap());
while timer.try_wait().is_err() {
compiler_fence(Ordering::SeqCst);
}
}
writeln!(stdout, "+60s").unwrap()
}
} |
longfangsong
commented
Feb 13, 2021
Comment on lines
+8
to
+9
| timer: &'a $TIMER, | ||
| channel_id: usize, |
Contributor
Author
There was a problem hiding this comment.
I think this should take a CHANNEL instance and provide a free function to return it back. However, I did not find a way to move a CHANNEL out of timer0::RegisterBlock::channel
Timer trait in embedded_hal for Channels in hardware timer.Timer trait in embedded_hal for Channels in hardware timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pr implement
Timertrait inembedded_halfor eachCHANNELin aTIMER, which supports a nicer way to create delays.