123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- extern "C" {
- typedef struct
- {
- NRF_TWIS_Type * p_reg;
- uint8_t drv_inst_idx;
- } nrfx_twis_t;
- enum {
- NRFX_TWIS0_INST_IDX,
- NRFX_TWIS1_INST_IDX,
- NRFX_TWIS2_INST_IDX,
- NRFX_TWIS3_INST_IDX,
- NRFX_TWIS_ENABLED_COUNT
- };
- { \
- .p_reg = NRFX_CONCAT_2(NRF_TWIS, id), \
- .drv_inst_idx = NRFX_CONCAT_3(NRFX_TWIS, id, _INST_IDX), \
- }
- typedef enum
- {
- NRFX_TWIS_EVT_READ_REQ,
-
- NRFX_TWIS_EVT_READ_DONE,
- NRFX_TWIS_EVT_READ_ERROR,
- NRFX_TWIS_EVT_WRITE_REQ,
-
- NRFX_TWIS_EVT_WRITE_DONE,
- NRFX_TWIS_EVT_WRITE_ERROR,
- NRFX_TWIS_EVT_GENERAL_ERROR
- } nrfx_twis_evt_type_t;
- typedef enum
- {
- NRFX_TWIS_ERROR_OVERFLOW = NRF_TWIS_ERROR_OVERFLOW,
- NRFX_TWIS_ERROR_DATA_NACK = NRF_TWIS_ERROR_DATA_NACK,
- NRFX_TWIS_ERROR_OVERREAD = NRF_TWIS_ERROR_OVERREAD,
- NRFX_TWIS_ERROR_UNEXPECTED_EVENT = 1 << 8
- } nrfx_twis_error_t;
- typedef struct
- {
- nrfx_twis_evt_type_t type;
- union
- {
- bool buf_req;
-
- uint32_t tx_amount;
- uint32_t rx_amount;
- uint32_t error;
- } data;
- } nrfx_twis_evt_t;
- typedef void (*nrfx_twis_event_handler_t)(nrfx_twis_evt_t const * p_event);
- typedef struct
- {
- uint32_t addr[2];
- uint32_t scl;
- uint32_t sda;
- nrf_gpio_pin_pull_t scl_pull;
- nrf_gpio_pin_pull_t sda_pull;
- uint8_t interrupt_priority;
- } nrfx_twis_config_t;
- { \
- .addr = { NRFX_TWIS_DEFAULT_CONFIG_ADDR0, \
- NRFX_TWIS_DEFAULT_CONFIG_ADDR1 }, \
- .scl = 31, \
- .sda = 31, \
- .scl_pull = (nrf_gpio_pin_pull_t)NRFX_TWIS_DEFAULT_CONFIG_SCL_PULL, \
- .sda_pull = (nrf_gpio_pin_pull_t)NRFX_TWIS_DEFAULT_CONFIG_SDA_PULL, \
- .interrupt_priority = NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY \
- }
- nrfx_err_t nrfx_twis_init(nrfx_twis_t const * p_instance,
- nrfx_twis_config_t const * p_config,
- nrfx_twis_event_handler_t event_handler);
- void nrfx_twis_uninit(nrfx_twis_t const * p_instance);
- void nrfx_twis_enable(nrfx_twis_t const * p_instance);
- void nrfx_twis_disable(nrfx_twis_t const * p_instance);
- uint32_t nrfx_twis_error_get_and_clear(nrfx_twis_t const * p_instance);
- nrfx_err_t nrfx_twis_tx_prepare(nrfx_twis_t const * p_instance,
- void const * p_buf,
- size_t size);
- __STATIC_INLINE size_t nrfx_twis_tx_amount(nrfx_twis_t const * p_instance);
- nrfx_err_t nrfx_twis_rx_prepare(nrfx_twis_t const * p_instance,
- void * p_buf,
- size_t size);
- __STATIC_INLINE size_t nrfx_twis_rx_amount(nrfx_twis_t const * p_instance);
- bool nrfx_twis_is_busy(nrfx_twis_t const * p_instance);
- bool nrfx_twis_is_waiting_tx_buff(nrfx_twis_t const * p_instance);
- bool nrfx_twis_is_waiting_rx_buff(nrfx_twis_t const * p_instance);
- bool nrfx_twis_is_pending_tx(nrfx_twis_t const * p_instance);
- bool nrfx_twis_is_pending_rx(nrfx_twis_t const * p_instance);
- __STATIC_INLINE size_t nrfx_twis_tx_amount(nrfx_twis_t const * p_instance)
- {
- return nrf_twis_tx_amount_get(p_instance->p_reg);
- }
- __STATIC_INLINE size_t nrfx_twis_rx_amount(nrfx_twis_t const * p_instance)
- {
- return nrf_twis_rx_amount_get(p_instance->p_reg);
- }
- void nrfx_twis_0_irq_handler(void);
- void nrfx_twis_1_irq_handler(void);
- void nrfx_twis_2_irq_handler(void);
- void nrfx_twis_3_irq_handler(void);
- }
|