mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +00:00
rename get_width_ticks and add info!() in examples
This commit is contained in:
parent
a23fa8dcb2
commit
292c1dd0b8
@ -114,8 +114,8 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
|
||||
self.inner.get_capture_value(self.channel)
|
||||
}
|
||||
|
||||
/// Get the duty tick count
|
||||
pub fn get_duty_ticks(&self) -> u32 {
|
||||
/// Get the pulse width tick count
|
||||
pub fn get_width_ticks(&self) -> u32 {
|
||||
self.inner.get_capture_value(match self.channel {
|
||||
Channel::Ch1 => Channel::Ch2,
|
||||
Channel::Ch2 => Channel::Ch1,
|
||||
@ -129,6 +129,6 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
|
||||
if period == 0 {
|
||||
return 0.;
|
||||
}
|
||||
100. * (self.get_duty_ticks() as f32) / (period as f32)
|
||||
100. * (self.get_width_ticks() as f32) / (period as f32)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m::asm;
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
|
||||
@ -44,9 +43,9 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
loop {
|
||||
Timer::after_millis(500).await;
|
||||
let _per = pwm_input.get_period_ticks();
|
||||
let _dc = pwm_input.get_duty_ticks();
|
||||
let _pc = pwm_input.get_duty_cycle();
|
||||
asm::nop();
|
||||
let period = pwm_input.get_period_ticks();
|
||||
let width = pwm_input.get_width_ticks();
|
||||
let duty_cycle = pwm_input.get_duty_cycle();
|
||||
info!("period ticks: {} width ticks: {} duty cycle: {}", period, width, duty_cycle);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m::asm;
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
|
||||
@ -44,9 +43,9 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
loop {
|
||||
Timer::after_millis(500).await;
|
||||
let _per = pwm_input.get_period_ticks();
|
||||
let _dc = pwm_input.get_duty_ticks();
|
||||
let _pc = pwm_input.get_duty_cycle();
|
||||
asm::nop();
|
||||
let period = pwm_input.get_period_ticks();
|
||||
let width = pwm_input.get_width_ticks();
|
||||
let duty_cycle = pwm_input.get_duty_cycle();
|
||||
info!("period ticks: {} width ticks: {} duty cycle: {}", period, width, duty_cycle);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user