Skip to content

Commit

Permalink
Audio-en during pause
Browse files Browse the repository at this point in the history
  • Loading branch information
ceigel committed Oct 14, 2020
1 parent 65223d0 commit abb9f4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ const APP: () = {
struct Resources {
playing_resources: PlayingResources,
audio_out: gpioa::PA4<Analog>,
audio_en: gpioa::PA12<Output<PushPull>>,
#[init(None)]
current_playlist: Option<Playlist>,
buttons: Buttons,
Expand Down Expand Up @@ -279,7 +278,7 @@ const APP: () = {

let mut gpioa = device.GPIOA.split(&mut rcc.ahb2);
let audio_out = gpioa.pa4.into_analog(&mut gpioa.moder, &mut gpioa.pupdr); // Speaker out
let mut audio_en = gpioa
let audio_en = gpioa
.pa12
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);

Expand Down Expand Up @@ -346,6 +345,7 @@ const APP: () = {
device.TIM2,
device.DAC1,
device.DMA1,
audio_en,
);

let leds = Leds::new(device.GPIOE.split(&mut rcc.ahb2));
Expand All @@ -363,7 +363,6 @@ const APP: () = {
let card_scan_pause = time_computer.to_cycles(CARD_SCAN_PAUSE);
let user_cyclic_time = time_computer.to_cycles(USER_CYCLIC_TIME);

audio_en.set_high().expect("To be able to set audio_en");
info!("Init finished");
init::LateResources {
playing_resources: PlayingResources {
Expand All @@ -372,7 +371,6 @@ const APP: () = {
card_reader,
},
audio_out,
audio_en,
buttons,
rfid_reader,
leds,
Expand Down
19 changes: 18 additions & 1 deletion src/sound_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::data_reader::{DataReader, DirectoryNavigator};
use crate::mp3_player::{Mp3Player, PlayError};
use log::{error, info};
use rtic::cyccnt::{Duration, Instant};
use stm32l4xx_hal::gpio::{gpioa, Output, PushPull};
use stm32l4xx_hal::prelude::OutputPin;
use stm32l4xx_hal::stm32 as stm32l431;
use stm32l4xx_hal::stm32::Interrupt;
use stm32l4xx_hal::time;
Expand Down Expand Up @@ -60,6 +62,7 @@ pub struct SoundDevice<'a> {
pub stopping: bool,
pub debug_data: DebuggingData,
play_pause_start: Option<Instant>,
audio_en: gpioa::PA12<Output<PushPull>>,
}

impl<'a> SoundDevice<'a> {
Expand All @@ -69,6 +72,7 @@ impl<'a> SoundDevice<'a> {
tim2: stm32l431::TIM2,
dac: stm32l431::DAC1,
dma1: stm32l431::DMA1,
audio_en: gpioa::PA12<Output<PushPull>>,
) -> Self {
let apb1enr = apb1enr();
let ahbenr = ahbenr();
Expand All @@ -82,6 +86,7 @@ impl<'a> SoundDevice<'a> {
stopping: false,
debug_data: DebuggingData::new(),
play_pause_start: None,
audio_en,
};
let apb1rstr = apb1rstr();
obj.init_tim2(apb1enr, apb1rstr);
Expand All @@ -96,7 +101,7 @@ impl<'a> SoundDevice<'a> {
data_reader: &mut DataReader,
directory_navigator: &mut impl DirectoryNavigator,
) -> Result<(), PlayError> {
info!("start playing");
info!("start playing called");
self.stop_playing();
self.fill_pcm_buffer(0, mp3_player, data_reader, directory_navigator)?;
self.fill_pcm_buffer(1, mp3_player, data_reader, directory_navigator)?;
Expand All @@ -117,6 +122,9 @@ impl<'a> SoundDevice<'a> {
self.stopping = false;
self.stop_at_buffer_len = None;
self.play_pause_start.replace(Instant::now());
self.audio_en
.set_high()
.expect("To be able to set audio_en");
Ok(())
}

Expand Down Expand Up @@ -189,12 +197,21 @@ impl<'a> SoundDevice<'a> {
}
pub fn toggle_pause(&mut self) {
self.tim2.cr1.modify(|r, w| w.cen().bit(!r.cen().bit()));
if self.tim2.cr1.read().cen().is_enabled() {
self.audio_en.set_high()
} else {
self.audio_en.set_low()
}
.expect("To be able to re-set audio_en");
}

pub fn stop_playing(&mut self) {
self.tim2.cr1.modify(|_, w| w.cen().disabled());
self.dma1.ccr3.modify(|_, w| w.en().disabled());
self.play_pause_start.take();
self.audio_en
.set_low()
.expect("To be able to re-set audio_en");
}

pub fn set_dma_stop(&mut self, state: DmaState) -> DmaState {
Expand Down

0 comments on commit abb9f4d

Please sign in to comment.