Skip to content

Commit 6c7d15d

Browse files
committed
Re-enabled SPI after adjusting HAL implementation to slightly different API.
1 parent 52b9563 commit 6c7d15d

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

hal/targets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@
13881388
"supported_form_factors": ["ARDUINO"],
13891389
"inherits": ["MCU_NRF51_32K"],
13901390
"progen": {"target": "nrf51-dk"},
1391-
"device_has": ["ERROR_PATTERN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "RTC", "SERIAL_ASYNCH", "SLEEP"]
1391+
"device_has": ["ERROR_PATTERN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH"]
13921392
},
13931393
"NRF51_DK_BOOT": {
13941394
"supported_form_factors": ["ARDUINO"],
@@ -1764,6 +1764,6 @@
17641764
"supported_form_factors": ["ARDUINO"],
17651765
"inherits": ["MCU_NRF52"],
17661766
"progen": {"target": "nrf52-dk"},
1767-
"device_has": ["ERROR_PATTERN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP"]
1767+
"device_has": ["ERROR_PATTERN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH"]
17681768
}
17691769
}

hal/targets/hal/TARGET_NORDIC/TARGET_NRF5/i2c_api.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
17+
#include "i2c_api.h"
18+
19+
#if DEVICE_I2C
20+
1621
#include "mbed_assert.h"
1722
#include "mbed_error.h"
18-
#include "i2c_api.h"
1923
#include "nrf_drv_twi.h"
2024
#include "app_util_platform.h"
2125

22-
#if DEVICE_I2C
23-
2426
#if DEVICE_I2C_ASYNCH
2527
#define TWI_IDX(obj) ((obj)->i2c.twi_idx)
2628
#else

hal/targets/hal/TARGET_NORDIC/TARGET_NRF5/spi_api.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
//#include <math.h>
1716

1817
#include "spi_api.h"
18+
19+
#if DEVICE_SPI
20+
1921
#include "cmsis.h"
2022
#include "pinmap.h"
2123
#include "mbed_assert.h"
2224
#include "mbed_error.h"
2325
#include "nrf_drv_spi.h"
2426
#include "app_util_platform.h"
2527

26-
#if DEVICE_SPI
27-
2828
#define SPI_MESSAGE_SIZE 1
2929
volatile uint8_t m_tx_buf[SPI_MESSAGE_SIZE] = {0};
3030
volatile uint8_t m_rx_buf[SPI_MESSAGE_SIZE] = {0};
@@ -55,15 +55,16 @@ static void master_event_handler(nrf_drv_spi_evt_t const * event)
5555
}
5656
}
5757

58-
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk)
58+
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
5959
{
60-
m_config.sck_pin = sclk;
61-
m_config.mosi_pin = mosi;
62-
m_config.miso_pin = miso;
63-
60+
m_config.sck_pin = (uint8_t)sclk;
61+
m_config.mosi_pin = (mosi != NC) ? (uint8_t)mosi : NRF_DRV_SPI_PIN_NOT_USED;
62+
m_config.miso_pin = (miso != NC) ? (uint8_t)miso : NRF_DRV_SPI_PIN_NOT_USED;
63+
m_config.ss_pin = (ssel != NC) ? (uint8_t)ssel : NRF_DRV_SPI_PIN_NOT_USED;
64+
6465
SPI_S(obj)->busy = false;
6566
m_spi_struct = obj;
66-
67+
6768
SPI_DRV(obj) = &spi1;
6869
(void)nrf_drv_spi_init(&spi1, &m_config, master_event_handler);
6970
}
@@ -122,13 +123,15 @@ static nrf_drv_spi_frequency_t freq_translate(int hz)
122123
return frequency;
123124
}
124125

125-
void spi_format(spi_t *obj, int bits, int mode, spi_bitorder_t order)
126+
void spi_format(spi_t *obj, int bits, int mode, int slave)
126127
{
127128
if (bits != 8) {
128129
error("Only 8bits SPI supported");
129130
}
130-
131-
m_config.bit_order = ((order == SPI_MSB) ? NRF_DRV_SPI_BIT_ORDER_MSB_FIRST : NRF_DRV_SPI_BIT_ORDER_LSB_FIRST);
131+
if (slave != 0) {
132+
error("SPI slave mode is not supported");
133+
}
134+
132135
nrf_drv_spi_mode_t config_mode = mode_translate(mode);
133136

134137
if (m_config.mode != config_mode) {
@@ -182,14 +185,14 @@ void spi_slave_write(spi_t *obj, int value)
182185

183186
#if DEVICE_SPI_ASYNCH
184187

185-
186188
void spi_master_transfer(spi_t *obj,
187-
void *tx, size_t tx_length,
188-
void *rx, size_t rx_length,
189-
uint32_t handler,
190-
uint32_t event,
191-
DMAUsage hint)
189+
const void *tx, size_t tx_length,
190+
void *rx, size_t rx_length, uint8_t bit_width,
191+
uint32_t handler, uint32_t event, DMAUsage hint)
192192
{
193+
(void)hint;
194+
(void)bit_width;
195+
193196
m_user_handler = (user_handler_t)handler;
194197
m_event = event;
195198

@@ -213,6 +216,7 @@ void spi_abort_asynch(spi_t *obj)
213216
{
214217
nrf_drv_spi_abort(SPI_DRV(obj));
215218
}
216-
#endif
219+
220+
#endif // DEVICE_SPI_ASYNCH
217221

218222
#endif // DEVICE_SPI

0 commit comments

Comments
 (0)