@@ -396,24 +396,30 @@ def SPI(**spi_args):
396396 raise SPIBadArgs (
397397 'unrecognized keyword argument %s' % kwargs .popitem ()[0 ])
398398 if all ((
399- SpiDev is not None ,
400399 spi_args ['clock_pin' ] == 11 ,
401400 spi_args ['mosi_pin' ] == 10 ,
402401 spi_args ['miso_pin' ] == 9 ,
403402 spi_args ['select_pin' ] in (7 , 8 ),
404403 )):
405- try :
406- if shared :
407- return SharedSPIHardwareInterface (
408- port = 0 , device = {8 : 0 , 7 : 1 }[spi_args ['select_pin' ]])
409- else :
410- return SPIHardwareInterface (
411- port = 0 , device = {8 : 0 , 7 : 1 }[spi_args ['select_pin' ]])
412- except Exception as e :
404+ if SpiDev is None :
413405 warnings .warn (
414406 SPISoftwareFallback (
415- 'failed to initialize hardware SPI, falling back to '
416- 'software (error was: %s)' % str (e )))
407+ 'failed to import spidev, falling back to software SPI' ))
408+ else :
409+ try :
410+ hardware_spi_args = {
411+ port : 0 ,
412+ device : {8 : 0 , 7 : 1 }[spi_args ['select_pin' ]],
413+ }
414+ if shared :
415+ return SharedSPIHardwareInterface (** hardware_spi_args )
416+ else :
417+ return SPIHardwareInterface (** hardware_spi_args )
418+ except Exception as e :
419+ warnings .warn (
420+ SPISoftwareFallback (
421+ 'failed to initialize hardware SPI, falling back to '
422+ 'software (error was: %s)' % str (e )))
417423 if shared :
418424 return SharedSPISoftwareInterface (** spi_args )
419425 else :
0 commit comments