test
Fork of mbed-dev by
Diff: targets/TARGET_NORDIC/TARGET_NRF5/spi_api.c
- Revision:
- 164:41567bf02252
- Parent:
- 150:02e0a0aed4ec
--- a/targets/TARGET_NORDIC/TARGET_NRF5/spi_api.c Tue Feb 28 17:13:35 2017 +0000 +++ b/targets/TARGET_NORDIC/TARGET_NRF5/spi_api.c Fri Nov 10 01:00:38 2017 +0000 @@ -254,6 +254,28 @@ PinName mosi, PinName miso, PinName sclk, PinName ssel) { int i; + + + // This block is only a workaround that allows to create SPI object several + // times, what would be otherwise impossible in the current implementation + // of mbed driver that does not call spi_free() from SPI destructor. + // Once this mbed's imperfection is corrected, this block should be removed. + for (i = 0; i < SPI_COUNT; ++i) { + spi_info_t *p_spi_info = &m_spi_info[i]; + if (p_spi_info->initialized && + p_spi_info->mosi_pin == (uint8_t)mosi && + p_spi_info->miso_pin == (uint8_t)miso && + p_spi_info->sck_pin == (uint8_t)sclk && + p_spi_info->ss_pin == (uint8_t)ssel) { + // Reuse the already allocated SPI instance (instead of allocating + // a new one), if it appears to be initialized with exactly the same + // pin assignments. + SPI_IDX(obj) = i; + return; + } + } + + for (i = 0; i < SPI_COUNT; ++i) { spi_info_t *p_spi_info = &m_spi_info[i]; if (!p_spi_info->initialized) {