1 // Copyright 2020 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 //! `cros_alsa` crate currently supports interacting with alsa 6 //! controls by using the control interface API of alsa-lib. 7 //! 8 //! # Examples 9 //! This is an example of how to use the provided `Control` objects. 10 //! 11 //! ``` no_run 12 //! use std::error::Error; 13 //! use std::result::Result; 14 //! 15 //! use cros_alsa::{Card, SwitchControl, IntControl, StereoVolumeControl}; 16 //! 17 //! fn main() -> Result<(), Box<dyn Error>> { 18 //! 19 //! let mut card = Card::new("sofmax98390d")?; 20 //! 21 //! // Uses a SwitchControl to turn on and off a mixer control that has a single boolean state. 22 //! let mut calib_ctrl:SwitchControl = card.control_by_name("Left DSM Calibration")?; 23 //! calib_ctrl.on()?; 24 //! assert_eq!(calib_ctrl.state()?, true); 25 //! calib_ctrl.off()?; 26 //! 27 //! // Uses an IntControl to read and write a mixer control that has a single integer value. 28 //! let mut rdc_ctrl:IntControl = card.control_by_name("Left Rdc")?; 29 //! let _rdc = rdc_ctrl.get()?; 30 //! rdc_ctrl.set(13000)?; 31 //! 32 //! // Uses a StereoVolumeControl to manipulate stereo volume related functionality. 33 //! let mut volume_ctrl:StereoVolumeControl = card.control_by_name("Master Playback Volume")?; 34 //! volume_ctrl.set_volume(184, 184)?; 35 //! 36 //! Ok(()) 37 //! } 38 //! ``` 39 40 // Allow the maximum recursive depth = 256 for macro expansion. 41 #![recursion_limit = "256"] 42 #![deny(missing_docs)] 43 44 mod card; 45 mod control; 46 mod control_primitive; 47 pub mod control_tlv; 48 pub mod elem; 49 50 pub use self::card::Card; 51 pub use self::control::{Control, ControlOps, IntControl, StereoVolumeControl, SwitchControl}; 52 pub use self::control_primitive::{Ctl, ElemId}; 53 pub use self::control_tlv::{ControlTLV, TLV}; 54 55 pub use self::card::Error as CardError; 56 pub use self::control::Error as ControlError; 57 pub use self::control_tlv::Error as ControlTLVError; 58 pub use self::elem::Error as ElemError; 59 60 #[allow(unused_imports)] 61 pub use cros_alsa_derive::*; 62