cros_ec_python.ioports

Description

This submodule contains the classes for the different IO port interfaces supported by the library.

If you don't understand what this does, just use cros_ec_python.ioports.PortIO() to import the correct class.

All IO port classes should inherit from cros_ec_python.ioports.baseportio.PortIOClass, and implement the methods described in that class. This allows everything to use the standardised methods to interact with the IO ports in a platform-independent way.

Examples

Initialisation

# Automatically pick the right class (Recommended)
from cros_ec_python.ioports import PortIO
portio = PortIO()

# Manually pick portio library (Linux, preferred)
from cros_ec_python.ioports.x86portio import IoPortIo
portio = IoPortIo()

# Manually pick `/dev/port` (Linux, fallback)
from cros_ec_python.ioports.devportio import DevPortIO
portio = DevPortIO()

# Manually pick WinRing0 (Windows)
from cros_ec_python.ioports.winportio import WinPortIO
portio = WinPortIO()

# Manually pick `/dev/io` (FreeBSD)
from cros_ec_python.ioports.freebsdportio import FreeBsdPortIO
portio = FreeBsdPortIO()

Reading from a port

# Assuming `portio` is already initialised
data = portio.inb(0x80)
print(data)

Writing to a port

# Assuming `portio` is already initialised
portio.outb(0x55, 0x80)

See cros_ec_python.ioports.baseportio.PortIOClass for the full list of common methods.

Some classes may have additional methods, such as cros_ec_python.ioports.x86portio.IoPortIo.

 1"""
 2# Description
 3
 4This submodule contains the classes for the different IO port interfaces supported by the library.
 5
 6If you don't understand what this does, just use `cros_ec_python.ioports.PortIO()` to import the correct class.
 7
 8All IO port classes should inherit from `cros_ec_python.ioports.baseportio.PortIOClass`,
 9and implement the methods described in that class. This allows everything to use the standardised
10methods to interact with the IO ports in a platform-independent way.
11
12## Examples
13
14**Initialisation**
15
16```python
17# Automatically pick the right class (Recommended)
18from cros_ec_python.ioports import PortIO
19portio = PortIO()
20
21# Manually pick portio library (Linux, preferred)
22from cros_ec_python.ioports.x86portio import IoPortIo
23portio = IoPortIo()
24
25# Manually pick `/dev/port` (Linux, fallback)
26from cros_ec_python.ioports.devportio import DevPortIO
27portio = DevPortIO()
28
29# Manually pick WinRing0 (Windows)
30from cros_ec_python.ioports.winportio import WinPortIO
31portio = WinPortIO()
32
33# Manually pick `/dev/io` (FreeBSD)
34from cros_ec_python.ioports.freebsdportio import FreeBsdPortIO
35portio = FreeBsdPortIO()
36```
37
38**Reading from a port**
39
40```python
41# Assuming `portio` is already initialised
42data = portio.inb(0x80)
43print(data)
44```
45
46**Writing to a port**
47
48```python
49# Assuming `portio` is already initialised
50portio.outb(0x55, 0x80)
51```
52
53See `cros_ec_python.ioports.baseportio.PortIOClass` for the full list of common methods.
54
55Some classes may have additional methods, such as `cros_ec_python.ioports.x86portio.IoPortIo`.
56"""
57
58import sys
59
60if sys.platform == "linux":
61    try:
62        from .x86portio import IoPortIo as PortIO
63    except ImportError:
64        from .devportio import DevPortIO as PortIO
65elif sys.platform == "win32":
66    from .winportio import WinPortIO as PortIO
67elif sys.platform.startswith("freebsd"):
68    from .freebsdportio import FreeBsdPortIO as PortIO
69else:
70    raise Exception("Unsupported OS")
71
72# This is for pdoc
73from .baseportio import PortIOClass
74
75PortIO: PortIOClass
76"Automatically picked IO port class."

Automatically picked IO port class.