Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Dicklessgreat committed Sep 6, 2024
1 parent a9d4b80 commit 4afc330
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
36 changes: 17 additions & 19 deletions src/audio.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::codec::{Codec, Pins as CodecPins};
use defmt::info;
use defmt::unwrap;
use embassy_stm32 as hal;
Expand All @@ -14,8 +15,6 @@ use hal::{
},
time::Hertz,
};
use crate::codec::{Codec, Pins as CodecPins};


// - global constants ---------------------------------------------------------

Expand Down Expand Up @@ -47,8 +46,8 @@ pub struct AudioPeripherals {

impl AudioPeripherals {
pub async fn prepare_interface<'a>(self, audio_config: AudioConfig) -> Interface<'a> {

#[cfg(feature = "seed_1_1")] {
#[cfg(feature = "seed_1_1")]
{
info!("set up i2c");
let i2c_config = hal::i2c::Config::default();
let mut i2c = embassy_stm32::i2c::I2c::new_blocking(
Expand Down Expand Up @@ -77,7 +76,7 @@ impl AudioPeripherals {
sai_rx_config.frame_length = 64;
sai_rx_config.frame_sync_active_level_length = embassy_stm32::sai::word::U7(32);
sai_rx_config.fifo_threshold = FifoThreshold::Quarter;

let mut sai_tx_config = sai_rx_config;
sai_tx_config.mode = Mode::Slave;
sai_tx_config.tx_rx = TxRx::Transmitter;
Expand All @@ -99,7 +98,6 @@ impl AudioPeripherals {
sai_tx_config,
);


let rx_buffer: &mut [u32] = unsafe {
RX_BUFFER.initialize_all_copied(0);
let (ptr, len) = RX_BUFFER.get_ptr_len();
Expand All @@ -126,7 +124,8 @@ impl AudioPeripherals {
}
}

#[cfg(feature = "seed_1_2")] {
#[cfg(feature = "seed_1_2")]
{
let (sub_block_tx, sub_block_rx) = hal::sai::split_subblocks(self.sai1);
let mut sai_tx_config = hal::sai::Config::default();
sai_tx_config.mode = Mode::Master;
Expand All @@ -142,22 +141,20 @@ impl AudioPeripherals {
sai_tx_config.frame_length = 64;
sai_tx_config.frame_sync_active_level_length = embassy_stm32::sai::word::U7(32);
sai_tx_config.fifo_threshold = FifoThreshold::Quarter;

let mut sai_rx_config = sai_tx_config.clone();
sai_rx_config.mode = Mode::Slave;
sai_rx_config.tx_rx = TxRx::Receiver;
sai_rx_config.sync_input = SyncInput::Internal;
sai_rx_config.clock_strobe = ClockStrobe::Rising;
sai_rx_config.sync_output = false;


let tx_buffer: &mut [u32] = unsafe {
TX_BUFFER.initialize_all_copied(0);
let (ptr, len) = TX_BUFFER.get_ptr_len();
core::slice::from_raw_parts_mut(ptr, len)
};


let rx_buffer: &mut [u32] = unsafe {
RX_BUFFER.initialize_all_copied(0);
let (ptr, len) = RX_BUFFER.get_ptr_len();
Expand All @@ -175,21 +172,24 @@ impl AudioPeripherals {
sai_tx_config,
);
let sai_rx = Sai::new_synchronous(
sub_block_rx, self.codec_pins.SD_B, self.dma1_ch1, rx_buffer, sai_rx_config
sub_block_rx,
self.codec_pins.SD_B,
self.dma1_ch1,
rx_buffer,
sai_rx_config,
);

Interface {
sai_rx_config,
sai_tx_config,
sai_rx,
sai_tx,
i2c: None, // pcm3060 'hardware mode' doesn't need i2c
i2c: None, // pcm3060 'hardware mode' doesn't need i2c
}
}
}
}


pub struct Interface<'a> {
sai_tx_config: sai::Config,
sai_rx_config: sai::Config,
Expand All @@ -213,7 +213,7 @@ impl<'a> Interface<'a> {
pub fn sai_rx_config(&self) -> &sai::Config {
&self.sai_rx_config
}

pub fn sai_tx_config(&self) -> &sai::Config {
&self.sai_tx_config
}
Expand All @@ -231,23 +231,22 @@ impl<'a> Interface<'a> {
}

async fn setup(&mut self) {
#[cfg(feature = "seed_1_1")] {
#[cfg(feature = "seed_1_1")]
{
info!("setup WM8731");
Codec::write_wm8731_reg(
&mut self.i2c.as_mut().unwrap(),
self.i2c.as_mut().unwrap(),
wm8731::WM8731::power_down(Codec::final_power_settings),
);
Timer::after_micros(10).await;
}


info!("start SAI");
self.sai_tx.start();
self.sai_rx.start();
}
}


#[derive(Clone, Copy)]
pub enum Fs {
Fs8000,
Expand All @@ -274,7 +273,6 @@ impl Fs {
}
}


pub struct AudioConfig {
pub fs: Fs,
}
Expand Down
4 changes: 2 additions & 2 deletions src/codec/wm8731.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use embassy_stm32 as hal;
use hal::peripherals::*;

use embassy_time::Timer;
use defmt::{info, unwrap};
use embassy_time::Timer;

use crate::audio::Fs;

Expand Down Expand Up @@ -121,7 +121,7 @@ impl Codec {

pub fn write_wm8731_reg(i2c: &mut hal::i2c::I2c<'_, hal::mode::Blocking>, r: wm8731::Register) {
const AD: u8 = 0x1a; // or 0x1b if CSB is high

// WM8731 has 16 bits registers.
// The first 7 bits are for the addresses, and the rest 9 bits are for the "value"s.
// Let's pack wm8731::Register into 16 bits.
Expand Down
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ compile_error!(
"target board must be selected using a feature: \"seed_1_2\" | \"seed_1_1\" | \"seed\" | \"patch_sm\""
);


pub mod audio;
pub mod codec;
pub mod board;
pub mod codec;
pub mod flash;
pub mod led;
pub mod pins;
pub mod sdram;
pub mod usb;

pub use board::DaisyBoard;
pub use embassy_stm32 as hal;
pub use codec::{Codec, Pins as CodecPins};
pub use embassy_stm32 as hal;

pub fn default_rcc() -> hal::Config {
let mut config = hal::Config::default();
Expand Down Expand Up @@ -135,7 +134,6 @@ macro_rules! new_daisy_board {
audio_peripherals: daisy_embassy::audio::AudioPeripherals {
codec: daisy_embassy::Codec {},
codec_pins: daisy_embassy::CodecPins {

// For audio, I2C only needed for WM8731
#[cfg(feature = "seed_1_1")]
SCL: $p.PH4,
Expand Down

0 comments on commit 4afc330

Please sign in to comment.