protect against edge case

This commit is contained in:
Hierophect 2019-09-30 13:33:20 -04:00
parent 56eb9666ea
commit 1f90cffc89
1 changed files with 4 additions and 2 deletions

View File

@ -97,10 +97,12 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
if (mcu_spi_mosi_list[j].pin == mosi) {
//miso
for(uint k=0; k<miso_len;k++) {
if ((mcu_spi_miso_list[k].pin == miso)
if ((mcu_spi_miso_list[k].pin == miso) //everything needs the same index
&& (mcu_spi_sck_list[i].spi_index == mcu_spi_mosi_list[j].spi_index)
&& (mcu_spi_sck_list[i].spi_index == mcu_spi_miso_list[k].spi_index)) {
//everything needs the same index
//keep looking if the SPI is taken, edge case
if(reserved_spi[mcu_spi_sck_list[i].spi_index-1]) continue;
//store pins if not
self->sck = &mcu_spi_sck_list[j];
self->mosi = &mcu_spi_mosi_list[j];
self->miso = &mcu_spi_miso_list[k];