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.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_NRF51_DK/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/drivers_nrf/hal/nrf_spim.h@169:a7c7b631e539
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew 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 /**
AnnaBridge 143:86740a56073b 41 * @defgroup nrf_spim_hal SPIM HAL
AnnaBridge 143:86740a56073b 42 * @{
AnnaBridge 143:86740a56073b 43 * @ingroup nrf_spi_master
AnnaBridge 143:86740a56073b 44 *
AnnaBridge 143:86740a56073b 45 * @brief Hardware access layer for accessing the SPIM peripheral.
AnnaBridge 143:86740a56073b 46 */
AnnaBridge 143:86740a56073b 47
AnnaBridge 143:86740a56073b 48 #ifndef NRF_SPIM_H__
AnnaBridge 143:86740a56073b 49 #define NRF_SPIM_H__
AnnaBridge 143:86740a56073b 50
AnnaBridge 143:86740a56073b 51 #include <stddef.h>
AnnaBridge 143:86740a56073b 52 #include <stdbool.h>
AnnaBridge 143:86740a56073b 53 #include <stdint.h>
AnnaBridge 143:86740a56073b 54
AnnaBridge 143:86740a56073b 55 #include "nrf.h"
AnnaBridge 143:86740a56073b 56
AnnaBridge 143:86740a56073b 57
AnnaBridge 143:86740a56073b 58 /**
AnnaBridge 143:86740a56073b 59 * @brief This value can be used as a parameter for the @ref nrf_spim_pins_set
AnnaBridge 143:86740a56073b 60 * function to specify that a given SPI signal (SCK, MOSI, or MISO)
AnnaBridge 143:86740a56073b 61 * shall not be connected to a physical pin.
AnnaBridge 143:86740a56073b 62 */
AnnaBridge 143:86740a56073b 63 #define NRF_SPIM_PIN_NOT_CONNECTED 0xFFFFFFFF
AnnaBridge 143:86740a56073b 64
AnnaBridge 143:86740a56073b 65
AnnaBridge 143:86740a56073b 66 /**
AnnaBridge 143:86740a56073b 67 * @brief SPIM tasks.
AnnaBridge 143:86740a56073b 68 */
AnnaBridge 143:86740a56073b 69 typedef enum
AnnaBridge 143:86740a56073b 70 {
AnnaBridge 143:86740a56073b 71 /*lint -save -e30*/
AnnaBridge 143:86740a56073b 72 NRF_SPIM_TASK_START = offsetof(NRF_SPIM_Type, TASKS_START), ///< Start SPI transaction.
AnnaBridge 143:86740a56073b 73 NRF_SPIM_TASK_STOP = offsetof(NRF_SPIM_Type, TASKS_STOP), ///< Stop SPI transaction.
AnnaBridge 143:86740a56073b 74 NRF_SPIM_TASK_SUSPEND = offsetof(NRF_SPIM_Type, TASKS_SUSPEND), ///< Suspend SPI transaction.
AnnaBridge 143:86740a56073b 75 NRF_SPIM_TASK_RESUME = offsetof(NRF_SPIM_Type, TASKS_RESUME) ///< Resume SPI transaction.
AnnaBridge 143:86740a56073b 76 /*lint -restore*/
AnnaBridge 143:86740a56073b 77 } nrf_spim_task_t;
AnnaBridge 143:86740a56073b 78
AnnaBridge 143:86740a56073b 79 /**
AnnaBridge 143:86740a56073b 80 * @brief SPIM events.
AnnaBridge 143:86740a56073b 81 */
AnnaBridge 143:86740a56073b 82 typedef enum
AnnaBridge 143:86740a56073b 83 {
AnnaBridge 143:86740a56073b 84 /*lint -save -e30*/
AnnaBridge 143:86740a56073b 85 NRF_SPIM_EVENT_STOPPED = offsetof(NRF_SPIM_Type, EVENTS_STOPPED), ///< SPI transaction has stopped.
AnnaBridge 143:86740a56073b 86 NRF_SPIM_EVENT_ENDRX = offsetof(NRF_SPIM_Type, EVENTS_ENDRX), ///< End of RXD buffer reached.
AnnaBridge 143:86740a56073b 87 #ifdef NRF52
AnnaBridge 143:86740a56073b 88 NRF_SPIM_EVENT_END = offsetof(NRF_SPIM_Type, EVENTS_END), ///< End of RXD buffer and TXD buffer reached.
AnnaBridge 143:86740a56073b 89 #endif
AnnaBridge 143:86740a56073b 90 NRF_SPIM_EVENT_ENDTX = offsetof(NRF_SPIM_Type, EVENTS_ENDTX), ///< End of TXD buffer reached.
AnnaBridge 143:86740a56073b 91 NRF_SPIM_EVENT_STARTED = offsetof(NRF_SPIM_Type, EVENTS_STARTED) ///< Transaction started.
AnnaBridge 143:86740a56073b 92 /*lint -restore*/
AnnaBridge 143:86740a56073b 93 } nrf_spim_event_t;
AnnaBridge 143:86740a56073b 94
AnnaBridge 143:86740a56073b 95 #ifdef NRF52
AnnaBridge 143:86740a56073b 96 /**
AnnaBridge 143:86740a56073b 97 * @brief SPIM shortcuts.
AnnaBridge 143:86740a56073b 98 */
AnnaBridge 143:86740a56073b 99 typedef enum
AnnaBridge 143:86740a56073b 100 {
AnnaBridge 143:86740a56073b 101 NRF_SPIM_SHORT_END_START_MASK = SPIM_SHORTS_END_START_Msk ///< Shortcut between END event and START task.
AnnaBridge 143:86740a56073b 102 } nrf_spim_short_mask_t;
AnnaBridge 143:86740a56073b 103 #endif
AnnaBridge 143:86740a56073b 104
AnnaBridge 143:86740a56073b 105 /**
AnnaBridge 143:86740a56073b 106 * @brief SPIM interrupts.
AnnaBridge 143:86740a56073b 107 */
AnnaBridge 143:86740a56073b 108 typedef enum
AnnaBridge 143:86740a56073b 109 {
AnnaBridge 143:86740a56073b 110 NRF_SPIM_INT_STOPPED_MASK = SPIM_INTENSET_STOPPED_Msk, ///< Interrupt on STOPPED event.
AnnaBridge 143:86740a56073b 111 NRF_SPIM_INT_ENDRX_MASK = SPIM_INTENSET_ENDRX_Msk, ///< Interrupt on ENDRX event.
AnnaBridge 143:86740a56073b 112 #ifdef NRF52
AnnaBridge 143:86740a56073b 113 NRF_SPIM_INT_END_MASK = SPIM_INTENSET_END_Msk, ///< Interrupt on END event.
AnnaBridge 143:86740a56073b 114 #endif
AnnaBridge 143:86740a56073b 115 NRF_SPIM_INT_ENDTX_MASK = SPIM_INTENSET_ENDTX_Msk, ///< Interrupt on ENDTX event.
AnnaBridge 143:86740a56073b 116 NRF_SPIM_INT_STARTED_MASK = SPIM_INTENSET_STARTED_Msk ///< Interrupt on STARTED event.
AnnaBridge 143:86740a56073b 117 } nrf_spim_int_mask_t;
AnnaBridge 143:86740a56073b 118
AnnaBridge 143:86740a56073b 119 /**
AnnaBridge 143:86740a56073b 120 * @brief SPI master data rates.
AnnaBridge 143:86740a56073b 121 */
AnnaBridge 143:86740a56073b 122 typedef enum
AnnaBridge 143:86740a56073b 123 {
AnnaBridge 143:86740a56073b 124 NRF_SPIM_FREQ_125K = SPIM_FREQUENCY_FREQUENCY_K125, ///< 125 kbps.
AnnaBridge 143:86740a56073b 125 NRF_SPIM_FREQ_250K = SPIM_FREQUENCY_FREQUENCY_K250, ///< 250 kbps.
AnnaBridge 143:86740a56073b 126 NRF_SPIM_FREQ_500K = SPIM_FREQUENCY_FREQUENCY_K500, ///< 500 kbps.
AnnaBridge 143:86740a56073b 127 NRF_SPIM_FREQ_1M = SPIM_FREQUENCY_FREQUENCY_M1, ///< 1 Mbps.
AnnaBridge 143:86740a56073b 128 NRF_SPIM_FREQ_2M = SPIM_FREQUENCY_FREQUENCY_M2, ///< 2 Mbps.
AnnaBridge 143:86740a56073b 129 NRF_SPIM_FREQ_4M = SPIM_FREQUENCY_FREQUENCY_M4, ///< 4 Mbps.
AnnaBridge 143:86740a56073b 130 // [conversion to 'int' needed to prevent compilers from complaining
AnnaBridge 143:86740a56073b 131 // that the provided value (0x80000000UL) is out of range of "int"]
AnnaBridge 143:86740a56073b 132 NRF_SPIM_FREQ_8M = (int)SPIM_FREQUENCY_FREQUENCY_M8 ///< 8 Mbps.
AnnaBridge 143:86740a56073b 133 } nrf_spim_frequency_t;
AnnaBridge 143:86740a56073b 134
AnnaBridge 143:86740a56073b 135 /**
AnnaBridge 143:86740a56073b 136 * @brief SPI modes.
AnnaBridge 143:86740a56073b 137 */
AnnaBridge 143:86740a56073b 138 typedef enum
AnnaBridge 143:86740a56073b 139 {
AnnaBridge 143:86740a56073b 140 NRF_SPIM_MODE_0, ///< SCK active high, sample on leading edge of clock.
AnnaBridge 143:86740a56073b 141 NRF_SPIM_MODE_1, ///< SCK active high, sample on trailing edge of clock.
AnnaBridge 143:86740a56073b 142 NRF_SPIM_MODE_2, ///< SCK active low, sample on leading edge of clock.
AnnaBridge 143:86740a56073b 143 NRF_SPIM_MODE_3 ///< SCK active low, sample on trailing edge of clock.
AnnaBridge 143:86740a56073b 144 } nrf_spim_mode_t;
AnnaBridge 143:86740a56073b 145
AnnaBridge 143:86740a56073b 146 /**
AnnaBridge 143:86740a56073b 147 * @brief SPI bit orders.
AnnaBridge 143:86740a56073b 148 */
AnnaBridge 143:86740a56073b 149 typedef enum
AnnaBridge 143:86740a56073b 150 {
AnnaBridge 143:86740a56073b 151 NRF_SPIM_BIT_ORDER_MSB_FIRST = SPIM_CONFIG_ORDER_MsbFirst, ///< Most significant bit shifted out first.
AnnaBridge 143:86740a56073b 152 NRF_SPIM_BIT_ORDER_LSB_FIRST = SPIM_CONFIG_ORDER_LsbFirst ///< Least significant bit shifted out first.
AnnaBridge 143:86740a56073b 153 } nrf_spim_bit_order_t;
AnnaBridge 143:86740a56073b 154
AnnaBridge 143:86740a56073b 155
AnnaBridge 143:86740a56073b 156 /**
AnnaBridge 143:86740a56073b 157 * @brief Function for activating a specific SPIM task.
AnnaBridge 143:86740a56073b 158 *
AnnaBridge 143:86740a56073b 159 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 160 * @param[in] spim_task Task to activate.
AnnaBridge 143:86740a56073b 161 */
AnnaBridge 143:86740a56073b 162 __STATIC_INLINE void nrf_spim_task_trigger(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 163 nrf_spim_task_t spim_task);
AnnaBridge 143:86740a56073b 164
AnnaBridge 143:86740a56073b 165 /**
AnnaBridge 143:86740a56073b 166 * @brief Function for getting the address of a specific SPIM task register.
AnnaBridge 143:86740a56073b 167 *
AnnaBridge 143:86740a56073b 168 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 169 * @param[in] spim_task Requested task.
AnnaBridge 143:86740a56073b 170 *
AnnaBridge 143:86740a56073b 171 * @return Address of the specified task register.
AnnaBridge 143:86740a56073b 172 */
AnnaBridge 143:86740a56073b 173 __STATIC_INLINE uint32_t nrf_spim_task_address_get(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 174 nrf_spim_task_t spim_task);
AnnaBridge 143:86740a56073b 175
AnnaBridge 143:86740a56073b 176 /**
AnnaBridge 143:86740a56073b 177 * @brief Function for clearing a specific SPIM event.
AnnaBridge 143:86740a56073b 178 *
AnnaBridge 143:86740a56073b 179 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 180 * @param[in] spim_event Event to clear.
AnnaBridge 143:86740a56073b 181 */
AnnaBridge 143:86740a56073b 182 __STATIC_INLINE void nrf_spim_event_clear(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 183 nrf_spim_event_t spim_event);
AnnaBridge 143:86740a56073b 184
AnnaBridge 143:86740a56073b 185 /**
AnnaBridge 143:86740a56073b 186 * @brief Function for checking the state of a specific SPIM event.
AnnaBridge 143:86740a56073b 187 *
AnnaBridge 143:86740a56073b 188 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 189 * @param[in] spim_event Event to check.
AnnaBridge 143:86740a56073b 190 *
AnnaBridge 143:86740a56073b 191 * @retval true If the event is set.
AnnaBridge 143:86740a56073b 192 * @retval false If the event is not set.
AnnaBridge 143:86740a56073b 193 */
AnnaBridge 143:86740a56073b 194 __STATIC_INLINE bool nrf_spim_event_check(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 195 nrf_spim_event_t spim_event);
AnnaBridge 143:86740a56073b 196
AnnaBridge 143:86740a56073b 197 /**
AnnaBridge 143:86740a56073b 198 * @brief Function for getting the address of a specific SPIM event register.
AnnaBridge 143:86740a56073b 199 *
AnnaBridge 143:86740a56073b 200 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 201 * @param[in] spim_event Requested event.
AnnaBridge 143:86740a56073b 202 *
AnnaBridge 143:86740a56073b 203 * @return Address of the specified event register.
AnnaBridge 143:86740a56073b 204 */
AnnaBridge 143:86740a56073b 205 __STATIC_INLINE uint32_t nrf_spim_event_address_get(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 206 nrf_spim_event_t spim_event);
AnnaBridge 143:86740a56073b 207 #ifdef NRF52
AnnaBridge 143:86740a56073b 208 /**
AnnaBridge 143:86740a56073b 209 * @brief Function for enabling specified shortcuts.
AnnaBridge 143:86740a56073b 210 *
AnnaBridge 143:86740a56073b 211 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 212 * @param[in] spim_shorts_mask Shortcuts to enable.
AnnaBridge 143:86740a56073b 213 */
AnnaBridge 143:86740a56073b 214 __STATIC_INLINE void nrf_spim_shorts_enable(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 215 uint32_t spim_shorts_mask);
AnnaBridge 143:86740a56073b 216
AnnaBridge 143:86740a56073b 217 /**
AnnaBridge 143:86740a56073b 218 * @brief Function for disabling specified shortcuts.
AnnaBridge 143:86740a56073b 219 *
AnnaBridge 143:86740a56073b 220 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 221 * @param[in] spim_shorts_mask Shortcuts to disable.
AnnaBridge 143:86740a56073b 222 */
AnnaBridge 143:86740a56073b 223 __STATIC_INLINE void nrf_spim_shorts_disable(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 224 uint32_t spim_shorts_mask);
AnnaBridge 143:86740a56073b 225
AnnaBridge 143:86740a56073b 226 /**
AnnaBridge 143:86740a56073b 227 * @brief Function for getting shorts setting.
AnnaBridge 143:86740a56073b 228 *
AnnaBridge 143:86740a56073b 229 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 230 */
AnnaBridge 143:86740a56073b 231 __STATIC_INLINE uint32_t nrf_spim_shorts_get(NRF_SPIM_Type * p_spim);
AnnaBridge 143:86740a56073b 232 #endif
AnnaBridge 143:86740a56073b 233 /**
AnnaBridge 143:86740a56073b 234 * @brief Function for enabling specified interrupts.
AnnaBridge 143:86740a56073b 235 *
AnnaBridge 143:86740a56073b 236 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 237 * @param[in] spim_int_mask Interrupts to enable.
AnnaBridge 143:86740a56073b 238 */
AnnaBridge 143:86740a56073b 239 __STATIC_INLINE void nrf_spim_int_enable(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 240 uint32_t spim_int_mask);
AnnaBridge 143:86740a56073b 241
AnnaBridge 143:86740a56073b 242 /**
AnnaBridge 143:86740a56073b 243 * @brief Function for disabling specified interrupts.
AnnaBridge 143:86740a56073b 244 *
AnnaBridge 143:86740a56073b 245 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 246 * @param[in] spim_int_mask Interrupts to disable.
AnnaBridge 143:86740a56073b 247 */
AnnaBridge 143:86740a56073b 248 __STATIC_INLINE void nrf_spim_int_disable(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 249 uint32_t spim_int_mask);
AnnaBridge 143:86740a56073b 250
AnnaBridge 143:86740a56073b 251 /**
AnnaBridge 143:86740a56073b 252 * @brief Function for retrieving the state of a given interrupt.
AnnaBridge 143:86740a56073b 253 *
AnnaBridge 143:86740a56073b 254 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 255 * @param[in] spim_int Interrupt to check.
AnnaBridge 143:86740a56073b 256 *
AnnaBridge 143:86740a56073b 257 * @retval true If the interrupt is enabled.
AnnaBridge 143:86740a56073b 258 * @retval false If the interrupt is not enabled.
AnnaBridge 143:86740a56073b 259 */
AnnaBridge 143:86740a56073b 260 __STATIC_INLINE bool nrf_spim_int_enable_check(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 261 nrf_spim_int_mask_t spim_int);
AnnaBridge 143:86740a56073b 262
AnnaBridge 143:86740a56073b 263 /**
AnnaBridge 143:86740a56073b 264 * @brief Function for enabling the SPIM peripheral.
AnnaBridge 143:86740a56073b 265 *
AnnaBridge 143:86740a56073b 266 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 267 */
AnnaBridge 143:86740a56073b 268 __STATIC_INLINE void nrf_spim_enable(NRF_SPIM_Type * p_spim);
AnnaBridge 143:86740a56073b 269
AnnaBridge 143:86740a56073b 270 /**
AnnaBridge 143:86740a56073b 271 * @brief Function for disabling the SPIM peripheral.
AnnaBridge 143:86740a56073b 272 *
AnnaBridge 143:86740a56073b 273 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 274 */
AnnaBridge 143:86740a56073b 275 __STATIC_INLINE void nrf_spim_disable(NRF_SPIM_Type * p_spim);
AnnaBridge 143:86740a56073b 276
AnnaBridge 143:86740a56073b 277 /**
AnnaBridge 143:86740a56073b 278 * @brief Function for configuring SPIM pins.
AnnaBridge 143:86740a56073b 279 *
AnnaBridge 143:86740a56073b 280 * If a given signal is not needed, pass the @ref NRF_SPIM_PIN_NOT_CONNECTED
AnnaBridge 143:86740a56073b 281 * value instead of its pin number.
AnnaBridge 143:86740a56073b 282 *
AnnaBridge 143:86740a56073b 283 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 284 * @param[in] sck_pin SCK pin number.
AnnaBridge 143:86740a56073b 285 * @param[in] mosi_pin MOSI pin number.
AnnaBridge 143:86740a56073b 286 * @param[in] miso_pin MISO pin number.
AnnaBridge 143:86740a56073b 287 */
AnnaBridge 143:86740a56073b 288 __STATIC_INLINE void nrf_spim_pins_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 289 uint32_t sck_pin,
AnnaBridge 143:86740a56073b 290 uint32_t mosi_pin,
AnnaBridge 143:86740a56073b 291 uint32_t miso_pin);
AnnaBridge 143:86740a56073b 292
AnnaBridge 143:86740a56073b 293 /**
AnnaBridge 143:86740a56073b 294 * @brief Function for setting the SPI master data rate.
AnnaBridge 143:86740a56073b 295 *
AnnaBridge 143:86740a56073b 296 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 297 * @param[in] frequency SPI frequency.
AnnaBridge 143:86740a56073b 298 */
AnnaBridge 143:86740a56073b 299 __STATIC_INLINE void nrf_spim_frequency_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 300 nrf_spim_frequency_t frequency);
AnnaBridge 143:86740a56073b 301
AnnaBridge 143:86740a56073b 302 /**
AnnaBridge 143:86740a56073b 303 * @brief Function for setting the transmit buffer.
AnnaBridge 143:86740a56073b 304 *
AnnaBridge 143:86740a56073b 305 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 306 * @param[in] p_buffer Pointer to the buffer with data to send.
AnnaBridge 143:86740a56073b 307 * @param[in] length Maximum number of data bytes to transmit.
AnnaBridge 143:86740a56073b 308 */
AnnaBridge 143:86740a56073b 309 __STATIC_INLINE void nrf_spim_tx_buffer_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 310 uint8_t const * p_buffer,
AnnaBridge 143:86740a56073b 311 uint8_t length);
AnnaBridge 143:86740a56073b 312
AnnaBridge 143:86740a56073b 313 /**
AnnaBridge 143:86740a56073b 314 * @brief Function for setting the receive buffer.
AnnaBridge 143:86740a56073b 315 *
AnnaBridge 143:86740a56073b 316 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 317 * @param[in] p_buffer Pointer to the buffer for received data.
AnnaBridge 143:86740a56073b 318 * @param[in] length Maximum number of data bytes to receive.
AnnaBridge 143:86740a56073b 319 */
AnnaBridge 143:86740a56073b 320 __STATIC_INLINE void nrf_spim_rx_buffer_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 321 uint8_t * p_buffer,
AnnaBridge 143:86740a56073b 322 uint8_t length);
AnnaBridge 143:86740a56073b 323
AnnaBridge 143:86740a56073b 324 /**
AnnaBridge 143:86740a56073b 325 * @brief Function for setting the SPI configuration.
AnnaBridge 143:86740a56073b 326 *
AnnaBridge 143:86740a56073b 327 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 328 * @param[in] spi_mode SPI mode.
AnnaBridge 143:86740a56073b 329 * @param[in] spi_bit_order SPI bit order.
AnnaBridge 143:86740a56073b 330 */
AnnaBridge 143:86740a56073b 331 __STATIC_INLINE void nrf_spim_configure(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 332 nrf_spim_mode_t spi_mode,
AnnaBridge 143:86740a56073b 333 nrf_spim_bit_order_t spi_bit_order);
AnnaBridge 143:86740a56073b 334
AnnaBridge 143:86740a56073b 335 /**
AnnaBridge 143:86740a56073b 336 * @brief Function for setting the over-read character.
AnnaBridge 143:86740a56073b 337 *
AnnaBridge 143:86740a56073b 338 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 339 * @param[in] orc Over-read character that is clocked out in case of
AnnaBridge 143:86740a56073b 340 * an over-read of the TXD buffer.
AnnaBridge 143:86740a56073b 341 */
AnnaBridge 143:86740a56073b 342 __STATIC_INLINE void nrf_spim_orc_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 343 uint8_t orc);
AnnaBridge 143:86740a56073b 344
AnnaBridge 143:86740a56073b 345 #ifdef NRF52
AnnaBridge 143:86740a56073b 346 /**
AnnaBridge 143:86740a56073b 347 * @brief Function for enabling the TX list feature.
AnnaBridge 143:86740a56073b 348 *
AnnaBridge 143:86740a56073b 349 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 350 */
AnnaBridge 143:86740a56073b 351 __STATIC_INLINE void nrf_spim_tx_list_enable(NRF_SPIM_Type * p_spim);
AnnaBridge 143:86740a56073b 352
AnnaBridge 143:86740a56073b 353 /**
AnnaBridge 143:86740a56073b 354 * @brief Function for disabling the TX list feature.
AnnaBridge 143:86740a56073b 355 *
AnnaBridge 143:86740a56073b 356 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 357 */
AnnaBridge 143:86740a56073b 358 __STATIC_INLINE void nrf_spim_tx_list_disable(NRF_SPIM_Type * p_spim);
AnnaBridge 143:86740a56073b 359
AnnaBridge 143:86740a56073b 360 /**
AnnaBridge 143:86740a56073b 361 * @brief Function for enabling the RX list feature.
AnnaBridge 143:86740a56073b 362 *
AnnaBridge 143:86740a56073b 363 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 364 */
AnnaBridge 143:86740a56073b 365 __STATIC_INLINE void nrf_spim_rx_list_enable(NRF_SPIM_Type * p_spim);
AnnaBridge 143:86740a56073b 366
AnnaBridge 143:86740a56073b 367 /**
AnnaBridge 143:86740a56073b 368 * @brief Function for disabling the RX list feature.
AnnaBridge 143:86740a56073b 369 *
AnnaBridge 143:86740a56073b 370 * @param[in] p_spim SPIM instance.
AnnaBridge 143:86740a56073b 371 */
AnnaBridge 143:86740a56073b 372 __STATIC_INLINE void nrf_spim_rx_list_disable(NRF_SPIM_Type * p_spim);
AnnaBridge 143:86740a56073b 373 #endif
AnnaBridge 143:86740a56073b 374 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
AnnaBridge 143:86740a56073b 375
AnnaBridge 143:86740a56073b 376 __STATIC_INLINE void nrf_spim_task_trigger(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 377 nrf_spim_task_t spim_task)
AnnaBridge 143:86740a56073b 378 {
AnnaBridge 143:86740a56073b 379 *((volatile uint32_t *)((uint8_t *)p_spim + (uint32_t)spim_task)) = 0x1UL;
AnnaBridge 143:86740a56073b 380 }
AnnaBridge 143:86740a56073b 381
AnnaBridge 143:86740a56073b 382 __STATIC_INLINE uint32_t nrf_spim_task_address_get(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 383 nrf_spim_task_t spim_task)
AnnaBridge 143:86740a56073b 384 {
AnnaBridge 143:86740a56073b 385 return (uint32_t)((uint8_t *)p_spim + (uint32_t)spim_task);
AnnaBridge 143:86740a56073b 386 }
AnnaBridge 143:86740a56073b 387
AnnaBridge 143:86740a56073b 388 __STATIC_INLINE void nrf_spim_event_clear(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 389 nrf_spim_event_t spim_event)
AnnaBridge 143:86740a56073b 390 {
AnnaBridge 143:86740a56073b 391 *((volatile uint32_t *)((uint8_t *)p_spim + (uint32_t)spim_event)) = 0x0UL;
AnnaBridge 143:86740a56073b 392 }
AnnaBridge 143:86740a56073b 393
AnnaBridge 143:86740a56073b 394 __STATIC_INLINE bool nrf_spim_event_check(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 395 nrf_spim_event_t spim_event)
AnnaBridge 143:86740a56073b 396 {
AnnaBridge 143:86740a56073b 397 return (bool)*(volatile uint32_t *)((uint8_t *)p_spim + (uint32_t)spim_event);
AnnaBridge 143:86740a56073b 398 }
AnnaBridge 143:86740a56073b 399
AnnaBridge 143:86740a56073b 400 __STATIC_INLINE uint32_t nrf_spim_event_address_get(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 401 nrf_spim_event_t spim_event)
AnnaBridge 143:86740a56073b 402 {
AnnaBridge 143:86740a56073b 403 return (uint32_t)((uint8_t *)p_spim + (uint32_t)spim_event);
AnnaBridge 143:86740a56073b 404 }
AnnaBridge 143:86740a56073b 405
AnnaBridge 143:86740a56073b 406 #ifdef NRF52
AnnaBridge 143:86740a56073b 407 __STATIC_INLINE void nrf_spim_shorts_enable(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 408 uint32_t spim_shorts_mask)
AnnaBridge 143:86740a56073b 409 {
AnnaBridge 143:86740a56073b 410 p_spim->SHORTS |= spim_shorts_mask;
AnnaBridge 143:86740a56073b 411 }
AnnaBridge 143:86740a56073b 412
AnnaBridge 143:86740a56073b 413 __STATIC_INLINE void nrf_spim_shorts_disable(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 414 uint32_t spim_shorts_mask)
AnnaBridge 143:86740a56073b 415 {
AnnaBridge 143:86740a56073b 416 p_spim->SHORTS &= ~(spim_shorts_mask);
AnnaBridge 143:86740a56073b 417 }
AnnaBridge 143:86740a56073b 418
AnnaBridge 143:86740a56073b 419 __STATIC_INLINE uint32_t nrf_spim_shorts_get(NRF_SPIM_Type * p_spim)
AnnaBridge 143:86740a56073b 420 {
AnnaBridge 143:86740a56073b 421 return p_spim->SHORTS;
AnnaBridge 143:86740a56073b 422 }
AnnaBridge 143:86740a56073b 423 #endif
AnnaBridge 143:86740a56073b 424 __STATIC_INLINE void nrf_spim_int_enable(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 425 uint32_t spim_int_mask)
AnnaBridge 143:86740a56073b 426 {
AnnaBridge 143:86740a56073b 427 p_spim->INTENSET = spim_int_mask;
AnnaBridge 143:86740a56073b 428 }
AnnaBridge 143:86740a56073b 429
AnnaBridge 143:86740a56073b 430 __STATIC_INLINE void nrf_spim_int_disable(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 431 uint32_t spim_int_mask)
AnnaBridge 143:86740a56073b 432 {
AnnaBridge 143:86740a56073b 433 p_spim->INTENCLR = spim_int_mask;
AnnaBridge 143:86740a56073b 434 }
AnnaBridge 143:86740a56073b 435
AnnaBridge 143:86740a56073b 436 __STATIC_INLINE bool nrf_spim_int_enable_check(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 437 nrf_spim_int_mask_t spim_int)
AnnaBridge 143:86740a56073b 438 {
AnnaBridge 143:86740a56073b 439 return (bool)(p_spim->INTENSET & spim_int);
AnnaBridge 143:86740a56073b 440 }
AnnaBridge 143:86740a56073b 441
AnnaBridge 143:86740a56073b 442 __STATIC_INLINE void nrf_spim_enable(NRF_SPIM_Type * p_spim)
AnnaBridge 143:86740a56073b 443 {
AnnaBridge 143:86740a56073b 444 p_spim->ENABLE = (SPIM_ENABLE_ENABLE_Enabled << SPIM_ENABLE_ENABLE_Pos);
AnnaBridge 143:86740a56073b 445 }
AnnaBridge 143:86740a56073b 446
AnnaBridge 143:86740a56073b 447 __STATIC_INLINE void nrf_spim_disable(NRF_SPIM_Type * p_spim)
AnnaBridge 143:86740a56073b 448 {
AnnaBridge 143:86740a56073b 449 p_spim->ENABLE = (SPIM_ENABLE_ENABLE_Disabled << SPIM_ENABLE_ENABLE_Pos);
AnnaBridge 143:86740a56073b 450 }
AnnaBridge 143:86740a56073b 451
AnnaBridge 143:86740a56073b 452 __STATIC_INLINE void nrf_spim_pins_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 453 uint32_t sck_pin,
AnnaBridge 143:86740a56073b 454 uint32_t mosi_pin,
AnnaBridge 143:86740a56073b 455 uint32_t miso_pin)
AnnaBridge 143:86740a56073b 456 {
AnnaBridge 143:86740a56073b 457 p_spim->PSEL.SCK = sck_pin;
AnnaBridge 143:86740a56073b 458 p_spim->PSEL.MOSI = mosi_pin;
AnnaBridge 143:86740a56073b 459 p_spim->PSEL.MISO = miso_pin;
AnnaBridge 143:86740a56073b 460 }
AnnaBridge 143:86740a56073b 461
AnnaBridge 143:86740a56073b 462 __STATIC_INLINE void nrf_spim_frequency_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 463 nrf_spim_frequency_t frequency)
AnnaBridge 143:86740a56073b 464 {
AnnaBridge 143:86740a56073b 465 p_spim->FREQUENCY = frequency;
AnnaBridge 143:86740a56073b 466 }
AnnaBridge 143:86740a56073b 467
AnnaBridge 143:86740a56073b 468 __STATIC_INLINE void nrf_spim_tx_buffer_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 469 uint8_t const * p_buffer,
AnnaBridge 143:86740a56073b 470 uint8_t length)
AnnaBridge 143:86740a56073b 471 {
AnnaBridge 143:86740a56073b 472 p_spim->TXD.PTR = (uint32_t)p_buffer;
AnnaBridge 143:86740a56073b 473 p_spim->TXD.MAXCNT = length;
AnnaBridge 143:86740a56073b 474 }
AnnaBridge 143:86740a56073b 475
AnnaBridge 143:86740a56073b 476 __STATIC_INLINE void nrf_spim_rx_buffer_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 477 uint8_t * p_buffer,
AnnaBridge 143:86740a56073b 478 uint8_t length)
AnnaBridge 143:86740a56073b 479 {
AnnaBridge 143:86740a56073b 480 p_spim->RXD.PTR = (uint32_t)p_buffer;
AnnaBridge 143:86740a56073b 481 p_spim->RXD.MAXCNT = length;
AnnaBridge 143:86740a56073b 482 }
AnnaBridge 143:86740a56073b 483
AnnaBridge 143:86740a56073b 484 __STATIC_INLINE void nrf_spim_configure(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 485 nrf_spim_mode_t spi_mode,
AnnaBridge 143:86740a56073b 486 nrf_spim_bit_order_t spi_bit_order)
AnnaBridge 143:86740a56073b 487 {
AnnaBridge 143:86740a56073b 488 uint32_t config = (spi_bit_order == NRF_SPIM_BIT_ORDER_MSB_FIRST ?
AnnaBridge 143:86740a56073b 489 SPIM_CONFIG_ORDER_MsbFirst : SPIM_CONFIG_ORDER_LsbFirst);
AnnaBridge 143:86740a56073b 490 switch (spi_mode)
AnnaBridge 143:86740a56073b 491 {
AnnaBridge 143:86740a56073b 492 default:
AnnaBridge 143:86740a56073b 493 case NRF_SPIM_MODE_0:
AnnaBridge 143:86740a56073b 494 config |= (SPIM_CONFIG_CPOL_ActiveHigh << SPIM_CONFIG_CPOL_Pos) |
AnnaBridge 143:86740a56073b 495 (SPIM_CONFIG_CPHA_Leading << SPIM_CONFIG_CPHA_Pos);
AnnaBridge 143:86740a56073b 496 break;
AnnaBridge 143:86740a56073b 497
AnnaBridge 143:86740a56073b 498 case NRF_SPIM_MODE_1:
AnnaBridge 143:86740a56073b 499 config |= (SPIM_CONFIG_CPOL_ActiveHigh << SPIM_CONFIG_CPOL_Pos) |
AnnaBridge 143:86740a56073b 500 (SPIM_CONFIG_CPHA_Trailing << SPIM_CONFIG_CPHA_Pos);
AnnaBridge 143:86740a56073b 501 break;
AnnaBridge 143:86740a56073b 502
AnnaBridge 143:86740a56073b 503 case NRF_SPIM_MODE_2:
AnnaBridge 143:86740a56073b 504 config |= (SPIM_CONFIG_CPOL_ActiveLow << SPIM_CONFIG_CPOL_Pos) |
AnnaBridge 143:86740a56073b 505 (SPIM_CONFIG_CPHA_Leading << SPIM_CONFIG_CPHA_Pos);
AnnaBridge 143:86740a56073b 506 break;
AnnaBridge 143:86740a56073b 507
AnnaBridge 143:86740a56073b 508 case NRF_SPIM_MODE_3:
AnnaBridge 143:86740a56073b 509 config |= (SPIM_CONFIG_CPOL_ActiveLow << SPIM_CONFIG_CPOL_Pos) |
AnnaBridge 143:86740a56073b 510 (SPIM_CONFIG_CPHA_Trailing << SPIM_CONFIG_CPHA_Pos);
AnnaBridge 143:86740a56073b 511 break;
AnnaBridge 143:86740a56073b 512 }
AnnaBridge 143:86740a56073b 513 p_spim->CONFIG = config;
AnnaBridge 143:86740a56073b 514 }
AnnaBridge 143:86740a56073b 515
AnnaBridge 143:86740a56073b 516 __STATIC_INLINE void nrf_spim_orc_set(NRF_SPIM_Type * p_spim,
AnnaBridge 143:86740a56073b 517 uint8_t orc)
AnnaBridge 143:86740a56073b 518 {
AnnaBridge 143:86740a56073b 519 p_spim->ORC = orc;
AnnaBridge 143:86740a56073b 520 }
AnnaBridge 143:86740a56073b 521
AnnaBridge 143:86740a56073b 522 #ifdef NRF52
AnnaBridge 143:86740a56073b 523 __STATIC_INLINE void nrf_spim_tx_list_enable(NRF_SPIM_Type * p_spim)
AnnaBridge 143:86740a56073b 524 {
AnnaBridge 143:86740a56073b 525 p_spim->TXD.LIST = 1;
AnnaBridge 143:86740a56073b 526 }
AnnaBridge 143:86740a56073b 527
AnnaBridge 143:86740a56073b 528 __STATIC_INLINE void nrf_spim_tx_list_disable(NRF_SPIM_Type * p_spim)
AnnaBridge 143:86740a56073b 529 {
AnnaBridge 143:86740a56073b 530 p_spim->TXD.LIST = 0;
AnnaBridge 143:86740a56073b 531 }
AnnaBridge 143:86740a56073b 532
AnnaBridge 143:86740a56073b 533 __STATIC_INLINE void nrf_spim_rx_list_enable(NRF_SPIM_Type * p_spim)
AnnaBridge 143:86740a56073b 534 {
AnnaBridge 143:86740a56073b 535 p_spim->RXD.LIST = 1;
AnnaBridge 143:86740a56073b 536 }
AnnaBridge 143:86740a56073b 537
AnnaBridge 143:86740a56073b 538 __STATIC_INLINE void nrf_spim_rx_list_disable(NRF_SPIM_Type * p_spim)
AnnaBridge 143:86740a56073b 539 {
AnnaBridge 143:86740a56073b 540 p_spim->RXD.LIST = 0;
AnnaBridge 143:86740a56073b 541 }
AnnaBridge 143:86740a56073b 542 #endif
AnnaBridge 143:86740a56073b 543 #endif // SUPPRESS_INLINE_IMPLEMENTATION
AnnaBridge 143:86740a56073b 544
AnnaBridge 143:86740a56073b 545 #endif // NRF_SPIM_H__
AnnaBridge 143:86740a56073b 546
AnnaBridge 143:86740a56073b 547 /** @} */