Created
January 8, 2020 16:19
-
-
Save hierophect/8d304e7d44c9816e294874529937019d to your computer and use it in GitHub Desktop.
Less nesting pin search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SCK is not optional. MOSI and MISO are | |
for (uint i=0; i<sck_len;i++) { | |
if (mcu_spi_sck_list[i].pin == sck) { | |
uint j = 0; | |
if (miso != mp_const_none) { | |
for (j=0; j<miso_len;j++) { | |
RETRY: | |
if ((mcu_spi_miso_list[j].pin == miso) //only SCK and MISO need the same index | |
&& (mcu_spi_sck_list[i].spi_index == mcu_spi_miso_list[j].spi_index)) { | |
//store pins if not | |
if (mosi == mp_const_none) { | |
self->sck = &mcu_spi_sck_list[i]; | |
self->mosi = NULL; | |
self->miso = &mcu_spi_miso_list[j]; | |
} | |
break; | |
} | |
} | |
if (mosi != mp_const_none) { | |
for (uint k=0; k<mosi_len;k++) { | |
if ((mcu_spi_mosi_list[k].pin == mosi) //only SCK and MOSI need the same index | |
&& (mcu_spi_sck_list[i].spi_index == mcu_spi_mosi_list[k].spi_index)) { | |
if (miso == mp_const_none) { | |
//keep looking if the SPI is taken, edge case | |
if (reserved_spi[mcu_spi_sck_list[i].spi_index-1]) { | |
spi_taken = true; | |
continue; | |
} | |
//store pins if not | |
self->sck = &mcu_spi_sck_list[i]; | |
self->mosi = &mcu_spi_mosi_list[j]; | |
self->miso = NULL; | |
} else if (mcu_spi_sck_list[i].spi_index == mcu_spi_miso_list[j].spi_index) { | |
//keep looking if the SPI is taken, edge case | |
if (reserved_spi[mcu_spi_sck_list[i].spi_index-1]) { | |
spi_taken = true; | |
continue; | |
} | |
//store pins if not | |
self->sck = &mcu_spi_sck_list[i]; | |
self->mosi = &mcu_spi_mosi_list[j]; | |
self->miso = &mcu_spi_mosi_list[k]; | |
} | |
break; | |
} | |
} | |
} | |
if (self->mosi == NULL && mosi != mp_const_none && j<miso_len) { | |
goto: RETRY; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment