123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- extern "C" {
- typedef struct
- {
- NRF_TWIM_Type * p_twim;
- uint8_t drv_inst_idx;
- } nrfx_twim_t;
- { \
- .p_twim = NRFX_CONCAT_2(NRF_TWIM, id), \
- .drv_inst_idx = NRFX_CONCAT_3(NRFX_TWIM, id, _INST_IDX), \
- }
- enum {
- NRFX_TWIM0_INST_IDX,
- NRFX_TWIM1_INST_IDX,
- NRFX_TWIM2_INST_IDX,
- NRFX_TWIM3_INST_IDX,
- NRFX_TWIM_ENABLED_COUNT
- };
- typedef struct
- {
- uint32_t scl;
- uint32_t sda;
- nrf_twim_frequency_t frequency;
- uint8_t interrupt_priority;
- bool hold_bus_uninit;
- } nrfx_twim_config_t;
- { \
- .scl = 31, \
- .sda = 31, \
- .frequency = (nrf_twim_frequency_t)NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY, \
- .interrupt_priority = NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY, \
- .hold_bus_uninit = NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT, \
- }
- typedef enum
- {
- NRFX_TWIM_EVT_DONE,
- NRFX_TWIM_EVT_ADDRESS_NACK,
- NRFX_TWIM_EVT_DATA_NACK,
- NRFX_TWIM_EVT_OVERRUN,
- NRFX_TWIM_EVT_BUS_ERROR
- } nrfx_twim_evt_type_t;
- typedef enum
- {
- NRFX_TWIM_XFER_TX,
- NRFX_TWIM_XFER_RX,
- NRFX_TWIM_XFER_TXRX,
- NRFX_TWIM_XFER_TXTX
- } nrfx_twim_xfer_type_t;
- typedef struct
- {
- nrfx_twim_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_twim_xfer_desc_t;
- { \
- .type = NRFX_TWIM_XFER_TX, \
- .address = (addr), \
- .primary_length = (length), \
- .secondary_length = 0, \
- .p_primary_buf = (p_data), \
- .p_secondary_buf = NULL, \
- }
- { \
- .type = NRFX_TWIM_XFER_RX, \
- .address = (addr), \
- .primary_length = (length), \
- .secondary_length = 0, \
- .p_primary_buf = (p_data), \
- .p_secondary_buf = NULL, \
- }
- { \
- .type = NRFX_TWIM_XFER_TXRX, \
- .address = (addr), \
- .primary_length = (tx_len), \
- .secondary_length = (rx_len), \
- .p_primary_buf = (p_tx), \
- .p_secondary_buf = (p_rx), \
- }
- { \
- .type = NRFX_TWIM_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_twim_evt_type_t type;
- nrfx_twim_xfer_desc_t xfer_desc;
- } nrfx_twim_evt_t;
- typedef void (* nrfx_twim_evt_handler_t)(nrfx_twim_evt_t const * p_event,
- void * p_context);
- nrfx_err_t nrfx_twim_init(nrfx_twim_t const * p_instance,
- nrfx_twim_config_t const * p_config,
- nrfx_twim_evt_handler_t event_handler,
- void * p_context);
- void nrfx_twim_uninit(nrfx_twim_t const * p_instance);
- void nrfx_twim_enable(nrfx_twim_t const * p_instance);
- void nrfx_twim_disable(nrfx_twim_t const * p_instance);
- nrfx_err_t nrfx_twim_tx(nrfx_twim_t const * p_instance,
- uint8_t address,
- uint8_t const * p_data,
- size_t length,
- bool no_stop);
- nrfx_err_t nrfx_twim_rx(nrfx_twim_t const * p_instance,
- uint8_t address,
- uint8_t * p_data,
- size_t length);
- nrfx_err_t nrfx_twim_xfer(nrfx_twim_t const * p_instance,
- nrfx_twim_xfer_desc_t const * p_xfer_desc,
- uint32_t flags);
- bool nrfx_twim_is_busy(nrfx_twim_t const * p_instance);
- uint32_t nrfx_twim_start_task_get(nrfx_twim_t const * p_instance, nrfx_twim_xfer_type_t xfer_type);
- uint32_t nrfx_twim_stopped_event_get(nrfx_twim_t const * p_instance);
- __STATIC_INLINE nrfx_err_t nrfx_twim_bus_recover(uint32_t scl_pin, uint32_t sda_pin);
- __STATIC_INLINE nrfx_err_t nrfx_twim_bus_recover(uint32_t scl_pin, uint32_t sda_pin)
- {
- return nrfx_twi_twim_bus_recover(scl_pin, sda_pin);
- }
- void nrfx_twim_0_irq_handler(void);
- void nrfx_twim_1_irq_handler(void);
- void nrfx_twim_2_irq_handler(void);
- void nrfx_twim_3_irq_handler(void);
- }
|