123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- #ifndef NRFX_SPIM_H__
- #define NRFX_SPIM_H__
- #include <nrfx.h>
- #include <hal/nrf_spim.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct
- {
- NRF_SPIM_Type * p_reg;
- uint8_t drv_inst_idx;
- } nrfx_spim_t;
- #ifndef __NRFX_DOXYGEN__
- enum {
- #if NRFX_CHECK(NRFX_SPIM0_ENABLED)
- NRFX_SPIM0_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_SPIM1_ENABLED)
- NRFX_SPIM1_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_SPIM2_ENABLED)
- NRFX_SPIM2_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_SPIM3_ENABLED)
- NRFX_SPIM3_INST_IDX,
- #endif
- NRFX_SPIM_ENABLED_COUNT
- };
- #endif
- #define NRFX_SPIM_INSTANCE(id) \
- { \
- .p_reg = NRFX_CONCAT_2(NRF_SPIM, id), \
- .drv_inst_idx = NRFX_CONCAT_3(NRFX_SPIM, id, _INST_IDX), \
- }
- #define NRFX_SPIM_PIN_NOT_USED 0xFF
- typedef struct
- {
- uint8_t sck_pin;
- uint8_t mosi_pin;
-
- uint8_t miso_pin;
-
- uint8_t ss_pin;
-
- bool ss_active_high;
- uint8_t irq_priority;
- uint8_t orc;
-
- nrf_spim_frequency_t frequency;
- nrf_spim_mode_t mode;
- nrf_spim_bit_order_t bit_order;
- #if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED) || defined(__NRFX_DOXYGEN__)
- uint8_t dcx_pin;
- uint8_t rx_delay;
-
- bool use_hw_ss;
- uint8_t ss_duration;
-
- #endif
- } nrfx_spim_config_t;
- #if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED) || defined(__NRFX_DOXYGEN__)
- #define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG \
- .dcx_pin = NRFX_SPIM_PIN_NOT_USED, \
- .rx_delay = 0x02, \
- .use_hw_ss = false, \
- .ss_duration = 0x02,
- #else
- #define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG
- #endif
- #define NRFX_SPIM_DEFAULT_CONFIG \
- { \
- .sck_pin = NRFX_SPIM_PIN_NOT_USED, \
- .mosi_pin = NRFX_SPIM_PIN_NOT_USED, \
- .miso_pin = NRFX_SPIM_PIN_NOT_USED, \
- .ss_pin = NRFX_SPIM_PIN_NOT_USED, \
- .ss_active_high = false, \
- .irq_priority = NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY, \
- .orc = 0xFF, \
- .frequency = NRF_SPIM_FREQ_4M, \
- .mode = NRF_SPIM_MODE_0, \
- .bit_order = NRF_SPIM_BIT_ORDER_MSB_FIRST, \
- NRFX_SPIM_DEFAULT_EXTENDED_CONFIG \
- }
- #define NRFX_SPIM_FLAG_TX_POSTINC (1UL << 0)
- #define NRFX_SPIM_FLAG_RX_POSTINC (1UL << 1)
- #define NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER (1UL << 2)
- #define NRFX_SPIM_FLAG_HOLD_XFER (1UL << 3)
- #define NRFX_SPIM_FLAG_REPEATED_XFER (1UL << 4)
- typedef struct
- {
- uint8_t const * p_tx_buffer;
- size_t tx_length;
- uint8_t * p_rx_buffer;
- size_t rx_length;
- } nrfx_spim_xfer_desc_t;
- #define NRFX_SPIM_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_SPIM_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length) \
- NRFX_SPIM_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)
- #define NRFX_SPIM_XFER_TX(p_buf, length) \
- NRFX_SPIM_SINGLE_XFER(p_buf, length, NULL, 0)
- #define NRFX_SPIM_XFER_RX(p_buf, length) \
- NRFX_SPIM_SINGLE_XFER(NULL, 0, p_buf, length)
- typedef enum
- {
- NRFX_SPIM_EVENT_DONE,
- } nrfx_spim_evt_type_t;
- typedef struct
- {
- nrfx_spim_evt_type_t type;
- nrfx_spim_xfer_desc_t xfer_desc;
- } nrfx_spim_evt_t;
- typedef void (* nrfx_spim_evt_handler_t)(nrfx_spim_evt_t const * p_event,
- void * p_context);
- nrfx_err_t nrfx_spim_init(nrfx_spim_t const * const p_instance,
- nrfx_spim_config_t const * p_config,
- nrfx_spim_evt_handler_t handler,
- void * p_context);
- void nrfx_spim_uninit(nrfx_spim_t const * const p_instance);
- nrfx_err_t nrfx_spim_xfer(nrfx_spim_t const * const p_instance,
- nrfx_spim_xfer_desc_t const * p_xfer_desc,
- uint32_t flags);
- #if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED) || defined(__NRFX_DOXYGEN__)
- nrfx_err_t nrfx_spim_xfer_dcx(nrfx_spim_t const * const p_instance,
- nrfx_spim_xfer_desc_t const * p_xfer_desc,
- uint32_t flags,
- uint8_t cmd_length);
- #endif
- uint32_t nrfx_spim_start_task_get(nrfx_spim_t const * p_instance);
- uint32_t nrfx_spim_end_event_get(nrfx_spim_t const * p_instance);
- void nrfx_spim_abort(nrfx_spim_t const * p_instance);
- void nrfx_spim_0_irq_handler(void);
- void nrfx_spim_1_irq_handler(void);
- void nrfx_spim_2_irq_handler(void);
- void nrfx_spim_3_irq_handler(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
|