From 292c1dd0b858fe8dde74edd2f60a96f4c9e588da Mon Sep 17 00:00:00 2001
From: Bruno Bousquet <21108660+brunob45@users.noreply.github.com>
Date: Wed, 29 May 2024 09:58:46 -0400
Subject: [PATCH] rename get_width_ticks and add info!() in examples

---
 embassy-stm32/src/timer/pwm_input.rs  | 6 +++---
 examples/stm32f1/src/bin/pwm_input.rs | 9 ++++-----
 examples/stm32f4/src/bin/pwm_input.rs | 9 ++++-----
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs
index d3fe7632a..7bcb7802a 100644
--- a/embassy-stm32/src/timer/pwm_input.rs
+++ b/embassy-stm32/src/timer/pwm_input.rs
@@ -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)
     }
 }
diff --git a/examples/stm32f1/src/bin/pwm_input.rs b/examples/stm32f1/src/bin/pwm_input.rs
index de6949eb4..9883280cf 100644
--- a/examples/stm32f1/src/bin/pwm_input.rs
+++ b/examples/stm32f1/src/bin/pwm_input.rs
@@ -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);
     }
 }
diff --git a/examples/stm32f4/src/bin/pwm_input.rs b/examples/stm32f4/src/bin/pwm_input.rs
index 30cefac3a..8fe1fdb5b 100644
--- a/examples/stm32f4/src/bin/pwm_input.rs
+++ b/examples/stm32f4/src/bin/pwm_input.rs
@@ -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);
     }
 }