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 /// `DeviceSettings` includes the settings of max98373. It currently includes: 9 /// * the settings of amplifier calibration. 10 /// * the path of dsm_param. 11 #[derive(Debug, Default, PartialEq, Deserialize, Clone)] 12 pub struct DeviceSettings { 13 pub amp_calibrations: AmpCalibSettings, 14 } 15 16 /// `AmpCalibSettings` includes the settings needed for amplifier calibration. 17 #[derive(Debug, Default, PartialEq, Deserialize, Clone)] 18 pub struct AmpCalibSettings { 19 pub dsm_param_read_ctrl: String, 20 pub dsm_param_write_ctrl: String, 21 pub temp_ctrl: Vec<String>, 22 // Path of the dsm_param.bin file. 23 pub dsm_param: String, 24 pub boot_time_calibration_enabled: bool, 25 } 26 27 impl AmpCalibSettings { 28 /// Returns the number of channels. num_channels(&self) -> usize29 pub fn num_channels(&self) -> usize { 30 self.temp_ctrl.len() 31 } 32 } 33 34 impl DeviceSettings { 35 /// Creates a `DeviceSettings` from a yaml str. from_yaml_str(conf: &str) -> Result<DeviceSettings>36 pub fn from_yaml_str(conf: &str) -> Result<DeviceSettings> { 37 let settings: DeviceSettings = serde_yaml::from_str(conf) 38 .map_err(|e| Error::DeserializationFailed("DeviceSettings".to_owned(), e))?; 39 Ok(settings) 40 } 41 } 42