Skip to content

Commit 8c2b233

Browse files
committed
Updates
* Make next_state() private * Added Gain enum and doc comments * Changed Function args to use Gain enum rather than u8
1 parent 8bdda80 commit 8c2b233

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

examples/fmac.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![no_main]
44
#![no_std]
55

6-
use cortex_m::asm::wfi;
76
use hal::prelude::*;
87
use hal::stm32;
98
use stm32g4xx_hal as hal;
@@ -17,7 +16,7 @@ use utils::logger::info;
1716

1817
use 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();

src/fmac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<Layout: BufferLayoutConfig> Fmac<Layout, Stopped> {
200200

201201
impl<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
}

src/fmac/function.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
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
418
pub trait Function {
519
/// The function ID loaded into the FUNC field
@@ -64,7 +78,8 @@ impl Function for LoadY {
6478
pub 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
86101
pub 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

94112
impl 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
}

0 commit comments

Comments
 (0)