diff options
author | Quentin Schulz <quentin.schulz@theobroma-systems.com> | 2023-11-29 10:38:14 +0100 |
---|---|---|
committer | Quentin Schulz <quentin.schulz@theobroma-systems.com> | 2023-11-30 14:09:23 +0100 |
commit | 53ca6e89559859d90baab7e8590b37150ff0fab6 (patch) | |
tree | 063a7f3a5bc98756ebb7e7d8ffd095d867255cbf | |
parent | 792716a87fa3bd7ea4c0b07e920ef8c223cc150c (diff) |
mule-attiny: i2c_flash: migrate to C-bindings-based official gpiod Python package
The unofficial pure-Python gpiod package was replaced by
C-bindings-based official gpiod Python package on Pypi and the former is
deprecated.
c.f. https://pypi.org/project/gpiod/
"""
Versions 1.5.4 and prior are the deprecated, unofficial, pure-Python
bindings.
"""
While this isn't necessarily something we should worry about in the
short term, it turns out that distros actually do not package the
pure-Python, so this makes it less easy to install the dependencies for
i2c_flash.py. We could support v1.6.3 gpiod to be able to install it
from Debian package feed, however v1.6.x is in maintenance-only state
and v2.x is actively being developed with additional features, so let's
just play it safe and migrate to v2.x version.
We bump the requirements to the latest available version so that it uses
the C-bindings-based official implementation hosted on Pypi.
See https://github.com/hhk7734/python3-gpiod/issues/39 for the
discussions and history behind gpiod on Pypi.
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
-rw-r--r-- | mule-attiny/i2c-flash/README.md | 2 | ||||
-rw-r--r-- | mule-attiny/i2c-flash/pyproject.toml | 2 | ||||
-rw-r--r-- | mule-attiny/i2c-flash/requirements.txt | 2 | ||||
-rwxr-xr-x | mule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py | 26 |
4 files changed, 17 insertions, 15 deletions
diff --git a/mule-attiny/i2c-flash/README.md b/mule-attiny/i2c-flash/README.md index 7a0fe7c..b4b5591 100644 --- a/mule-attiny/i2c-flash/README.md +++ b/mule-attiny/i2c-flash/README.md @@ -8,7 +8,7 @@ it is possible to flash the application firmware (`APP_SECTION`) via I2C. # Dependencies This depends on: -- `gpiod` Python package, +- `gpiod` Python package (the C-bindings-based one (https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git), NOT pure-Python one), - `smbus2` Python package, - `nice` binary (available in `coreutils` package), - `updi_reset` binary (sources available at diff --git a/mule-attiny/i2c-flash/pyproject.toml b/mule-attiny/i2c-flash/pyproject.toml index 28260b5..9f9d382 100644 --- a/mule-attiny/i2c-flash/pyproject.toml +++ b/mule-attiny/i2c-flash/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ "Topic :: Utilities", ] dependencies = [ - "gpiod==1.5.4", + "gpiod==2.1.3", "smbus2==0.4.2", ] diff --git a/mule-attiny/i2c-flash/requirements.txt b/mule-attiny/i2c-flash/requirements.txt index 553b331..c56ae26 100644 --- a/mule-attiny/i2c-flash/requirements.txt +++ b/mule-attiny/i2c-flash/requirements.txt @@ -1,2 +1,2 @@ -gpiod==1.5.4 +gpiod==2.1.3 smbus2==0.4.2 diff --git a/mule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py b/mule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py index c362384..3954b98 100755 --- a/mule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py +++ b/mule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py @@ -37,20 +37,22 @@ def load_bin(firmware_path): class BootModeController: def __init__(self, bootReqGpioChip, bootReqGpio, updiResetGpioChip, updiResetGpio): - chip = gpiod.chip(bootReqGpioChip) - self.__bootReq = chip.get_line(bootReqGpio) + self.__chip = gpiod.Chip(f"/dev/gpiochip{bootReqGpioChip}") + self.__bootReqGpio = bootReqGpio self.__updiResetGpioChip = updiResetGpioChip self.__updiResetGpio = updiResetGpio self.__flashMode = False + self.__bootReq = None def enterFlashloader(self): - config = gpiod.line_request() - config.consumer = "bootPin" - config.request_type = gpiod.line_request.DIRECTION_OUTPUT - - self.__bootReq.request(config) - self.__bootReq.set_value(1) + self.__bootReq = self.__chip.request_lines( + consumer="bootPin", + config={ + self.__bootReqGpio: gpiod.LineSettings(direction=gpiod.line.Direction.OUTPUT, + output_value=gpiod.line.Value.ACTIVE) + } + ) self.__updi_reset() # Wait until ATtiny starts-up. Startup time (Power-ON <--dt--> Code-Exec) is fused to 64 ms (fuse 0x6). @@ -62,15 +64,15 @@ class BootModeController: # Flashloader sub-mode (read-only: read bootloader data) def enterRoMode(self): if self.__flashMode: - self.__bootReq.set_value(0) + self.__bootReq.set_value(self.__bootReqGpio, gpiod.line.Value.INACTIVE) def exitRoMode(self): if self.__flashMode: - self.__bootReq.set_value(1) + self.__bootReq.set_value(self.__bootReqGpio, gpiod.line.Value.ACTIVE) def exitFlashloader(self): - if self.__bootReq.is_requested(): - self.__bootReq.set_value(0) + if self.__bootReq: + self.__bootReq.set_value(self.__bootReqGpio, gpiod.line.Value.INACTIVE) self.__bootReq.release() if (self.__flashMode): # Don't leave ATtiny in flashloader mode when error occurs |