1
1
mirror of https://github.com/OpenVoiceOS/OpenVoiceOS synced 2025-06-05 22:19:21 +02:00

[RPI] Refactor SPI and GPIO handling for XVF3510 initialization

This commit significantly overhauls the script for setting the XVF3510 board to boot from SPI slave mode and for loading a binary file. The refactor not only aims at improving code readability, maintainability, and robustness but also addresses compatibility issues with the latest Raspberry Pi models, specifically the Raspberry Pi 5, which does not support the RPi.GPIO library.

Changes made:
- Switched from `smbus` to `smbus2` for I2C communication, offering a more modern and robust interface.
- Replaced `RPi.GPIO` and `spidev` with `digitalio` and `busio` from the `adafruit_blinka` library, enhancing cross-platform compatibility and providing a more Pythonic API for GPIO and SPI operations.
- Introduced type annotations for function signatures, improving code readability and type safety.
- Added exception handling around I2C operations and file reading, increasing the script's robustness by gracefully handling potential errors.
- Defined global variables for GPIO pin configurations, making the code cleaner and easier to modify for different setups.
- Encapsulated GPIO setup and reset logic into dedicated functions (`setup_direct_gpio`), streamlining the main logic flow and separating concerns.
- Modularized SPI setup (`setup_spi`) and data transmission logic (`send_data_over_spi` and `handle_block_transfer`), enhancing code organization and maintainability.

Benefits:
- The use of `smbus2` and `adafruit_blinka` libraries modernizes the script and may improve compatibility with a wider range of devices and future Python versions.
- Type annotations and structured exception handling make the script more understandable and safer to execute, reducing the risk of runtime errors.
- The refactoring into more granular functions and the introduction of global variables for configuration parameters make the script easier to read, modify, and extend.
- Improved error handling ensures that the script fails gracefully, providing clear error messages and avoiding potential resource leaks.
This commit is contained in:
Bohdan Buinich
2024-02-04 01:24:43 +02:00
parent 379e94dad3
commit c0442cc0e6
21 changed files with 290 additions and 185 deletions

View File

@@ -1,5 +1,5 @@
# md5, sha256 from https://pypi.org/pypi/pyftdi/json
md5 d8969beb9cd11c123f1249963bf8c0d8 pyftdi-0.54.0.tar.gz
sha256 8df9af22077d17533d2f95b508b1d87959877627ea5dc2369056e90a3b5a232d pyftdi-0.54.0.tar.gz
md5 fa9feda5b80db51d538ed9b98e25504e pyftdi-0.55.0.tar.gz
sha256 a747bbbccc4eeea26cefa2c8bd3d2b8bef8c94ecb6969bb9c75a63640887519a pyftdi-0.55.0.tar.gz
# Locally computed sha256 checksums
sha256 7342c9ccf3ec21eee9a23c6c74af15fb08ac1b79ddbccb4e063ddeaa6ef7c52d pyftdi/doc/license.rst

View File

@@ -4,9 +4,9 @@
#
################################################################################
PYTHON_PYFTDI_VERSION = 0.54.0
PYTHON_PYFTDI_VERSION = 0.55.0
PYTHON_PYFTDI_SOURCE = pyftdi-$(PYTHON_PYFTDI_VERSION).tar.gz
PYTHON_PYFTDI_SITE = https://files.pythonhosted.org/packages/49/a3/6cd09c0493662b285b2ba87a08b1378a5b13e5cab44eb6a3f740c801c804
PYTHON_PYFTDI_SITE = https://files.pythonhosted.org/packages/da/db/b900789a154e32dba50f132a2a76837331801f8b521b7e1bcbb852b01a35
PYTHON_PYFTDI_SETUP_TYPE = setuptools
PYTHON_PYFTDI_LICENSE = FIXME: please specify the exact BSD version
PYTHON_PYFTDI_LICENSE_FILES = pyftdi/doc/license.rst