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 33#![ no_main]
44#![ no_std]
55
6- use cortex_m:: asm:: wfi;
76use hal:: prelude:: * ;
87use hal:: stm32;
98use stm32g4xx_hal as hal;
@@ -17,7 +16,7 @@ use utils::logger::info;
1716
1817use stm32g4xx_hal:: fmac:: {
1918 buffer:: { BufferLayout , Watermark } ,
20- function:: IIR ,
19+ function:: { Gain , IIR } ,
2120 Buffer , FmacExt ,
2221} ;
2322
@@ -76,7 +75,7 @@ fn main() -> ! {
7675 fmac. select_function ( IIR {
7776 feedforward_coeffs : 1 ,
7877 feedback_coeffs : 1 ,
79- gain : 0 ,
78+ gain : Gain :: ZeroDB ,
8079 } ) ;
8180
8281 let fmac = fmac. start ( ) ;
Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ impl<Layout: BufferLayoutConfig> Fmac<Layout, Stopped> {
200200
201201impl < Layout : BufferLayoutConfig , S : State > Fmac < Layout , S > {
202202 /// Transition to the next state
203- pub fn next_state ( ) -> Self {
203+ fn next_state ( ) -> Self {
204204 Fmac {
205205 _phantom : PhantomData ,
206206 }
Original file line number Diff line number Diff line change 11//! FMAC Functions
22
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+
317/// FMAC Function trait. This defines the function specific data that is loaded into the PARAM register
418pub trait Function {
519 /// The function ID loaded into the FUNC field
@@ -64,7 +78,8 @@ impl Function for LoadY {
6478pub struct Convolution {
6579 /// Number of coefficients in the X2 buffer
6680 pub length : u8 ,
67- pub gain : u8 ,
81+ /// Gain parameter in the range 0dB to 42dB in 6dB increments
82+ pub gain : Gain ,
6883}
6984
7085/// Finite Impulse Response (FIR) / Convolution / Dot Product function
@@ -78,17 +93,20 @@ impl Function for Convolution {
7893
7994 #[ inline( always) ]
8095 fn r ( & self ) -> Option < u8 > {
81- Some ( self . gain )
96+ Some ( self . gain as u8 )
8297 }
8398}
8499
85100/// Infinite Impulse Response (IIR) filter / Multiply Accumulate
86101pub struct IIR {
87102 /// The number of feedforward coefficients in the X2 buffer
103+ /// X2 buffer size should be at least 2*feedforward_coeffs + 2*feedback_coeffs
88104 pub feedforward_coeffs : u8 ,
89105 /// The number of feedback coefficients in the X2 buffer
106+ /// X2 buffer size should be at least 2*feedforward_coeffs + 2*feedback_coeffs
90107 pub feedback_coeffs : u8 ,
91- pub gain : u8 ,
108+ /// Gain parameter in the range 0dB to 42dB in 6dB increments
109+ pub gain : Gain ,
92110}
93111
94112impl Function for IIR {
@@ -104,6 +122,6 @@ impl Function for IIR {
104122 }
105123
106124 fn r ( & self ) -> Option < u8 > {
107- Some ( self . gain )
125+ Some ( self . gain as u8 )
108126 }
109127}
You can’t perform that action at this time.
0 commit comments