mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Raise warning when spidev missing for hardware SPI
This commit is contained in:
@@ -396,24 +396,30 @@ def SPI(**spi_args):
|
|||||||
raise SPIBadArgs(
|
raise SPIBadArgs(
|
||||||
'unrecognized keyword argument %s' % kwargs.popitem()[0])
|
'unrecognized keyword argument %s' % kwargs.popitem()[0])
|
||||||
if all((
|
if all((
|
||||||
SpiDev is not None,
|
|
||||||
spi_args['clock_pin'] == 11,
|
spi_args['clock_pin'] == 11,
|
||||||
spi_args['mosi_pin'] == 10,
|
spi_args['mosi_pin'] == 10,
|
||||||
spi_args['miso_pin'] == 9,
|
spi_args['miso_pin'] == 9,
|
||||||
spi_args['select_pin'] in (7, 8),
|
spi_args['select_pin'] in (7, 8),
|
||||||
)):
|
)):
|
||||||
try:
|
if SpiDev is None:
|
||||||
if shared:
|
|
||||||
return SharedSPIHardwareInterface(
|
|
||||||
port=0, device={8: 0, 7: 1}[spi_args['select_pin']])
|
|
||||||
else:
|
|
||||||
return SPIHardwareInterface(
|
|
||||||
port=0, device={8: 0, 7: 1}[spi_args['select_pin']])
|
|
||||||
except Exception as e:
|
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
SPISoftwareFallback(
|
SPISoftwareFallback(
|
||||||
'failed to initialize hardware SPI, falling back to '
|
'failed to import spidev, falling back to software SPI'))
|
||||||
'software (error was: %s)' % str(e)))
|
else:
|
||||||
|
try:
|
||||||
|
hardware_spi_args = {
|
||||||
|
port: 0,
|
||||||
|
device: {8: 0, 7: 1}[spi_args['select_pin']],
|
||||||
|
}
|
||||||
|
if shared:
|
||||||
|
return SharedSPIHardwareInterface(**hardware_spi_args)
|
||||||
|
else:
|
||||||
|
return SPIHardwareInterface(**hardware_spi_args)
|
||||||
|
except Exception as e:
|
||||||
|
warnings.warn(
|
||||||
|
SPISoftwareFallback(
|
||||||
|
'failed to initialize hardware SPI, falling back to '
|
||||||
|
'software (error was: %s)' % str(e)))
|
||||||
if shared:
|
if shared:
|
||||||
return SharedSPISoftwareInterface(**spi_args)
|
return SharedSPISoftwareInterface(**spi_args)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user