ak4490: add mute/unmute/proper volume implementation
This commit is contained in:
@@ -24,6 +24,7 @@ enum RegisterAddress {
|
||||
pub struct Ak4490Dac<T> {
|
||||
i2c: T,
|
||||
pins: CodecPins, // this dependency is unfortunate, but non trivial to generalize
|
||||
volume: (u8, u8),
|
||||
}
|
||||
|
||||
impl<T> Ak4490Dac<T>
|
||||
@@ -43,6 +44,10 @@ where
|
||||
_ => 5,
|
||||
}
|
||||
}
|
||||
fn set_volume_impl(&mut self, left: u8, right: u8) {
|
||||
self.write_reg(RegisterAddress::LeftAtt, left);
|
||||
self.write_reg(RegisterAddress::RightAtt, right);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Dac<T> for Ak4490Dac<T>
|
||||
@@ -50,7 +55,11 @@ where
|
||||
T: _embedded_hal_blocking_i2c_WriteRead + _embedded_hal_blocking_i2c_Write,
|
||||
{
|
||||
fn new(i2c: T, pins: CodecPins) -> Self {
|
||||
Self { i2c, pins }
|
||||
Self {
|
||||
i2c,
|
||||
pins,
|
||||
volume: (0xff, 0xff),
|
||||
}
|
||||
}
|
||||
fn init(&mut self) {
|
||||
// bring out of reset
|
||||
@@ -66,7 +75,13 @@ where
|
||||
self.write_reg(RegisterAddress::Control4, (dfs & 0x4) >> 1);
|
||||
}
|
||||
fn set_volume(&mut self, left: u8, right: u8) {
|
||||
self.write_reg(RegisterAddress::LeftAtt, left);
|
||||
self.write_reg(RegisterAddress::RightAtt, right);
|
||||
self.set_volume_impl(left, right);
|
||||
self.volume = (left, right);
|
||||
}
|
||||
fn mute(&mut self) {
|
||||
self.set_volume_impl(0, 0);
|
||||
}
|
||||
fn unmute(&mut self) {
|
||||
self.set_volume_impl(self.volume.0, self.volume.1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user