i2c-api 0.20.0__tar.gz → 0.20.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {i2c_api-0.20.0/src/i2c_api.egg-info → i2c_api-0.20.1}/PKG-INFO +7 -5
- {i2c_api-0.20.0 → i2c_api-0.20.1}/README.md +4 -4
- {i2c_api-0.20.0 → i2c_api-0.20.1}/pyproject.toml +6 -1
- i2c_api-0.20.1/src/i2c_api/__init__.py +21 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api/language.py +6 -2
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api/master.py +47 -7
- i2c_api-0.20.1/src/i2c_api/provider.py +24 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1/src/i2c_api.egg-info}/PKG-INFO +7 -5
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api.egg-info/SOURCES.txt +1 -0
- i2c_api-0.20.0/src/i2c_api/__init__.py +0 -5
- {i2c_api-0.20.0 → i2c_api-0.20.1}/LICENSE +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/setup.cfg +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api/commands.py +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api/exec_results.py +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api/log.py +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api/logger.py +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api.egg-info/dependency_links.txt +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api.egg-info/requires.txt +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/src/i2c_api.egg-info/top_level.txt +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/tests/test_language.py +0 -0
- {i2c_api-0.20.0 → i2c_api-0.20.1}/tests/test_master.py +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: i2c_api
|
|
3
|
-
Version: 0.20.
|
|
3
|
+
Version: 0.20.1
|
|
4
4
|
Summary: I2C API
|
|
5
|
+
Project-URL: Homepage, https://brainless-software.github.io/i2c_api
|
|
6
|
+
Project-URL: Repository, https://github.com/Brainless-Software/i2c_api
|
|
5
7
|
Requires-Python: >=3.13
|
|
6
8
|
Description-Content-Type: text/markdown
|
|
7
9
|
License-File: LICENSE
|
|
@@ -11,7 +13,7 @@ Dynamic: license-file
|
|
|
11
13
|
# I²C API
|
|
12
14
|
|
|
13
15
|
[](https://github.com/Brainless-Software/i2c_api/blob/master/LICENSE)
|
|
14
|
-
[](https://pypi.org/project/i2c-api/)
|
|
15
17
|
[](https://github.com/Brainless-Software/i2c_api/actions/workflows/test.yml)
|
|
16
18
|
[](https://brainless-software.github.io/i2c_api/)
|
|
17
19
|
|
|
@@ -26,11 +28,11 @@ implements this API for several common USB-to-I2C dongles.
|
|
|
26
28
|
To add this library to your project do
|
|
27
29
|
|
|
28
30
|
```shell
|
|
29
|
-
uv add
|
|
31
|
+
uv add i2c-api
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
or with `
|
|
34
|
+
or with `i2c-drivers`
|
|
33
35
|
|
|
34
36
|
```shell
|
|
35
|
-
uv add
|
|
37
|
+
uv add i2c-api i2c-drivers
|
|
36
38
|
```
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# I²C API
|
|
2
2
|
|
|
3
3
|
[](https://github.com/Brainless-Software/i2c_api/blob/master/LICENSE)
|
|
4
|
-
[](https://pypi.org/project/i2c-api/)
|
|
5
5
|
[](https://github.com/Brainless-Software/i2c_api/actions/workflows/test.yml)
|
|
6
6
|
[](https://brainless-software.github.io/i2c_api/)
|
|
7
7
|
|
|
@@ -16,11 +16,11 @@ implements this API for several common USB-to-I2C dongles.
|
|
|
16
16
|
To add this library to your project do
|
|
17
17
|
|
|
18
18
|
```shell
|
|
19
|
-
uv add
|
|
19
|
+
uv add i2c-api
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
or with `
|
|
22
|
+
or with `i2c-drivers`
|
|
23
23
|
|
|
24
24
|
```shell
|
|
25
|
-
uv add
|
|
25
|
+
uv add i2c-api i2c-drivers
|
|
26
26
|
```
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "i2c_api"
|
|
3
3
|
description = "I2C API"
|
|
4
|
-
|
|
4
|
+
dynamic = ["version"]
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.13"
|
|
7
7
|
dependencies = [
|
|
8
8
|
"bitstring >= 5.0.0, < 6.0.0",
|
|
9
9
|
]
|
|
10
10
|
|
|
11
|
+
[project.urls]
|
|
12
|
+
Homepage = "https://brainless-software.github.io/i2c_api"
|
|
13
|
+
Repository = "https://github.com/Brainless-Software/i2c_api"
|
|
14
|
+
|
|
11
15
|
[build-system]
|
|
12
16
|
requires = ["setuptools", "wheel", "setuptools-git-versioning"]
|
|
13
17
|
build-backend = "setuptools.build_meta"
|
|
@@ -37,6 +41,7 @@ dev = [
|
|
|
37
41
|
"ruff",
|
|
38
42
|
"mkdocs>=1.6.1",
|
|
39
43
|
"mkdocs-material>=9.7.7",
|
|
44
|
+
"mypy>=2.4.1",
|
|
40
45
|
]
|
|
41
46
|
|
|
42
47
|
[tool.pytest]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from .exec_results import ExecResults
|
|
2
|
+
from .language import I2CTransaction, I2CTransactionBuilder
|
|
3
|
+
from .log import I2CMessage
|
|
4
|
+
from .logger import I2CLogger
|
|
5
|
+
from .master import I2CMaster, RegisterAddress
|
|
6
|
+
from .provider import I2CMasterProvider, I2CMasterProviderDummy
|
|
7
|
+
|
|
8
|
+
I2CAPI_IMPL: list[I2CMasterProvider] = [I2CMasterProviderDummy]
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"ExecResults",
|
|
12
|
+
"I2CTransaction",
|
|
13
|
+
"I2CTransactionBuilder",
|
|
14
|
+
"I2CMessage",
|
|
15
|
+
"I2CLogger",
|
|
16
|
+
"I2CMaster",
|
|
17
|
+
"RegisterAddress",
|
|
18
|
+
"I2CMasterProvider",
|
|
19
|
+
"I2CAPI_IMPL",
|
|
20
|
+
"I2CMasterProviderDummy"
|
|
21
|
+
]
|
|
@@ -18,7 +18,9 @@ class I2CTransaction:
|
|
|
18
18
|
def __repr__(self) -> str:
|
|
19
19
|
return ".".join(str(c) for c in self._i2c._i2c_commands)
|
|
20
20
|
|
|
21
|
-
def exec(self, master: I2CMaster, device_address: int = -1) -> ExecResults:
|
|
21
|
+
def exec(self, master: I2CMaster | None = None, device_address: int = -1) -> ExecResults:
|
|
22
|
+
master = self._i2c._i2c_master if master is None else master
|
|
23
|
+
device_address = self._i2c._default_device_address if device_address == -1 else device_address
|
|
22
24
|
if master is None:
|
|
23
25
|
raise ValueError("I2CMaster must be provided to execute this transaction")
|
|
24
26
|
|
|
@@ -124,8 +126,10 @@ class I2CAddress:
|
|
|
124
126
|
|
|
125
127
|
|
|
126
128
|
class I2CTransactionBuilder:
|
|
127
|
-
def __init__(self):
|
|
129
|
+
def __init__(self, i2c_master: I2CMaster | None = None, default_device_address: int = -1):
|
|
128
130
|
self._i2c_commands: list[Command] = []
|
|
131
|
+
self._i2c_master = i2c_master
|
|
132
|
+
self._default_device_address = default_device_address
|
|
129
133
|
|
|
130
134
|
def start(self) -> I2CAddress:
|
|
131
135
|
new_root = I2CTransactionBuilder()
|
|
@@ -27,8 +27,12 @@ class RegisterAddress:
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
class I2CMaster(ABC):
|
|
30
|
-
def __init__(self, logger: I2CLogger | None = None):
|
|
30
|
+
def __init__(self, port: str | None, logger: I2CLogger | None = None):
|
|
31
31
|
self.__logger: I2CLogger = DummyI2CLogger() if logger is None else logger
|
|
32
|
+
self.port = port
|
|
33
|
+
|
|
34
|
+
def __repr__(self) -> str:
|
|
35
|
+
return f"{self.__class__.__name__}" if self.port is None else f"{self.__class__.__name__} :: {self.port}"
|
|
32
36
|
|
|
33
37
|
@staticmethod
|
|
34
38
|
def __pad_up_to_bytes(data: BitArray, num_bytes: int | None) -> BitArray:
|
|
@@ -77,8 +81,8 @@ class I2CMaster(ABC):
|
|
|
77
81
|
issue Stop condition and will release the clock line.
|
|
78
82
|
|
|
79
83
|
:param address: i2c address of the target device
|
|
80
|
-
:param data: array of bits to send to the target device; if int or list[int], then these are assumed to be
|
|
81
|
-
If it is a string, then BitArray is constructed from that string and that is used as a payload.
|
|
84
|
+
:param data: array of bits to send to the target device; if int or list[int], then these are assumed to be
|
|
85
|
+
bytes. If it is a string, then BitArray is constructed from that string and that is used as a payload.
|
|
82
86
|
:param num_bytes: number of bytes to send or if None, then send all bits in `data` padded with zero bits to fit
|
|
83
87
|
payload into fixed number of bytes. Raises ValueError if num_bytes is not None and is less than data width.
|
|
84
88
|
:return: True or False indicating if write succeeded, which is that client responded with ACK bits.
|
|
@@ -127,10 +131,10 @@ class I2CMaster(ABC):
|
|
|
127
131
|
def exec(self, transaction: I2CTransaction, device_address: int = -1) -> ExecResults:
|
|
128
132
|
"""
|
|
129
133
|
Executes I2C commands in a single transaction and returns a named tuple `ExecResults` where first value is list
|
|
130
|
-
of lists of read bytes if any and second value is True or False indicating if transaction completed
|
|
131
|
-
Unsuccessful completion usual means that slave device responded with NACK at some point during
|
|
132
|
-
between master and the slave. Each sub-list within the list corresponds contiguous sequence of
|
|
133
|
-
from the slave.
|
|
134
|
+
of lists of read bytes if any and second value is True or False indicating if transaction completed
|
|
135
|
+
successfully. Unsuccessful completion usual means that slave device responded with NACK at some point during
|
|
136
|
+
communication between master and the slave. Each sub-list within the list corresponds contiguous sequence of
|
|
137
|
+
read bytes coming from the slave.
|
|
134
138
|
"""
|
|
135
139
|
if not isinstance(transaction, I2CTransaction):
|
|
136
140
|
raise ValueError("transaction argument must be instance of I2CTransaction")
|
|
@@ -145,6 +149,10 @@ class I2CMaster(ABC):
|
|
|
145
149
|
)
|
|
146
150
|
return self._exec(transaction, device_address)
|
|
147
151
|
|
|
152
|
+
@abstractmethod
|
|
153
|
+
def display_name(self) -> str:
|
|
154
|
+
pass
|
|
155
|
+
|
|
148
156
|
@abstractmethod
|
|
149
157
|
def _exec(self, transaction: I2CTransaction, device_address: int = -1) -> ExecResults:
|
|
150
158
|
pass
|
|
@@ -312,3 +320,35 @@ class I2CMaster(ABC):
|
|
|
312
320
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
313
321
|
self.close()
|
|
314
322
|
return False
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
class DummyI2CMaster(I2CMaster):
|
|
326
|
+
def display_name(self) -> str:
|
|
327
|
+
return "Demo :: DummyI2CDongle"
|
|
328
|
+
|
|
329
|
+
def _exec(self, transaction: I2CTransaction, device_address: int = -1) -> ExecResults:
|
|
330
|
+
pass
|
|
331
|
+
|
|
332
|
+
def scan(self) -> list[int]:
|
|
333
|
+
return []
|
|
334
|
+
|
|
335
|
+
def list_pullups(self) -> list[str]:
|
|
336
|
+
return ["disabled"]
|
|
337
|
+
|
|
338
|
+
def set_pullup(self, pullup_value: str) -> None:
|
|
339
|
+
pass
|
|
340
|
+
|
|
341
|
+
def get_pullup(self) -> str:
|
|
342
|
+
return "disabled"
|
|
343
|
+
|
|
344
|
+
def list_clk_speeds(self) -> list[int]:
|
|
345
|
+
return [100]
|
|
346
|
+
|
|
347
|
+
def get_clk_speed(self) -> int:
|
|
348
|
+
return 100
|
|
349
|
+
|
|
350
|
+
def set_clk_speed(self, speed: int) -> None:
|
|
351
|
+
pass
|
|
352
|
+
|
|
353
|
+
def close(self):
|
|
354
|
+
pass
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Callable, Optional
|
|
3
|
+
|
|
4
|
+
from i2c_api.master import DummyI2CMaster, I2CLogger, I2CMaster
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True)
|
|
8
|
+
class I2CMasterProvider:
|
|
9
|
+
make: str
|
|
10
|
+
model: str
|
|
11
|
+
new_i2c_master: Callable[[str, I2CLogger], I2CMaster]
|
|
12
|
+
ports_required: bool
|
|
13
|
+
list_ports: Callable[[], Optional[list[str]]] = lambda: None
|
|
14
|
+
|
|
15
|
+
def make_and_model(self):
|
|
16
|
+
return self.make + " :: " + self.model
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
I2CMasterProviderDummy = I2CMasterProvider(
|
|
20
|
+
make="Demo",
|
|
21
|
+
model="DummyI2CDongle",
|
|
22
|
+
new_i2c_master=lambda port, logger: DummyI2CMaster(port, logger),
|
|
23
|
+
ports_required=False,
|
|
24
|
+
)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: i2c_api
|
|
3
|
-
Version: 0.20.
|
|
3
|
+
Version: 0.20.1
|
|
4
4
|
Summary: I2C API
|
|
5
|
+
Project-URL: Homepage, https://brainless-software.github.io/i2c_api
|
|
6
|
+
Project-URL: Repository, https://github.com/Brainless-Software/i2c_api
|
|
5
7
|
Requires-Python: >=3.13
|
|
6
8
|
Description-Content-Type: text/markdown
|
|
7
9
|
License-File: LICENSE
|
|
@@ -11,7 +13,7 @@ Dynamic: license-file
|
|
|
11
13
|
# I²C API
|
|
12
14
|
|
|
13
15
|
[](https://github.com/Brainless-Software/i2c_api/blob/master/LICENSE)
|
|
14
|
-
[](https://pypi.org/project/i2c-api/)
|
|
15
17
|
[](https://github.com/Brainless-Software/i2c_api/actions/workflows/test.yml)
|
|
16
18
|
[](https://brainless-software.github.io/i2c_api/)
|
|
17
19
|
|
|
@@ -26,11 +28,11 @@ implements this API for several common USB-to-I2C dongles.
|
|
|
26
28
|
To add this library to your project do
|
|
27
29
|
|
|
28
30
|
```shell
|
|
29
|
-
uv add
|
|
31
|
+
uv add i2c-api
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
or with `
|
|
34
|
+
or with `i2c-drivers`
|
|
33
35
|
|
|
34
36
|
```shell
|
|
35
|
-
uv add
|
|
37
|
+
uv add i2c-api i2c-drivers
|
|
36
38
|
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|