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
// Copyright (c) 2024 Jake Swensen
// SPDX-License-Identifier: MPL-2.0
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use bitfield::bitfield;
use super::RegisterOffset;
use crate::hacky_round;
use emc230x_macros::RegisterOffset;
bitfield! {
#[derive(Clone, Copy, RegisterOffset)]
#[register(offset = 0x08, default = 0x66)]
pub struct FanMinimumDrive(u8);
impl Debug;
/// Minimum Drive
///
/// The minimum PWM duty cycle that the device will output to the fan.
pub min_drive, set_min_drive: 7, 0;
}
impl FanMinimumDrive {
pub fn duty_cycle(&self) -> u8 {
let duty = (self.0 as f64 / 255.0) * 100.0;
hacky_round(duty)
}
pub fn from_duty_cycle(duty: u8) -> Self {
let raw = (duty as f64 / 100.0) * 255.0;
let raw = hacky_round(raw);
FanMinimumDrive(raw)
}
}