aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-12-16 16:09:01 +0100
committerDario Nieuwenhuis <[email protected]>2024-12-16 16:15:28 +0100
commit2846647c94d75b433232c959655b88558c560767 (patch)
tree15d07ab18e40fcfd12c8092e31e1f5ab324f4eed /examples/stm32f4/src
parent87280463b24ce4d50b655aa526ab034b0dc2ad61 (diff)
Remove use of static mut.
Diffstat (limited to 'examples/stm32f4/src')
-rw-r--r--examples/stm32f4/src/bin/usb_uac_speaker.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/examples/stm32f4/src/bin/usb_uac_speaker.rs b/examples/stm32f4/src/bin/usb_uac_speaker.rs
index 8d83afd1a..e22e07e63 100644
--- a/examples/stm32f4/src/bin/usb_uac_speaker.rs
+++ b/examples/stm32f4/src/bin/usb_uac_speaker.rs
@@ -1,7 +1,7 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3 3
4use core::cell::RefCell; 4use core::cell::{Cell, RefCell};
5 5
6use defmt::{panic, *}; 6use defmt::{panic, *};
7use embassy_executor::Spawner; 7use embassy_executor::Spawner;
@@ -217,8 +217,8 @@ async fn usb_control_task(control_monitor: speaker::ControlMonitor<'static>) {
217/// This gives an (ideal) counter value of 336.000 for every update of the `FEEDBACK_SIGNAL`. 217/// This gives an (ideal) counter value of 336.000 for every update of the `FEEDBACK_SIGNAL`.
218#[interrupt] 218#[interrupt]
219fn TIM2() { 219fn TIM2() {
220 static mut LAST_TICKS: u32 = 0; 220 static LAST_TICKS: Mutex<CriticalSectionRawMutex, Cell<u32>> = Mutex::new(Cell::new(0));
221 static mut FRAME_COUNT: usize = 0; 221 static FRAME_COUNT: Mutex<CriticalSectionRawMutex, Cell<usize>> = Mutex::new(Cell::new(0));
222 222
223 critical_section::with(|cs| { 223 critical_section::with(|cs| {
224 // Read timer counter. 224 // Read timer counter.
@@ -230,11 +230,14 @@ fn TIM2() {
230 if status.ccif(CHANNEL_INDEX) { 230 if status.ccif(CHANNEL_INDEX) {
231 let ticks = timer.ccr(CHANNEL_INDEX).read(); 231 let ticks = timer.ccr(CHANNEL_INDEX).read();
232 232
233 *FRAME_COUNT += 1; 233 let frame_count = FRAME_COUNT.borrow(cs);
234 if *FRAME_COUNT >= FEEDBACK_REFRESH_PERIOD.frame_count() { 234 let last_ticks = LAST_TICKS.borrow(cs);
235 *FRAME_COUNT = 0; 235
236 FEEDBACK_SIGNAL.signal(ticks.wrapping_sub(*LAST_TICKS)); 236 frame_count.set(frame_count.get() + 1);
237 *LAST_TICKS = ticks; 237 if frame_count.get() >= FEEDBACK_REFRESH_PERIOD.frame_count() {
238 frame_count.set(0);
239 FEEDBACK_SIGNAL.signal(ticks.wrapping_sub(last_ticks.get()));
240 last_ticks.set(ticks);
238 } 241 }
239 }; 242 };
240 243