File tree Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Original file line number Diff line number Diff line change 3
3
#![ no_main]
4
4
#![ no_std]
5
5
6
- use cortex_m:: asm:: wfi;
7
6
use hal:: prelude:: * ;
8
7
use hal:: stm32;
9
8
use stm32g4xx_hal as hal;
@@ -17,7 +16,7 @@ use utils::logger::info;
17
16
18
17
use stm32g4xx_hal:: fmac:: {
19
18
buffer:: { BufferLayout , Watermark } ,
20
- function:: IIR ,
19
+ function:: { Gain , IIR } ,
21
20
Buffer , FmacExt ,
22
21
} ;
23
22
@@ -76,7 +75,7 @@ fn main() -> ! {
76
75
fmac. select_function ( IIR {
77
76
feedforward_coeffs : 1 ,
78
77
feedback_coeffs : 1 ,
79
- gain : 0 ,
78
+ gain : Gain :: ZeroDB ,
80
79
} ) ;
81
80
82
81
let fmac = fmac. start ( ) ;
Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ impl<Layout: BufferLayoutConfig> Fmac<Layout, Stopped> {
200
200
201
201
impl < Layout : BufferLayoutConfig , S : State > Fmac < Layout , S > {
202
202
/// Transition to the next state
203
- pub fn next_state ( ) -> Self {
203
+ fn next_state ( ) -> Self {
204
204
Fmac {
205
205
_phantom : PhantomData ,
206
206
}
Original file line number Diff line number Diff line change 1
1
//! FMAC Functions
2
2
3
+ /// Programmable gain parameter in the range 0dB to 42dB in 6dB increments.
4
+ #[ repr( u8 ) ]
5
+ #[ derive( Copy , Clone ) ]
6
+ pub enum Gain {
7
+ ZeroDB = 0 ,
8
+ SixDB = 1 ,
9
+ TwelveDB = 2 ,
10
+ EighteenDB = 3 ,
11
+ TwentyFourDB = 4 ,
12
+ ThirtyDB = 5 ,
13
+ ThirtySixDB = 6 ,
14
+ FortyTwoDB = 7 ,
15
+ }
16
+
3
17
/// FMAC Function trait. This defines the function specific data that is loaded into the PARAM register
4
18
pub trait Function {
5
19
/// The function ID loaded into the FUNC field
@@ -64,7 +78,8 @@ impl Function for LoadY {
64
78
pub struct Convolution {
65
79
/// Number of coefficients in the X2 buffer
66
80
pub length : u8 ,
67
- pub gain : u8 ,
81
+ /// Gain parameter in the range 0dB to 42dB in 6dB increments
82
+ pub gain : Gain ,
68
83
}
69
84
70
85
/// Finite Impulse Response (FIR) / Convolution / Dot Product function
@@ -78,17 +93,20 @@ impl Function for Convolution {
78
93
79
94
#[ inline( always) ]
80
95
fn r ( & self ) -> Option < u8 > {
81
- Some ( self . gain )
96
+ Some ( self . gain as u8 )
82
97
}
83
98
}
84
99
85
100
/// Infinite Impulse Response (IIR) filter / Multiply Accumulate
86
101
pub struct IIR {
87
102
/// The number of feedforward coefficients in the X2 buffer
103
+ /// X2 buffer size should be at least 2*feedforward_coeffs + 2*feedback_coeffs
88
104
pub feedforward_coeffs : u8 ,
89
105
/// The number of feedback coefficients in the X2 buffer
106
+ /// X2 buffer size should be at least 2*feedforward_coeffs + 2*feedback_coeffs
90
107
pub feedback_coeffs : u8 ,
91
- pub gain : u8 ,
108
+ /// Gain parameter in the range 0dB to 42dB in 6dB increments
109
+ pub gain : Gain ,
92
110
}
93
111
94
112
impl Function for IIR {
@@ -104,6 +122,6 @@ impl Function for IIR {
104
122
}
105
123
106
124
fn r ( & self ) -> Option < u8 > {
107
- Some ( self . gain )
125
+ Some ( self . gain as u8 )
108
126
}
109
127
}
You can’t perform that action at this time.
0 commit comments