123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- #ifndef NRF_SPI_MNGR_H__
- #define NRF_SPI_MNGR_H__
- #include <stdint.h>
- #include "nrf_drv_spi.h"
- #include "sdk_errors.h"
- #include "nrf_queue.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #ifndef NRF_SPI_MNGR_BUFFERS_IN_RAM
- #define NRF_SPI_MNGR_BUFFERS_IN_RAM defined(SPIM_PRESENT)
- #endif
- #if NRF_SPI_MNGR_BUFFERS_IN_RAM
- #define NRF_SPI_MNGR_BUFFER_LOC_IND
- #else
- #define NRF_SPI_MNGR_BUFFER_LOC_IND const
- #endif
- #define NRF_SPI_MNGR_TRANSFER(_p_tx_data, _tx_length, _p_rx_data, _rx_length) \
- { \
- .p_tx_data = (uint8_t const *)_p_tx_data, \
- .tx_length = (uint8_t) _tx_length, \
- .p_rx_data = (uint8_t *) _p_rx_data, \
- .rx_length = (uint8_t) _rx_length, \
- }
- typedef void (* nrf_spi_mngr_callback_end_t)(ret_code_t result, void * p_user_data);
- typedef void (* nrf_spi_mngr_callback_begin_t)(void * p_user_data);
- typedef struct
- {
- uint8_t const * p_tx_data;
- uint8_t tx_length;
- uint8_t * p_rx_data;
- uint8_t rx_length;
- } nrf_spi_mngr_transfer_t;
- typedef struct
- {
- nrf_spi_mngr_callback_begin_t begin_callback;
-
- nrf_spi_mngr_callback_end_t end_callback;
-
- void * p_user_data;
-
- nrf_spi_mngr_transfer_t const * p_transfers;
-
- uint8_t number_of_transfers;
-
- nrf_drv_spi_config_t const * p_required_spi_cfg;
-
- } nrf_spi_mngr_transaction_t;
- typedef struct
- {
- nrf_spi_mngr_transaction_t const * volatile p_current_transaction;
-
- nrf_drv_spi_config_t default_configuration;
-
- nrf_drv_spi_config_t const * p_current_configuration;
-
- uint8_t volatile current_transfer_idx;
-
- } nrf_spi_mngr_cb_t;
- typedef struct
- {
- nrf_spi_mngr_cb_t * p_nrf_spi_mngr_cb;
-
- nrf_queue_t const * p_queue;
-
- nrf_drv_spi_t spi;
-
- } nrf_spi_mngr_t;
- #define NRF_SPI_MNGR_DEF(_nrf_spi_mngr_name, _queue_size, _spi_idx) \
- NRF_QUEUE_DEF(nrf_spi_mngr_transaction_t const *, \
- _nrf_spi_mngr_name##_queue, \
- (_queue_size), \
- NRF_QUEUE_MODE_NO_OVERFLOW); \
- static nrf_spi_mngr_cb_t CONCAT_2(_nrf_spi_mngr_name, _cb); \
- static const nrf_spi_mngr_t _nrf_spi_mngr_name = \
- { \
- .p_nrf_spi_mngr_cb = &CONCAT_2(_nrf_spi_mngr_name, _cb), \
- .p_queue = &_nrf_spi_mngr_name##_queue, \
- .spi = NRF_DRV_SPI_INSTANCE(_spi_idx) \
- }
-
- ret_code_t nrf_spi_mngr_init(nrf_spi_mngr_t const * p_nrf_spi_mngr,
- nrf_drv_spi_config_t const * p_default_spi_config);
- void nrf_spi_mngr_uninit(nrf_spi_mngr_t const * p_nrf_spi_mngr);
- ret_code_t nrf_spi_mngr_schedule(nrf_spi_mngr_t const * p_nrf_spi_mngr,
- nrf_spi_mngr_transaction_t const * p_transaction);
- ret_code_t nrf_spi_mngr_perform(nrf_spi_mngr_t const * p_nrf_spi_mngr,
- nrf_drv_spi_config_t const * p_config,
- nrf_spi_mngr_transfer_t const * p_transfers,
- uint8_t number_of_transfers,
- void (* user_function)(void));
- __STATIC_INLINE bool nrf_spi_mngr_is_idle(nrf_spi_mngr_t const * p_nrf_spi_mngr)
- {
- return (p_nrf_spi_mngr->p_nrf_spi_mngr_cb->p_current_transaction == NULL);
- }
- #ifdef __cplusplus
- }
- #endif
- #endif
|