Skip to content

Commit 15353c0

Browse files
committed
Updated I2S examples: lower volume, hardware clarification
1 parent cba55bc commit 15353c0

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

examples/i2s-audio-out-dma.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! # Hardware required
88
//!
9-
//! * STM32F411E-DISCO evaluation board
9+
//! * STM32F407G-DISC1 or STM32F411E-DISCO evaluation board
1010
//! * Headphones or speakers with a headphone plug
1111
//!
1212
//! # Procedure
@@ -64,6 +64,11 @@ use stm32f4xx_hal::stm32::{DMA1, SPI3};
6464

6565
use cs43l22::{Cs43L22, Register};
6666

67+
/// Volume in decibels
68+
///
69+
/// Depending on your speakers, you may need to adjust this value.
70+
const VOLUME: i8 = -100;
71+
6772
const SINE_SAMPLES: usize = 64;
6873

6974
/// A sine wave spanning 64 samples
@@ -164,12 +169,9 @@ fn main() -> ! {
164169
// Word length 16 bits
165170
dac.write(Register::InterfaceCtl1, 0b0_0_0_0_01_11).unwrap();
166171

167-
// Reduce the headphone volume to make the demo less annoying
168-
let headphone_volume = -30i8 as u8;
169-
dac.write(Register::HeadphoneAVol, headphone_volume)
170-
.unwrap();
171-
dac.write(Register::HeadphoneBVol, headphone_volume)
172-
.unwrap();
172+
// Reduce the headphone volume something more comfortable
173+
dac.write(Register::HeadphoneAVol, VOLUME as u8).unwrap();
174+
dac.write(Register::HeadphoneBVol, VOLUME as u8).unwrap();
173175

174176
// Power up DAC
175177
dac.write(Register::PowerCtl1, 0b1001_1110).unwrap();

examples/i2s-audio-out.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//!
66
//! # Hardware required
77
//!
8-
//! * STM32F411E-DISCO evaluation board
8+
//! * STM32F407G-DISC1 or STM32F411E-DISCO evaluation board
99
//! * Headphones or speakers with a headphone plug
1010
//!
1111
//! # Procedure
@@ -54,6 +54,11 @@ use stm32f4xx_hal::prelude::*;
5454

5555
use cs43l22::{Cs43L22, Register};
5656

57+
/// Volume in decibels
58+
///
59+
/// Depending on your speakers, you may need to adjust this value.
60+
const VOLUME: i8 = -100;
61+
5762
/// A sine wave spanning 64 samples
5863
///
5964
/// With a sample rate of 48 kHz, this produces a 750 Hz tone.
@@ -161,12 +166,9 @@ fn main() -> ! {
161166
// Word length 16 bits
162167
dac.write(Register::InterfaceCtl1, 0b0_0_0_0_01_11).unwrap();
163168

164-
// Reduce the headphone volume to make the demo less annoying
165-
let headphone_volume = -30i8 as u8;
166-
dac.write(Register::HeadphoneAVol, headphone_volume)
167-
.unwrap();
168-
dac.write(Register::HeadphoneBVol, headphone_volume)
169-
.unwrap();
169+
// Reduce the headphone volume something more comfortable
170+
dac.write(Register::HeadphoneAVol, VOLUME as u8).unwrap();
171+
dac.write(Register::HeadphoneBVol, VOLUME as u8).unwrap();
170172

171173
// Power up DAC
172174
dac.write(Register::PowerCtl1, 0b1001_1110).unwrap();

0 commit comments

Comments
 (0)