diff --git a/firmware/baseband/audio_dma.cpp b/firmware/baseband/audio_dma.cpp index f493fd93..356faea3 100644 --- a/firmware/baseband/audio_dma.cpp +++ b/firmware/baseband/audio_dma.cpp @@ -162,14 +162,6 @@ static void rx_error() { disable(); } -void init() { - gpdma_channel_i2s0_tx.set_handlers(tx_transfer_complete, tx_error); - gpdma_channel_i2s0_rx.set_handlers(rx_transfer_complete, rx_error); - - // LPC_GPDMA->SYNC |= (1 << gpdma_rx_peripheral); - // LPC_GPDMA->SYNC |= (1 << gpdma_tx_peripheral); -} - static void configure_tx() { const auto peripheral = reinterpret_cast(&LPC_I2S0->TXFIFO); const auto control_value = control_tx(transfer_bytes); @@ -194,22 +186,34 @@ static void configure_rx() { } } -void configure() { - configure_tx(); - configure_rx(); +static void enable_tx() { + const auto gpdma_config_tx = config_tx(); + gpdma_channel_i2s0_tx.configure(lli_tx_loop[0], gpdma_config_tx); + gpdma_channel_i2s0_tx.enable(); } -void enable() { - const auto gpdma_config_tx = config_tx(); +static void enable_rx() { const auto gpdma_config_rx = config_rx(); - - gpdma_channel_i2s0_tx.configure(lli_tx_loop[0], gpdma_config_tx); gpdma_channel_i2s0_rx.configure(lli_rx_loop[0], gpdma_config_rx); - - gpdma_channel_i2s0_tx.enable(); gpdma_channel_i2s0_rx.enable(); } +void init_audio_out() { + gpdma_channel_i2s0_tx.set_handlers(tx_transfer_complete, tx_error); + // LPC_GPDMA->SYNC |= (1 << gpdma_tx_peripheral); + configure_tx(); + enable_tx(); + nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY)); +} + +void init_audio_in() { + gpdma_channel_i2s0_rx.set_handlers(rx_transfer_complete, rx_error); + // LPC_GPDMA->SYNC |= (1 << gpdma_rx_peripheral); + configure_rx(); + enable_rx(); + nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY)); +} + void disable() { gpdma_channel_i2s0_tx.disable(); gpdma_channel_i2s0_rx.disable(); @@ -217,6 +221,10 @@ void disable() { void shrink_tx_buffer(bool shrink) { single_tx_buffer = shrink; + + if (transfers_per_buffer == 1) + return; + if (single_tx_buffer) lli_tx_loop[0].lli = lli_pointer(&lli_tx_loop[0]); else diff --git a/firmware/baseband/audio_dma.hpp b/firmware/baseband/audio_dma.hpp index 8634de82..41573524 100644 --- a/firmware/baseband/audio_dma.hpp +++ b/firmware/baseband/audio_dma.hpp @@ -43,9 +43,8 @@ using buffer_t = buffer_t; namespace dma { -void init(); -void configure(); -void enable(); +void init_audio_in(); +void init_audio_out(); void disable(); void shrink_tx_buffer(bool shrink); diff --git a/firmware/baseband/baseband.cpp b/firmware/baseband/baseband.cpp index 5de5ec46..aac665fd 100644 --- a/firmware/baseband/baseband.cpp +++ b/firmware/baseband/baseband.cpp @@ -28,14 +28,8 @@ #include "gpdma.hpp" -#include "audio_dma.hpp" - static void init() { - audio::dma::init(); - audio::dma::configure(); - audio::dma::enable(); - - nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY)); + // Audio DMA initialization was moved to baseband proc's that actually use DMA audio, to save memory. } static void halt() { diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp.unused similarity index 100% rename from firmware/baseband/main.cpp rename to firmware/baseband/main.cpp.unused diff --git a/firmware/baseband/proc_afskrx.cpp b/firmware/baseband/proc_afskrx.cpp index 27b1b461..804518ec 100644 --- a/firmware/baseband/proc_afskrx.cpp +++ b/firmware/baseband/proc_afskrx.cpp @@ -23,6 +23,8 @@ #include "proc_afskrx.hpp" #include "portapack_shared_memory.hpp" +#include "audio_dma.hpp" + #include "event_m4.hpp" void AFSKRxProcessor::execute(const buffer_c8_t& buffer) { @@ -181,6 +183,8 @@ void AFSKRxProcessor::configure(const AFSKRxConfigureMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_am_audio.cpp b/firmware/baseband/proc_am_audio.cpp index 16035630..a1304c46 100644 --- a/firmware/baseband/proc_am_audio.cpp +++ b/firmware/baseband/proc_am_audio.cpp @@ -22,6 +22,7 @@ #include "proc_am_audio.hpp" #include "audio_output.hpp" +#include "audio_dma.hpp" #include "event_m4.hpp" @@ -112,6 +113,8 @@ void NarrowbandAMAudio::capture_config(const CaptureConfigMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_aprsrx.cpp b/firmware/baseband/proc_aprsrx.cpp index 616bbb41..60b048b0 100644 --- a/firmware/baseband/proc_aprsrx.cpp +++ b/firmware/baseband/proc_aprsrx.cpp @@ -23,6 +23,8 @@ #include "proc_aprsrx.hpp" #include "portapack_shared_memory.hpp" +#include "audio_dma.hpp" + #include "event_m4.hpp" #include "stdio.h" @@ -244,6 +246,8 @@ void APRSRxProcessor::configure(const APRSRxConfigureMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_audiotx.cpp b/firmware/baseband/proc_audiotx.cpp index d7991cce..b8d70660 100644 --- a/firmware/baseband/proc_audiotx.cpp +++ b/firmware/baseband/proc_audiotx.cpp @@ -24,6 +24,7 @@ #include "portapack_shared_memory.hpp" #include "sine_table_int8.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include @@ -139,6 +140,8 @@ void AudioTXProcessor::sample_rate_config(const SampleRateConfigMessage& message } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_mictx.cpp b/firmware/baseband/proc_mictx.cpp index be37c9c9..9f0d3771 100644 --- a/firmware/baseband/proc_mictx.cpp +++ b/firmware/baseband/proc_mictx.cpp @@ -25,6 +25,7 @@ #include "sine_table_int8.hpp" #include "tonesets.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include @@ -167,6 +168,8 @@ void MicTXProcessor::on_message(const Message* const msg) { } int main() { + audio::dma::init_audio_in(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_nfm_audio.cpp b/firmware/baseband/proc_nfm_audio.cpp index 6b4e6135..47e1f7d4 100644 --- a/firmware/baseband/proc_nfm_audio.cpp +++ b/firmware/baseband/proc_nfm_audio.cpp @@ -24,6 +24,8 @@ #include "sine_table_int8.hpp" #include "portapack_shared_memory.hpp" +#include "audio_dma.hpp" + #include "event_m4.hpp" #include @@ -174,6 +176,8 @@ void NarrowbandFMAudio::capture_config(const CaptureConfigMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_pocsag.cpp b/firmware/baseband/proc_pocsag.cpp index 0101b748..b05abd49 100644 --- a/firmware/baseband/proc_pocsag.cpp +++ b/firmware/baseband/proc_pocsag.cpp @@ -27,6 +27,7 @@ #include "dsp_iir_config.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include #include @@ -530,6 +531,8 @@ uint32_t POCSAGProcessor::getRate() const { // // ==================================================================== int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_pocsag2.cpp b/firmware/baseband/proc_pocsag2.cpp index 15c15738..1170a520 100644 --- a/firmware/baseband/proc_pocsag2.cpp +++ b/firmware/baseband/proc_pocsag2.cpp @@ -26,6 +26,7 @@ #include "proc_pocsag2.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include #include @@ -416,6 +417,8 @@ void POCSAGProcessor::send_packet() { /* main **************************************************/ int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_sonde.cpp b/firmware/baseband/proc_sonde.cpp index 1477c357..7c145ed3 100644 --- a/firmware/baseband/proc_sonde.cpp +++ b/firmware/baseband/proc_sonde.cpp @@ -27,6 +27,7 @@ #include "event_m4.hpp" #include "audio_output.hpp" +#include "audio_dma.hpp" SondeProcessor::SondeProcessor() { decim_0.configure(taps_11k0_decim_0.taps); @@ -141,6 +142,8 @@ void SondeProcessor::pitch_rssi_config(const PitchRSSIConfigureMessage& message) } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); diff --git a/firmware/baseband/proc_tones.cpp b/firmware/baseband/proc_tones.cpp index 1af4bc47..f59c554b 100644 --- a/firmware/baseband/proc_tones.cpp +++ b/firmware/baseband/proc_tones.cpp @@ -23,6 +23,7 @@ #include "proc_tones.hpp" #include "sine_table_int8.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include @@ -154,6 +155,8 @@ void TonesProcessor::on_message(const Message* const p) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_wfm_audio.cpp b/firmware/baseband/proc_wfm_audio.cpp index f6a3cb39..7a59c73f 100644 --- a/firmware/baseband/proc_wfm_audio.cpp +++ b/firmware/baseband/proc_wfm_audio.cpp @@ -26,6 +26,7 @@ #include "audio_output.hpp" #include "dsp_fft.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include @@ -188,6 +189,8 @@ void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_wideband_spectrum.cpp b/firmware/baseband/proc_wideband_spectrum.cpp index a7377b0b..35aef2ee 100644 --- a/firmware/baseband/proc_wideband_spectrum.cpp +++ b/firmware/baseband/proc_wideband_spectrum.cpp @@ -20,6 +20,7 @@ */ #include "proc_wideband_spectrum.hpp" +#include "audio_dma.hpp" #include "event_m4.hpp" @@ -82,6 +83,8 @@ void WidebandSpectrum::on_message(const Message* const msg) { } int main() { + audio::dma::init_audio_out(); // for AudioRX app (enables audio output while this baseband image is running) + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0;