refactor flatten_closures
This commit is contained in:
parent
3b73783635
commit
93081c25c2
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use core::sync::atomic::{fence, Ordering};
|
use core::sync::atomic::{fence, Ordering};
|
||||||
|
|
||||||
use stabilizer::{hardware, net};
|
use stabilizer::{flatten_closures, hardware, net};
|
||||||
|
|
||||||
use miniconf::Miniconf;
|
use miniconf::Miniconf;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@ -52,15 +52,6 @@ impl Default for Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! flatten_closures {
|
|
||||||
($fn:ident, $e:ident, $fun:block) => {
|
|
||||||
$e.$fn(|$e| $fun ).unwrap()
|
|
||||||
};
|
|
||||||
($fn:ident, $e:ident, $($es:ident),+, $fun:block) => {
|
|
||||||
$e.$fn(|$e| flatten_closures!($fn, $($es),*, $fun)).unwrap()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)]
|
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
struct Resources {
|
struct Resources {
|
||||||
|
@ -10,9 +10,9 @@ use serde::Deserialize;
|
|||||||
|
|
||||||
use dsp::{Accu, Complex, ComplexExt, Lockin, RPLL};
|
use dsp::{Accu, Complex, ComplexExt, Lockin, RPLL};
|
||||||
|
|
||||||
use stabilizer::net;
|
use stabilizer::{flatten_closures, hardware, net};
|
||||||
|
|
||||||
use stabilizer::hardware::{
|
use hardware::{
|
||||||
design_parameters, setup, Adc0Input, Adc1Input, AdcCode, AfeGain,
|
design_parameters, setup, Adc0Input, Adc1Input, AdcCode, AfeGain,
|
||||||
Dac0Output, Dac1Output, DacCode, DigitalInput0, DigitalInput1,
|
Dac0Output, Dac1Output, DacCode, DigitalInput0, DigitalInput1,
|
||||||
InputStamper, SystemTimer, AFE0, AFE1,
|
InputStamper, SystemTimer, AFE0, AFE1,
|
||||||
@ -80,15 +80,6 @@ impl Default for Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! flatten_closures {
|
|
||||||
($fn:ident, $e:ident, $fun:block) => {
|
|
||||||
$e.$fn(|$e| $fun ).unwrap()
|
|
||||||
};
|
|
||||||
($fn:ident, $e:ident, $($es:ident),+, $fun:block) => {
|
|
||||||
$e.$fn(|$e| flatten_closures!($fn, $($es),*, $fun)).unwrap()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)]
|
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
struct Resources {
|
struct Resources {
|
||||||
|
13
src/lib.rs
13
src/lib.rs
@ -3,3 +3,16 @@
|
|||||||
|
|
||||||
pub mod hardware;
|
pub mod hardware;
|
||||||
pub mod net;
|
pub mod net;
|
||||||
|
|
||||||
|
/// Macro to reduce rightward drift when calling the same closure-based API
|
||||||
|
/// on multiple structs simultaneously, e.g. when accessing DMA buffers.
|
||||||
|
/// This could be improved a bit using the tuple-based style from `mutex-trait`.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! flatten_closures {
|
||||||
|
($fn:ident, $e:ident, $fun:block) => {
|
||||||
|
$e.$fn(|$e| $fun ).unwrap()
|
||||||
|
};
|
||||||
|
($fn:ident, $e:ident, $($es:ident),+, $fun:block) => {
|
||||||
|
$e.$fn(|$e| flatten_closures!($fn, $($es),*, $fun)).unwrap()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user