123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- extern "C" {
- typedef struct
- {
- NRF_TWI_Type * p_twi;
- uint8_t drv_inst_idx;
- } nrfx_twi_t;
- { \
- .p_twi = NRFX_CONCAT_2(NRF_TWI, id), \
- .drv_inst_idx = NRFX_CONCAT_3(NRFX_TWI, id, _INST_IDX), \
- }
- enum {
- NRFX_TWI0_INST_IDX,
- NRFX_TWI1_INST_IDX,
- NRFX_TWI_ENABLED_COUNT
- };
- typedef struct
- {
- uint32_t scl;
- uint32_t sda;
- nrf_twi_frequency_t frequency;
- uint8_t interrupt_priority;
- bool hold_bus_uninit;
- } nrfx_twi_config_t;
- { \
- .frequency = (nrf_twi_frequency_t)NRFX_TWI_DEFAULT_CONFIG_FREQUENCY, \
- .scl = 31, \
- .sda = 31, \
- .interrupt_priority = NRFX_TWI_DEFAULT_CONFIG_IRQ_PRIORITY, \
- .hold_bus_uninit = NRFX_TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT, \
- }
- typedef enum
- {
- NRFX_TWI_EVT_DONE,
- NRFX_TWI_EVT_ADDRESS_NACK,
- NRFX_TWI_EVT_DATA_NACK,
- NRFX_TWI_EVT_OVERRUN,
- NRFX_TWI_EVT_BUS_ERROR
- } nrfx_twi_evt_type_t;
- typedef enum
- {
- NRFX_TWI_XFER_TX,
- NRFX_TWI_XFER_RX,
- NRFX_TWI_XFER_TXRX,
- NRFX_TWI_XFER_TXTX
- } nrfx_twi_xfer_type_t;
- typedef struct
- {
- nrfx_twi_xfer_type_t type;
- uint8_t address;
- size_t primary_length;
- size_t secondary_length;
- uint8_t * p_primary_buf;
- uint8_t * p_secondary_buf;
- } nrfx_twi_xfer_desc_t;
- { \
- .type = NRFX_TWI_XFER_TX, \
- .address = (addr), \
- .primary_length = (length), \
- .secondary_length = 0, \
- .p_primary_buf = (p_data), \
- .p_secondary_buf = NULL, \
- }
- { \
- .type = NRFX_TWI_XFER_RX, \
- .address = (addr), \
- .primary_length = (length), \
- .secondary_length = 0, \
- .p_primary_buf = (p_data), \
- .p_secondary_buf = NULL, \
- }
- { \
- .type = NRFX_TWI_XFER_TXRX, \
- .address = (addr), \
- .primary_length = (tx_len), \
- .secondary_length = (rx_len), \
- .p_primary_buf = (p_tx), \
- .p_secondary_buf = (p_rx), \
- }
- { \
- .type = NRFX_TWI_XFER_TXTX, \
- .address = (addr), \
- .primary_length = (tx_len), \
- .secondary_length = (tx_len2), \
- .p_primary_buf = (p_tx), \
- .p_secondary_buf = (p_tx2), \
- }
- typedef struct
- {
- nrfx_twi_evt_type_t type;
- nrfx_twi_xfer_desc_t xfer_desc;
- } nrfx_twi_evt_t;
- typedef void (* nrfx_twi_evt_handler_t)(nrfx_twi_evt_t const * p_event,
- void * p_context);
- nrfx_err_t nrfx_twi_init(nrfx_twi_t const * p_instance,
- nrfx_twi_config_t const * p_config,
- nrfx_twi_evt_handler_t event_handler,
- void * p_context);
- void nrfx_twi_uninit(nrfx_twi_t const * p_instance);
- void nrfx_twi_enable(nrfx_twi_t const * p_instance);
- void nrfx_twi_disable(nrfx_twi_t const * p_instance);
- nrfx_err_t nrfx_twi_tx(nrfx_twi_t const * p_instance,
- uint8_t address,
- uint8_t const * p_data,
- size_t length,
- bool no_stop);
- nrfx_err_t nrfx_twi_rx(nrfx_twi_t const * p_instance,
- uint8_t address,
- uint8_t * p_data,
- size_t length);
- nrfx_err_t nrfx_twi_xfer(nrfx_twi_t const * p_instance,
- nrfx_twi_xfer_desc_t const * p_xfer_desc,
- uint32_t flags);
- bool nrfx_twi_is_busy(nrfx_twi_t const * p_instance);
- size_t nrfx_twi_data_count_get(nrfx_twi_t const * const p_instance);
- uint32_t nrfx_twi_stopped_event_get(nrfx_twi_t const * p_instance);
- __STATIC_INLINE nrfx_err_t nrfx_twi_bus_recover(uint32_t scl_pin, uint32_t sda_pin);
- __STATIC_INLINE nrfx_err_t nrfx_twi_bus_recover(uint32_t scl_pin, uint32_t sda_pin)
- {
- return nrfx_twi_twim_bus_recover(scl_pin, sda_pin);
- }
- void nrfx_twi_0_irq_handler(void);
- void nrfx_twi_1_irq_handler(void);
- }
|