Skip to content

Commit

Permalink
SPI mutex lock
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Jun 29, 2024
1 parent 2ece915 commit b82e554
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ void arduino::MbedSPI::beginTransaction(SPISettings settings) {
dev->obj->frequency(settings.getClockFreq());
this->settings = settings;
}
spiLockMutex.lock();
}

void arduino::MbedSPI::endTransaction(void) {
spiLockMutex.unlock();
// spinlock until transmission is over (if using ASYNC transfer)
}

Expand Down
2 changes: 2 additions & 0 deletions libraries/SPI/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "Arduino.h"
#include "api/HardwareSPI.h"
#include <Mutex.h>

typedef struct _mbed_spi mbed_spi;

Expand Down Expand Up @@ -50,6 +51,7 @@ class MbedSPI : public SPIClass
private:
SPISettings settings = SPISettings(0, MSBFIRST, SPI_MODE0);
_mbed_spi* dev = NULL;
rtos::Mutex spiLockMutex;
PinName _miso;
PinName _mosi;
PinName _sck;
Expand Down

0 comments on commit b82e554

Please sign in to comment.