diff options
author | Jorge E. Moreira <jemoreira@google.com> | 2021-04-09 16:07:03 -0700 |
---|---|---|
committer | Jorge E. Moreira <jemoreira@google.com> | 2021-04-09 16:07:03 -0700 |
commit | 072dce8ca50bdf87b113490cdf14bde14724914f (patch) | |
tree | 7e0e07b9d8d50fc5dd352d5b36d74fa3cb3427db /sound_card_init/amp/src/lib.rs | |
parent | 0aaab56eba431583969e73f177a0efdcebf46cac (diff) | |
parent | 3624a4296888926a21462bfd499d4ba91268046b (diff) | |
download | adhd-android-s-beta-2.tar.gz |
Merge remote-tracking branch 'aosp/upstream-main' into masterandroid-s-beta-2android-s-beta-1main-cg-testing-release
This merge is necessary to update crosvm to the latest version
Bug: 163867676
Test: locally
Change-Id: Ia0681ee12911ac60f44b04008c5a0590032733a3
Diffstat (limited to 'sound_card_init/amp/src/lib.rs')
-rw-r--r-- | sound_card_init/amp/src/lib.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/sound_card_init/amp/src/lib.rs b/sound_card_init/amp/src/lib.rs new file mode 100644 index 00000000..7114233d --- /dev/null +++ b/sound_card_init/amp/src/lib.rs @@ -0,0 +1,58 @@ +// Copyright 2021 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. +//! `amp` crate provides `Amp` trait for amplifier initializations and `AmpBuilder` +//! to create `Amp` objects. +#![deny(missing_docs)] + +mod max98373d; +mod max98390d; +use std::path::PathBuf; + +use dsm::Error; + +use max98373d::Max98373; +use max98390d::Max98390; + +type Result<T> = std::result::Result<T, Error>; +const CONF_DIR: &str = "/etc/sound_card_init"; + +/// It creates `Amp` object based on the sound card name. +pub struct AmpBuilder<'a> { + sound_card_id: &'a str, + config_path: PathBuf, +} + +impl<'a> AmpBuilder<'a> { + /// Creates an `AmpBuilder`. + /// # Arguments + /// + /// * `card_name` - card name. + /// * `conf_file` - config file name. + pub fn new(sound_card_id: &'a str, conf_file: &'a str) -> Self { + let config_path = PathBuf::from(CONF_DIR).join(conf_file); + AmpBuilder { + sound_card_id, + config_path, + } + } + + /// Creates an `Amp` based on the sound card name. + pub fn build(&self) -> Result<Box<dyn Amp>> { + match self.sound_card_id { + "sofcmlmax98390d" => { + Ok(Box::new(Max98390::new(self.sound_card_id, &self.config_path)?) as Box<dyn Amp>) + } + "sofrt5682" => { + Ok(Box::new(Max98373::new(self.sound_card_id, &self.config_path)?) as Box<dyn Amp>) + } + _ => Err(Error::UnsupportedSoundCard(self.sound_card_id.to_owned())), + } + } +} + +/// It defines the required functions of amplifier objects. +pub trait Amp { + /// The amplifier boot time calibration flow. + fn boot_time_calibration(&mut self) -> Result<()>; +} |