@@ -480,11 +480,6 @@ void spi_frequency(spi_t *obj, int hz)
480
480
int spi_master_write (spi_t * obj , int value )
481
481
{
482
482
nrfx_err_t ret ;
483
- #if NRFX_CHECK (NRFX_SPIM_ENABLED )
484
- nrfx_spim_xfer_desc_t desc ;
485
- #elif NRFX_CHECK (NRFX_SPI_ENABLED )
486
- nrfx_spi_xfer_desc_t desc ;
487
- #endif
488
483
489
484
#if DEVICE_SPI_ASYNCH
490
485
struct spi_s * spi_inst = & obj -> spi ;
@@ -507,18 +502,20 @@ int spi_master_write(spi_t *obj, int value)
507
502
}
508
503
509
504
/* Transfer 1 byte. */
510
- desc .p_tx_buffer = & tx_buff ;
511
- desc .p_rx_buffer = & rx_buff ;
512
- desc .tx_length = 1 ;
513
- desc .rx_length = 1 ;
514
- #if NRFX_CHECK (NRFX_SPIM_ENABLED )
505
+ #if NRFX_CHECK (NRFX_SPIM_ENABLED )
506
+ nrfx_spim_xfer_desc_t desc = NRFX_SPIM_XFER_TRX (& tx_buff , 1 , & rx_buff , 1 );
507
+ #elif NRFX_CHECK (NRFX_SPI_ENABLED )
508
+ nrfx_spi_xfer_desc_t desc = NRFX_SPI_XFER_TRX (& tx_buff , 1 , & rx_buff , 1 );
509
+ #endif
510
+
511
+ #if NRFX_CHECK (NRFX_SPIM_ENABLED )
515
512
ret = nrfx_spim_xfer (& nordic_nrf5_spim_instance [instance ], & desc , 0 );
516
- #elif NRFX_CHECK (NRFX_SPI_ENABLED )
513
+ #elif NRFX_CHECK (NRFX_SPI_ENABLED )
517
514
ret = nrfx_spi_xfer (& nordic_nrf5_spi_instance [instance ], & desc , 0 );
518
515
#endif
519
516
520
517
if (ret != NRFX_SUCCESS ) {
521
- DEBUG_PRINTF ("%d error returned from nrf_spi_xfer\n\r" );
518
+ DEBUG_PRINTF ("%d error returned from nrf_spi_xfer\n\r" , ret );
522
519
}
523
520
524
521
/* Manually set chip select pin if defined. */
@@ -547,12 +544,6 @@ int spi_master_write(spi_t *obj, int value)
547
544
*/
548
545
int spi_master_block_write (spi_t * obj , const char * tx_buffer , int tx_length , char * rx_buffer , int rx_length , char write_fill )
549
546
{
550
- #if NRFX_CHECK (NRFX_SPIM_ENABLED )
551
- nrfx_spim_xfer_desc_t desc ;
552
- #elif NRFX_CHECK (NRFX_SPI_ENABLED )
553
- nrfx_spi_xfer_desc_t desc ;
554
- #endif
555
-
556
547
#if DEVICE_SPI_ASYNCH
557
548
struct spi_s * spi_inst = & obj -> spi ;
558
549
#else
@@ -586,6 +577,10 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, cha
586
577
587
578
ret_code_t result = NRFX_SUCCESS ;
588
579
580
+ #if NRFX_CHECK (NRFX_SPIM_ENABLED )
581
+ nrfx_spim_xfer_desc_t desc = NRFX_SPIM_XFER_TRX (tx_buffer , tx_length , rx_buffer , rx_length );
582
+ result = nrfx_spim_xfer (& nordic_nrf5_spim_instance [instance ], & desc , 0 );
583
+ #elif NRFX_CHECK (NRFX_SPI_ENABLED )
589
584
/* Loop until all data is sent and received. */
590
585
while (((tx_length > 0 ) || (rx_length > 0 )) && (result == NRFX_SUCCESS )) {
591
586
@@ -606,24 +601,17 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, cha
606
601
NULL ;
607
602
608
603
/* Blocking transfer. */
609
- desc .p_tx_buffer = tx_actual_buffer ;
610
- desc .p_rx_buffer = rx_actual_buffer ;
611
- desc .tx_length = tx_actual_length ;
612
- desc .rx_length = rx_actual_length ;
613
- #if NRFX_CHECK (NRFX_SPIM_ENABLED )
614
- result = nrfx_spim_xfer (& nordic_nrf5_spim_instance [instance ],
615
- & desc , 0 );
616
- #elif NRFX_CHECK (NRFX_SPI_ENABLED )
604
+ nrfx_spi_xfer_desc_t desc = NRFX_SPI_XFER_TRX (tx_actual_buffer , tx_actual_length , rx_actual_buffer , rx_actual_length );
617
605
result = nrfx_spi_xfer (& nordic_nrf5_spi_instance [instance ],
618
606
& desc , 0 );
619
- #endif
620
607
/* Update loop variables. */
621
608
tx_length -= tx_actual_length ;
622
609
tx_offset += tx_actual_length ;
623
610
624
611
rx_length -= rx_actual_length ;
625
612
rx_offset += rx_actual_length ;
626
613
}
614
+ #endif
627
615
628
616
/* Manually set chip select pin if defined. */
629
617
if (spi_inst -> cs != NC ) {
0 commit comments