diff --git a/firmware/application/Makefile b/firmware/application/Makefile index 5b2262e6..c3d347ef 100755 --- a/firmware/application/Makefile +++ b/firmware/application/Makefile @@ -146,6 +146,7 @@ CPPSRC = main.cpp \ touch.cpp \ touch_adc.cpp \ encoder.cpp \ + audio.cpp \ lcd_ili9341.cpp \ ui.cpp \ ui_text.cpp \ diff --git a/firmware/application/analog_audio_app.cpp b/firmware/application/analog_audio_app.cpp index fcd9cda1..37c1e308 100644 --- a/firmware/application/analog_audio_app.cpp +++ b/firmware/application/analog_audio_app.cpp @@ -25,6 +25,9 @@ #include "portapack_shared_memory.hpp" using namespace portapack; +#include "i2s.hpp" +using namespace lpc43xx; + #include "utility.hpp" namespace ui { @@ -136,6 +139,8 @@ AnalogAudioView::AnalogAudioView( AnalogAudioView::~AnalogAudioView() { // TODO: Manipulating audio codec here, and in ui_receiver.cpp. Good to do // both? + i2s::i2s0::tx_mute(); + audio_codec.headphone_mute(); receiver_model.disable(); @@ -294,6 +299,8 @@ void AnalogAudioView::update_modulation(const ReceiverModel::Mode modulation) { }); receiver_model.set_baseband_bandwidth(is_wideband_spectrum_mode ? 12000000 : 1750000); receiver_model.enable(); + + i2s::i2s0::tx_unmute(); } } /* namespace ui */ diff --git a/firmware/common/audio.cpp b/firmware/application/audio.cpp similarity index 100% rename from firmware/common/audio.cpp rename to firmware/application/audio.cpp diff --git a/firmware/common/audio.hpp b/firmware/application/audio.hpp similarity index 92% rename from firmware/common/audio.hpp rename to firmware/application/audio.hpp index a9ccaefa..d672f744 100644 --- a/firmware/common/audio.hpp +++ b/firmware/application/audio.hpp @@ -22,25 +22,11 @@ #ifndef __AUDIO_H__ #define __AUDIO_H__ -#include "buffer.hpp" - #include "i2s.hpp" using namespace lpc43xx; namespace audio { -struct sample_t { - union { - struct { - int16_t left; - int16_t right; - }; - uint32_t raw; - }; -}; - -using buffer_t = buffer_t; - constexpr i2s::ConfigTX i2s0_config_tx { .dao = i2s::DAO { .wordwidth = i2s::WordWidth::Bits16, diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 6621a5b8..7b463cc8 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -32,6 +32,7 @@ using namespace hackrf::one; #include "i2c_pp.hpp" #include "touch_adc.hpp" +#include "audio.hpp" namespace portapack { @@ -133,6 +134,14 @@ void init() { clock_manager.start_audio_pll(); audio_codec.init(); + i2s::i2s0::configure( + audio::i2s0_config_tx, + audio::i2s0_config_rx, + audio::i2s0_config_dma + ); + i2s::i2s0::tx_start(); + i2s::i2s0::rx_start(); + clock_manager.enable_first_if_clock(); clock_manager.enable_second_if_clock(); clock_manager.enable_codec_clocks(); diff --git a/firmware/baseband/Makefile b/firmware/baseband/Makefile index 413ed0de..3aba34e1 100755 --- a/firmware/baseband/Makefile +++ b/firmware/baseband/Makefile @@ -154,7 +154,6 @@ CPPSRC = main.cpp \ rssi.cpp \ rssi_dma.cpp \ rssi_thread.cpp \ - audio.cpp \ audio_output.cpp \ audio_dma.cpp \ audio_stats_collector.cpp \ diff --git a/firmware/baseband/audio_dma.hpp b/firmware/baseband/audio_dma.hpp index ec85f080..863a4f39 100644 --- a/firmware/baseband/audio_dma.hpp +++ b/firmware/baseband/audio_dma.hpp @@ -24,9 +24,22 @@ #include -#include "audio.hpp" +#include "buffer.hpp" namespace audio { + +struct sample_t { + union { + struct { + int16_t left; + int16_t right; + }; + uint32_t raw; + }; +}; + +using buffer_t = buffer_t; + namespace dma { void init(); diff --git a/firmware/baseband/audio_output.cpp b/firmware/baseband/audio_output.cpp index fa67eab2..7b9f9799 100644 --- a/firmware/baseband/audio_output.cpp +++ b/firmware/baseband/audio_output.cpp @@ -77,10 +77,7 @@ void AudioOutput::on_block( audio_present_history = (audio_present_history << 1) | (audio_present_now ? 1 : 0); const bool audio_present = (audio_present_history != 0); - if( audio_present ) { - i2s::i2s0::tx_unmute(); - } else { - i2s::i2s0::tx_mute(); + if( !audio_present ) { for(size_t i=0; iDMAMUX = portapack::gpdma_mux; gpdma::controller.enable(); nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY));