The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_TY51822R3/TOOLCHAIN_IAR/nrf_twi.h@171:3a7713b1edbc, 2018-11-08 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Nov 08 11:45:42 2018 +0000
- Revision:
- 171:3a7713b1edbc
- Parent:
- TARGET_TY51822R3/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/drivers_nrf/hal/nrf_twi.h@169:a7c7b631e539
mbed library. Release version 164
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 143:86740a56073b | 1 | /* |
AnnaBridge | 143:86740a56073b | 2 | * Copyright (c) 2015 Nordic Semiconductor ASA |
AnnaBridge | 143:86740a56073b | 3 | * All rights reserved. |
AnnaBridge | 143:86740a56073b | 4 | * |
AnnaBridge | 143:86740a56073b | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 143:86740a56073b | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 143:86740a56073b | 7 | * |
AnnaBridge | 143:86740a56073b | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 143:86740a56073b | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 143:86740a56073b | 10 | * |
AnnaBridge | 143:86740a56073b | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
AnnaBridge | 143:86740a56073b | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
AnnaBridge | 143:86740a56073b | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
AnnaBridge | 143:86740a56073b | 14 | * the documentation and/or other materials provided with the distribution. |
AnnaBridge | 143:86740a56073b | 15 | * |
AnnaBridge | 143:86740a56073b | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
AnnaBridge | 143:86740a56073b | 17 | * used to endorse or promote products derived from this software without specific prior |
AnnaBridge | 143:86740a56073b | 18 | * written permission. |
AnnaBridge | 143:86740a56073b | 19 | * |
AnnaBridge | 143:86740a56073b | 20 | * 4. This software, with or without modification, must only be used with a |
AnnaBridge | 143:86740a56073b | 21 | * Nordic Semiconductor ASA integrated circuit. |
AnnaBridge | 143:86740a56073b | 22 | * |
AnnaBridge | 143:86740a56073b | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
AnnaBridge | 143:86740a56073b | 24 | * engineered, decompiled, modified and/or disassembled. |
AnnaBridge | 143:86740a56073b | 25 | * |
AnnaBridge | 143:86740a56073b | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 143:86740a56073b | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 143:86740a56073b | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 143:86740a56073b | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 143:86740a56073b | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 143:86740a56073b | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 143:86740a56073b | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 143:86740a56073b | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 143:86740a56073b | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 143:86740a56073b | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 143:86740a56073b | 36 | * |
AnnaBridge | 143:86740a56073b | 37 | */ |
AnnaBridge | 143:86740a56073b | 38 | |
AnnaBridge | 143:86740a56073b | 39 | |
AnnaBridge | 143:86740a56073b | 40 | #ifndef NRF_TWI_H__ |
AnnaBridge | 143:86740a56073b | 41 | #define NRF_TWI_H__ |
AnnaBridge | 143:86740a56073b | 42 | |
AnnaBridge | 143:86740a56073b | 43 | /** |
AnnaBridge | 143:86740a56073b | 44 | * @defgroup nrf_twi_hal TWI HAL |
AnnaBridge | 143:86740a56073b | 45 | * @{ |
AnnaBridge | 143:86740a56073b | 46 | * @ingroup nrf_twi_master |
AnnaBridge | 143:86740a56073b | 47 | * |
AnnaBridge | 143:86740a56073b | 48 | * @brief Hardware access layer for managing the TWI peripheral. |
AnnaBridge | 143:86740a56073b | 49 | */ |
AnnaBridge | 143:86740a56073b | 50 | |
AnnaBridge | 143:86740a56073b | 51 | #include <stdint.h> |
AnnaBridge | 143:86740a56073b | 52 | #include <stddef.h> |
AnnaBridge | 143:86740a56073b | 53 | #include <stdbool.h> |
AnnaBridge | 143:86740a56073b | 54 | |
AnnaBridge | 143:86740a56073b | 55 | #include "nrf.h" |
AnnaBridge | 143:86740a56073b | 56 | |
AnnaBridge | 143:86740a56073b | 57 | /** |
AnnaBridge | 143:86740a56073b | 58 | * @brief TWI tasks. |
AnnaBridge | 143:86740a56073b | 59 | */ |
AnnaBridge | 143:86740a56073b | 60 | typedef enum |
AnnaBridge | 143:86740a56073b | 61 | { |
AnnaBridge | 143:86740a56073b | 62 | /*lint -save -e30*/ |
AnnaBridge | 143:86740a56073b | 63 | NRF_TWI_TASK_STARTRX = offsetof(NRF_TWI_Type, TASKS_STARTRX), ///< Start TWI receive sequence. |
AnnaBridge | 143:86740a56073b | 64 | NRF_TWI_TASK_STARTTX = offsetof(NRF_TWI_Type, TASKS_STARTTX), ///< Start TWI transmit sequence. |
AnnaBridge | 143:86740a56073b | 65 | NRF_TWI_TASK_STOP = offsetof(NRF_TWI_Type, TASKS_STOP), ///< Stop TWI transaction. |
AnnaBridge | 143:86740a56073b | 66 | NRF_TWI_TASK_SUSPEND = offsetof(NRF_TWI_Type, TASKS_SUSPEND), ///< Suspend TWI transaction. |
AnnaBridge | 143:86740a56073b | 67 | NRF_TWI_TASK_RESUME = offsetof(NRF_TWI_Type, TASKS_RESUME) ///< Resume TWI transaction. |
AnnaBridge | 143:86740a56073b | 68 | /*lint -restore*/ |
AnnaBridge | 143:86740a56073b | 69 | } nrf_twi_task_t; |
AnnaBridge | 143:86740a56073b | 70 | |
AnnaBridge | 143:86740a56073b | 71 | /** |
AnnaBridge | 143:86740a56073b | 72 | * @brief TWI events. |
AnnaBridge | 143:86740a56073b | 73 | */ |
AnnaBridge | 143:86740a56073b | 74 | typedef enum |
AnnaBridge | 143:86740a56073b | 75 | { |
AnnaBridge | 143:86740a56073b | 76 | /*lint -save -e30*/ |
AnnaBridge | 143:86740a56073b | 77 | NRF_TWI_EVENT_STOPPED = offsetof(NRF_TWI_Type, EVENTS_STOPPED), ///< TWI stopped. |
AnnaBridge | 143:86740a56073b | 78 | NRF_TWI_EVENT_RXDREADY = offsetof(NRF_TWI_Type, EVENTS_RXDREADY), ///< TWI RXD byte received. |
AnnaBridge | 143:86740a56073b | 79 | NRF_TWI_EVENT_TXDSENT = offsetof(NRF_TWI_Type, EVENTS_TXDSENT), ///< TWI TXD byte sent. |
AnnaBridge | 143:86740a56073b | 80 | NRF_TWI_EVENT_ERROR = offsetof(NRF_TWI_Type, EVENTS_ERROR), ///< TWI error. |
AnnaBridge | 143:86740a56073b | 81 | NRF_TWI_EVENT_BB = offsetof(NRF_TWI_Type, EVENTS_BB), ///< TWI byte boundary, generated before each byte that is sent or received. |
AnnaBridge | 143:86740a56073b | 82 | NRF_TWI_EVENT_SUSPENDED = offsetof(NRF_TWI_Type, EVENTS_SUSPENDED) ///< TWI entered the suspended state. |
AnnaBridge | 143:86740a56073b | 83 | /*lint -restore*/ |
AnnaBridge | 143:86740a56073b | 84 | } nrf_twi_event_t; |
AnnaBridge | 143:86740a56073b | 85 | |
AnnaBridge | 143:86740a56073b | 86 | /** |
AnnaBridge | 143:86740a56073b | 87 | * @brief TWI shortcuts. |
AnnaBridge | 143:86740a56073b | 88 | */ |
AnnaBridge | 143:86740a56073b | 89 | typedef enum |
AnnaBridge | 143:86740a56073b | 90 | { |
AnnaBridge | 143:86740a56073b | 91 | NRF_TWI_SHORT_BB_SUSPEND_MASK = TWI_SHORTS_BB_SUSPEND_Msk, ///< Shortcut between BB event and SUSPEND task. |
AnnaBridge | 143:86740a56073b | 92 | NRF_TWI_SHORT_BB_STOP_MASK = TWI_SHORTS_BB_STOP_Msk, ///< Shortcut between BB event and STOP task. |
AnnaBridge | 143:86740a56073b | 93 | } nrf_twi_short_mask_t; |
AnnaBridge | 143:86740a56073b | 94 | |
AnnaBridge | 143:86740a56073b | 95 | /** |
AnnaBridge | 143:86740a56073b | 96 | * @brief TWI interrupts. |
AnnaBridge | 143:86740a56073b | 97 | */ |
AnnaBridge | 143:86740a56073b | 98 | typedef enum |
AnnaBridge | 143:86740a56073b | 99 | { |
AnnaBridge | 143:86740a56073b | 100 | NRF_TWI_INT_STOPPED_MASK = TWI_INTENSET_STOPPED_Msk, ///< Interrupt on STOPPED event. |
AnnaBridge | 143:86740a56073b | 101 | NRF_TWI_INT_RXDREADY_MASK = TWI_INTENSET_RXDREADY_Msk, ///< Interrupt on RXDREADY event. |
AnnaBridge | 143:86740a56073b | 102 | NRF_TWI_INT_TXDSENT_MASK = TWI_INTENSET_TXDSENT_Msk, ///< Interrupt on TXDSENT event. |
AnnaBridge | 143:86740a56073b | 103 | NRF_TWI_INT_ERROR_MASK = TWI_INTENSET_ERROR_Msk, ///< Interrupt on ERROR event. |
AnnaBridge | 143:86740a56073b | 104 | NRF_TWI_INT_BB_MASK = TWI_INTENSET_BB_Msk, ///< Interrupt on BB event. |
AnnaBridge | 143:86740a56073b | 105 | NRF_TWI_INT_SUSPENDED_MASK = TWI_INTENSET_SUSPENDED_Msk ///< Interrupt on SUSPENDED event. |
AnnaBridge | 143:86740a56073b | 106 | } nrf_twi_int_mask_t; |
AnnaBridge | 143:86740a56073b | 107 | |
AnnaBridge | 143:86740a56073b | 108 | /** |
AnnaBridge | 143:86740a56073b | 109 | * @brief TWI error source. |
AnnaBridge | 143:86740a56073b | 110 | */ |
AnnaBridge | 143:86740a56073b | 111 | typedef enum |
AnnaBridge | 143:86740a56073b | 112 | { |
AnnaBridge | 143:86740a56073b | 113 | NRF_TWI_ERROR_ADDRESS_NACK = TWI_ERRORSRC_ANACK_Msk, ///< NACK received after sending the address. |
AnnaBridge | 143:86740a56073b | 114 | NRF_TWI_ERROR_DATA_NACK = TWI_ERRORSRC_DNACK_Msk, ///< NACK received after sending a data byte. |
AnnaBridge | 143:86740a56073b | 115 | NRF_TWI_ERROR_OVERRUN = TWI_ERRORSRC_OVERRUN_Msk ///< Overrun error. |
AnnaBridge | 143:86740a56073b | 116 | /**< A new byte was received before the previous byte was read |
AnnaBridge | 143:86740a56073b | 117 | * from the RXD register (previous data is lost). */ |
AnnaBridge | 143:86740a56073b | 118 | } nrf_twi_error_t; |
AnnaBridge | 143:86740a56073b | 119 | |
AnnaBridge | 143:86740a56073b | 120 | /** |
AnnaBridge | 143:86740a56073b | 121 | * @brief TWI master clock frequency. |
AnnaBridge | 143:86740a56073b | 122 | */ |
AnnaBridge | 143:86740a56073b | 123 | typedef enum |
AnnaBridge | 143:86740a56073b | 124 | { |
AnnaBridge | 143:86740a56073b | 125 | NRF_TWI_FREQ_100K = TWI_FREQUENCY_FREQUENCY_K100, ///< 100 kbps. |
AnnaBridge | 143:86740a56073b | 126 | NRF_TWI_FREQ_250K = TWI_FREQUENCY_FREQUENCY_K250, ///< 250 kbps. |
AnnaBridge | 143:86740a56073b | 127 | NRF_TWI_FREQ_400K = TWI_FREQUENCY_FREQUENCY_K400 ///< 400 kbps. |
AnnaBridge | 143:86740a56073b | 128 | } nrf_twi_frequency_t; |
AnnaBridge | 143:86740a56073b | 129 | |
AnnaBridge | 143:86740a56073b | 130 | |
AnnaBridge | 143:86740a56073b | 131 | /** |
AnnaBridge | 143:86740a56073b | 132 | * @brief Function for activating a specific TWI task. |
AnnaBridge | 143:86740a56073b | 133 | * |
AnnaBridge | 143:86740a56073b | 134 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 135 | * @param[in] task Task to activate. |
AnnaBridge | 143:86740a56073b | 136 | */ |
AnnaBridge | 143:86740a56073b | 137 | __STATIC_INLINE void nrf_twi_task_trigger(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 138 | nrf_twi_task_t task); |
AnnaBridge | 143:86740a56073b | 139 | |
AnnaBridge | 143:86740a56073b | 140 | /** |
AnnaBridge | 143:86740a56073b | 141 | * @brief Function for getting the address of a specific TWI task register. |
AnnaBridge | 143:86740a56073b | 142 | * |
AnnaBridge | 143:86740a56073b | 143 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 144 | * @param[in] task Requested task. |
AnnaBridge | 143:86740a56073b | 145 | * |
AnnaBridge | 143:86740a56073b | 146 | * @return Address of the specified task register. |
AnnaBridge | 143:86740a56073b | 147 | */ |
AnnaBridge | 143:86740a56073b | 148 | __STATIC_INLINE uint32_t * nrf_twi_task_address_get(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 149 | nrf_twi_task_t task); |
AnnaBridge | 143:86740a56073b | 150 | |
AnnaBridge | 143:86740a56073b | 151 | /** |
AnnaBridge | 143:86740a56073b | 152 | * @brief Function for clearing a specific TWI event. |
AnnaBridge | 143:86740a56073b | 153 | * |
AnnaBridge | 143:86740a56073b | 154 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 155 | * @param[in] event Event to clear. |
AnnaBridge | 143:86740a56073b | 156 | */ |
AnnaBridge | 143:86740a56073b | 157 | __STATIC_INLINE void nrf_twi_event_clear(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 158 | nrf_twi_event_t event); |
AnnaBridge | 143:86740a56073b | 159 | |
AnnaBridge | 143:86740a56073b | 160 | /** |
AnnaBridge | 143:86740a56073b | 161 | * @brief Function for checking the state of a specific event. |
AnnaBridge | 143:86740a56073b | 162 | * |
AnnaBridge | 143:86740a56073b | 163 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 164 | * @param[in] event Event to check. |
AnnaBridge | 143:86740a56073b | 165 | * |
AnnaBridge | 143:86740a56073b | 166 | * @retval true If the event is set. |
AnnaBridge | 143:86740a56073b | 167 | * @retval false If the event is not set. |
AnnaBridge | 143:86740a56073b | 168 | */ |
AnnaBridge | 143:86740a56073b | 169 | __STATIC_INLINE bool nrf_twi_event_check(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 170 | nrf_twi_event_t event); |
AnnaBridge | 143:86740a56073b | 171 | |
AnnaBridge | 143:86740a56073b | 172 | /** |
AnnaBridge | 143:86740a56073b | 173 | * @brief Function for getting the address of a specific TWI event register. |
AnnaBridge | 143:86740a56073b | 174 | * |
AnnaBridge | 143:86740a56073b | 175 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 176 | * @param[in] event Requested event. |
AnnaBridge | 143:86740a56073b | 177 | * |
AnnaBridge | 143:86740a56073b | 178 | * @return Address of the specified event register. |
AnnaBridge | 143:86740a56073b | 179 | */ |
AnnaBridge | 143:86740a56073b | 180 | __STATIC_INLINE uint32_t * nrf_twi_event_address_get(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 181 | nrf_twi_event_t event); |
AnnaBridge | 143:86740a56073b | 182 | |
AnnaBridge | 143:86740a56073b | 183 | /** |
AnnaBridge | 143:86740a56073b | 184 | * @brief Function for enabling specified shortcuts. |
AnnaBridge | 143:86740a56073b | 185 | * |
AnnaBridge | 143:86740a56073b | 186 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 187 | * @param[in] shorts_mask Shortcuts to enable. |
AnnaBridge | 143:86740a56073b | 188 | */ |
AnnaBridge | 143:86740a56073b | 189 | __STATIC_INLINE void nrf_twi_shorts_enable(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 190 | uint32_t shorts_mask); |
AnnaBridge | 143:86740a56073b | 191 | |
AnnaBridge | 143:86740a56073b | 192 | /** |
AnnaBridge | 143:86740a56073b | 193 | * @brief Function for disabling specified shortcuts. |
AnnaBridge | 143:86740a56073b | 194 | * |
AnnaBridge | 143:86740a56073b | 195 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 196 | * @param[in] shorts_mask Shortcuts to disable. |
AnnaBridge | 143:86740a56073b | 197 | */ |
AnnaBridge | 143:86740a56073b | 198 | __STATIC_INLINE void nrf_twi_shorts_disable(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 199 | uint32_t shorts_mask); |
AnnaBridge | 143:86740a56073b | 200 | |
AnnaBridge | 143:86740a56073b | 201 | /** |
AnnaBridge | 143:86740a56073b | 202 | * @brief Function for enabling specified interrupts. |
AnnaBridge | 143:86740a56073b | 203 | * |
AnnaBridge | 143:86740a56073b | 204 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 205 | * @param[in] int_mask Interrupts to enable. |
AnnaBridge | 143:86740a56073b | 206 | */ |
AnnaBridge | 143:86740a56073b | 207 | __STATIC_INLINE void nrf_twi_int_enable(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 208 | uint32_t int_mask); |
AnnaBridge | 143:86740a56073b | 209 | |
AnnaBridge | 143:86740a56073b | 210 | /** |
AnnaBridge | 143:86740a56073b | 211 | * @brief Function for disabling specified interrupts. |
AnnaBridge | 143:86740a56073b | 212 | * |
AnnaBridge | 143:86740a56073b | 213 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 214 | * @param[in] int_mask Interrupts to disable. |
AnnaBridge | 143:86740a56073b | 215 | */ |
AnnaBridge | 143:86740a56073b | 216 | __STATIC_INLINE void nrf_twi_int_disable(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 217 | uint32_t int_mask); |
AnnaBridge | 143:86740a56073b | 218 | |
AnnaBridge | 143:86740a56073b | 219 | /** |
AnnaBridge | 143:86740a56073b | 220 | * @brief Function for retrieving the state of a given interrupt. |
AnnaBridge | 143:86740a56073b | 221 | * |
AnnaBridge | 143:86740a56073b | 222 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 223 | * @param[in] int_mask Interrupt to check. |
AnnaBridge | 143:86740a56073b | 224 | * |
AnnaBridge | 143:86740a56073b | 225 | * @retval true If the interrupt is enabled. |
AnnaBridge | 143:86740a56073b | 226 | * @retval false If the interrupt is not enabled. |
AnnaBridge | 143:86740a56073b | 227 | */ |
AnnaBridge | 143:86740a56073b | 228 | __STATIC_INLINE bool nrf_twi_int_enable_check(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 229 | nrf_twi_int_mask_t int_mask); |
AnnaBridge | 143:86740a56073b | 230 | |
AnnaBridge | 143:86740a56073b | 231 | /** |
AnnaBridge | 143:86740a56073b | 232 | * @brief Function for enabling the TWI peripheral. |
AnnaBridge | 143:86740a56073b | 233 | * |
AnnaBridge | 143:86740a56073b | 234 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 235 | */ |
AnnaBridge | 143:86740a56073b | 236 | __STATIC_INLINE void nrf_twi_enable(NRF_TWI_Type * p_twi); |
AnnaBridge | 143:86740a56073b | 237 | |
AnnaBridge | 143:86740a56073b | 238 | /** |
AnnaBridge | 143:86740a56073b | 239 | * @brief Function for disabling the TWI peripheral. |
AnnaBridge | 143:86740a56073b | 240 | * |
AnnaBridge | 143:86740a56073b | 241 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 242 | */ |
AnnaBridge | 143:86740a56073b | 243 | __STATIC_INLINE void nrf_twi_disable(NRF_TWI_Type * p_twi); |
AnnaBridge | 143:86740a56073b | 244 | |
AnnaBridge | 143:86740a56073b | 245 | /** |
AnnaBridge | 143:86740a56073b | 246 | * @brief Function for configuring TWI pins. |
AnnaBridge | 143:86740a56073b | 247 | * |
AnnaBridge | 143:86740a56073b | 248 | * |
AnnaBridge | 143:86740a56073b | 249 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 250 | * @param[in] scl_pin SCL pin number. |
AnnaBridge | 143:86740a56073b | 251 | * @param[in] sda_pin SDA pin number. |
AnnaBridge | 143:86740a56073b | 252 | */ |
AnnaBridge | 143:86740a56073b | 253 | __STATIC_INLINE void nrf_twi_pins_set(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 254 | uint32_t scl_pin, |
AnnaBridge | 143:86740a56073b | 255 | uint32_t sda_pin); |
AnnaBridge | 143:86740a56073b | 256 | |
AnnaBridge | 143:86740a56073b | 257 | /** |
AnnaBridge | 143:86740a56073b | 258 | * @brief Function for setting the TWI master clock frequency. |
AnnaBridge | 143:86740a56073b | 259 | * |
AnnaBridge | 143:86740a56073b | 260 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 261 | * @param[in] frequency TWI frequency. |
AnnaBridge | 143:86740a56073b | 262 | */ |
AnnaBridge | 143:86740a56073b | 263 | __STATIC_INLINE void nrf_twi_frequency_set(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 264 | nrf_twi_frequency_t frequency); |
AnnaBridge | 143:86740a56073b | 265 | |
AnnaBridge | 143:86740a56073b | 266 | /** |
AnnaBridge | 143:86740a56073b | 267 | * @brief Function for checking the TWI error source. |
AnnaBridge | 143:86740a56073b | 268 | * |
AnnaBridge | 143:86740a56073b | 269 | * The error flags are cleared after reading. |
AnnaBridge | 143:86740a56073b | 270 | * |
AnnaBridge | 143:86740a56073b | 271 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 272 | * |
AnnaBridge | 143:86740a56073b | 273 | * @return Mask with error source flags. |
AnnaBridge | 143:86740a56073b | 274 | */ |
AnnaBridge | 143:86740a56073b | 275 | __STATIC_INLINE uint32_t nrf_twi_errorsrc_get_and_clear(NRF_TWI_Type * p_twi); |
AnnaBridge | 143:86740a56073b | 276 | |
AnnaBridge | 143:86740a56073b | 277 | /** |
AnnaBridge | 143:86740a56073b | 278 | * @brief Function for setting the address to be used in TWI transfers. |
AnnaBridge | 143:86740a56073b | 279 | * |
AnnaBridge | 143:86740a56073b | 280 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 281 | * @param[in] address Address to be used in transfers. |
AnnaBridge | 143:86740a56073b | 282 | */ |
AnnaBridge | 143:86740a56073b | 283 | __STATIC_INLINE void nrf_twi_address_set(NRF_TWI_Type * p_twi, uint8_t address); |
AnnaBridge | 143:86740a56073b | 284 | |
AnnaBridge | 143:86740a56073b | 285 | /** |
AnnaBridge | 143:86740a56073b | 286 | * @brief Function for reading data received by TWI. |
AnnaBridge | 143:86740a56073b | 287 | * |
AnnaBridge | 143:86740a56073b | 288 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 289 | * |
AnnaBridge | 143:86740a56073b | 290 | * @return Received data. |
AnnaBridge | 143:86740a56073b | 291 | */ |
AnnaBridge | 143:86740a56073b | 292 | __STATIC_INLINE uint8_t nrf_twi_rxd_get(NRF_TWI_Type * p_twi); |
AnnaBridge | 143:86740a56073b | 293 | |
AnnaBridge | 143:86740a56073b | 294 | /** |
AnnaBridge | 143:86740a56073b | 295 | * @brief Function for writing data to be transmitted by TWI. |
AnnaBridge | 143:86740a56073b | 296 | * |
AnnaBridge | 143:86740a56073b | 297 | * @param[in] p_twi TWI instance. |
AnnaBridge | 143:86740a56073b | 298 | * @param[in] data Data to be transmitted. |
AnnaBridge | 143:86740a56073b | 299 | */ |
AnnaBridge | 143:86740a56073b | 300 | __STATIC_INLINE void nrf_twi_txd_set(NRF_TWI_Type * p_twi, uint8_t data); |
AnnaBridge | 143:86740a56073b | 301 | |
AnnaBridge | 143:86740a56073b | 302 | __STATIC_INLINE void nrf_twi_shorts_set(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 303 | uint32_t shorts_mask); |
AnnaBridge | 143:86740a56073b | 304 | |
AnnaBridge | 143:86740a56073b | 305 | /** |
AnnaBridge | 143:86740a56073b | 306 | * @} |
AnnaBridge | 143:86740a56073b | 307 | */ |
AnnaBridge | 143:86740a56073b | 308 | |
AnnaBridge | 143:86740a56073b | 309 | |
AnnaBridge | 143:86740a56073b | 310 | #ifndef SUPPRESS_INLINE_IMPLEMENTATION |
AnnaBridge | 143:86740a56073b | 311 | |
AnnaBridge | 143:86740a56073b | 312 | __STATIC_INLINE void nrf_twi_task_trigger(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 313 | nrf_twi_task_t task) |
AnnaBridge | 143:86740a56073b | 314 | { |
AnnaBridge | 143:86740a56073b | 315 | *((volatile uint32_t *)((uint8_t *)p_twi + (uint32_t)task)) = 0x1UL; |
AnnaBridge | 143:86740a56073b | 316 | } |
AnnaBridge | 143:86740a56073b | 317 | |
AnnaBridge | 143:86740a56073b | 318 | __STATIC_INLINE uint32_t * nrf_twi_task_address_get(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 319 | nrf_twi_task_t task) |
AnnaBridge | 143:86740a56073b | 320 | { |
AnnaBridge | 143:86740a56073b | 321 | return (uint32_t *)((uint8_t *)p_twi + (uint32_t)task); |
AnnaBridge | 143:86740a56073b | 322 | } |
AnnaBridge | 143:86740a56073b | 323 | |
AnnaBridge | 143:86740a56073b | 324 | __STATIC_INLINE void nrf_twi_event_clear(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 325 | nrf_twi_event_t event) |
AnnaBridge | 143:86740a56073b | 326 | { |
AnnaBridge | 143:86740a56073b | 327 | *((volatile uint32_t *)((uint8_t *)p_twi + (uint32_t)event)) = 0x0UL; |
AnnaBridge | 143:86740a56073b | 328 | } |
AnnaBridge | 143:86740a56073b | 329 | |
AnnaBridge | 143:86740a56073b | 330 | __STATIC_INLINE bool nrf_twi_event_check(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 331 | nrf_twi_event_t event) |
AnnaBridge | 143:86740a56073b | 332 | { |
AnnaBridge | 143:86740a56073b | 333 | return (bool)*(volatile uint32_t *)((uint8_t *)p_twi + (uint32_t)event); |
AnnaBridge | 143:86740a56073b | 334 | } |
AnnaBridge | 143:86740a56073b | 335 | |
AnnaBridge | 143:86740a56073b | 336 | __STATIC_INLINE uint32_t * nrf_twi_event_address_get(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 337 | nrf_twi_event_t event) |
AnnaBridge | 143:86740a56073b | 338 | { |
AnnaBridge | 143:86740a56073b | 339 | return (uint32_t *)((uint8_t *)p_twi + (uint32_t)event); |
AnnaBridge | 143:86740a56073b | 340 | } |
AnnaBridge | 143:86740a56073b | 341 | |
AnnaBridge | 143:86740a56073b | 342 | __STATIC_INLINE void nrf_twi_shorts_enable(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 343 | uint32_t shorts_mask) |
AnnaBridge | 143:86740a56073b | 344 | { |
AnnaBridge | 143:86740a56073b | 345 | p_twi->SHORTS |= shorts_mask; |
AnnaBridge | 143:86740a56073b | 346 | } |
AnnaBridge | 143:86740a56073b | 347 | |
AnnaBridge | 143:86740a56073b | 348 | __STATIC_INLINE void nrf_twi_shorts_disable(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 349 | uint32_t shorts_mask) |
AnnaBridge | 143:86740a56073b | 350 | { |
AnnaBridge | 143:86740a56073b | 351 | p_twi->SHORTS &= ~(shorts_mask); |
AnnaBridge | 143:86740a56073b | 352 | } |
AnnaBridge | 143:86740a56073b | 353 | |
AnnaBridge | 143:86740a56073b | 354 | __STATIC_INLINE void nrf_twi_int_enable(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 355 | uint32_t int_mask) |
AnnaBridge | 143:86740a56073b | 356 | { |
AnnaBridge | 143:86740a56073b | 357 | p_twi->INTENSET = int_mask; |
AnnaBridge | 143:86740a56073b | 358 | } |
AnnaBridge | 143:86740a56073b | 359 | |
AnnaBridge | 143:86740a56073b | 360 | __STATIC_INLINE void nrf_twi_int_disable(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 361 | uint32_t int_mask) |
AnnaBridge | 143:86740a56073b | 362 | { |
AnnaBridge | 143:86740a56073b | 363 | p_twi->INTENCLR = int_mask; |
AnnaBridge | 143:86740a56073b | 364 | } |
AnnaBridge | 143:86740a56073b | 365 | |
AnnaBridge | 143:86740a56073b | 366 | __STATIC_INLINE bool nrf_twi_int_enable_check(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 367 | nrf_twi_int_mask_t int_mask) |
AnnaBridge | 143:86740a56073b | 368 | { |
AnnaBridge | 143:86740a56073b | 369 | return (bool)(p_twi->INTENSET & int_mask); |
AnnaBridge | 143:86740a56073b | 370 | } |
AnnaBridge | 143:86740a56073b | 371 | |
AnnaBridge | 143:86740a56073b | 372 | __STATIC_INLINE void nrf_twi_enable(NRF_TWI_Type * p_twi) |
AnnaBridge | 143:86740a56073b | 373 | { |
AnnaBridge | 143:86740a56073b | 374 | p_twi->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos); |
AnnaBridge | 143:86740a56073b | 375 | } |
AnnaBridge | 143:86740a56073b | 376 | |
AnnaBridge | 143:86740a56073b | 377 | __STATIC_INLINE void nrf_twi_disable(NRF_TWI_Type * p_twi) |
AnnaBridge | 143:86740a56073b | 378 | { |
AnnaBridge | 143:86740a56073b | 379 | p_twi->ENABLE = (TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos); |
AnnaBridge | 143:86740a56073b | 380 | } |
AnnaBridge | 143:86740a56073b | 381 | |
AnnaBridge | 143:86740a56073b | 382 | __STATIC_INLINE void nrf_twi_pins_set(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 383 | uint32_t scl_pin, |
AnnaBridge | 143:86740a56073b | 384 | uint32_t sda_pin) |
AnnaBridge | 143:86740a56073b | 385 | { |
AnnaBridge | 143:86740a56073b | 386 | p_twi->PSELSCL = scl_pin; |
AnnaBridge | 143:86740a56073b | 387 | p_twi->PSELSDA = sda_pin; |
AnnaBridge | 143:86740a56073b | 388 | } |
AnnaBridge | 143:86740a56073b | 389 | |
AnnaBridge | 143:86740a56073b | 390 | __STATIC_INLINE void nrf_twi_frequency_set(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 391 | nrf_twi_frequency_t frequency) |
AnnaBridge | 143:86740a56073b | 392 | { |
AnnaBridge | 143:86740a56073b | 393 | p_twi->FREQUENCY = frequency; |
AnnaBridge | 143:86740a56073b | 394 | } |
AnnaBridge | 143:86740a56073b | 395 | |
AnnaBridge | 143:86740a56073b | 396 | __STATIC_INLINE uint32_t nrf_twi_errorsrc_get_and_clear(NRF_TWI_Type * p_twi) |
AnnaBridge | 143:86740a56073b | 397 | { |
AnnaBridge | 143:86740a56073b | 398 | uint32_t error_source = p_twi->ERRORSRC; |
AnnaBridge | 143:86740a56073b | 399 | |
AnnaBridge | 143:86740a56073b | 400 | // [error flags are cleared by writing '1' on their position] |
AnnaBridge | 143:86740a56073b | 401 | p_twi->ERRORSRC = error_source; |
AnnaBridge | 143:86740a56073b | 402 | |
AnnaBridge | 143:86740a56073b | 403 | return error_source; |
AnnaBridge | 143:86740a56073b | 404 | } |
AnnaBridge | 143:86740a56073b | 405 | |
AnnaBridge | 143:86740a56073b | 406 | __STATIC_INLINE void nrf_twi_address_set(NRF_TWI_Type * p_twi, uint8_t address) |
AnnaBridge | 143:86740a56073b | 407 | { |
AnnaBridge | 143:86740a56073b | 408 | p_twi->ADDRESS = address; |
AnnaBridge | 143:86740a56073b | 409 | } |
AnnaBridge | 143:86740a56073b | 410 | |
AnnaBridge | 143:86740a56073b | 411 | __STATIC_INLINE uint8_t nrf_twi_rxd_get(NRF_TWI_Type * p_twi) |
AnnaBridge | 143:86740a56073b | 412 | { |
AnnaBridge | 143:86740a56073b | 413 | return (uint8_t)p_twi->RXD; |
AnnaBridge | 143:86740a56073b | 414 | } |
AnnaBridge | 143:86740a56073b | 415 | |
AnnaBridge | 143:86740a56073b | 416 | __STATIC_INLINE void nrf_twi_txd_set(NRF_TWI_Type * p_twi, uint8_t data) |
AnnaBridge | 143:86740a56073b | 417 | { |
AnnaBridge | 143:86740a56073b | 418 | p_twi->TXD = data; |
AnnaBridge | 143:86740a56073b | 419 | } |
AnnaBridge | 143:86740a56073b | 420 | |
AnnaBridge | 143:86740a56073b | 421 | __STATIC_INLINE void nrf_twi_shorts_set(NRF_TWI_Type * p_twi, |
AnnaBridge | 143:86740a56073b | 422 | uint32_t shorts_mask) |
AnnaBridge | 143:86740a56073b | 423 | { |
AnnaBridge | 143:86740a56073b | 424 | p_twi->SHORTS = shorts_mask; |
AnnaBridge | 143:86740a56073b | 425 | } |
AnnaBridge | 143:86740a56073b | 426 | |
AnnaBridge | 143:86740a56073b | 427 | #endif // SUPPRESS_INLINE_IMPLEMENTATION |
AnnaBridge | 143:86740a56073b | 428 | |
AnnaBridge | 143:86740a56073b | 429 | #endif // NRF_TWI_H__ |