summaryrefslogtreecommitdiff
path: root/src/drivers/SpiMaster.cpp
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2021-06-12 10:58:28 +0200
committerJean-François Milants <jf@codingfield.com>2021-06-12 10:58:28 +0200
commit6d524ebea2c97e309633d5e01c3a1e37c182f27d (patch)
tree3f9c7f96f0fab64f581035c72480596a4cc4db43 /src/drivers/SpiMaster.cpp
parentb1925ff28638dd4b8400c4d0c49d796d8990b1af (diff)
Move most of the code from the constructor of the objects statically initialized in main() into Start()/Init() functions to avoid Static Initialization Order Fiasco (https://en.cppreference.com/w/cpp/language/siof). See https://github.com/JF002/InfiniTime/pull/415#issuecomment-859004238.
Diffstat (limited to 'src/drivers/SpiMaster.cpp')
-rw-r--r--src/drivers/SpiMaster.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/drivers/SpiMaster.cpp b/src/drivers/SpiMaster.cpp
index e2be5027..0d5bb83c 100644
--- a/src/drivers/SpiMaster.cpp
+++ b/src/drivers/SpiMaster.cpp
@@ -7,11 +7,14 @@
using namespace Pinetime::Drivers;
SpiMaster::SpiMaster(const SpiMaster::SpiModule spi, const SpiMaster::Parameters& params) : spi {spi}, params {params} {
- mutex = xSemaphoreCreateBinary();
- ASSERT(mutex != NULL);
}
bool SpiMaster::Init() {
+ if(mutex == nullptr) {
+ mutex = xSemaphoreCreateBinary();
+ ASSERT(mutex != nullptr);
+ }
+
/* Configure GPIO pins used for pselsck, pselmosi, pselmiso and pselss for SPI0 */
nrf_gpio_pin_set(params.pinSCK);
nrf_gpio_cfg_output(params.pinSCK);