Skip to content

Commit

Permalink
Updated I2S examples: lower volume, hardware clarification
Browse files Browse the repository at this point in the history
  • Loading branch information
samcrow committed Apr 10, 2021
1 parent cba55bc commit 15353c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions examples/i2s-audio-out-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! # Hardware required
//!
//! * STM32F411E-DISCO evaluation board
//! * STM32F407G-DISC1 or STM32F411E-DISCO evaluation board
//! * Headphones or speakers with a headphone plug
//!
//! # Procedure
Expand Down Expand Up @@ -64,6 +64,11 @@ use stm32f4xx_hal::stm32::{DMA1, SPI3};

use cs43l22::{Cs43L22, Register};

/// Volume in decibels
///
/// Depending on your speakers, you may need to adjust this value.
const VOLUME: i8 = -100;

const SINE_SAMPLES: usize = 64;

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

// Reduce the headphone volume to make the demo less annoying
let headphone_volume = -30i8 as u8;
dac.write(Register::HeadphoneAVol, headphone_volume)
.unwrap();
dac.write(Register::HeadphoneBVol, headphone_volume)
.unwrap();
// Reduce the headphone volume something more comfortable
dac.write(Register::HeadphoneAVol, VOLUME as u8).unwrap();
dac.write(Register::HeadphoneBVol, VOLUME as u8).unwrap();

// Power up DAC
dac.write(Register::PowerCtl1, 0b1001_1110).unwrap();
Expand Down
16 changes: 9 additions & 7 deletions examples/i2s-audio-out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! # Hardware required
//!
//! * STM32F411E-DISCO evaluation board
//! * STM32F407G-DISC1 or STM32F411E-DISCO evaluation board
//! * Headphones or speakers with a headphone plug
//!
//! # Procedure
Expand Down Expand Up @@ -54,6 +54,11 @@ use stm32f4xx_hal::prelude::*;

use cs43l22::{Cs43L22, Register};

/// Volume in decibels
///
/// Depending on your speakers, you may need to adjust this value.
const VOLUME: i8 = -100;

/// A sine wave spanning 64 samples
///
/// With a sample rate of 48 kHz, this produces a 750 Hz tone.
Expand Down Expand Up @@ -161,12 +166,9 @@ fn main() -> ! {
// Word length 16 bits
dac.write(Register::InterfaceCtl1, 0b0_0_0_0_01_11).unwrap();

// Reduce the headphone volume to make the demo less annoying
let headphone_volume = -30i8 as u8;
dac.write(Register::HeadphoneAVol, headphone_volume)
.unwrap();
dac.write(Register::HeadphoneBVol, headphone_volume)
.unwrap();
// Reduce the headphone volume something more comfortable
dac.write(Register::HeadphoneAVol, VOLUME as u8).unwrap();
dac.write(Register::HeadphoneBVol, VOLUME as u8).unwrap();

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

0 comments on commit 15353c0

Please sign in to comment.