• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 use std::string::String;
5 
6 use dsm::{self, Error, Result};
7 use serde::Deserialize;
8 
9 /// `DeviceSettings` includes the settings of max98390. It currently includes:
10 /// * the settings of amplifier calibration.
11 /// * the path of dsm_param.
12 #[derive(Debug, Default, PartialEq, Deserialize, Clone)]
13 pub struct DeviceSettings {
14     pub amp_calibrations: AmpCalibSettings,
15 }
16 #[derive(Debug, Default, PartialEq, Deserialize, Clone)]
17 pub struct AmpCalibCtrl {
18     // Mixer control to get/set rdc value.
19     pub rdc_ctrl: String,
20     // Mixer control to get/set ambient temperature value.
21     pub temp_ctrl: String,
22     // Mixer control to trigger calibration.
23     pub calib_ctrl: String,
24     // Mixer control to adjust volume.
25     pub volume_ctrl: String,
26 }
27 
28 /// `AmpCalibSettings` includes the settings needed for amplifier calibration.
29 #[derive(Debug, Default, PartialEq, Deserialize, Clone)]
30 pub struct AmpCalibSettings {
31     // Mixer control to get/set rdc value.
32     pub controls: Vec<AmpCalibCtrl>,
33     // Path of the dsm_param.bin file.
34     pub dsm_param: String,
35 }
36 
37 impl AmpCalibSettings {
38     /// Returns the number of channels.
num_channels(&self) -> usize39     pub fn num_channels(&self) -> usize {
40         self.controls.len()
41     }
42 }
43 
44 impl DeviceSettings {
45     /// Creates a `DeviceSettings` from a yaml str.
from_yaml_str(conf: &str) -> Result<DeviceSettings>46     pub fn from_yaml_str(conf: &str) -> Result<DeviceSettings> {
47         let settings: DeviceSettings = serde_yaml::from_str(conf)
48             .map_err(|e| Error::DeserializationFailed("DeviceSettings".to_owned(), e))?;
49         Ok(settings)
50     }
51 }
52