cros_ec_python.devices
Description
The classes for each of the different interfaces supported by the library live in this submodule.
If you don't understand what this does, just use cros_ec_python.cros_ec.get_cros_ec() to pick an interface.
All device class implementations should inherit from cros_ec_python.baseclass.CrosEcClass,
and implement the methods described in that class. This allows everything to use the standardised
cros_ec_python.baseclass.CrosEcClass.command method to send commands to the EC, and
cros_ec_python.baseclass.CrosEcClass.memmap to read memory from the EC.
Devices can have optional specific arguments in their __init__ method, but other methods should be the same.
Examples
Initialisation
# Pick one of the following:
# Automatically pick the right class
from cros_ec_python import get_cros_ec
ec = get_cros_ec()
# Manually pick LinuxDev
from cros_ec_python import CrosEcDev
ec = CrosEcDev()
# Manually pick LPC
from cros_ec_python import CrosEcLpc
ec = CrosEcLpc()
# Manually pick LPC with a specific address
ec = CrosEcLpc(address=0xE00)
Sending a command (See cros_ec_python.commands for easier to use abstractions)
from cros_ec_python import general
# Assuming `ec` is already initialised
data = b'\xa0\xb0\xc0\xd0'
resp = ec.command(0, general.EC_CMD_HELLO, len(data), 4, data)
print(resp)
# Output should equal b'\xa4\xb3\xc2\xd1'
assert resp == b'\xa4\xb3\xc2\xd1'
Reading the memmap (See cros_ec_python.commands.memmap for easier to use abstractions)
from cros_ec_python.constants import MEMMAP
# Assuming `ec` is already initialised
resp = ec.memmap(MEMMAP.EC_MEMMAP_ID, 2)
print(resp)
# Output should equal b'EC'
assert resp == b'EC'
1r""" 2# Description 3 4The classes for each of the different interfaces supported by the library live in this submodule. 5 6If you don't understand what this does, just use `cros_ec_python.cros_ec.get_cros_ec()` to pick an interface. 7 8All device class implementations should inherit from `cros_ec_python.baseclass.CrosEcClass`, 9and implement the methods described in that class. This allows everything to use the standardised 10`cros_ec_python.baseclass.CrosEcClass.command` method to send commands to the EC, and 11`cros_ec_python.baseclass.CrosEcClass.memmap` to read memory from the EC. 12 13Devices can have optional specific arguments in their `__init__` method, but other methods should be the same. 14 15## Examples 16 17**Initialisation** 18 19```python 20# Pick one of the following: 21 22# Automatically pick the right class 23from cros_ec_python import get_cros_ec 24ec = get_cros_ec() 25 26# Manually pick LinuxDev 27from cros_ec_python import CrosEcDev 28ec = CrosEcDev() 29 30# Manually pick LPC 31from cros_ec_python import CrosEcLpc 32ec = CrosEcLpc() 33 34# Manually pick LPC with a specific address 35ec = CrosEcLpc(address=0xE00) 36``` 37 38**Sending a command** (See `cros_ec_python.commands` for easier to use abstractions) 39 40```python 41from cros_ec_python import general 42# Assuming `ec` is already initialised 43 44data = b'\xa0\xb0\xc0\xd0' 45 46resp = ec.command(0, general.EC_CMD_HELLO, len(data), 4, data) 47print(resp) 48 49# Output should equal b'\xa4\xb3\xc2\xd1' 50assert resp == b'\xa4\xb3\xc2\xd1' 51``` 52 53**Reading the memmap** (See `cros_ec_python.commands.memmap` for easier to use abstractions) 54 55```python 56from cros_ec_python.constants import MEMMAP 57# Assuming `ec` is already initialised 58 59resp = ec.memmap(MEMMAP.EC_MEMMAP_ID, 2) 60print(resp) 61 62# Output should equal b'EC' 63assert resp == b'EC' 64``` 65"""