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_spi.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 146:22da6e220af6 | 1 | /* |
AnnaBridge | 146:22da6e220af6 | 2 | * Copyright (c) 2015 Nordic Semiconductor ASA |
AnnaBridge | 146:22da6e220af6 | 3 | * All rights reserved. |
AnnaBridge | 146:22da6e220af6 | 4 | * |
AnnaBridge | 146:22da6e220af6 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 146:22da6e220af6 | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 146:22da6e220af6 | 7 | * |
AnnaBridge | 146:22da6e220af6 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 146:22da6e220af6 | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 146:22da6e220af6 | 10 | * |
AnnaBridge | 146:22da6e220af6 | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
AnnaBridge | 146:22da6e220af6 | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
AnnaBridge | 146:22da6e220af6 | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
AnnaBridge | 146:22da6e220af6 | 14 | * the documentation and/or other materials provided with the distribution. |
AnnaBridge | 146:22da6e220af6 | 15 | * |
AnnaBridge | 146:22da6e220af6 | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
AnnaBridge | 146:22da6e220af6 | 17 | * used to endorse or promote products derived from this software without specific prior |
AnnaBridge | 146:22da6e220af6 | 18 | * written permission. |
AnnaBridge | 146:22da6e220af6 | 19 | * |
AnnaBridge | 146:22da6e220af6 | 20 | * 4. This software, with or without modification, must only be used with a |
AnnaBridge | 146:22da6e220af6 | 21 | * Nordic Semiconductor ASA integrated circuit. |
AnnaBridge | 146:22da6e220af6 | 22 | * |
AnnaBridge | 146:22da6e220af6 | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
AnnaBridge | 146:22da6e220af6 | 24 | * engineered, decompiled, modified and/or disassembled. |
AnnaBridge | 146:22da6e220af6 | 25 | * |
AnnaBridge | 146:22da6e220af6 | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 146:22da6e220af6 | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 146:22da6e220af6 | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 146:22da6e220af6 | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 146:22da6e220af6 | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 146:22da6e220af6 | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 146:22da6e220af6 | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 146:22da6e220af6 | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 146:22da6e220af6 | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 146:22da6e220af6 | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 146:22da6e220af6 | 36 | * |
AnnaBridge | 146:22da6e220af6 | 37 | */ |
AnnaBridge | 146:22da6e220af6 | 38 | |
AnnaBridge | 146:22da6e220af6 | 39 | |
AnnaBridge | 146:22da6e220af6 | 40 | /** |
AnnaBridge | 146:22da6e220af6 | 41 | * @defgroup nrf_spi_hal SPI HAL |
AnnaBridge | 146:22da6e220af6 | 42 | * @{ |
AnnaBridge | 146:22da6e220af6 | 43 | * @ingroup nrf_spi_master |
AnnaBridge | 146:22da6e220af6 | 44 | * |
AnnaBridge | 146:22da6e220af6 | 45 | * @brief Hardware access layer for accessing the SPI peripheral. |
AnnaBridge | 146:22da6e220af6 | 46 | */ |
AnnaBridge | 146:22da6e220af6 | 47 | |
AnnaBridge | 146:22da6e220af6 | 48 | #ifndef NRF_SPI_H__ |
AnnaBridge | 146:22da6e220af6 | 49 | #define NRF_SPI_H__ |
AnnaBridge | 146:22da6e220af6 | 50 | |
AnnaBridge | 146:22da6e220af6 | 51 | #include <stddef.h> |
AnnaBridge | 146:22da6e220af6 | 52 | #include <stdbool.h> |
AnnaBridge | 146:22da6e220af6 | 53 | #include <stdint.h> |
AnnaBridge | 146:22da6e220af6 | 54 | |
AnnaBridge | 146:22da6e220af6 | 55 | #include "nrf.h" |
AnnaBridge | 146:22da6e220af6 | 56 | |
AnnaBridge | 146:22da6e220af6 | 57 | |
AnnaBridge | 146:22da6e220af6 | 58 | /** |
AnnaBridge | 146:22da6e220af6 | 59 | * @brief This value can be used as a parameter for the @ref nrf_spi_pins_set |
AnnaBridge | 146:22da6e220af6 | 60 | * function to specify that a given SPI signal (SCK, MOSI, or MISO) |
AnnaBridge | 146:22da6e220af6 | 61 | * shall not be connected to a physical pin. |
AnnaBridge | 146:22da6e220af6 | 62 | */ |
AnnaBridge | 146:22da6e220af6 | 63 | #define NRF_SPI_PIN_NOT_CONNECTED 0xFFFFFFFF |
AnnaBridge | 146:22da6e220af6 | 64 | |
AnnaBridge | 146:22da6e220af6 | 65 | |
AnnaBridge | 146:22da6e220af6 | 66 | /** |
AnnaBridge | 146:22da6e220af6 | 67 | * @brief SPI events. |
AnnaBridge | 146:22da6e220af6 | 68 | */ |
AnnaBridge | 146:22da6e220af6 | 69 | typedef enum |
AnnaBridge | 146:22da6e220af6 | 70 | { |
AnnaBridge | 146:22da6e220af6 | 71 | /*lint -save -e30*/ |
AnnaBridge | 146:22da6e220af6 | 72 | NRF_SPI_EVENT_READY = offsetof(NRF_SPI_Type, EVENTS_READY) ///< TXD byte sent and RXD byte received. |
AnnaBridge | 146:22da6e220af6 | 73 | /*lint -restore*/ |
AnnaBridge | 146:22da6e220af6 | 74 | } nrf_spi_event_t; |
AnnaBridge | 146:22da6e220af6 | 75 | |
AnnaBridge | 146:22da6e220af6 | 76 | /** |
AnnaBridge | 146:22da6e220af6 | 77 | * @brief SPI interrupts. |
AnnaBridge | 146:22da6e220af6 | 78 | */ |
AnnaBridge | 146:22da6e220af6 | 79 | typedef enum |
AnnaBridge | 146:22da6e220af6 | 80 | { |
AnnaBridge | 146:22da6e220af6 | 81 | NRF_SPI_INT_READY_MASK = SPI_INTENSET_READY_Msk ///< Interrupt on READY event. |
AnnaBridge | 146:22da6e220af6 | 82 | } nrf_spi_int_mask_t; |
AnnaBridge | 146:22da6e220af6 | 83 | |
AnnaBridge | 146:22da6e220af6 | 84 | /** |
AnnaBridge | 146:22da6e220af6 | 85 | * @brief SPI data rates. |
AnnaBridge | 146:22da6e220af6 | 86 | */ |
AnnaBridge | 146:22da6e220af6 | 87 | typedef enum |
AnnaBridge | 146:22da6e220af6 | 88 | { |
AnnaBridge | 146:22da6e220af6 | 89 | NRF_SPI_FREQ_125K = SPI_FREQUENCY_FREQUENCY_K125, ///< 125 kbps. |
AnnaBridge | 146:22da6e220af6 | 90 | NRF_SPI_FREQ_250K = SPI_FREQUENCY_FREQUENCY_K250, ///< 250 kbps. |
AnnaBridge | 146:22da6e220af6 | 91 | NRF_SPI_FREQ_500K = SPI_FREQUENCY_FREQUENCY_K500, ///< 500 kbps. |
AnnaBridge | 146:22da6e220af6 | 92 | NRF_SPI_FREQ_1M = SPI_FREQUENCY_FREQUENCY_M1, ///< 1 Mbps. |
AnnaBridge | 146:22da6e220af6 | 93 | NRF_SPI_FREQ_2M = SPI_FREQUENCY_FREQUENCY_M2, ///< 2 Mbps. |
AnnaBridge | 146:22da6e220af6 | 94 | NRF_SPI_FREQ_4M = SPI_FREQUENCY_FREQUENCY_M4, ///< 4 Mbps. |
AnnaBridge | 146:22da6e220af6 | 95 | // [conversion to 'int' needed to prevent compilers from complaining |
AnnaBridge | 146:22da6e220af6 | 96 | // that the provided value (0x80000000UL) is out of range of "int"] |
AnnaBridge | 146:22da6e220af6 | 97 | NRF_SPI_FREQ_8M = (int)SPI_FREQUENCY_FREQUENCY_M8 ///< 8 Mbps. |
AnnaBridge | 146:22da6e220af6 | 98 | } nrf_spi_frequency_t; |
AnnaBridge | 146:22da6e220af6 | 99 | |
AnnaBridge | 146:22da6e220af6 | 100 | /** |
AnnaBridge | 146:22da6e220af6 | 101 | * @brief SPI modes. |
AnnaBridge | 146:22da6e220af6 | 102 | */ |
AnnaBridge | 146:22da6e220af6 | 103 | typedef enum |
AnnaBridge | 146:22da6e220af6 | 104 | { |
AnnaBridge | 146:22da6e220af6 | 105 | NRF_SPI_MODE_0, ///< SCK active high, sample on leading edge of clock. |
AnnaBridge | 146:22da6e220af6 | 106 | NRF_SPI_MODE_1, ///< SCK active high, sample on trailing edge of clock. |
AnnaBridge | 146:22da6e220af6 | 107 | NRF_SPI_MODE_2, ///< SCK active low, sample on leading edge of clock. |
AnnaBridge | 146:22da6e220af6 | 108 | NRF_SPI_MODE_3 ///< SCK active low, sample on trailing edge of clock. |
AnnaBridge | 146:22da6e220af6 | 109 | } nrf_spi_mode_t; |
AnnaBridge | 146:22da6e220af6 | 110 | |
AnnaBridge | 146:22da6e220af6 | 111 | /** |
AnnaBridge | 146:22da6e220af6 | 112 | * @brief SPI bit orders. |
AnnaBridge | 146:22da6e220af6 | 113 | */ |
AnnaBridge | 146:22da6e220af6 | 114 | typedef enum |
AnnaBridge | 146:22da6e220af6 | 115 | { |
AnnaBridge | 146:22da6e220af6 | 116 | NRF_SPI_BIT_ORDER_MSB_FIRST = SPI_CONFIG_ORDER_MsbFirst, ///< Most significant bit shifted out first. |
AnnaBridge | 146:22da6e220af6 | 117 | NRF_SPI_BIT_ORDER_LSB_FIRST = SPI_CONFIG_ORDER_LsbFirst ///< Least significant bit shifted out first. |
AnnaBridge | 146:22da6e220af6 | 118 | } nrf_spi_bit_order_t; |
AnnaBridge | 146:22da6e220af6 | 119 | |
AnnaBridge | 146:22da6e220af6 | 120 | |
AnnaBridge | 146:22da6e220af6 | 121 | /** |
AnnaBridge | 146:22da6e220af6 | 122 | * @brief Function for clearing a specific SPI event. |
AnnaBridge | 146:22da6e220af6 | 123 | * |
AnnaBridge | 146:22da6e220af6 | 124 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 125 | * @param[in] spi_event Event to clear. |
AnnaBridge | 146:22da6e220af6 | 126 | */ |
AnnaBridge | 146:22da6e220af6 | 127 | __STATIC_INLINE void nrf_spi_event_clear(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 128 | nrf_spi_event_t spi_event); |
AnnaBridge | 146:22da6e220af6 | 129 | |
AnnaBridge | 146:22da6e220af6 | 130 | /** |
AnnaBridge | 146:22da6e220af6 | 131 | * @brief Function for checking the state of a specific SPI event. |
AnnaBridge | 146:22da6e220af6 | 132 | * |
AnnaBridge | 146:22da6e220af6 | 133 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 134 | * @param[in] spi_event Event to check. |
AnnaBridge | 146:22da6e220af6 | 135 | * |
AnnaBridge | 146:22da6e220af6 | 136 | * @retval true If the event is set. |
AnnaBridge | 146:22da6e220af6 | 137 | * @retval false If the event is not set. |
AnnaBridge | 146:22da6e220af6 | 138 | */ |
AnnaBridge | 146:22da6e220af6 | 139 | __STATIC_INLINE bool nrf_spi_event_check(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 140 | nrf_spi_event_t spi_event); |
AnnaBridge | 146:22da6e220af6 | 141 | |
AnnaBridge | 146:22da6e220af6 | 142 | /** |
AnnaBridge | 146:22da6e220af6 | 143 | * @brief Function for getting the address of a specific SPI event register. |
AnnaBridge | 146:22da6e220af6 | 144 | * |
AnnaBridge | 146:22da6e220af6 | 145 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 146 | * @param[in] spi_event Requested event. |
AnnaBridge | 146:22da6e220af6 | 147 | * |
AnnaBridge | 146:22da6e220af6 | 148 | * @return Address of the specified event register. |
AnnaBridge | 146:22da6e220af6 | 149 | */ |
AnnaBridge | 146:22da6e220af6 | 150 | __STATIC_INLINE uint32_t * nrf_spi_event_address_get(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 151 | nrf_spi_event_t spi_event); |
AnnaBridge | 146:22da6e220af6 | 152 | |
AnnaBridge | 146:22da6e220af6 | 153 | /** |
AnnaBridge | 146:22da6e220af6 | 154 | * @brief Function for enabling specified interrupts. |
AnnaBridge | 146:22da6e220af6 | 155 | * |
AnnaBridge | 146:22da6e220af6 | 156 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 157 | * @param[in] spi_int_mask Interrupts to enable. |
AnnaBridge | 146:22da6e220af6 | 158 | */ |
AnnaBridge | 146:22da6e220af6 | 159 | __STATIC_INLINE void nrf_spi_int_enable(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 160 | uint32_t spi_int_mask); |
AnnaBridge | 146:22da6e220af6 | 161 | |
AnnaBridge | 146:22da6e220af6 | 162 | /** |
AnnaBridge | 146:22da6e220af6 | 163 | * @brief Function for disabling specified interrupts. |
AnnaBridge | 146:22da6e220af6 | 164 | * |
AnnaBridge | 146:22da6e220af6 | 165 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 166 | * @param[in] spi_int_mask Interrupts to disable. |
AnnaBridge | 146:22da6e220af6 | 167 | */ |
AnnaBridge | 146:22da6e220af6 | 168 | __STATIC_INLINE void nrf_spi_int_disable(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 169 | uint32_t spi_int_mask); |
AnnaBridge | 146:22da6e220af6 | 170 | |
AnnaBridge | 146:22da6e220af6 | 171 | /** |
AnnaBridge | 146:22da6e220af6 | 172 | * @brief Function for retrieving the state of a given interrupt. |
AnnaBridge | 146:22da6e220af6 | 173 | * |
AnnaBridge | 146:22da6e220af6 | 174 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 175 | * @param[in] spi_int Interrupt to check. |
AnnaBridge | 146:22da6e220af6 | 176 | * |
AnnaBridge | 146:22da6e220af6 | 177 | * @retval true If the interrupt is enabled. |
AnnaBridge | 146:22da6e220af6 | 178 | * @retval false If the interrupt is not enabled. |
AnnaBridge | 146:22da6e220af6 | 179 | */ |
AnnaBridge | 146:22da6e220af6 | 180 | __STATIC_INLINE bool nrf_spi_int_enable_check(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 181 | nrf_spi_int_mask_t spi_int); |
AnnaBridge | 146:22da6e220af6 | 182 | |
AnnaBridge | 146:22da6e220af6 | 183 | /** |
AnnaBridge | 146:22da6e220af6 | 184 | * @brief Function for enabling the SPI peripheral. |
AnnaBridge | 146:22da6e220af6 | 185 | * |
AnnaBridge | 146:22da6e220af6 | 186 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 187 | */ |
AnnaBridge | 146:22da6e220af6 | 188 | __STATIC_INLINE void nrf_spi_enable(NRF_SPI_Type * p_spi); |
AnnaBridge | 146:22da6e220af6 | 189 | |
AnnaBridge | 146:22da6e220af6 | 190 | /** |
AnnaBridge | 146:22da6e220af6 | 191 | * @brief Function for disabling the SPI peripheral. |
AnnaBridge | 146:22da6e220af6 | 192 | * |
AnnaBridge | 146:22da6e220af6 | 193 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 194 | */ |
AnnaBridge | 146:22da6e220af6 | 195 | __STATIC_INLINE void nrf_spi_disable(NRF_SPI_Type * p_spi); |
AnnaBridge | 146:22da6e220af6 | 196 | |
AnnaBridge | 146:22da6e220af6 | 197 | /** |
AnnaBridge | 146:22da6e220af6 | 198 | * @brief Function for configuring SPI pins. |
AnnaBridge | 146:22da6e220af6 | 199 | * |
AnnaBridge | 146:22da6e220af6 | 200 | * If a given signal is not needed, pass the @ref NRF_SPI_PIN_NOT_CONNECTED |
AnnaBridge | 146:22da6e220af6 | 201 | * value instead of its pin number. |
AnnaBridge | 146:22da6e220af6 | 202 | * |
AnnaBridge | 146:22da6e220af6 | 203 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 204 | * @param[in] sck_pin SCK pin number. |
AnnaBridge | 146:22da6e220af6 | 205 | * @param[in] mosi_pin MOSI pin number. |
AnnaBridge | 146:22da6e220af6 | 206 | * @param[in] miso_pin MISO pin number. |
AnnaBridge | 146:22da6e220af6 | 207 | */ |
AnnaBridge | 146:22da6e220af6 | 208 | __STATIC_INLINE void nrf_spi_pins_set(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 209 | uint32_t sck_pin, |
AnnaBridge | 146:22da6e220af6 | 210 | uint32_t mosi_pin, |
AnnaBridge | 146:22da6e220af6 | 211 | uint32_t miso_pin); |
AnnaBridge | 146:22da6e220af6 | 212 | |
AnnaBridge | 146:22da6e220af6 | 213 | /** |
AnnaBridge | 146:22da6e220af6 | 214 | * @brief Function for writing data to the SPI transmitter register. |
AnnaBridge | 146:22da6e220af6 | 215 | * |
AnnaBridge | 146:22da6e220af6 | 216 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 217 | * @param[in] data TX data to send. |
AnnaBridge | 146:22da6e220af6 | 218 | */ |
AnnaBridge | 146:22da6e220af6 | 219 | __STATIC_INLINE void nrf_spi_txd_set(NRF_SPI_Type * p_spi, uint8_t data); |
AnnaBridge | 146:22da6e220af6 | 220 | |
AnnaBridge | 146:22da6e220af6 | 221 | /** |
AnnaBridge | 146:22da6e220af6 | 222 | * @brief Function for reading data from the SPI receiver register. |
AnnaBridge | 146:22da6e220af6 | 223 | * |
AnnaBridge | 146:22da6e220af6 | 224 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 225 | * |
AnnaBridge | 146:22da6e220af6 | 226 | * @return RX data received. |
AnnaBridge | 146:22da6e220af6 | 227 | */ |
AnnaBridge | 146:22da6e220af6 | 228 | __STATIC_INLINE uint8_t nrf_spi_rxd_get(NRF_SPI_Type * p_spi); |
AnnaBridge | 146:22da6e220af6 | 229 | |
AnnaBridge | 146:22da6e220af6 | 230 | /** |
AnnaBridge | 146:22da6e220af6 | 231 | * @brief Function for setting the SPI master data rate. |
AnnaBridge | 146:22da6e220af6 | 232 | * |
AnnaBridge | 146:22da6e220af6 | 233 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 234 | * @param[in] frequency SPI frequency. |
AnnaBridge | 146:22da6e220af6 | 235 | */ |
AnnaBridge | 146:22da6e220af6 | 236 | __STATIC_INLINE void nrf_spi_frequency_set(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 237 | nrf_spi_frequency_t frequency); |
AnnaBridge | 146:22da6e220af6 | 238 | |
AnnaBridge | 146:22da6e220af6 | 239 | /** |
AnnaBridge | 146:22da6e220af6 | 240 | * @brief Function for setting the SPI configuration. |
AnnaBridge | 146:22da6e220af6 | 241 | * |
AnnaBridge | 146:22da6e220af6 | 242 | * @param[in] p_spi SPI instance. |
AnnaBridge | 146:22da6e220af6 | 243 | * @param[in] spi_mode SPI mode. |
AnnaBridge | 146:22da6e220af6 | 244 | * @param[in] spi_bit_order SPI bit order. |
AnnaBridge | 146:22da6e220af6 | 245 | */ |
AnnaBridge | 146:22da6e220af6 | 246 | __STATIC_INLINE void nrf_spi_configure(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 247 | nrf_spi_mode_t spi_mode, |
AnnaBridge | 146:22da6e220af6 | 248 | nrf_spi_bit_order_t spi_bit_order); |
AnnaBridge | 146:22da6e220af6 | 249 | |
AnnaBridge | 146:22da6e220af6 | 250 | |
AnnaBridge | 146:22da6e220af6 | 251 | #ifndef SUPPRESS_INLINE_IMPLEMENTATION |
AnnaBridge | 146:22da6e220af6 | 252 | |
AnnaBridge | 146:22da6e220af6 | 253 | __STATIC_INLINE void nrf_spi_event_clear(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 254 | nrf_spi_event_t spi_event) |
AnnaBridge | 146:22da6e220af6 | 255 | { |
AnnaBridge | 146:22da6e220af6 | 256 | *((volatile uint32_t *)((uint8_t *)p_spi + (uint32_t)spi_event)) = 0x0UL; |
AnnaBridge | 146:22da6e220af6 | 257 | } |
AnnaBridge | 146:22da6e220af6 | 258 | |
AnnaBridge | 146:22da6e220af6 | 259 | __STATIC_INLINE bool nrf_spi_event_check(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 260 | nrf_spi_event_t spi_event) |
AnnaBridge | 146:22da6e220af6 | 261 | { |
AnnaBridge | 146:22da6e220af6 | 262 | return (bool)*(volatile uint32_t *)((uint8_t *)p_spi + (uint32_t)spi_event); |
AnnaBridge | 146:22da6e220af6 | 263 | } |
AnnaBridge | 146:22da6e220af6 | 264 | |
AnnaBridge | 146:22da6e220af6 | 265 | __STATIC_INLINE uint32_t * nrf_spi_event_address_get(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 266 | nrf_spi_event_t spi_event) |
AnnaBridge | 146:22da6e220af6 | 267 | { |
AnnaBridge | 146:22da6e220af6 | 268 | return (uint32_t *)((uint8_t *)p_spi + (uint32_t)spi_event); |
AnnaBridge | 146:22da6e220af6 | 269 | } |
AnnaBridge | 146:22da6e220af6 | 270 | |
AnnaBridge | 146:22da6e220af6 | 271 | __STATIC_INLINE void nrf_spi_int_enable(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 272 | uint32_t spi_int_mask) |
AnnaBridge | 146:22da6e220af6 | 273 | { |
AnnaBridge | 146:22da6e220af6 | 274 | p_spi->INTENSET = spi_int_mask; |
AnnaBridge | 146:22da6e220af6 | 275 | } |
AnnaBridge | 146:22da6e220af6 | 276 | |
AnnaBridge | 146:22da6e220af6 | 277 | __STATIC_INLINE void nrf_spi_int_disable(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 278 | uint32_t spi_int_mask) |
AnnaBridge | 146:22da6e220af6 | 279 | { |
AnnaBridge | 146:22da6e220af6 | 280 | p_spi->INTENCLR = spi_int_mask; |
AnnaBridge | 146:22da6e220af6 | 281 | } |
AnnaBridge | 146:22da6e220af6 | 282 | |
AnnaBridge | 146:22da6e220af6 | 283 | __STATIC_INLINE bool nrf_spi_int_enable_check(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 284 | nrf_spi_int_mask_t spi_int) |
AnnaBridge | 146:22da6e220af6 | 285 | { |
AnnaBridge | 146:22da6e220af6 | 286 | return (bool)(p_spi->INTENSET & spi_int); |
AnnaBridge | 146:22da6e220af6 | 287 | } |
AnnaBridge | 146:22da6e220af6 | 288 | |
AnnaBridge | 146:22da6e220af6 | 289 | __STATIC_INLINE void nrf_spi_enable(NRF_SPI_Type * p_spi) |
AnnaBridge | 146:22da6e220af6 | 290 | { |
AnnaBridge | 146:22da6e220af6 | 291 | p_spi->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos); |
AnnaBridge | 146:22da6e220af6 | 292 | } |
AnnaBridge | 146:22da6e220af6 | 293 | |
AnnaBridge | 146:22da6e220af6 | 294 | __STATIC_INLINE void nrf_spi_disable(NRF_SPI_Type * p_spi) |
AnnaBridge | 146:22da6e220af6 | 295 | { |
AnnaBridge | 146:22da6e220af6 | 296 | p_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos); |
AnnaBridge | 146:22da6e220af6 | 297 | } |
AnnaBridge | 146:22da6e220af6 | 298 | |
AnnaBridge | 146:22da6e220af6 | 299 | __STATIC_INLINE void nrf_spi_pins_set(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 300 | uint32_t sck_pin, |
AnnaBridge | 146:22da6e220af6 | 301 | uint32_t mosi_pin, |
AnnaBridge | 146:22da6e220af6 | 302 | uint32_t miso_pin) |
AnnaBridge | 146:22da6e220af6 | 303 | { |
AnnaBridge | 146:22da6e220af6 | 304 | p_spi->PSELSCK = sck_pin; |
AnnaBridge | 146:22da6e220af6 | 305 | p_spi->PSELMOSI = mosi_pin; |
AnnaBridge | 146:22da6e220af6 | 306 | p_spi->PSELMISO = miso_pin; |
AnnaBridge | 146:22da6e220af6 | 307 | } |
AnnaBridge | 146:22da6e220af6 | 308 | |
AnnaBridge | 146:22da6e220af6 | 309 | __STATIC_INLINE void nrf_spi_txd_set(NRF_SPI_Type * p_spi, uint8_t data) |
AnnaBridge | 146:22da6e220af6 | 310 | { |
AnnaBridge | 146:22da6e220af6 | 311 | p_spi->TXD = data; |
AnnaBridge | 146:22da6e220af6 | 312 | } |
AnnaBridge | 146:22da6e220af6 | 313 | |
AnnaBridge | 146:22da6e220af6 | 314 | __STATIC_INLINE uint8_t nrf_spi_rxd_get(NRF_SPI_Type * p_spi) |
AnnaBridge | 146:22da6e220af6 | 315 | { |
AnnaBridge | 146:22da6e220af6 | 316 | return p_spi->RXD; |
AnnaBridge | 146:22da6e220af6 | 317 | } |
AnnaBridge | 146:22da6e220af6 | 318 | |
AnnaBridge | 146:22da6e220af6 | 319 | __STATIC_INLINE void nrf_spi_frequency_set(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 320 | nrf_spi_frequency_t frequency) |
AnnaBridge | 146:22da6e220af6 | 321 | { |
AnnaBridge | 146:22da6e220af6 | 322 | p_spi->FREQUENCY = frequency; |
AnnaBridge | 146:22da6e220af6 | 323 | } |
AnnaBridge | 146:22da6e220af6 | 324 | |
AnnaBridge | 146:22da6e220af6 | 325 | __STATIC_INLINE void nrf_spi_configure(NRF_SPI_Type * p_spi, |
AnnaBridge | 146:22da6e220af6 | 326 | nrf_spi_mode_t spi_mode, |
AnnaBridge | 146:22da6e220af6 | 327 | nrf_spi_bit_order_t spi_bit_order) |
AnnaBridge | 146:22da6e220af6 | 328 | { |
AnnaBridge | 146:22da6e220af6 | 329 | uint32_t config = (spi_bit_order == NRF_SPI_BIT_ORDER_MSB_FIRST ? |
AnnaBridge | 146:22da6e220af6 | 330 | SPI_CONFIG_ORDER_MsbFirst : SPI_CONFIG_ORDER_LsbFirst); |
AnnaBridge | 146:22da6e220af6 | 331 | switch (spi_mode) |
AnnaBridge | 146:22da6e220af6 | 332 | { |
AnnaBridge | 146:22da6e220af6 | 333 | default: |
AnnaBridge | 146:22da6e220af6 | 334 | case NRF_SPI_MODE_0: |
AnnaBridge | 146:22da6e220af6 | 335 | config |= (SPI_CONFIG_CPOL_ActiveHigh << SPI_CONFIG_CPOL_Pos) | |
AnnaBridge | 146:22da6e220af6 | 336 | (SPI_CONFIG_CPHA_Leading << SPI_CONFIG_CPHA_Pos); |
AnnaBridge | 146:22da6e220af6 | 337 | break; |
AnnaBridge | 146:22da6e220af6 | 338 | |
AnnaBridge | 146:22da6e220af6 | 339 | case NRF_SPI_MODE_1: |
AnnaBridge | 146:22da6e220af6 | 340 | config |= (SPI_CONFIG_CPOL_ActiveHigh << SPI_CONFIG_CPOL_Pos) | |
AnnaBridge | 146:22da6e220af6 | 341 | (SPI_CONFIG_CPHA_Trailing << SPI_CONFIG_CPHA_Pos); |
AnnaBridge | 146:22da6e220af6 | 342 | break; |
AnnaBridge | 146:22da6e220af6 | 343 | |
AnnaBridge | 146:22da6e220af6 | 344 | case NRF_SPI_MODE_2: |
AnnaBridge | 146:22da6e220af6 | 345 | config |= (SPI_CONFIG_CPOL_ActiveLow << SPI_CONFIG_CPOL_Pos) | |
AnnaBridge | 146:22da6e220af6 | 346 | (SPI_CONFIG_CPHA_Leading << SPI_CONFIG_CPHA_Pos); |
AnnaBridge | 146:22da6e220af6 | 347 | break; |
AnnaBridge | 146:22da6e220af6 | 348 | |
AnnaBridge | 146:22da6e220af6 | 349 | case NRF_SPI_MODE_3: |
AnnaBridge | 146:22da6e220af6 | 350 | config |= (SPI_CONFIG_CPOL_ActiveLow << SPI_CONFIG_CPOL_Pos) | |
AnnaBridge | 146:22da6e220af6 | 351 | (SPI_CONFIG_CPHA_Trailing << SPI_CONFIG_CPHA_Pos); |
AnnaBridge | 146:22da6e220af6 | 352 | break; |
AnnaBridge | 146:22da6e220af6 | 353 | } |
AnnaBridge | 146:22da6e220af6 | 354 | p_spi->CONFIG = config; |
AnnaBridge | 146:22da6e220af6 | 355 | } |
AnnaBridge | 146:22da6e220af6 | 356 | |
AnnaBridge | 146:22da6e220af6 | 357 | #endif // SUPPRESS_INLINE_IMPLEMENTATION |
AnnaBridge | 146:22da6e220af6 | 358 | |
AnnaBridge | 146:22da6e220af6 | 359 | #endif // NRF_SPI_H__ |
AnnaBridge | 146:22da6e220af6 | 360 | |
AnnaBridge | 146:22da6e220af6 | 361 | /** @} */ |