summaryrefslogtreecommitdiff
path: root/cros_alsa/src/lib.rs
blob: 070d221a81a232a7ef249dd980f421154a699c54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! `cros_alsa` crate currently supports interacting with alsa
//! controls by using the control interface API of alsa-lib.
//!
//! # Examples
//! This is an example of how to use the provided `Control` objects.
//!
//! ``` no_run
//! use std::error::Error;
//! use std::result::Result;
//!
//! use cros_alsa::{Card, SwitchControl, IntControl, StereoVolumeControl};
//!
//! fn main() -> Result<(), Box<dyn Error>> {
//!
//!   let mut card = Card::new("sofmax98390d")?;
//!
//!   // Uses a SwitchControl to turn on and off a mixer control that has a single boolean state.
//!   let mut calib_ctrl:SwitchControl = card.control_by_name("Left DSM Calibration")?;
//!   calib_ctrl.on()?;
//!   assert_eq!(calib_ctrl.state()?, true);
//!   calib_ctrl.off()?;
//!
//!   // Uses an IntControl to read and write a mixer control that has a single integer value.
//!   let mut rdc_ctrl:IntControl = card.control_by_name("Left Rdc")?;
//!   let _rdc = rdc_ctrl.get()?;
//!   rdc_ctrl.set(13000)?;
//!
//!   // Uses a StereoVolumeControl to manipulate stereo volume related functionality.
//!   let mut volume_ctrl:StereoVolumeControl = card.control_by_name("Master Playback Volume")?;
//!   volume_ctrl.set_volume(184, 184)?;
//!
//!   Ok(())
//! }
//! ```

// Allow the maximum recursive depth = 256 for macro expansion.
#![recursion_limit = "256"]
#![deny(missing_docs)]

mod card;
mod control;
mod control_primitive;
pub mod control_tlv;
pub mod elem;

pub use self::card::Card;
pub use self::control::{Control, ControlOps, IntControl, StereoVolumeControl, SwitchControl};
pub use self::control_primitive::{Ctl, ElemId};
pub use self::control_tlv::{ControlTLV, TLV};

pub use self::card::Error as CardError;
pub use self::control::Error as ControlError;
pub use self::control_tlv::Error as ControlTLVError;
pub use self::elem::Error as ElemError;

#[allow(unused_imports)]
pub use cros_alsa_derive::*;