Move a lot of WM8731 functions to .cpp.

This commit is contained in:
Jared Boone 2015-12-14 13:57:45 -08:00
parent fa3eaf0820
commit 552bba47ea
2 changed files with 134 additions and 117 deletions

View File

@ -27,6 +27,76 @@
namespace wolfson { namespace wolfson {
namespace wm8731 { 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) { void WM8731::write(const address_t reg_address, const reg_t value) {
const uint16_t word = (reg_address << 9) | value; const uint16_t word = (reg_address << 9) | value;
const std::array<uint8_t, 2> values { const std::array<uint8_t, 2> values {
@ -40,5 +110,55 @@ reg_t WM8731::read(const address_t reg_address) {
return map.w[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 wm8731 */
} /* namespace wolfson */ } /* namespace wolfson */

View File

@ -289,71 +289,9 @@ public:
{ {
} }
void init() { void init();
reset();
write(PowerDownControl { void reset();
.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 set_line_in_volume(const volume_t volume) { void set_line_in_volume(const volume_t volume) {
const auto normalized = line_in_gain_range.normalize(volume); const auto normalized = line_in_gain_range.normalize(volume);
@ -401,61 +339,20 @@ private:
const I2C::address_t bus_address; const I2C::address_t bus_address;
RegisterMap map { default_after_reset }; RegisterMap map { default_after_reset };
void write(const Register reg) { void write(const Register reg);
write(toUType(reg), map.w[toUType(reg)]);
}
void write(const address_t reg_address, const reg_t value); void write(const address_t reg_address, const reg_t value);
void write(const LeftLineIn value) { void write(const LeftLineIn value);
map.r.left_line_in = value; void write(const RightLineIn value);
write(Register::LeftLineIn); void write(const LeftHeadphoneOut value);
} void write(const RightHeadphoneOut value);
void write(const AnalogAudioPathControl value);
void write(const RightLineIn value) { void write(const DigitalAudioPathControl value);
map.r.right_line_in = value; void write(const PowerDownControl value);
write(Register::RightLineIn); void write(const DigitalAudioInterfaceFormat value);
} void write(const SamplingControl value);
void write(const ActiveControl value);
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);
}
}; };
} /* namespace wm8731 */ } /* namespace wm8731 */