mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: targets/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c
- Revision:
- 167:e84263d55307
- Parent:
- 163:74e0ce7f98e8
- Child:
- 170:19eb464bc2be
--- a/targets/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c Thu Jun 08 15:02:37 2017 +0100 +++ b/targets/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c Wed Jun 21 17:46:44 2017 +0100 @@ -196,6 +196,7 @@ /* Enabling pins and setting location */ #ifdef _USART_ROUTEPEN_RESETVALUE uint32_t route = USART_ROUTEPEN_CLKPEN; + obj->spi.spi->ROUTELOC0 &= ~_USART_ROUTELOC0_CLKLOC_MASK; obj->spi.spi->ROUTELOC0 |= pin_location(clk, PinMap_SPI_CLK)<<_USART_ROUTELOC0_CLKLOC_SHIFT; if (mosi != NC) { @@ -206,12 +207,12 @@ if (miso != NC) { route |= USART_ROUTEPEN_RXPEN; obj->spi.spi->ROUTELOC0 &= ~_USART_ROUTELOC0_RXLOC_MASK; - obj->spi.spi->ROUTELOC0 |= pin_location(miso, PinMap_SPI_MOSI)<<_USART_ROUTELOC0_RXLOC_SHIFT; + obj->spi.spi->ROUTELOC0 |= pin_location(miso, PinMap_SPI_MISO)<<_USART_ROUTELOC0_RXLOC_SHIFT; } if (!obj->spi.master) { route |= USART_ROUTEPEN_CSPEN; obj->spi.spi->ROUTELOC0 &= ~_USART_ROUTELOC0_CSLOC_MASK; - obj->spi.spi->ROUTELOC0 |= pin_location(cs, PinMap_SPI_MOSI)<<_USART_ROUTELOC0_CSLOC_SHIFT; + obj->spi.spi->ROUTELOC0 |= pin_location(cs, PinMap_SPI_CS)<<_USART_ROUTELOC0_CSLOC_SHIFT; } obj->spi.location = obj->spi.spi->ROUTELOC0; obj->spi.route = route; @@ -390,6 +391,20 @@ return spi_read(obj); } +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { + int total = (tx_length > rx_length) ? tx_length : rx_length; + + for (int i = 0; i < total; i++) { + char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char in = spi_master_write(obj, out); + if (i < rx_length) { + rx_buffer[i] = in; + } + } + + return total; +} + inline uint8_t spi_master_tx_ready(spi_t *obj) { return (obj->spi.spi->STATUS & USART_STATUS_TXBL) ? true : false;