Skip to content

Commit

Permalink
Protect against initializing SPI more than once
Browse files Browse the repository at this point in the history
If radio.begin() is called multiple times, it causes an error. Protect
against initializing SPI more than once when radio.begin() is called.
  • Loading branch information
TMRh20 committed May 16, 2019
1 parent b19c3d8 commit 304d2bb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion utility/SPIDEV/spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
SPI::SPI():fd(-1), _spi_speed(RF24_SPIDEV_SPEED) {
}

bool spiIsInitialized = 0;

void SPI::begin(int busNo,uint32_t spi_speed){

if(spiIsInitialized){
return;
}
/* set spidev accordingly to busNo like:
* busNo = 23 -> /dev/spidev2.3
*
Expand All @@ -50,7 +55,7 @@ void SPI::begin(int busNo,uint32_t spi_speed){
abort();
}*/

spiIsInitialized = true;
init(spi_speed);
}

Expand Down

0 comments on commit 304d2bb

Please sign in to comment.