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/Adafruit-PlatformDetect/json
md5 7e7b10a48f6e6a7c650bb6bd432ec613 Adafruit-PlatformDetect-3.32.0.tar.gz
sha256 31bad17fb91c3cd61bd62fb9712902bcef5225bbeb3c078a196c6d7e2d4599a4 Adafruit-PlatformDetect-3.32.0.tar.gz
md5 4e80a7d7200a67d4528d580b16d3ca98 Adafruit-PlatformDetect-3.60.0.tar.gz
sha256 644deb113c00ba1bfba4703fcd80cab52b5638d4a1146f2d58378df4af09746f Adafruit-PlatformDetect-3.60.0.tar.gz
# Locally computed sha256 checksums
sha256 50e0c3b5b4486be0ed420639f8a1f6f115f29101feee6bcd954a4b81db04d0f3 LICENSE

View File

@ -4,9 +4,9 @@
#
################################################################################
PYTHON_ADAFRUIT_PLATFORMDETECT_VERSION = 3.32.0
PYTHON_ADAFRUIT_PLATFORMDETECT_VERSION = 3.60.0
PYTHON_ADAFRUIT_PLATFORMDETECT_SOURCE = Adafruit-PlatformDetect-$(PYTHON_ADAFRUIT_PLATFORMDETECT_VERSION).tar.gz
PYTHON_ADAFRUIT_PLATFORMDETECT_SITE = https://files.pythonhosted.org/packages/15/42/2192f64a9732878ddb39bb4359864d1398849e90f39f5591a23005e65d8e
PYTHON_ADAFRUIT_PLATFORMDETECT_SITE = https://files.pythonhosted.org/packages/e5/e3/71ba7ff4cbcecf40783613c192bd0ec6c69a70053915567a998ce41050bc
PYTHON_ADAFRUIT_PLATFORMDETECT_SETUP_TYPE = setuptools
PYTHON_ADAFRUIT_PLATFORMDETECT_LICENSE = MIT
PYTHON_ADAFRUIT_PLATFORMDETECT_LICENSE_FILES = LICENSE