Move I2S management to application side.

This commit is contained in:
Jared Boone 2016-02-05 15:22:28 -08:00
parent cefab197da
commit 9430c94dec
9 changed files with 32 additions and 30 deletions

View File

@ -146,6 +146,7 @@ CPPSRC = main.cpp \
touch.cpp \
touch_adc.cpp \
encoder.cpp \
audio.cpp \
lcd_ili9341.cpp \
ui.cpp \
ui_text.cpp \

View File

@ -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 */

View File

@ -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<sample_t>;
constexpr i2s::ConfigTX i2s0_config_tx {
.dao = i2s::DAO {
.wordwidth = i2s::WordWidth::Bits16,

View File

@ -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();

View File

@ -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 \

View File

@ -24,9 +24,22 @@
#include <cstdint>
#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<sample_t>;
namespace dma {
void init();

View File

@ -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; i<audio.count; i++) {
audio.p[i] = 0;
}

View File

@ -42,7 +42,6 @@
#include "debug.hpp"
#include "audio.hpp"
#include "audio_dma.hpp"
#include "gcc.hpp"
@ -73,19 +72,10 @@ void __late_init(void) {
}
static void init() {
i2s::i2s0::configure(
audio::i2s0_config_tx,
audio::i2s0_config_rx,
audio::i2s0_config_dma
);
audio::dma::init();
audio::dma::configure();
audio::dma::enable();
i2s::i2s0::tx_start();
i2s::i2s0::rx_start();
LPC_CREG->DMAMUX = portapack::gpdma_mux;
gpdma::controller.enable();
nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY));