cros_ec_python.commands.thermal

Thermal engine commands. Note that there are two implementations. We'll reuse the command number, but the data and behavior is incompatible.

Version 0 is what originally shipped on Link.

Version 1 separates the CPU thermal limits from the fan control.

 1"""
 2Thermal engine commands. Note that there are two implementations.
 3We'll reuse the command number, but the data and behavior is incompatible.
 4
 5Version 0 is what originally shipped on Link.
 6
 7Version 1 separates the CPU thermal limits from the fan control.
 8"""
 9
10from typing import Final
11from enum import Enum, auto
12import struct
13from ..baseclass import CrosEcClass
14from ..constants.COMMON import *
15from .memmap import get_temps
16
17EC_CMD_THERMAL_SET_THRESHOLD: Final = 0x0050
18EC_CMD_THERMAL_GET_THRESHOLD: Final = 0x0051
19
20EC_CMD_THERMAL_AUTO_FAN_CTRL: Final = 0x0052
21
22
23def thermal_auto_fan_ctrl(ec: CrosEcClass, fan_idx: UInt8 | None = None) -> None:
24    """
25    Toggle automatic fan control.
26    :param ec: The CrOS_EC object.
27    :param fan_idx: The fan index to control (v1 command). If None, it will set all fans (v0 command).
28    """
29    if fan_idx is None:
30        ec.command(0, EC_CMD_THERMAL_AUTO_FAN_CTRL, 0, 0)
31    else:
32        data = struct.pack("<B", fan_idx)
33        ec.command(1, EC_CMD_THERMAL_AUTO_FAN_CTRL, 1, 0, data)
34
35
36EC_CMD_TMP006_GET_CALIBRATION: Final = 0x0053
37EC_CMD_TMP006_SET_CALIBRATION: Final = 0x0054
38EC_CMD_TMP006_GET_RAW: Final = 0x0055
39
40EC_CMD_TEMP_SENSOR_GET_INFO: Final = 0x0070
41
42class EcTempSensorType(Enum):
43    TEMP_SENSOR_TYPE_IGNORED = -1
44    TEMP_SENSOR_TYPE_CPU = 0
45    TEMP_SENSOR_TYPE_BOARD = auto()
46    TEMP_SENSOR_TYPE_CASE = auto()
47    TEMP_SENSOR_TYPE_BATTERY = auto()
48
49    TEMP_SENSOR_TYPE_COUNT = auto()
50
51def temp_sensor_get_info(ec: CrosEcClass, sensor_idx: UInt8) -> dict[str, EcTempSensorType]:
52    """
53    Get information about a temperature sensor.
54    :param ec: The CrOS_EC object.
55    :param sensor_idx: The sensor index.
56    :return: The response data.
57    """
58    data = struct.pack("<B", sensor_idx)
59    resp = ec.command(0, EC_CMD_TEMP_SENSOR_GET_INFO, 1, 33, data)
60    unpacked = struct.unpack("<32sB", resp)
61    return {
62        "name": unpacked[0].decode("utf-8").rstrip("\x00"),
63        "type": EcTempSensorType(unpacked[1])
64    }
65
66def get_temp_sensors(ec: CrosEcClass) -> dict[str, tuple[int, EcTempSensorType]]:
67    """
68    Get information about all temperature sensors.
69    :param ec: The CrOS_EC object.
70    :return: The response data.
71    """
72    temps = get_temps(ec)
73    ret = {}
74    for i, j in enumerate(temps):
75        info = temp_sensor_get_info(ec, i)
76        ret[info["name"]] = (j, info["type"])
77    return ret
78    
EC_CMD_THERMAL_SET_THRESHOLD: Final = 80
EC_CMD_THERMAL_GET_THRESHOLD: Final = 81
EC_CMD_THERMAL_AUTO_FAN_CTRL: Final = 82
def thermal_auto_fan_ctrl( ec: cros_ec_python.baseclass.CrosEcClass, fan_idx: int | None = None) -> None:
24def thermal_auto_fan_ctrl(ec: CrosEcClass, fan_idx: UInt8 | None = None) -> None:
25    """
26    Toggle automatic fan control.
27    :param ec: The CrOS_EC object.
28    :param fan_idx: The fan index to control (v1 command). If None, it will set all fans (v0 command).
29    """
30    if fan_idx is None:
31        ec.command(0, EC_CMD_THERMAL_AUTO_FAN_CTRL, 0, 0)
32    else:
33        data = struct.pack("<B", fan_idx)
34        ec.command(1, EC_CMD_THERMAL_AUTO_FAN_CTRL, 1, 0, data)

Toggle automatic fan control.

Parameters
  • ec: The CrOS_EC object.
  • fan_idx: The fan index to control (v1 command). If None, it will set all fans (v0 command).
EC_CMD_TMP006_GET_CALIBRATION: Final = 83
EC_CMD_TMP006_SET_CALIBRATION: Final = 84
EC_CMD_TMP006_GET_RAW: Final = 85
EC_CMD_TEMP_SENSOR_GET_INFO: Final = 112
class EcTempSensorType(enum.Enum):
43class EcTempSensorType(Enum):
44    TEMP_SENSOR_TYPE_IGNORED = -1
45    TEMP_SENSOR_TYPE_CPU = 0
46    TEMP_SENSOR_TYPE_BOARD = auto()
47    TEMP_SENSOR_TYPE_CASE = auto()
48    TEMP_SENSOR_TYPE_BATTERY = auto()
49
50    TEMP_SENSOR_TYPE_COUNT = auto()
TEMP_SENSOR_TYPE_IGNORED = <EcTempSensorType.TEMP_SENSOR_TYPE_IGNORED: -1>
TEMP_SENSOR_TYPE_CPU = <EcTempSensorType.TEMP_SENSOR_TYPE_CPU: 0>
TEMP_SENSOR_TYPE_BOARD = <EcTempSensorType.TEMP_SENSOR_TYPE_BOARD: 1>
TEMP_SENSOR_TYPE_CASE = <EcTempSensorType.TEMP_SENSOR_TYPE_CASE: 2>
TEMP_SENSOR_TYPE_BATTERY = <EcTempSensorType.TEMP_SENSOR_TYPE_BATTERY: 3>
TEMP_SENSOR_TYPE_COUNT = <EcTempSensorType.TEMP_SENSOR_TYPE_COUNT: 4>
def temp_sensor_get_info( ec: cros_ec_python.baseclass.CrosEcClass, sensor_idx: int) -> dict[str, EcTempSensorType]:
52def temp_sensor_get_info(ec: CrosEcClass, sensor_idx: UInt8) -> dict[str, EcTempSensorType]:
53    """
54    Get information about a temperature sensor.
55    :param ec: The CrOS_EC object.
56    :param sensor_idx: The sensor index.
57    :return: The response data.
58    """
59    data = struct.pack("<B", sensor_idx)
60    resp = ec.command(0, EC_CMD_TEMP_SENSOR_GET_INFO, 1, 33, data)
61    unpacked = struct.unpack("<32sB", resp)
62    return {
63        "name": unpacked[0].decode("utf-8").rstrip("\x00"),
64        "type": EcTempSensorType(unpacked[1])
65    }

Get information about a temperature sensor.

Parameters
  • ec: The CrOS_EC object.
  • sensor_idx: The sensor index.
Returns

The response data.

def get_temp_sensors( ec: cros_ec_python.baseclass.CrosEcClass) -> dict[str, tuple[int, EcTempSensorType]]:
67def get_temp_sensors(ec: CrosEcClass) -> dict[str, tuple[int, EcTempSensorType]]:
68    """
69    Get information about all temperature sensors.
70    :param ec: The CrOS_EC object.
71    :return: The response data.
72    """
73    temps = get_temps(ec)
74    ret = {}
75    for i, j in enumerate(temps):
76        info = temp_sensor_get_info(ec, i)
77        ret[info["name"]] = (j, info["type"])
78    return ret

Get information about all temperature sensors.

Parameters
  • ec: The CrOS_EC object.
Returns

The response data.