Skip to content

Commit 41e2356

Browse files
committed
Minor documentation changes
1 parent 5fc39f3 commit 41e2356

File tree

8 files changed

+28
-13
lines changed

8 files changed

+28
-13
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# CrOS_EC_Python
22

3-
A Python library for interacting with a Chrome OS EC.
3+
A Python library for interacting with a Chrome OS EC. Commonly found in Chromebooks and Framework laptops.
44

5-
It provides a somewhat low-level interface to the CrOS EC, allowing you to send and receive any EC command,
5+
It provides a somewhat lower-level interface to the CrOS EC, allowing you to send and receive any EC command,
66
and read any byte from the memory map.
77
As well as a higher-level abstracted interface for easy access to some of the more common commands.
88

@@ -30,8 +30,8 @@ which is usually only accessible by root. You can either run your script as root
3030
or just manually change the permissions. Read permission is not needed, only write.
3131

3232
#### LPC Bus Interface
33-
This library requires access to IO ports with the `CAP_SYS_RAWIO` capability.
34-
It's easiest just to run python as root (use a venv though).
33+
This library requires access to IO ports using the `CAP_SYS_RAWIO` capability.
34+
It's easiest just to run your script as root.
3535

3636
## Documentation
3737

cros_ec_python/commands/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
# We can subtract this to get the input back
3333
print("Input Echoed:", resp - 0x01020304)
3434
```
35-
"""
35+
"""

cros_ec_python/constants/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
tempC = tempK - 273
2828
print(f"Temp Sensor {i}: {tempK}K ({tempC}°C)")
2929
```
30-
"""
30+
"""

cros_ec_python/devices/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@
6161
# Output should equal b'EC'
6262
assert resp == b'EC'
6363
```
64-
"""
64+
"""

cros_ec_python/devices/dev.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def ec_exit(self) -> None:
7272
"""
7373
Close the file on exit.
7474
"""
75-
if self.fd:
75+
if hasattr(self, "fd"):
7676
self.fd.close()
7777

7878
def command(

cros_ec_python/devices/lpc.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
try:
1111
import portio
12+
_import_portio_error = None
1213
except ImportError as e:
14+
_import_portio_error = e
1315
warnings.warn(f"Failed to import portio: {e}, using /dev/port instead.", ImportWarning)
1416
from ..utils import devportio as portio
1517

@@ -19,12 +21,17 @@ class CrosEcLpc(CrosEcClass):
1921
Class to interact with the EC using the LPC interface.
2022
"""
2123

22-
def __init__(self, init: bool = True, address: Int32 = None):
24+
def __init__(self, init: bool = True, address: Int32 = None, portio_warn: bool = True):
2325
"""
2426
Detect and initialise the EC.
2527
:param init: Whether to initialise the EC on creation. Default is True.
2628
:param address: Specify a custom memmap address, will be detected if not specified.
29+
:param portio_warn: Whether to warn if portio couldn't be imported. Default is True.
2730
"""
31+
if portio_warn and _import_portio_error is not None:
32+
warnings.warn(f"Failed to import portio: {_import_portio_error}, using /dev/port instead.",
33+
RuntimeWarning)
34+
2835
self.address = address
2936
if init:
3037
self.ec_init()

cros_ec_python/utils/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
This submodule contains some utility functions that are used by the library.
3+
"""

cros_ec_python/utils/devportio.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
# This file provides a way to interact with the /dev/port device file as an alternative to the portio library.
2-
# This is a lot slower than the portio library, but it doesn't require an extra package.
1+
"""
2+
This file provides a way to interact with the `/dev/port` device file
3+
as an alternative to the [portio](https://pypi.org/project/portio/) library.
4+
5+
This is *a lot* slower than the portio library (especially since `/dev/port` is opened on every function call),
6+
but it doesn't require an extra package.
7+
"""
38

49
def out_bytes(data: bytes, port: int) -> None:
510
"""
@@ -173,13 +178,13 @@ def insl(port: int, data: bytearray, count: int) -> None:
173178

174179
def ioperm(port: int, num: int, turn_on: bool) -> None:
175180
"""
176-
ioperm stub function. It's not required for /dev/port.
181+
`ioperm` stub function. It's not required for `/dev/port`.
177182
"""
178183
pass
179184

180185

181186
def iopl(level: int) -> None:
182187
"""
183-
iopl stub function. It's not required for /dev/port.
188+
`iopl` stub function. It's not required for `/dev/port`.
184189
"""
185190
pass

0 commit comments

Comments
 (0)