mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-10-18 09:11:47 +00:00
WM8731: Add Codec abstraction.
This commit is contained in:
@@ -22,11 +22,8 @@
|
||||
#include "audio.hpp"
|
||||
|
||||
#include "portapack.hpp"
|
||||
using portapack::i2c0;
|
||||
using portapack::clock_manager;
|
||||
|
||||
#include "wm8731.hpp"
|
||||
using wolfson::wm8731::WM8731;
|
||||
#include "portapack_hal.hpp"
|
||||
|
||||
#include "i2s.hpp"
|
||||
@@ -98,9 +95,7 @@ constexpr i2s::ConfigDMA i2s0_config_dma {
|
||||
},
|
||||
};
|
||||
|
||||
constexpr uint8_t wm8731_i2c_address = 0x1a;
|
||||
|
||||
WM8731 audio_codec { i2c0, wm8731_i2c_address };
|
||||
static audio::Codec* audio_codec = nullptr;
|
||||
|
||||
} /* namespace */
|
||||
|
||||
@@ -118,12 +113,12 @@ void stop() {
|
||||
|
||||
void mute() {
|
||||
i2s::i2s0::tx_mute();
|
||||
|
||||
audio_codec.headphone_mute();
|
||||
audio_codec->headphone_disable();
|
||||
}
|
||||
|
||||
void unmute() {
|
||||
i2s::i2s0::tx_unmute();
|
||||
audio_codec->headphone_enable();
|
||||
}
|
||||
|
||||
} /* namespace output */
|
||||
@@ -131,30 +126,40 @@ void unmute() {
|
||||
namespace headphone {
|
||||
|
||||
volume_range_t volume_range() {
|
||||
return wolfson::wm8731::headphone_gain_range;
|
||||
return audio_codec->headphone_gain_range();
|
||||
}
|
||||
|
||||
void set_volume(const volume_t volume) {
|
||||
audio_codec.set_headphone_volume(volume);
|
||||
audio_codec->set_headphone_volume(volume);
|
||||
}
|
||||
|
||||
} /* namespace headphone */
|
||||
|
||||
namespace debug {
|
||||
|
||||
int reg_count() {
|
||||
return wolfson::wm8731::reg_count;
|
||||
size_t reg_count() {
|
||||
return audio_codec->reg_count();
|
||||
}
|
||||
|
||||
uint16_t reg_read(const int register_number) {
|
||||
return audio_codec.read(register_number);
|
||||
uint32_t reg_read(const size_t register_number) {
|
||||
return audio_codec->reg_read(register_number);
|
||||
}
|
||||
|
||||
std::string codec_name() {
|
||||
return audio_codec->name();
|
||||
}
|
||||
|
||||
size_t reg_bits() {
|
||||
return audio_codec->reg_bits();
|
||||
}
|
||||
|
||||
} /* namespace debug */
|
||||
|
||||
void init() {
|
||||
void init(audio::Codec* const codec) {
|
||||
audio_codec = codec;
|
||||
|
||||
clock_manager.start_audio_pll();
|
||||
audio_codec.init();
|
||||
audio_codec->init();
|
||||
|
||||
i2s::i2s0::configure(
|
||||
i2s0_config_tx,
|
||||
@@ -167,7 +172,7 @@ void init() {
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
audio_codec.reset();
|
||||
audio_codec->reset();
|
||||
output::stop();
|
||||
}
|
||||
|
||||
|
@@ -73,12 +73,14 @@ void set_volume(const volume_t volume);
|
||||
|
||||
namespace debug {
|
||||
|
||||
int reg_count();
|
||||
uint16_t reg_read(const int register_number);
|
||||
size_t reg_count();
|
||||
uint32_t reg_read(const size_t register_number);
|
||||
std::string codec_name();
|
||||
size_t reg_bits();
|
||||
|
||||
} /* namespace debug */
|
||||
|
||||
void init();
|
||||
void init(audio::Codec* const codec);
|
||||
void shutdown();
|
||||
|
||||
enum class Rate {
|
||||
|
@@ -33,6 +33,9 @@ using namespace hackrf::one;
|
||||
#include "touch_adc.hpp"
|
||||
#include "audio.hpp"
|
||||
|
||||
#include "wm8731.hpp"
|
||||
using wolfson::wm8731::WM8731;
|
||||
|
||||
#include "cpld_update.hpp"
|
||||
|
||||
namespace portapack {
|
||||
@@ -61,6 +64,8 @@ ClockManager clock_manager {
|
||||
i2c0, clock_generator
|
||||
};
|
||||
|
||||
WM8731 audio_codec_wm8731 { i2c0, 0x1a };
|
||||
|
||||
ReceiverModel receiver_model;
|
||||
|
||||
TemperatureLogger temperature_logger;
|
||||
@@ -154,7 +159,7 @@ void init() {
|
||||
|
||||
portapack::io.init();
|
||||
|
||||
audio::init();
|
||||
audio::init(&audio_codec_wm8731);
|
||||
|
||||
clock_manager.enable_first_if_clock();
|
||||
clock_manager.enable_second_if_clock();
|
||||
|
@@ -260,8 +260,8 @@ DebugPeripheralsMenuView::DebugPeripheralsMenuView(NavigationView& nav) {
|
||||
"Si5351C", RegistersWidgetConfig { 96, 8 },
|
||||
[](const size_t register_number) { return portapack::clock_generator.read_register(register_number); }
|
||||
); } },
|
||||
{ "WM8731", [&nav](){ nav.push<RegistersView>(
|
||||
"WM8731", RegistersWidgetConfig { audio::debug::reg_count(), 9 },
|
||||
{ audio::debug::codec_name(), [&nav](){ nav.push<RegistersView>(
|
||||
audio::debug::codec_name(), RegistersWidgetConfig { audio::debug::reg_count(), audio::debug::reg_bits() },
|
||||
[](const size_t register_number) { return audio::debug::reg_read(register_number); }
|
||||
); } },
|
||||
});
|
||||
|
Reference in New Issue
Block a user