123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- #ifndef NRFX_SPIS_H__
- #define NRFX_SPIS_H__
- #include <nrfx.h>
- #include <hal/nrf_spis.h>
- #include <hal/nrf_gpio.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct
- {
- NRF_SPIS_Type * p_reg;
- uint8_t drv_inst_idx;
- } nrfx_spis_t;
- #ifndef __NRFX_DOXYGEN__
- enum {
- #if NRFX_CHECK(NRFX_SPIS0_ENABLED)
- NRFX_SPIS0_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_SPIS1_ENABLED)
- NRFX_SPIS1_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_SPIS2_ENABLED)
- NRFX_SPIS2_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_SPIS3_ENABLED)
- NRFX_SPIS3_INST_IDX,
- #endif
- NRFX_SPIS_ENABLED_COUNT
- };
- #endif
- #define NRFX_SPIS_INSTANCE(id) \
- { \
- .p_reg = NRFX_CONCAT_2(NRF_SPIS, id), \
- .drv_inst_idx = NRFX_CONCAT_3(NRFX_SPIS, id, _INST_IDX), \
- }
- #define NRFX_SPIS_PIN_NOT_USED 0xFF
- #define NRFX_SPIS_DEFAULT_CSN_PULLUP NRF_GPIO_PIN_NOPULL
- #define NRFX_SPIS_DEFAULT_MISO_DRIVE NRF_GPIO_PIN_S0S1
- typedef enum
- {
- NRFX_SPIS_BUFFERS_SET_DONE,
- NRFX_SPIS_XFER_DONE,
- NRFX_SPIS_EVT_TYPE_MAX
- } nrfx_spis_evt_type_t;
- typedef struct
- {
- nrfx_spis_evt_type_t evt_type;
- size_t rx_amount;
- size_t tx_amount;
- } nrfx_spis_evt_t;
- #define NRFX_SPIS_DEFAULT_CONFIG \
- { \
- .miso_pin = NRFX_SPIS_PIN_NOT_USED, \
- .mosi_pin = NRFX_SPIS_PIN_NOT_USED, \
- .sck_pin = NRFX_SPIS_PIN_NOT_USED, \
- .csn_pin = NRFX_SPIS_PIN_NOT_USED, \
- .mode = NRF_SPIS_MODE_0, \
- .bit_order = NRF_SPIS_BIT_ORDER_MSB_FIRST, \
- .csn_pullup = NRFX_SPIS_DEFAULT_CSN_PULLUP, \
- .miso_drive = NRFX_SPIS_DEFAULT_MISO_DRIVE, \
- .def = NRFX_SPIS_DEFAULT_DEF, \
- .orc = NRFX_SPIS_DEFAULT_ORC, \
- .irq_priority = NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY, \
- }
- typedef struct
- {
- uint32_t miso_pin;
-
- uint32_t mosi_pin;
-
- uint32_t sck_pin;
- uint32_t csn_pin;
- nrf_spis_mode_t mode;
- nrf_spis_bit_order_t bit_order;
- nrf_gpio_pin_pull_t csn_pullup;
- nrf_gpio_pin_drive_t miso_drive;
- uint8_t def;
- uint8_t orc;
- uint8_t irq_priority;
- } nrfx_spis_config_t;
- typedef void (*nrfx_spis_event_handler_t)(nrfx_spis_evt_t const * p_event,
- void * p_context);
- nrfx_err_t nrfx_spis_init(nrfx_spis_t const * const p_instance,
- nrfx_spis_config_t const * p_config,
- nrfx_spis_event_handler_t event_handler,
- void * p_context);
- void nrfx_spis_uninit(nrfx_spis_t const * const p_instance);
- nrfx_err_t nrfx_spis_buffers_set(nrfx_spis_t const * const p_instance,
- uint8_t const * p_tx_buffer,
- size_t tx_buffer_length,
- uint8_t * p_rx_buffer,
- size_t rx_buffer_length);
- void nrfx_spis_0_irq_handler(void);
- void nrfx_spis_1_irq_handler(void);
- void nrfx_spis_2_irq_handler(void);
- void nrfx_spis_3_irq_handler(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
|