123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #ifndef NRFX_SPI_H__
- #define NRFX_SPI_H__
- #include <nrfx.h>
- #include <hal/nrf_spi.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct
- {
- NRF_SPI_Type * p_reg;
- uint8_t drv_inst_idx;
- } nrfx_spi_t;
- enum {
- #if NRFX_CHECK(NRFX_SPI0_ENABLED)
- NRFX_SPI0_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_SPI1_ENABLED)
- NRFX_SPI1_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_SPI2_ENABLED)
- NRFX_SPI2_INST_IDX,
- #endif
- NRFX_SPI_ENABLED_COUNT
- };
- #define NRFX_SPI_INSTANCE(id) \
- { \
- .p_reg = NRFX_CONCAT_2(NRF_SPI, id), \
- .drv_inst_idx = NRFX_CONCAT_3(NRFX_SPI, id, _INST_IDX), \
- }
- #define NRFX_SPI_PIN_NOT_USED 0xFF
- typedef struct
- {
- uint8_t sck_pin;
- uint8_t mosi_pin;
-
- uint8_t miso_pin;
-
- uint8_t ss_pin;
-
- uint8_t irq_priority;
- uint8_t orc;
-
- nrf_spi_frequency_t frequency;
- nrf_spi_mode_t mode;
- nrf_spi_bit_order_t bit_order;
- } nrfx_spi_config_t;
- #define NRFX_SPI_DEFAULT_CONFIG \
- { \
- .sck_pin = NRFX_SPI_PIN_NOT_USED, \
- .mosi_pin = NRFX_SPI_PIN_NOT_USED, \
- .miso_pin = NRFX_SPI_PIN_NOT_USED, \
- .ss_pin = NRFX_SPI_PIN_NOT_USED, \
- .irq_priority = NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY, \
- .orc = 0xFF, \
- .frequency = NRF_SPI_FREQ_4M, \
- .mode = NRF_SPI_MODE_0, \
- .bit_order = NRF_SPI_BIT_ORDER_MSB_FIRST, \
- }
- typedef struct
- {
- uint8_t const * p_tx_buffer;
- size_t tx_length;
- uint8_t * p_rx_buffer;
- size_t rx_length;
- }nrfx_spi_xfer_desc_t;
- #define NRFX_SPI_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len) \
- { \
- .p_tx_buffer = (uint8_t const *)(p_tx), \
- .tx_length = (tx_len), \
- .p_rx_buffer = (p_rx), \
- .rx_length = (rx_len), \
- }
- #define NRFX_SPI_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length) \
- NRFX_SPI_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)
- #define NRFX_SPI_XFER_TX(p_buf, length) \
- NRFX_SPI_SINGLE_XFER(p_buf, length, NULL, 0)
- #define NRFX_SPI_XFER_RX(p_buf, length) \
- NRFX_SPI_SINGLE_XFER(NULL, 0, p_buf, length)
- typedef enum
- {
- NRFX_SPI_EVENT_DONE,
- } nrfx_spi_evt_type_t;
- typedef struct
- {
- nrfx_spi_evt_type_t type;
- nrfx_spi_xfer_desc_t xfer_desc;
- } nrfx_spi_evt_t;
- typedef void (* nrfx_spi_evt_handler_t)(nrfx_spi_evt_t const * p_event,
- void * p_context);
- nrfx_err_t nrfx_spi_init(nrfx_spi_t const * const p_instance,
- nrfx_spi_config_t const * p_config,
- nrfx_spi_evt_handler_t handler,
- void * p_context);
- void nrfx_spi_uninit(nrfx_spi_t const * const p_instance);
- nrfx_err_t nrfx_spi_xfer(nrfx_spi_t const * const p_instance,
- nrfx_spi_xfer_desc_t const * p_xfer_desc,
- uint32_t flags);
- void nrfx_spi_abort(nrfx_spi_t const * p_instance);
- void nrfx_spi_0_irq_handler(void);
- void nrfx_spi_1_irq_handler(void);
- void nrfx_spi_2_irq_handler(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
|