cros_ec_python.cros_ec
This submodule provides some helper functions to make it easier to use the library.
For example, you can use get_cros_ec() instead of manually picking between
cros_ec_python.devices.lpc.CrosEcLpc and cros_ec_python.devices.dev.CrosEcDev.
1""" 2This submodule provides some helper functions to make it easier to use the library. 3 4For example, you can use `get_cros_ec()` instead of manually picking between 5`cros_ec_python.devices.lpc.CrosEcLpc` and `cros_ec_python.devices.dev.CrosEcDev`. 6""" 7 8import sys 9 10from .constants.COMMON import * 11from .baseclass import CrosEcClass 12from .devices import lpc 13if sys.platform == "linux": 14 from .devices import dev 15else: 16 dev = None 17if sys.platform == "win32": 18 from .devices import pawnio, win_fw_ec 19else: 20 pawnio = win_fw_ec = None 21 22class DeviceTypes(Enum): 23 """ 24 An Enum of different interfaces supported by the library. 25 """ 26 LinuxDev = 0 27 """ 28 This is the Linux device interface, which uses the `/dev/cros_ec` device file. 29 *Recommended if you have the `cros_ec_dev` kernel module loaded.* 30 """ 31 WinFrameworkEC = 1 32 """ 33 This is the Framework Windows driver interface. 34 *Recommended if you have a Framework laptop with a supported BIOS and driver.* 35 """ 36 PawnIO = 2 37 "This is the Windows PawnIO interface, which is recommended on Windows Systems." 38 LPC = 3 39 "This manually talks to the EC over the LPC interface, using the ioports." 40 41 42def pick_device() -> DeviceTypes: 43 """ 44 Pick the device to use. Used by `get_cros_ec`. 45 Devices are picked in the following order: 46 * `DeviceTypes.LinuxDev` (see `cros_ec_python.devices.dev.CrosEcDev.detect()`) 47 * `DeviceTypes.LPC` (see `cros_ec_python.devices.lpc.CrosEcLpc.detect()`) 48 """ 49 if dev and dev.CrosEcDev.detect(): 50 return DeviceTypes.LinuxDev 51 elif win_fw_ec and win_fw_ec.WinFrameworkEc.detect(): 52 return DeviceTypes.WinFrameworkEC 53 elif pawnio and pawnio.CrosEcPawnIO.detect(): 54 return DeviceTypes.PawnIO 55 elif lpc and lpc.CrosEcLpc.detect(): 56 return DeviceTypes.LPC 57 else: 58 raise OSError("Could not auto detect device, check you have the required permissions, or specify manually.") 59 60 61def get_cros_ec(dev_type: DeviceTypes | None = None, **kwargs) -> CrosEcClass: 62 """ 63 Find and initialise the correct CrosEc class. 64 This is the recommended way of obtaining a `cros_ec_python.baseclass.CrosEcClass` object. 65 :param dev_type: The device type to use. If None, it will be picked automatically. 66 :param kwargs: Keyword arguments to pass to the CrosEc class. 67 """ 68 69 if dev_type is None: 70 dev_type = pick_device() 71 72 match dev_type: 73 case DeviceTypes.LinuxDev: 74 return dev.CrosEcDev(**kwargs) 75 case DeviceTypes.WinFrameworkEC: 76 return win_fw_ec.WinFrameworkEc(**kwargs) 77 case DeviceTypes.PawnIO: 78 return pawnio.CrosEcPawnIO(**kwargs) 79 case DeviceTypes.LPC: 80 return lpc.CrosEcLpc(**kwargs) 81 case _: 82 raise ValueError("Invalid device type.")
23class DeviceTypes(Enum): 24 """ 25 An Enum of different interfaces supported by the library. 26 """ 27 LinuxDev = 0 28 """ 29 This is the Linux device interface, which uses the `/dev/cros_ec` device file. 30 *Recommended if you have the `cros_ec_dev` kernel module loaded.* 31 """ 32 WinFrameworkEC = 1 33 """ 34 This is the Framework Windows driver interface. 35 *Recommended if you have a Framework laptop with a supported BIOS and driver.* 36 """ 37 PawnIO = 2 38 "This is the Windows PawnIO interface, which is recommended on Windows Systems." 39 LPC = 3 40 "This manually talks to the EC over the LPC interface, using the ioports."
An Enum of different interfaces supported by the library.
This is the Linux device interface, which uses the /dev/cros_ec device file.
Recommended if you have the cros_ec_dev kernel module loaded.
This is the Framework Windows driver interface. Recommended if you have a Framework laptop with a supported BIOS and driver.
This is the Windows PawnIO interface, which is recommended on Windows Systems.
43def pick_device() -> DeviceTypes: 44 """ 45 Pick the device to use. Used by `get_cros_ec`. 46 Devices are picked in the following order: 47 * `DeviceTypes.LinuxDev` (see `cros_ec_python.devices.dev.CrosEcDev.detect()`) 48 * `DeviceTypes.LPC` (see `cros_ec_python.devices.lpc.CrosEcLpc.detect()`) 49 """ 50 if dev and dev.CrosEcDev.detect(): 51 return DeviceTypes.LinuxDev 52 elif win_fw_ec and win_fw_ec.WinFrameworkEc.detect(): 53 return DeviceTypes.WinFrameworkEC 54 elif pawnio and pawnio.CrosEcPawnIO.detect(): 55 return DeviceTypes.PawnIO 56 elif lpc and lpc.CrosEcLpc.detect(): 57 return DeviceTypes.LPC 58 else: 59 raise OSError("Could not auto detect device, check you have the required permissions, or specify manually.")
Pick the device to use. Used by get_cros_ec.
Devices are picked in the following order:
62def get_cros_ec(dev_type: DeviceTypes | None = None, **kwargs) -> CrosEcClass: 63 """ 64 Find and initialise the correct CrosEc class. 65 This is the recommended way of obtaining a `cros_ec_python.baseclass.CrosEcClass` object. 66 :param dev_type: The device type to use. If None, it will be picked automatically. 67 :param kwargs: Keyword arguments to pass to the CrosEc class. 68 """ 69 70 if dev_type is None: 71 dev_type = pick_device() 72 73 match dev_type: 74 case DeviceTypes.LinuxDev: 75 return dev.CrosEcDev(**kwargs) 76 case DeviceTypes.WinFrameworkEC: 77 return win_fw_ec.WinFrameworkEc(**kwargs) 78 case DeviceTypes.PawnIO: 79 return pawnio.CrosEcPawnIO(**kwargs) 80 case DeviceTypes.LPC: 81 return lpc.CrosEcLpc(**kwargs) 82 case _: 83 raise ValueError("Invalid device type.")
Find and initialise the correct CrosEc class.
This is the recommended way of obtaining a cros_ec_python.baseclass.CrosEcClass object.
Parameters
- dev_type: The device type to use. If None, it will be picked automatically.
- kwargs: Keyword arguments to pass to the CrosEc class.