123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- #ifndef NRF_TWIS_H__
- #define NRF_TWIS_H__
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef enum
- {
- NRF_TWIS_TASK_STOP = offsetof(NRF_TWIS_Type, TASKS_STOP),
- NRF_TWIS_TASK_SUSPEND = offsetof(NRF_TWIS_Type, TASKS_SUSPEND),
- NRF_TWIS_TASK_RESUME = offsetof(NRF_TWIS_Type, TASKS_RESUME),
- NRF_TWIS_TASK_PREPARERX = offsetof(NRF_TWIS_Type, TASKS_PREPARERX),
- NRF_TWIS_TASK_PREPARETX = offsetof(NRF_TWIS_Type, TASKS_PREPARETX)
- } nrf_twis_task_t;
- typedef enum
- {
- NRF_TWIS_EVENT_STOPPED = offsetof(NRF_TWIS_Type, EVENTS_STOPPED),
- NRF_TWIS_EVENT_ERROR = offsetof(NRF_TWIS_Type, EVENTS_ERROR),
- NRF_TWIS_EVENT_RXSTARTED = offsetof(NRF_TWIS_Type, EVENTS_RXSTARTED),
- NRF_TWIS_EVENT_TXSTARTED = offsetof(NRF_TWIS_Type, EVENTS_TXSTARTED),
- NRF_TWIS_EVENT_WRITE = offsetof(NRF_TWIS_Type, EVENTS_WRITE),
- NRF_TWIS_EVENT_READ = offsetof(NRF_TWIS_Type, EVENTS_READ)
- } nrf_twis_event_t;
- typedef enum
- {
- NRF_TWIS_SHORT_WRITE_SUSPEND_MASK = TWIS_SHORTS_WRITE_SUSPEND_Msk,
- NRF_TWIS_SHORT_READ_SUSPEND_MASK = TWIS_SHORTS_READ_SUSPEND_Msk,
- } nrf_twis_short_mask_t;
- typedef enum
- {
- NRF_TWIS_INT_STOPPED_MASK = TWIS_INTEN_STOPPED_Msk,
- NRF_TWIS_INT_ERROR_MASK = TWIS_INTEN_ERROR_Msk,
- NRF_TWIS_INT_RXSTARTED_MASK = TWIS_INTEN_RXSTARTED_Msk,
- NRF_TWIS_INT_TXSTARTED_MASK = TWIS_INTEN_TXSTARTED_Msk,
- NRF_TWIS_INT_WRITE_MASK = TWIS_INTEN_WRITE_Msk,
- NRF_TWIS_INT_READ_MASK = TWIS_INTEN_READ_Msk,
- } nrf_twis_int_mask_t;
- typedef enum
- {
- NRF_TWIS_ERROR_OVERFLOW = TWIS_ERRORSRC_OVERFLOW_Msk,
- NRF_TWIS_ERROR_DATA_NACK = TWIS_ERRORSRC_DNACK_Msk,
- NRF_TWIS_ERROR_OVERREAD = TWIS_ERRORSRC_OVERREAD_Msk
- } nrf_twis_error_t;
- typedef enum
- {
- NRF_TWIS_CONFIG_ADDRESS0_MASK = TWIS_CONFIG_ADDRESS0_Msk,
- NRF_TWIS_CONFIG_ADDRESS1_MASK = TWIS_CONFIG_ADDRESS1_Msk,
- NRF_TWIS_CONFIG_ADDRESS01_MASK = TWIS_CONFIG_ADDRESS0_Msk | TWIS_CONFIG_ADDRESS1_Msk
- } nrf_twis_config_addr_mask_t;
- typedef uint8_t nrf_twis_amount_t;
- typedef uint8_t nrf_twis_address_t;
- __STATIC_INLINE void nrf_twis_task_trigger(NRF_TWIS_Type * p_reg, nrf_twis_task_t task);
- __STATIC_INLINE uint32_t nrf_twis_task_address_get(NRF_TWIS_Type const * p_reg,
- nrf_twis_task_t task);
- __STATIC_INLINE void nrf_twis_event_clear(NRF_TWIS_Type * p_reg,
- nrf_twis_event_t event);
- __STATIC_INLINE bool nrf_twis_event_check(NRF_TWIS_Type const * p_reg,
- nrf_twis_event_t event);
- __STATIC_INLINE bool nrf_twis_event_get_and_clear(NRF_TWIS_Type * p_reg,
- nrf_twis_event_t event);
- __STATIC_INLINE uint32_t nrf_twis_event_address_get(NRF_TWIS_Type const * p_reg,
- nrf_twis_event_t event);
- __STATIC_INLINE void nrf_twis_shorts_enable(NRF_TWIS_Type * p_reg, uint32_t mask);
- __STATIC_INLINE void nrf_twis_shorts_disable(NRF_TWIS_Type * p_reg, uint32_t mask);
- __STATIC_INLINE uint32_t nrf_twis_shorts_get(NRF_TWIS_Type const * p_reg);
- __STATIC_INLINE void nrf_twis_int_enable(NRF_TWIS_Type * p_reg, uint32_t mask);
- __STATIC_INLINE bool nrf_twis_int_enable_check(NRF_TWIS_Type const * p_reg, uint32_t mask);
- __STATIC_INLINE void nrf_twis_int_disable(NRF_TWIS_Type * p_reg, uint32_t mask);
- #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
- __STATIC_INLINE void nrf_twis_subscribe_set(NRF_TWIS_Type * p_reg,
- nrf_twis_task_t task,
- uint8_t channel);
- __STATIC_INLINE void nrf_twis_subscribe_clear(NRF_TWIS_Type * p_reg,
- nrf_twis_task_t task);
- __STATIC_INLINE void nrf_twis_publish_set(NRF_TWIS_Type * p_reg,
- nrf_twis_event_t event,
- uint8_t channel);
- __STATIC_INLINE void nrf_twis_publish_clear(NRF_TWIS_Type * p_reg,
- nrf_twis_event_t event);
- #endif
- __STATIC_INLINE uint32_t nrf_twis_error_source_get_and_clear(NRF_TWIS_Type * const p_reg);
- __STATIC_INLINE uint_fast8_t nrf_twis_match_get(NRF_TWIS_Type const * p_reg);
- __STATIC_INLINE void nrf_twis_enable(NRF_TWIS_Type * p_reg);
- __STATIC_INLINE void nrf_twis_disable(NRF_TWIS_Type * p_reg);
- __STATIC_INLINE void nrf_twis_pins_set(NRF_TWIS_Type * p_reg, uint32_t scl, uint32_t sda);
- __STATIC_INLINE void nrf_twis_rx_buffer_set(NRF_TWIS_Type * p_reg,
- uint8_t * p_buf,
- size_t length);
- __STATIC_INLINE void nrf_twis_rx_prepare(NRF_TWIS_Type * p_reg,
- uint8_t * p_buf,
- size_t length);
- __STATIC_INLINE size_t nrf_twis_rx_amount_get(NRF_TWIS_Type const * p_reg);
- __STATIC_INLINE void nrf_twis_tx_buffer_set(NRF_TWIS_Type * p_reg,
- uint8_t const * p_buf,
- size_t length);
- __STATIC_INLINE void nrf_twis_tx_prepare(NRF_TWIS_Type * p_reg,
- uint8_t const * p_buf,
- size_t length);
- __STATIC_INLINE size_t nrf_twis_tx_amount_get(NRF_TWIS_Type const * p_reg);
- __STATIC_INLINE void nrf_twis_address_set(NRF_TWIS_Type * p_reg,
- uint_fast8_t n,
- nrf_twis_address_t addr);
- __STATIC_INLINE nrf_twis_address_t nrf_twis_address_get(NRF_TWIS_Type const * p_reg,
- uint_fast8_t n);
- __STATIC_INLINE void nrf_twis_config_address_set(NRF_TWIS_Type * p_reg,
- nrf_twis_config_addr_mask_t addr_mask);
- __STATIC_INLINE nrf_twis_config_addr_mask_t nrf_twis_config_address_get(
- NRF_TWIS_Type const * p_reg);
- __STATIC_INLINE void nrf_twis_orc_set(NRF_TWIS_Type * p_reg,
- uint8_t orc);
- __STATIC_INLINE uint8_t nrf_twis_orc_get(NRF_TWIS_Type const * p_reg);
-
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE volatile uint32_t* nrf_twis_getRegPtr(NRF_TWIS_Type const * p_reg, uint32_t offset)
- {
- return (volatile uint32_t*)((uint8_t *)p_reg + (uint32_t)offset);
- }
- __STATIC_INLINE volatile const uint32_t* nrf_twis_getRegPtr_c(NRF_TWIS_Type const * p_reg,
- uint32_t offset)
- {
- return (volatile const uint32_t*)((uint8_t *)p_reg + (uint32_t)offset);
- }
- __STATIC_INLINE void nrf_twis_task_trigger(NRF_TWIS_Type * p_reg, nrf_twis_task_t task)
- {
- *(nrf_twis_getRegPtr(p_reg, (uint32_t)task)) = 1UL;
- }
- __STATIC_INLINE uint32_t nrf_twis_task_address_get(NRF_TWIS_Type const * p_reg,
- nrf_twis_task_t task)
- {
- return (uint32_t)nrf_twis_getRegPtr_c(p_reg, (uint32_t)task);
- }
- __STATIC_INLINE void nrf_twis_event_clear(NRF_TWIS_Type * p_reg, nrf_twis_event_t event)
- {
- *(nrf_twis_getRegPtr(p_reg, (uint32_t)event)) = 0UL;
- #if __CORTEX_M == 0x04
- volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event));
- (void)dummy;
- #endif
- }
- __STATIC_INLINE bool nrf_twis_event_check(NRF_TWIS_Type const * p_reg, nrf_twis_event_t event)
- {
- return (bool)*nrf_twis_getRegPtr_c(p_reg, (uint32_t)event);
- }
- __STATIC_INLINE bool nrf_twis_event_get_and_clear(NRF_TWIS_Type * p_reg, nrf_twis_event_t event)
- {
- bool ret = nrf_twis_event_check(p_reg, event);
- if (ret)
- {
- nrf_twis_event_clear(p_reg, event);
- }
- return ret;
- }
- __STATIC_INLINE uint32_t nrf_twis_event_address_get(NRF_TWIS_Type const * p_reg,
- nrf_twis_event_t event)
- {
- return (uint32_t)nrf_twis_getRegPtr_c(p_reg, (uint32_t)event);
- }
- __STATIC_INLINE void nrf_twis_shorts_enable(NRF_TWIS_Type * p_reg, uint32_t mask)
- {
- p_reg->SHORTS |= mask;
- }
- __STATIC_INLINE void nrf_twis_shorts_disable(NRF_TWIS_Type * p_reg, uint32_t mask)
- {
- if (~0U == mask)
- {
-
- p_reg->SHORTS = 0;
- }
- else
- {
- p_reg->SHORTS &= ~mask;
- }
- }
- __STATIC_INLINE uint32_t nrf_twis_shorts_get(NRF_TWIS_Type const * p_reg)
- {
- return p_reg->SHORTS;
- }
- __STATIC_INLINE void nrf_twis_int_enable(NRF_TWIS_Type * p_reg, uint32_t mask)
- {
- p_reg->INTENSET = mask;
- }
- __STATIC_INLINE bool nrf_twis_int_enable_check(NRF_TWIS_Type const * p_reg, uint32_t mask)
- {
- return (bool)(p_reg->INTENSET & mask);
- }
- __STATIC_INLINE void nrf_twis_int_disable(NRF_TWIS_Type * const p_reg, uint32_t mask)
- {
- p_reg->INTENCLR = mask;
- }
- #if defined(DPPI_PRESENT)
- __STATIC_INLINE void nrf_twis_subscribe_set(NRF_TWIS_Type * p_reg,
- nrf_twis_task_t task,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
- ((uint32_t)channel | TWIS_SUBSCRIBE_STOP_EN_Msk);
- }
- __STATIC_INLINE void nrf_twis_subscribe_clear(NRF_TWIS_Type * p_reg,
- nrf_twis_task_t task)
- {
- *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
- }
- __STATIC_INLINE void nrf_twis_publish_set(NRF_TWIS_Type * p_reg,
- nrf_twis_event_t event,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) =
- ((uint32_t)channel | TWIS_PUBLISH_STOPPED_EN_Msk);
- }
- __STATIC_INLINE void nrf_twis_publish_clear(NRF_TWIS_Type * p_reg,
- nrf_twis_event_t event)
- {
- *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = 0;
- }
- #endif
- __STATIC_INLINE uint32_t nrf_twis_error_source_get_and_clear(NRF_TWIS_Type * p_reg)
- {
- uint32_t ret = p_reg->ERRORSRC;
- p_reg->ERRORSRC = ret;
- return ret;
- }
- __STATIC_INLINE uint_fast8_t nrf_twis_match_get(NRF_TWIS_Type const * p_reg)
- {
- return (uint_fast8_t)p_reg->MATCH;
- }
- __STATIC_INLINE void nrf_twis_enable(NRF_TWIS_Type * p_reg)
- {
- p_reg->ENABLE = (TWIS_ENABLE_ENABLE_Enabled << TWIS_ENABLE_ENABLE_Pos);
- }
- __STATIC_INLINE void nrf_twis_disable(NRF_TWIS_Type * p_reg)
- {
- p_reg->ENABLE = (TWIS_ENABLE_ENABLE_Disabled << TWIS_ENABLE_ENABLE_Pos);
- }
- __STATIC_INLINE void nrf_twis_pins_set(NRF_TWIS_Type * p_reg, uint32_t scl, uint32_t sda)
- {
- p_reg->PSEL.SCL = scl;
- p_reg->PSEL.SDA = sda;
- }
- __STATIC_INLINE void nrf_twis_rx_buffer_set(NRF_TWIS_Type * p_reg,
- uint8_t * p_buf,
- size_t length)
- {
- p_reg->RXD.PTR = (uint32_t)p_buf;
- p_reg->RXD.MAXCNT = length;
- }
- __STATIC_INLINE void nrf_twis_rx_prepare(NRF_TWIS_Type * p_reg,
- uint8_t * p_buf,
- size_t length)
- {
- nrf_twis_rx_buffer_set(p_reg, p_buf, length);
- nrf_twis_task_trigger(p_reg, NRF_TWIS_TASK_PREPARERX);
- }
- __STATIC_INLINE size_t nrf_twis_rx_amount_get(NRF_TWIS_Type const * p_reg)
- {
- return p_reg->RXD.AMOUNT;
- }
- __STATIC_INLINE void nrf_twis_tx_buffer_set(NRF_TWIS_Type * p_reg,
- uint8_t const * p_buf,
- size_t length)
- {
- p_reg->TXD.PTR = (uint32_t)p_buf;
- p_reg->TXD.MAXCNT = length;
- }
- __STATIC_INLINE void nrf_twis_tx_prepare(NRF_TWIS_Type * p_reg,
- uint8_t const * p_buf,
- size_t length)
- {
- nrf_twis_tx_buffer_set(p_reg, p_buf, length);
- nrf_twis_task_trigger(p_reg, NRF_TWIS_TASK_PREPARETX);
- }
- __STATIC_INLINE size_t nrf_twis_tx_amount_get(NRF_TWIS_Type const * p_reg)
- {
- return p_reg->TXD.AMOUNT;
- }
- __STATIC_INLINE void nrf_twis_address_set(NRF_TWIS_Type * p_reg,
- uint_fast8_t n,
- nrf_twis_address_t addr)
- {
- p_reg->ADDRESS[n] = addr;
- }
- __STATIC_INLINE nrf_twis_address_t nrf_twis_address_get(NRF_TWIS_Type const * p_reg, uint_fast8_t n)
- {
- return (nrf_twis_address_t)p_reg->ADDRESS[n];
- }
- __STATIC_INLINE void nrf_twis_config_address_set(NRF_TWIS_Type * p_reg,
- nrf_twis_config_addr_mask_t addr_mask)
- {
-
- p_reg->CONFIG = addr_mask;
- }
- __STATIC_INLINE nrf_twis_config_addr_mask_t nrf_twis_config_address_get(NRF_TWIS_Type const * p_reg)
- {
- return (nrf_twis_config_addr_mask_t)(p_reg->CONFIG & TWIS_ADDRESS_ADDRESS_Msk);
- }
- __STATIC_INLINE void nrf_twis_orc_set(NRF_TWIS_Type * p_reg, uint8_t orc)
- {
- p_reg->ORC = orc;
- }
- __STATIC_INLINE uint8_t nrf_twis_orc_get(NRF_TWIS_Type const * p_reg)
- {
- return (uint8_t)p_reg->ORC;
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|