Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion feeph/emc2101/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
# the following imports are provided for user convenience
# flake8: noqa: F401
from feeph.emc2101.calibration import calibrate_pwm_fan
from feeph.emc2101.config_register import ConfigRegister
from feeph.emc2101.core import CONVERSIONS_PER_SECOND, DEFAULTS, ExternalSensorStatus, SpinUpDuration, SpinUpStrength
from feeph.emc2101.ets_config import ExternalTemperatureSensorConfig, ets_2n3904, ets_2n3906
from feeph.emc2101.fan_configs import FanConfig, RpmControlMode, Steps, export_fan_config, generic_pwm_fan
from feeph.emc2101.pwm import DeviceConfig, Emc2101_PWM, ExternalTemperatureSensorConfig, FanSpeedUnit, PinSixMode, TemperatureLimitType, emc2101_default_config, ets_2n3904, ets_2n3906
from feeph.emc2101.pwm import DeviceConfig, Emc2101_PWM, FanSpeedUnit, PinSixMode, emc2101_default_config
5 changes: 3 additions & 2 deletions feeph/emc2101/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def calibrate_pwm_fan(i2c_bus: busio.I2C, model: str, pwm_frequency: int = 22500
LH.info("Calibrating fan parameters.")
pwm_d, pwm_f = feeph.emc2101.utilities.calculate_pwm_factors(pwm_frequency=pwm_frequency)
steps_list = list(range(pwm_f * 2))
emc2101 = feeph.emc2101.core.Emc2101_core(i2c_bus=i2c_bus)
emc2101.configure_pin_six_as_tacho()
# tacho signal on pin 6, device uses PWM control
config = feeph.emc2101.core.ConfigRegister(alt_tach=True, dac=False)
emc2101 = feeph.emc2101.core.Emc2101(i2c_bus=i2c_bus, config=config)
emc2101.configure_pwm_control(pwm_d=pwm_d, pwm_f=pwm_f, step_max=max(steps_list))
# -----------------------------------------------------------------
LH.debug("Disabling gradual speed rampup.")
Expand Down
72 changes: 72 additions & 0 deletions feeph/emc2101/config_register.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env

from attrs import define


@define(eq=True)
class ConfigRegister:
"""
a representation of the EMC2101's config register (0x03)

this is not the entire configuration, there are additional registers
which configure different aspects of this chip, e.g. fan configuration
register (0x4A)

for an exhaustive description refer to EMC2101 datasheet section 6.5
"""
# the comment describes what happens if the value is set to True
mask: bool = False # disable ALERT/TACH when in interrupt mode
standby: bool = False # enable low power standby mode
fan_standby: bool = False # disable fan output while in standby
dac: bool = False # enable DAC output on FAN pin
dis_to: bool = False # disable SMBUS timeout
alt_tach: bool = False # configure pin six as tacho input
trcit_ovrd: bool = False # unlock tcrit limit and allow one-time write
queue: bool = False # alert after 3 critical temperature readings

def as_int(self):
"""
compute the config register's value
"""
config = 0x00
if self.mask:
config |= 0b1000_0000
if self.standby:
config |= 0b0100_0000
if self.fan_standby:
config |= 0b0010_0000
if self.dac:
config |= 0b0001_0000
if self.dis_to:
config |= 0b0000_1000
if self.alt_tach:
config |= 0b0000_0100
if self.trcit_ovrd:
config |= 0b0000_0010
if self.queue:
config |= 0b0000_0001
return config


def parse_config_register(value: int) -> ConfigRegister:
"""
parse the config register's value
"""
params = dict()
if value & 0b1000_0000:
params['mask'] = True
if value & 0b0100_0000:
params['standby'] = True
if value & 0b0010_0000:
params['fan_standby'] = True
if value & 0b0001_0000:
params['dac'] = True
if value & 0b0000_1000:
params['dis_to'] = True
if value & 0b0000_0100:
params['alt_tach'] = True
if value & 0b0000_0010:
params['trcit_ovrd'] = True
if value & 0b0000_0001:
params['queue'] = True
return ConfigRegister(**params)
Loading