summaryrefslogtreecommitdiff
path: root/cros_alsa/src/card.rs
diff options
context:
space:
mode:
authorJudy Hsiao <judyhsiao@google.com>2020-12-07 13:04:49 +0800
committerCommit Bot <commit-bot@chromium.org>2021-01-15 05:49:00 +0000
commite4ba53351176857be2b264cf768bfa1e8fb3ef05 (patch)
tree60dd80c0e5ea0416f14b96bf3f4f04e4ab238bee /cros_alsa/src/card.rs
parent7dd7322b3ee0e3e1d814c78bb924328627b453ad (diff)
downloadadhd-e4ba53351176857be2b264cf768bfa1e8fb3ef05.tar.gz
cros_alsa: add ControlTLV
Add ControlTLV to support read and write of alsa TLV byte controls. BUG=b:157210111 TEST=cargo build Change-Id: I31e76d3d64a12f4ec50609d6eaf095525143eb8d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/2595659 Tested-by: Judy Hsiao <judyhsiao@chromium.org> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Commit-Queue: Judy Hsiao <judyhsiao@chromium.org>
Diffstat (limited to 'cros_alsa/src/card.rs')
-rw-r--r--cros_alsa/src/card.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/cros_alsa/src/card.rs b/cros_alsa/src/card.rs
index fa88018f..99f72210 100644
--- a/cros_alsa/src/card.rs
+++ b/cros_alsa/src/card.rs
@@ -10,6 +10,7 @@ use remain::sorted;
use crate::control::{self, Control};
use crate::control_primitive;
use crate::control_primitive::{Ctl, ElemId, ElemIface};
+use crate::control_tlv::{self, ControlTLV};
pub type Result<T> = std::result::Result<T, Error>;
@@ -21,6 +22,8 @@ pub enum Error {
AlsaControlAPI(control_primitive::Error),
/// Error occurs in Control.
Control(control::Error),
+ /// Error occurs in ControlTLV.
+ ControlTLV(control_tlv::Error),
}
impl error::Error for Error {}
@@ -31,6 +34,12 @@ impl From<control::Error> for Error {
}
}
+impl From<control_tlv::Error> for Error {
+ fn from(err: control_tlv::Error) -> Error {
+ Error::ControlTLV(err)
+ }
+}
+
impl From<control_primitive::Error> for Error {
fn from(err: control_primitive::Error) -> Error {
Error::AlsaControlAPI(err)
@@ -43,6 +52,7 @@ impl fmt::Display for Error {
match self {
AlsaControlAPI(e) => write!(f, "{}", e),
Control(e) => write!(f, "{}", e),
+ ControlTLV(e) => write!(f, "{}", e),
}
}
}
@@ -82,7 +92,7 @@ impl Card {
/// # Errors
///
/// * If control name is an invalid CString.
- /// * If control dose not exist.
+ /// * If control does not exist.
/// * If `Control` elem_type() mismatches the type of underlying mixer control.
/// * If `Control` size() mismatches the number of value entries of underlying mixer control.
pub fn control_by_name<'a, T: 'a>(&'a mut self, control_name: &str) -> Result<T>
@@ -92,4 +102,15 @@ impl Card {
let id = ElemId::new(ElemIface::Mixer, control_name)?;
Ok(T::from(&mut self.handle, id)?)
}
+
+ /// Creates a `ControlTLV` from control name.
+ ///
+ /// # Errors
+ ///
+ /// * If control name is an invalid CString.
+ /// * If control does not exist.
+ pub fn control_tlv_by_name<'a>(&'a mut self, control_name: &str) -> Result<ControlTLV<'a>> {
+ let id = ElemId::new(ElemIface::Mixer, control_name)?;
+ Ok(ControlTLV::new(&mut self.handle, id)?)
+ }
}