@@ -695,6 +695,7 @@ static PyObject *
695695SPI_open (SPI * self , PyObject * args , PyObject * kwds )
696696{
697697 int bus , device ;
698+ int bus_path ;
698699 int max_dt_length = 15 ;
699700 char device_tree_name [max_dt_length ];
700701 char path [MAXPATH ];
@@ -703,7 +704,7 @@ SPI_open(SPI *self, PyObject *args, PyObject *kwds)
703704 static char * kwlist [] = {"bus" , "device" , NULL };
704705 if (!PyArg_ParseTupleAndKeywords (args , kwds , "ii:open" , kwlist , & bus , & device ))
705706 return NULL ;
706- if (snprintf (device_tree_name , max_dt_length , "ADAFRUIT-SPI %d" , bus ) >= max_dt_length ) {
707+ if (snprintf (device_tree_name , max_dt_length , "BB-SPIDEV %d" , bus ) >= max_dt_length ) {
707708 PyErr_SetString (PyExc_OverflowError ,
708709 "Bus and/or device number is invalid." );
709710 return NULL ;
@@ -713,7 +714,14 @@ SPI_open(SPI *self, PyObject *args, PyObject *kwds)
713714 return NULL ;
714715 }
715716
716- if (snprintf (path , MAXPATH , "/dev/spidev%d.%d" , bus + 1 , device ) >= MAXPATH ) {
717+ bus_path = get_spi_bus_path_number (bus );
718+ if (bus_path == -1 ) {
719+ PyErr_SetString (PyExc_OverflowError ,
720+ "Unable to find loaded spi bus path." );
721+ return NULL ;
722+ }
723+
724+ if (snprintf (path , MAXPATH , "/dev/spidev%d.%d" , bus_path , device ) >= MAXPATH ) {
717725 PyErr_SetString (PyExc_OverflowError ,
718726 "Bus and/or device number is invalid." );
719727 return NULL ;
0 commit comments