Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
stm32,
stm32::rcc::d2ccip1r::SAI1SEL_A,
time::Hertz,
traits::i2s::FullDuplex,

Check warning on line 26 in src/audio.rs

View workflow job for this annotation

GitHub Actions / ci

unused import: `traits::i2s::FullDuplex`
};

// Process samples at 1000 Hz
Expand Down Expand Up @@ -182,6 +182,8 @@
.memory_increment(true)
.peripheral_increment(false)
.circular_buffer(true)
.transfer_complete_interrupt(true)
.half_transfer_interrupt(true)
.fifo_enable(false);
let mut output_stream = dma::Transfer::init(
dma1_stream0,
Expand All @@ -206,11 +208,10 @@

info!("Set up SAI...");
let sai1_rec = sai1_p.kernel_clk_mux(SAI1SEL_A::Pll3P);
let master_config =
I2SChanConfig::new(I2SDir::Rx).set_frame_sync_active_high(false);
let master_config = I2SChanConfig::new(I2SDir::Rx).set_frame_sync_active_high(true);
let slave_config = I2SChanConfig::new(I2SDir::Tx)
.set_sync_type(I2SSync::Internal)
.set_frame_sync_active_high(false);
.set_frame_sync_active_high(true);

let pins_a = (
sai_mclk_a.into_alternate(),
Expand Down Expand Up @@ -258,16 +259,9 @@
input_stream.start(|_sai1_rb| {
sai.enable_dma(SaiChannel::ChannelA);
});

output_stream.start(|sai1_rb| {
sai.enable();
output_stream.start(|_sai1_rb| {
sai.enable_dma(SaiChannel::ChannelB);

// wait until sai1's fifo starts to receive data
info!("Sai1 fifo waiting to receive data.");
while sai1_rb.chb().sr.read().flvl().is_empty() {}
info!("Audio started!");
sai.enable();
sai.try_send(0, 0).unwrap();
});

let max_transfer_size = block_size * 2;
Expand Down Expand Up @@ -334,11 +328,10 @@

info!("Setup up SAI...");
let sai1_rec = sai1_p.kernel_clk_mux(SAI1SEL_A::Pll3P);
let master_config =
I2SChanConfig::new(I2SDir::Tx).set_frame_sync_active_high(false);
let master_config = I2SChanConfig::new(I2SDir::Tx).set_frame_sync_active_high(true);
let slave_config = I2SChanConfig::new(I2SDir::Rx)
.set_sync_type(I2SSync::Internal)
.set_frame_sync_active_high(false);
.set_frame_sync_active_high(true);

let pins_a = (
sai_mclk_a.into_alternate(),
Expand Down Expand Up @@ -453,6 +446,8 @@
.memory_increment(true)
.peripheral_increment(false)
.circular_buffer(true)
.transfer_complete_interrupt(true)
.half_transfer_interrupt(true)
.fifo_enable(false);

let mut output_stream = dma::Transfer::init(
Expand Down Expand Up @@ -480,10 +475,10 @@
info!("Set up SAI...");
let sai1_rec = sai1_p.kernel_clk_mux(SAI1SEL_A::Pll3P);
let master_config =
sai::I2SChanConfig::new(sai::I2SDir::Rx).set_frame_sync_active_high(false);
sai::I2SChanConfig::new(sai::I2SDir::Rx).set_frame_sync_active_high(true);
let slave_config = sai::I2SChanConfig::new(sai::I2SDir::Tx)
.set_sync_type(sai::I2SSync::Internal)
.set_frame_sync_active_high(false);
.set_frame_sync_active_high(true);

let pins_a = (
sai_mclk_a.into_alternate(),
Expand Down Expand Up @@ -569,12 +564,12 @@
}

info!("Start audio stream...");
input_stream.start(|_sai1_rb| sai.enable_dma(sai::SaiChannel::ChannelA));
output_stream.start(|sai1_rb| {
sai.enable_dma(sai::SaiChannel::ChannelB);
while sai1_rb.chb().sr.read().flvl().is_empty() {}
sai.enable();
sai.try_send(0, 0).unwrap();
input_stream.start(|_sai1_rb| {
sai.enable_dma(SaiChannel::ChannelA);
});
sai.enable();
output_stream.start(|_sai1_rb| {
sai.enable_dma(SaiChannel::ChannelB);
});

let max_transfer_size = block_size * 2;
Expand Down Expand Up @@ -604,15 +599,15 @@
// Check interrupt(s)
match &mut self.audio_stream {
AudioStream::Normal { input, output } => {
output.clear_interrupts();
input.clear_interrupts();

if input.get_half_transfer_flag() {
input.clear_half_transfer_interrupt();
if output.get_half_transfer_flag() {
output.clear_half_transfer_interrupt();
self.input.set_index(0);
self.output.set_index(0);
true
} else if input.get_transfer_complete_flag() {
input.clear_transfer_complete_interrupt();
} else if output.get_transfer_complete_flag() {
output.clear_transfer_complete_interrupt();
self.input.set_index(self.max_transfer_size);
self.output.set_index(self.max_transfer_size);
true
Expand Down Expand Up @@ -645,8 +640,8 @@
// Check interrupt(s)
match &mut self.audio_stream {
AudioStream::Normal { input, output } => {
output.clear_interrupts();
input.get_half_transfer_flag() || input.get_transfer_complete_flag()
input.clear_interrupts();
output.get_half_transfer_flag() || output.get_transfer_complete_flag()
}
AudioStream::S2dfm { output, input } => {
input.clear_interrupts();
Expand All @@ -671,7 +666,7 @@
}
}

fn get_stereo_iter(&mut self) -> Option<StereoIterator> {

Check warning on line 669 in src/audio.rs

View workflow job for this annotation

GitHub Actions / ci

hiding a lifetime that's elided elsewhere is confusing
if self.read() {
return Some(StereoIterator::new(
&self.input.buffer[self.input.index..self.input.index + self.max_transfer_size],
Expand Down Expand Up @@ -803,7 +798,7 @@
}

/// Get StereoIterator(interleaved) iterator
pub fn get_stereo_iter(&self) -> Option<StereoIterator> {

Check warning on line 801 in src/audio.rs

View workflow job for this annotation

GitHub Actions / ci

hiding a lifetime that's elided elsewhere is confusing
Some(StereoIterator::new(&self.buffer[..2]))
}
}
Expand Down
Loading