From 552bba47ea15182d0315f4a5718506ddae7f29de Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 14 Dec 2015 13:57:45 -0800 Subject: [PATCH] Move a lot of WM8731 functions to .cpp. --- firmware/common/wm8731.cpp | 120 +++++++++++++++++++++++++++++++++ firmware/common/wm8731.hpp | 131 ++++--------------------------------- 2 files changed, 134 insertions(+), 117 deletions(-) diff --git a/firmware/common/wm8731.cpp b/firmware/common/wm8731.cpp index 15e7e6da..85ba5533 100644 --- a/firmware/common/wm8731.cpp +++ b/firmware/common/wm8731.cpp @@ -27,6 +27,76 @@ namespace wolfson { namespace wm8731 { +void WM8731::init() { + reset(); + + write(PowerDownControl { + .lineinpd = 1, + .micpd = 0, + .adcpd = 0, + .dacpd = 0, + .outpd = 0, + .oscpd = 1, + .clkoutpd = 1, + .poweroff = 0, + .reserved0 = 0, + }); + + // write(SamplingControl { + // .usb_normal = 0, + // .bosr = 0, + // .sr = 0, + // .clkidiv2 = 0, + // .clkodiv2 = 0, + // .reserved0 = 0, + // }); + + write(DigitalAudioInterfaceFormat { + .format = 2, + .iwl = 0, + .lrp = 0, + .lrswap = 0, + .ms = 0, + .bclkinv = 0, + .reserved0 = 0, + }); + + write(DigitalAudioPathControl { + .adchpd = 0, + .deemp = 0, + .dacmu = 0, + .hpor = 0, + .reserved0 = 0, + }); + + write(AnalogAudioPathControl { + .micboost = 1, // Enable 20dB boost + .mutemic = 0, // Disable mute (unmute) + .insel = 1, // Microphone input to ADC + .bypass = 0, + .dacsel = 1, + .sidetone = 0, + .sideatt = 0, + .reserved0 = 0, + }); + + write(ActiveControl { + .active = 1, + .reserved0 = 0, + }); + + set_line_in_volume(0.0_dB); + headphone_mute(); +} + +void WM8731::reset() { + write(0x0f, 0); +} + +void WM8731::write(const Register reg) { + write(toUType(reg), map.w[toUType(reg)]); +} + void WM8731::write(const address_t reg_address, const reg_t value) { const uint16_t word = (reg_address << 9) | value; const std::array values { @@ -40,5 +110,55 @@ reg_t WM8731::read(const address_t reg_address) { return map.w[reg_address]; } +void WM8731::write(const LeftLineIn value) { + map.r.left_line_in = value; + write(Register::LeftLineIn); +} + +void WM8731::write(const RightLineIn value) { + map.r.right_line_in = value; + write(Register::RightLineIn); +} + +void WM8731::write(const LeftHeadphoneOut value) { + map.r.left_headphone_out = value; + write(Register::LeftHeadphoneOut); +} + +void WM8731::write(const RightHeadphoneOut value) { + map.r.right_headphone_out = value; + write(Register::RightHeadphoneOut); +} + +void WM8731::write(const AnalogAudioPathControl value) { + map.r.analog_audio_path_control = value; + write(Register::AnalogAudioPathControl); +} + +void WM8731::write(const DigitalAudioPathControl value) { + map.r.digital_audio_path_control = value; + write(Register::DigitalAudioPathControl); +} + +void WM8731::write(const PowerDownControl value) { + map.r.power_down_control = value; + write(Register::PowerDownControl); +} + +void WM8731::write(const DigitalAudioInterfaceFormat value) { + map.r.digital_audio_interface_format = value; + write(Register::DigitalAudioInterfaceFormat); +} + +void WM8731::write(const SamplingControl value) { + map.r.sampling_control = value; + write(Register::SamplingControl); +} + +void WM8731::write(const ActiveControl value) { + map.r.active_control = value; + write(Register::ActiveControl); +} + } /* namespace wm8731 */ } /* namespace wolfson */ diff --git a/firmware/common/wm8731.hpp b/firmware/common/wm8731.hpp index 88e9440a..6a1fa05e 100644 --- a/firmware/common/wm8731.hpp +++ b/firmware/common/wm8731.hpp @@ -289,71 +289,9 @@ public: { } - void init() { - reset(); + void init(); - write(PowerDownControl { - .lineinpd = 1, - .micpd = 0, - .adcpd = 0, - .dacpd = 0, - .outpd = 0, - .oscpd = 1, - .clkoutpd = 1, - .poweroff = 0, - .reserved0 = 0, - }); - - // write(SamplingControl { - // .usb_normal = 0, - // .bosr = 0, - // .sr = 0, - // .clkidiv2 = 0, - // .clkodiv2 = 0, - // .reserved0 = 0, - // }); - - write(DigitalAudioInterfaceFormat { - .format = 2, - .iwl = 0, - .lrp = 0, - .lrswap = 0, - .ms = 0, - .bclkinv = 0, - .reserved0 = 0, - }); - - write(DigitalAudioPathControl { - .adchpd = 0, - .deemp = 0, - .dacmu = 0, - .hpor = 0, - .reserved0 = 0, - }); - - write(AnalogAudioPathControl { - .micboost = 1, // Enable 20dB boost - .mutemic = 0, // Disable mute (unmute) - .insel = 1, // Microphone input to ADC - .bypass = 0, - .dacsel = 1, - .sidetone = 0, - .sideatt = 0, - .reserved0 = 0, - }); - - write(ActiveControl { - .active = 1, - .reserved0 = 0, - }); - - set_line_in_volume(0.0_dB); - headphone_mute(); - } - - void reset() { - write(0x0f, 0); - } + void reset(); void set_line_in_volume(const volume_t volume) { const auto normalized = line_in_gain_range.normalize(volume); @@ -401,61 +339,20 @@ private: const I2C::address_t bus_address; RegisterMap map { default_after_reset }; - void write(const Register reg) { - write(toUType(reg), map.w[toUType(reg)]); - } - + void write(const Register reg); + void write(const address_t reg_address, const reg_t value); - void write(const LeftLineIn value) { - map.r.left_line_in = value; - write(Register::LeftLineIn); - } - - void write(const RightLineIn value) { - map.r.right_line_in = value; - write(Register::RightLineIn); - } - - void write(const LeftHeadphoneOut value) { - map.r.left_headphone_out = value; - write(Register::LeftHeadphoneOut); - } - - void write(const RightHeadphoneOut value) { - map.r.right_headphone_out = value; - write(Register::RightHeadphoneOut); - } - - void write(const AnalogAudioPathControl value) { - map.r.analog_audio_path_control = value; - write(Register::AnalogAudioPathControl); - } - - void write(const DigitalAudioPathControl value) { - map.r.digital_audio_path_control = value; - write(Register::DigitalAudioPathControl); - } - - void write(const PowerDownControl value) { - map.r.power_down_control = value; - write(Register::PowerDownControl); - } - - void write(const DigitalAudioInterfaceFormat value) { - map.r.digital_audio_interface_format = value; - write(Register::DigitalAudioInterfaceFormat); - } - - void write(const SamplingControl value) { - map.r.sampling_control = value; - write(Register::SamplingControl); - } - - void write(const ActiveControl value) { - map.r.active_control = value; - write(Register::ActiveControl); - } + void write(const LeftLineIn value); + void write(const RightLineIn value); + void write(const LeftHeadphoneOut value); + void write(const RightHeadphoneOut value); + void write(const AnalogAudioPathControl value); + void write(const DigitalAudioPathControl value); + void write(const PowerDownControl value); + void write(const DigitalAudioInterfaceFormat value); + void write(const SamplingControl value); + void write(const ActiveControl value); }; } /* namespace wm8731 */