t
Fork of mbed-dev by
Revision 178:c26431f84b0d, committed 2017-11-09
- Comitter:
- amithy
- Date:
- Thu Nov 09 22:14:37 2017 +0000
- Parent:
- 159:612c381a210f
- Commit message:
- test export
Changed in this revision
diff -r 612c381a210f -r c26431f84b0d targets/TARGET_NORDIC/TARGET_MCU_NRF51822/analogin_api.c --- a/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/analogin_api.c Tue Feb 28 17:13:35 2017 +0000 +++ b/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/analogin_api.c Thu Nov 09 22:14:37 2017 +0000 @@ -36,6 +36,7 @@ {NC, NC, 0} }; + void analogin_init(analogin_t *obj, PinName pin) { int analogInputPin = 0; @@ -71,7 +72,8 @@ while (!NRF_ADC->EVENTS_END) { } - return (uint16_t)NRF_ADC->RESULT; // 10 bit + uint16_t value = NRF_ADC->RESULT; + return (value << 6) | ((value >> 4) & 0x003F); // 10 bit } float analogin_read(analogin_t *obj)
diff -r 612c381a210f -r c26431f84b0d targets/TARGET_NORDIC/TARGET_NRF5/spi_api.c --- 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 Thu Nov 09 22:14:37 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) {