mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 11:17:58 +00:00
Formatted code (#1007)
* Updated style * Updated files * fixed new line * Updated spacing * File fix WIP * Updated to clang 13 * updated comment style * Removed old comment code
This commit is contained in:
@@ -37,95 +37,95 @@ namespace {
|
||||
|
||||
// "Master": I2S peripheral generates SCK/WS, transmits to audio codec.
|
||||
|
||||
constexpr i2s::ConfigTX i2s0_config_tx_master_base_clk {
|
||||
.dao = i2s::DAO {
|
||||
.wordwidth = i2s::WordWidth::Bits16,
|
||||
.mono = 0,
|
||||
.stop = 1,
|
||||
.reset = 0,
|
||||
.ws_sel = 0, // Master
|
||||
.ws_halfperiod = 0x0f,
|
||||
.mute = 1,
|
||||
},
|
||||
.txrate = i2s::MCLKRate {
|
||||
.x_divider = 0,
|
||||
.y_divider = 0,
|
||||
},
|
||||
.txbitrate = i2s::BitRate {
|
||||
.bitrate = 7,
|
||||
},
|
||||
.txmode = i2s::Mode {
|
||||
.clksel = i2s::ClockSelect::BaseAudioClkOrExternalMCLK,
|
||||
.four_pin = 0,
|
||||
.mclk_out_en = 1,
|
||||
},
|
||||
.sck_in_sel = 1,
|
||||
constexpr i2s::ConfigTX i2s0_config_tx_master_base_clk{
|
||||
.dao = i2s::DAO{
|
||||
.wordwidth = i2s::WordWidth::Bits16,
|
||||
.mono = 0,
|
||||
.stop = 1,
|
||||
.reset = 0,
|
||||
.ws_sel = 0, // Master
|
||||
.ws_halfperiod = 0x0f,
|
||||
.mute = 1,
|
||||
},
|
||||
.txrate = i2s::MCLKRate{
|
||||
.x_divider = 0,
|
||||
.y_divider = 0,
|
||||
},
|
||||
.txbitrate = i2s::BitRate{
|
||||
.bitrate = 7,
|
||||
},
|
||||
.txmode = i2s::Mode{
|
||||
.clksel = i2s::ClockSelect::BaseAudioClkOrExternalMCLK,
|
||||
.four_pin = 0,
|
||||
.mclk_out_en = 1,
|
||||
},
|
||||
.sck_in_sel = 1,
|
||||
};
|
||||
|
||||
constexpr i2s::ConfigRX i2s0_config_rx_four_wire {
|
||||
.dai = i2s::DAI {
|
||||
.wordwidth = i2s::WordWidth::Bits16,
|
||||
.mono = 0,
|
||||
.stop = 1,
|
||||
.reset = 0,
|
||||
.ws_sel = 0, // Master
|
||||
.ws_halfperiod = 0x0f,
|
||||
},
|
||||
.rxrate = i2s::MCLKRate {
|
||||
.x_divider = 0,
|
||||
.y_divider = 0,
|
||||
},
|
||||
.rxbitrate = i2s::BitRate {
|
||||
.bitrate = 7,
|
||||
},
|
||||
.rxmode = i2s::Mode {
|
||||
.clksel = i2s::ClockSelect::FractionalDivider,
|
||||
.four_pin = 1,
|
||||
.mclk_out_en = 0,
|
||||
},
|
||||
.sck_in_sel = 0,
|
||||
constexpr i2s::ConfigRX i2s0_config_rx_four_wire{
|
||||
.dai = i2s::DAI{
|
||||
.wordwidth = i2s::WordWidth::Bits16,
|
||||
.mono = 0,
|
||||
.stop = 1,
|
||||
.reset = 0,
|
||||
.ws_sel = 0, // Master
|
||||
.ws_halfperiod = 0x0f,
|
||||
},
|
||||
.rxrate = i2s::MCLKRate{
|
||||
.x_divider = 0,
|
||||
.y_divider = 0,
|
||||
},
|
||||
.rxbitrate = i2s::BitRate{
|
||||
.bitrate = 7,
|
||||
},
|
||||
.rxmode = i2s::Mode{
|
||||
.clksel = i2s::ClockSelect::FractionalDivider,
|
||||
.four_pin = 1,
|
||||
.mclk_out_en = 0,
|
||||
},
|
||||
.sck_in_sel = 0,
|
||||
};
|
||||
|
||||
// "Slave": I2S controlled by external SCK/WS, received from audio codec.
|
||||
|
||||
constexpr i2s::ConfigTX i2s0_config_tx_slave_base_clk {
|
||||
.dao = i2s::DAO {
|
||||
.wordwidth = i2s::WordWidth::Bits16,
|
||||
.mono = 0,
|
||||
.stop = 1,
|
||||
.reset = 0,
|
||||
.ws_sel = 1,
|
||||
.ws_halfperiod = 0x0f,
|
||||
.mute = 1,
|
||||
},
|
||||
.txrate = i2s::MCLKRate {
|
||||
.x_divider = 0,
|
||||
.y_divider = 0,
|
||||
},
|
||||
.txbitrate = i2s::BitRate {
|
||||
.bitrate = 0,
|
||||
},
|
||||
.txmode = i2s::Mode {
|
||||
.clksel = i2s::ClockSelect::FractionalDivider,
|
||||
.four_pin = 0,
|
||||
.mclk_out_en = 1,
|
||||
},
|
||||
.sck_in_sel = 1,
|
||||
constexpr i2s::ConfigTX i2s0_config_tx_slave_base_clk{
|
||||
.dao = i2s::DAO{
|
||||
.wordwidth = i2s::WordWidth::Bits16,
|
||||
.mono = 0,
|
||||
.stop = 1,
|
||||
.reset = 0,
|
||||
.ws_sel = 1,
|
||||
.ws_halfperiod = 0x0f,
|
||||
.mute = 1,
|
||||
},
|
||||
.txrate = i2s::MCLKRate{
|
||||
.x_divider = 0,
|
||||
.y_divider = 0,
|
||||
},
|
||||
.txbitrate = i2s::BitRate{
|
||||
.bitrate = 0,
|
||||
},
|
||||
.txmode = i2s::Mode{
|
||||
.clksel = i2s::ClockSelect::FractionalDivider,
|
||||
.four_pin = 0,
|
||||
.mclk_out_en = 1,
|
||||
},
|
||||
.sck_in_sel = 1,
|
||||
};
|
||||
|
||||
constexpr i2s::ConfigDMA i2s0_config_dma {
|
||||
.dma1 = i2s::DMA {
|
||||
.rx_enable = 1,
|
||||
.tx_enable = 0,
|
||||
.rx_depth = 4,
|
||||
.tx_depth = 0,
|
||||
},
|
||||
.dma2 = i2s::DMA {
|
||||
.rx_enable = 0,
|
||||
.tx_enable = 1,
|
||||
.rx_depth = 0,
|
||||
.tx_depth = 4,
|
||||
},
|
||||
constexpr i2s::ConfigDMA i2s0_config_dma{
|
||||
.dma1 = i2s::DMA{
|
||||
.rx_enable = 1,
|
||||
.tx_enable = 0,
|
||||
.rx_depth = 4,
|
||||
.tx_depth = 0,
|
||||
},
|
||||
.dma2 = i2s::DMA{
|
||||
.rx_enable = 0,
|
||||
.tx_enable = 1,
|
||||
.rx_depth = 0,
|
||||
.tx_depth = 4,
|
||||
},
|
||||
};
|
||||
|
||||
static audio::Codec* audio_codec = nullptr;
|
||||
@@ -135,47 +135,47 @@ static audio::Codec* audio_codec = nullptr;
|
||||
namespace output {
|
||||
|
||||
void start() {
|
||||
i2s::i2s0::tx_start();
|
||||
unmute();
|
||||
i2s::i2s0::tx_start();
|
||||
unmute();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
mute();
|
||||
i2s::i2s0::tx_stop();
|
||||
mute();
|
||||
i2s::i2s0::tx_stop();
|
||||
}
|
||||
|
||||
void mute() {
|
||||
i2s::i2s0::tx_mute();
|
||||
audio_codec->headphone_disable();
|
||||
i2s::i2s0::tx_mute();
|
||||
audio_codec->headphone_disable();
|
||||
}
|
||||
|
||||
void unmute() {
|
||||
i2s::i2s0::tx_unmute();
|
||||
audio_codec->headphone_enable();
|
||||
i2s::i2s0::tx_unmute();
|
||||
audio_codec->headphone_enable();
|
||||
}
|
||||
|
||||
void speaker_mute() {
|
||||
i2s::i2s0::tx_mute();
|
||||
audio_codec->speaker_disable();
|
||||
}
|
||||
i2s::i2s0::tx_mute();
|
||||
audio_codec->speaker_disable();
|
||||
}
|
||||
|
||||
void speaker_unmute() {
|
||||
i2s::i2s0::tx_unmute();
|
||||
audio_codec->speaker_enable();
|
||||
}
|
||||
void speaker_unmute() {
|
||||
i2s::i2s0::tx_unmute();
|
||||
audio_codec->speaker_enable();
|
||||
}
|
||||
|
||||
} /* namespace output */
|
||||
|
||||
namespace input {
|
||||
|
||||
void start(int8_t alc_mode) {
|
||||
audio_codec->microphone_enable(alc_mode); // added user-GUI selection for AK4951, ALC mode parameter.
|
||||
i2s::i2s0::rx_start();
|
||||
audio_codec->microphone_enable(alc_mode); // added user-GUI selection for AK4951, ALC mode parameter.
|
||||
i2s::i2s0::rx_start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
i2s::i2s0::rx_stop();
|
||||
audio_codec->microphone_disable();
|
||||
i2s::i2s0::rx_stop();
|
||||
audio_codec->microphone_disable();
|
||||
}
|
||||
|
||||
} /* namespace input */
|
||||
@@ -183,11 +183,11 @@ void stop() {
|
||||
namespace headphone {
|
||||
|
||||
volume_range_t volume_range() {
|
||||
return audio_codec->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 */
|
||||
@@ -195,52 +195,51 @@ void set_volume(const volume_t volume) {
|
||||
namespace debug {
|
||||
|
||||
size_t reg_count() {
|
||||
return audio_codec->reg_count();
|
||||
return audio_codec->reg_count();
|
||||
}
|
||||
|
||||
uint32_t reg_read(const size_t register_number) {
|
||||
return audio_codec->reg_read(register_number);
|
||||
return audio_codec->reg_read(register_number);
|
||||
}
|
||||
|
||||
std::string codec_name() {
|
||||
return audio_codec->name();
|
||||
return audio_codec->name();
|
||||
}
|
||||
|
||||
size_t reg_bits() {
|
||||
return audio_codec->reg_bits();
|
||||
return audio_codec->reg_bits();
|
||||
}
|
||||
|
||||
} /* namespace debug */
|
||||
|
||||
void init(audio::Codec* const codec) {
|
||||
clock_manager.start_audio_pll();
|
||||
clock_manager.start_audio_pll();
|
||||
|
||||
// Configure I2S before activating codec interface.
|
||||
i2s::i2s0::configure(
|
||||
i2s0_config_tx_master_base_clk,
|
||||
i2s0_config_rx_four_wire,
|
||||
i2s0_config_dma
|
||||
);
|
||||
// Configure I2S before activating codec interface.
|
||||
i2s::i2s0::configure(
|
||||
i2s0_config_tx_master_base_clk,
|
||||
i2s0_config_rx_four_wire,
|
||||
i2s0_config_dma);
|
||||
|
||||
audio_codec = codec;
|
||||
audio_codec->init();
|
||||
audio_codec = codec;
|
||||
audio_codec->init();
|
||||
|
||||
// Set pin mode, since it's likely GPIO (as left after CPLD JTAG interactions).
|
||||
portapack::pin_i2s0_rx_sda.mode(3);
|
||||
// Set pin mode, since it's likely GPIO (as left after CPLD JTAG interactions).
|
||||
portapack::pin_i2s0_rx_sda.mode(3);
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
audio_codec->reset();
|
||||
input::stop();
|
||||
output::stop();
|
||||
audio_codec->reset();
|
||||
input::stop();
|
||||
output::stop();
|
||||
|
||||
i2s::i2s0::shutdown();
|
||||
i2s::i2s0::shutdown();
|
||||
|
||||
clock_manager.stop_audio_pll();
|
||||
clock_manager.stop_audio_pll();
|
||||
}
|
||||
|
||||
void set_rate(const Rate rate) {
|
||||
clock_manager.set_base_audio_clock_divider(toUType(rate));
|
||||
clock_manager.set_base_audio_clock_divider(toUType(rate));
|
||||
}
|
||||
|
||||
} /* namespace audio */
|
||||
|
Reference in New Issue
Block a user