13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- //#include <math.h>
17
16
18
17
#include "spi_api.h"
18
+
19
+ #if DEVICE_SPI
20
+
19
21
#include "cmsis.h"
20
22
#include "pinmap.h"
21
23
#include "mbed_assert.h"
22
24
#include "mbed_error.h"
23
25
#include "nrf_drv_spi.h"
24
26
#include "app_util_platform.h"
25
27
26
- #if DEVICE_SPI
27
-
28
28
#define SPI_MESSAGE_SIZE 1
29
29
volatile uint8_t m_tx_buf [SPI_MESSAGE_SIZE ] = {0 };
30
30
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)
55
55
}
56
56
}
57
57
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 )
59
59
{
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
+
64
65
SPI_S (obj )-> busy = false;
65
66
m_spi_struct = obj ;
66
-
67
+
67
68
SPI_DRV (obj ) = & spi1 ;
68
69
(void )nrf_drv_spi_init (& spi1 , & m_config , master_event_handler );
69
70
}
@@ -122,13 +123,15 @@ static nrf_drv_spi_frequency_t freq_translate(int hz)
122
123
return frequency ;
123
124
}
124
125
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 )
126
127
{
127
128
if (bits != 8 ) {
128
129
error ("Only 8bits SPI supported" );
129
130
}
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
+
132
135
nrf_drv_spi_mode_t config_mode = mode_translate (mode );
133
136
134
137
if (m_config .mode != config_mode ) {
@@ -182,14 +185,14 @@ void spi_slave_write(spi_t *obj, int value)
182
185
183
186
#if DEVICE_SPI_ASYNCH
184
187
185
-
186
188
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 )
192
192
{
193
+ (void )hint ;
194
+ (void )bit_width ;
195
+
193
196
m_user_handler = (user_handler_t )handler ;
194
197
m_event = event ;
195
198
@@ -213,6 +216,7 @@ void spi_abort_asynch(spi_t *obj)
213
216
{
214
217
nrf_drv_spi_abort (SPI_DRV (obj ));
215
218
}
216
- #endif
219
+
220
+ #endif // DEVICE_SPI_ASYNCH
217
221
218
222
#endif // DEVICE_SPI
0 commit comments