Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Prototype RF Driver for STM Sub-1 GHz RF Expansion Boards based on the SPSGRF-868 and SPSGRF-915 Modules for STM32 Nucleo
Currently supported boards:
Note, in order to use expansion board X-NUCLEO-IDS01A4 in mbed you need to perform the following HW modifications on the board:
- Unmount resistor
R4 - Mount resistor
R7
Furthermore, on some Nucleo development boards (e.g. the NUCLEO_F429ZI), in order to be able to use Ethernet together with these Sub-1 GHz RF expansion boards, you need to compile this driver with macro SPIRIT1_SPI_MOSI=PB_5 defined, while the development board typically requires some HW modification as e.g. described here!
This driver can be used together with the 6LoWPAN stack (a.k.a. Nanostack).
source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Gpio.c@34:edda6a7238ec, 2016-11-22 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Tue Nov 22 11:40:10 2016 +0100
- Revision:
- 34:edda6a7238ec
- Child:
- 67:93bec0baf1de
Perform re-naming
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Wolfgang Betz |
34:edda6a7238ec | 1 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 2 | ****************************************************************************** |
| Wolfgang Betz |
34:edda6a7238ec | 3 | * @file SPIRIT_Gpio.c |
| Wolfgang Betz |
34:edda6a7238ec | 4 | * @author VMA division - AMS |
| Wolfgang Betz |
34:edda6a7238ec | 5 | * @version 3.2.2 |
| Wolfgang Betz |
34:edda6a7238ec | 6 | * @date 08-July-2015 |
| Wolfgang Betz |
34:edda6a7238ec | 7 | * @brief This file provides all the low level API to manage SPIRIT GPIO. |
| Wolfgang Betz |
34:edda6a7238ec | 8 | * @details |
| Wolfgang Betz |
34:edda6a7238ec | 9 | * |
| Wolfgang Betz |
34:edda6a7238ec | 10 | * @attention |
| Wolfgang Betz |
34:edda6a7238ec | 11 | * |
| Wolfgang Betz |
34:edda6a7238ec | 12 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
| Wolfgang Betz |
34:edda6a7238ec | 13 | * |
| Wolfgang Betz |
34:edda6a7238ec | 14 | * Redistribution and use in source and binary forms, with or without modification, |
| Wolfgang Betz |
34:edda6a7238ec | 15 | * are permitted provided that the following conditions are met: |
| Wolfgang Betz |
34:edda6a7238ec | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
| Wolfgang Betz |
34:edda6a7238ec | 17 | * this list of conditions and the following disclaimer. |
| Wolfgang Betz |
34:edda6a7238ec | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| Wolfgang Betz |
34:edda6a7238ec | 19 | * this list of conditions and the following disclaimer in the documentation |
| Wolfgang Betz |
34:edda6a7238ec | 20 | * and/or other materials provided with the distribution. |
| Wolfgang Betz |
34:edda6a7238ec | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| Wolfgang Betz |
34:edda6a7238ec | 22 | * may be used to endorse or promote products derived from this software |
| Wolfgang Betz |
34:edda6a7238ec | 23 | * without specific prior written permission. |
| Wolfgang Betz |
34:edda6a7238ec | 24 | * |
| Wolfgang Betz |
34:edda6a7238ec | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| Wolfgang Betz |
34:edda6a7238ec | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| Wolfgang Betz |
34:edda6a7238ec | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| Wolfgang Betz |
34:edda6a7238ec | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| Wolfgang Betz |
34:edda6a7238ec | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| Wolfgang Betz |
34:edda6a7238ec | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| Wolfgang Betz |
34:edda6a7238ec | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| Wolfgang Betz |
34:edda6a7238ec | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| Wolfgang Betz |
34:edda6a7238ec | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| Wolfgang Betz |
34:edda6a7238ec | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Wolfgang Betz |
34:edda6a7238ec | 35 | * |
| Wolfgang Betz |
34:edda6a7238ec | 36 | ****************************************************************************** |
| Wolfgang Betz |
34:edda6a7238ec | 37 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 38 | |
| Wolfgang Betz |
34:edda6a7238ec | 39 | /* Includes ------------------------------------------------------------------*/ |
| Wolfgang Betz |
34:edda6a7238ec | 40 | #include "SPIRIT_Gpio.h" |
| Wolfgang Betz |
34:edda6a7238ec | 41 | #include "MCU_Interface.h" |
| Wolfgang Betz |
34:edda6a7238ec | 42 | |
| Wolfgang Betz |
34:edda6a7238ec | 43 | |
| Wolfgang Betz |
34:edda6a7238ec | 44 | /** @addtogroup SPIRIT_Libraries |
| Wolfgang Betz |
34:edda6a7238ec | 45 | * @{ |
| Wolfgang Betz |
34:edda6a7238ec | 46 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 47 | |
| Wolfgang Betz |
34:edda6a7238ec | 48 | |
| Wolfgang Betz |
34:edda6a7238ec | 49 | /** @addtogroup SPIRIT_Gpio |
| Wolfgang Betz |
34:edda6a7238ec | 50 | * @{ |
| Wolfgang Betz |
34:edda6a7238ec | 51 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 52 | |
| Wolfgang Betz |
34:edda6a7238ec | 53 | |
| Wolfgang Betz |
34:edda6a7238ec | 54 | /** @defgroup Gpio_Private_TypesDefinitions GPIO Private Types Definitions |
| Wolfgang Betz |
34:edda6a7238ec | 55 | * @{ |
| Wolfgang Betz |
34:edda6a7238ec | 56 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 57 | |
| Wolfgang Betz |
34:edda6a7238ec | 58 | |
| Wolfgang Betz |
34:edda6a7238ec | 59 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 60 | * @} |
| Wolfgang Betz |
34:edda6a7238ec | 61 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 62 | |
| Wolfgang Betz |
34:edda6a7238ec | 63 | |
| Wolfgang Betz |
34:edda6a7238ec | 64 | /** @defgroup Gpio_Private_Defines GPIO Private Defines |
| Wolfgang Betz |
34:edda6a7238ec | 65 | * @{ |
| Wolfgang Betz |
34:edda6a7238ec | 66 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 67 | |
| Wolfgang Betz |
34:edda6a7238ec | 68 | |
| Wolfgang Betz |
34:edda6a7238ec | 69 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 70 | * @} |
| Wolfgang Betz |
34:edda6a7238ec | 71 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 72 | |
| Wolfgang Betz |
34:edda6a7238ec | 73 | |
| Wolfgang Betz |
34:edda6a7238ec | 74 | |
| Wolfgang Betz |
34:edda6a7238ec | 75 | /** @defgroup Gpio_Private_Macros GPIO Private Macros |
| Wolfgang Betz |
34:edda6a7238ec | 76 | * @{ |
| Wolfgang Betz |
34:edda6a7238ec | 77 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 78 | |
| Wolfgang Betz |
34:edda6a7238ec | 79 | |
| Wolfgang Betz |
34:edda6a7238ec | 80 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 81 | * @} |
| Wolfgang Betz |
34:edda6a7238ec | 82 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 83 | |
| Wolfgang Betz |
34:edda6a7238ec | 84 | |
| Wolfgang Betz |
34:edda6a7238ec | 85 | |
| Wolfgang Betz |
34:edda6a7238ec | 86 | /** @defgroup Gpio_Private_Variables GPIO Private Variables |
| Wolfgang Betz |
34:edda6a7238ec | 87 | * @{ |
| Wolfgang Betz |
34:edda6a7238ec | 88 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 89 | |
| Wolfgang Betz |
34:edda6a7238ec | 90 | |
| Wolfgang Betz |
34:edda6a7238ec | 91 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 92 | * @} |
| Wolfgang Betz |
34:edda6a7238ec | 93 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 94 | |
| Wolfgang Betz |
34:edda6a7238ec | 95 | |
| Wolfgang Betz |
34:edda6a7238ec | 96 | |
| Wolfgang Betz |
34:edda6a7238ec | 97 | /** @defgroup Gpio_Private_FunctionPrototypes GPIO Private Function Prototypes |
| Wolfgang Betz |
34:edda6a7238ec | 98 | * @{ |
| Wolfgang Betz |
34:edda6a7238ec | 99 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 100 | |
| Wolfgang Betz |
34:edda6a7238ec | 101 | |
| Wolfgang Betz |
34:edda6a7238ec | 102 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 103 | * @} |
| Wolfgang Betz |
34:edda6a7238ec | 104 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 105 | |
| Wolfgang Betz |
34:edda6a7238ec | 106 | |
| Wolfgang Betz |
34:edda6a7238ec | 107 | |
| Wolfgang Betz |
34:edda6a7238ec | 108 | /** @defgroup Gpio_Private_Functions GPIO Private Functions |
| Wolfgang Betz |
34:edda6a7238ec | 109 | * @{ |
| Wolfgang Betz |
34:edda6a7238ec | 110 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 111 | |
| Wolfgang Betz |
34:edda6a7238ec | 112 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 113 | * @brief Initializes the SPIRIT GPIOx according to the specified |
| Wolfgang Betz |
34:edda6a7238ec | 114 | * parameters in the pxGpioInitStruct. |
| Wolfgang Betz |
34:edda6a7238ec | 115 | * @param pxGpioInitStruct pointer to a SGpioInit structure that |
| Wolfgang Betz |
34:edda6a7238ec | 116 | * contains the configuration information for the specified SPIRIT GPIO. |
| Wolfgang Betz |
34:edda6a7238ec | 117 | * @retval None. |
| Wolfgang Betz |
34:edda6a7238ec | 118 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 119 | void SpiritGpioInit(SGpioInit* pxGpioInitStruct) |
| Wolfgang Betz |
34:edda6a7238ec | 120 | { |
| Wolfgang Betz |
34:edda6a7238ec | 121 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 122 | |
| Wolfgang Betz |
34:edda6a7238ec | 123 | /* Check the parameters */ |
| Wolfgang Betz |
34:edda6a7238ec | 124 | s_assert_param(IS_SPIRIT_GPIO(pxGpioInitStruct->xSpiritGpioPin)); |
| Wolfgang Betz |
34:edda6a7238ec | 125 | s_assert_param(IS_SPIRIT_GPIO_MODE(pxGpioInitStruct->xSpiritGpioMode)); |
| Wolfgang Betz |
34:edda6a7238ec | 126 | s_assert_param(IS_SPIRIT_GPIO_IO(pxGpioInitStruct->xSpiritGpioIO)); |
| Wolfgang Betz |
34:edda6a7238ec | 127 | |
| Wolfgang Betz |
34:edda6a7238ec | 128 | tempRegValue = ((uint8_t)(pxGpioInitStruct->xSpiritGpioMode) | (uint8_t)(pxGpioInitStruct->xSpiritGpioIO)); |
| Wolfgang Betz |
34:edda6a7238ec | 129 | |
| Wolfgang Betz |
34:edda6a7238ec | 130 | g_xStatus = SpiritSpiWriteRegisters(pxGpioInitStruct->xSpiritGpioPin, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 131 | |
| Wolfgang Betz |
34:edda6a7238ec | 132 | } |
| Wolfgang Betz |
34:edda6a7238ec | 133 | |
| Wolfgang Betz |
34:edda6a7238ec | 134 | |
| Wolfgang Betz |
34:edda6a7238ec | 135 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 136 | * @brief Enables or Disables the output of temperature sensor on SPIRIT GPIO_0. |
| Wolfgang Betz |
34:edda6a7238ec | 137 | * @param xNewState new state for temperature sensor. |
| Wolfgang Betz |
34:edda6a7238ec | 138 | * This parameter can be: S_ENABLE or S_DISABLE. |
| Wolfgang Betz |
34:edda6a7238ec | 139 | * @retval None. |
| Wolfgang Betz |
34:edda6a7238ec | 140 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 141 | void SpiritGpioTemperatureSensor(SpiritFunctionalState xNewState) |
| Wolfgang Betz |
34:edda6a7238ec | 142 | { |
| Wolfgang Betz |
34:edda6a7238ec | 143 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 144 | uint8_t gpio0tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 145 | |
| Wolfgang Betz |
34:edda6a7238ec | 146 | /* Check the parameters */ |
| Wolfgang Betz |
34:edda6a7238ec | 147 | s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); |
| Wolfgang Betz |
34:edda6a7238ec | 148 | |
| Wolfgang Betz |
34:edda6a7238ec | 149 | /* Reads the ANA_FUNC_CONF0 register and mask the result to enable or disable the |
| Wolfgang Betz |
34:edda6a7238ec | 150 | temperature sensor */ |
| Wolfgang Betz |
34:edda6a7238ec | 151 | g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 152 | if(xNewState == S_ENABLE) |
| Wolfgang Betz |
34:edda6a7238ec | 153 | { |
| Wolfgang Betz |
34:edda6a7238ec | 154 | tempRegValue |= TEMPERATURE_SENSOR_MASK; |
| Wolfgang Betz |
34:edda6a7238ec | 155 | } |
| Wolfgang Betz |
34:edda6a7238ec | 156 | else |
| Wolfgang Betz |
34:edda6a7238ec | 157 | { |
| Wolfgang Betz |
34:edda6a7238ec | 158 | tempRegValue &= (~TEMPERATURE_SENSOR_MASK); |
| Wolfgang Betz |
34:edda6a7238ec | 159 | gpio0tempRegValue = 0x0A; /* Default value */ |
| Wolfgang Betz |
34:edda6a7238ec | 160 | } |
| Wolfgang Betz |
34:edda6a7238ec | 161 | g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 162 | |
| Wolfgang Betz |
34:edda6a7238ec | 163 | /* Sets the SPIRIT GPIO_0 according to input request */ |
| Wolfgang Betz |
34:edda6a7238ec | 164 | g_xStatus = SpiritSpiWriteRegisters(GPIO0_CONF_BASE, 1, &gpio0tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 165 | |
| Wolfgang Betz |
34:edda6a7238ec | 166 | } |
| Wolfgang Betz |
34:edda6a7238ec | 167 | |
| Wolfgang Betz |
34:edda6a7238ec | 168 | |
| Wolfgang Betz |
34:edda6a7238ec | 169 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 170 | * @brief Forces SPIRIT GPIO_x configured as digital output, to VDD or GND. |
| Wolfgang Betz |
34:edda6a7238ec | 171 | * @param xGpioX Specifies the GPIO to be configured. |
| Wolfgang Betz |
34:edda6a7238ec | 172 | * This parameter can be one of following parameters: |
| Wolfgang Betz |
34:edda6a7238ec | 173 | * @arg SPIRIT_GPIO_0: SPIRIT GPIO_0 |
| Wolfgang Betz |
34:edda6a7238ec | 174 | * @arg SPIRIT_GPIO_1: SPIRIT GPIO_1 |
| Wolfgang Betz |
34:edda6a7238ec | 175 | * @arg SPIRIT_GPIO_2: SPIRIT GPIO_2 |
| Wolfgang Betz |
34:edda6a7238ec | 176 | * @arg SPIRIT_GPIO_3: SPIRIT GPIO_3 |
| Wolfgang Betz |
34:edda6a7238ec | 177 | * @param xLevel Specifies the level. |
| Wolfgang Betz |
34:edda6a7238ec | 178 | * This parameter can be: HIGH or LOW. |
| Wolfgang Betz |
34:edda6a7238ec | 179 | * @retval None. |
| Wolfgang Betz |
34:edda6a7238ec | 180 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 181 | void SpiritGpioSetLevel(SpiritGpioPin xGpioX, OutputLevel xLevel) |
| Wolfgang Betz |
34:edda6a7238ec | 182 | { |
| Wolfgang Betz |
34:edda6a7238ec | 183 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 184 | |
| Wolfgang Betz |
34:edda6a7238ec | 185 | /* Check the parameters */ |
| Wolfgang Betz |
34:edda6a7238ec | 186 | s_assert_param(IS_SPIRIT_GPIO(xGpioX)); |
| Wolfgang Betz |
34:edda6a7238ec | 187 | s_assert_param(IS_SPIRIT_GPIO_LEVEL(xLevel)); |
| Wolfgang Betz |
34:edda6a7238ec | 188 | |
| Wolfgang Betz |
34:edda6a7238ec | 189 | /* Reads the SPIRIT_GPIOx register and mask the GPIO_SELECT field */ |
| Wolfgang Betz |
34:edda6a7238ec | 190 | g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 191 | tempRegValue &= 0x04; |
| Wolfgang Betz |
34:edda6a7238ec | 192 | |
| Wolfgang Betz |
34:edda6a7238ec | 193 | /* Sets the value of the SPIRIT GPIO register according to the specified level */ |
| Wolfgang Betz |
34:edda6a7238ec | 194 | if(xLevel == HIGH) |
| Wolfgang Betz |
34:edda6a7238ec | 195 | { |
| Wolfgang Betz |
34:edda6a7238ec | 196 | tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_VDD | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP; |
| Wolfgang Betz |
34:edda6a7238ec | 197 | } |
| Wolfgang Betz |
34:edda6a7238ec | 198 | else |
| Wolfgang Betz |
34:edda6a7238ec | 199 | { |
| Wolfgang Betz |
34:edda6a7238ec | 200 | tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_GND | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP; |
| Wolfgang Betz |
34:edda6a7238ec | 201 | } |
| Wolfgang Betz |
34:edda6a7238ec | 202 | |
| Wolfgang Betz |
34:edda6a7238ec | 203 | /* Writes the SPIRIT GPIO register */ |
| Wolfgang Betz |
34:edda6a7238ec | 204 | g_xStatus = SpiritSpiWriteRegisters(xGpioX, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 205 | |
| Wolfgang Betz |
34:edda6a7238ec | 206 | } |
| Wolfgang Betz |
34:edda6a7238ec | 207 | |
| Wolfgang Betz |
34:edda6a7238ec | 208 | |
| Wolfgang Betz |
34:edda6a7238ec | 209 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 210 | * @brief Returns output value (VDD or GND) of SPIRIT GPIO_x, when it is configured as digital output. |
| Wolfgang Betz |
34:edda6a7238ec | 211 | * @param xGpioX Specifies the GPIO to be read. |
| Wolfgang Betz |
34:edda6a7238ec | 212 | * This parameter can be one of following parameters: |
| Wolfgang Betz |
34:edda6a7238ec | 213 | * @arg SPIRIT_GPIO_0: SPIRIT GPIO_0 |
| Wolfgang Betz |
34:edda6a7238ec | 214 | * @arg SPIRIT_GPIO_1: SPIRIT GPIO_1 |
| Wolfgang Betz |
34:edda6a7238ec | 215 | * @arg SPIRIT_GPIO_2: SPIRIT GPIO_2 |
| Wolfgang Betz |
34:edda6a7238ec | 216 | * @arg SPIRIT_GPIO_3: SPIRIT GPIO_3 |
| Wolfgang Betz |
34:edda6a7238ec | 217 | * @retval OutputLevel Logical level of selected GPIO configured as digital output. |
| Wolfgang Betz |
34:edda6a7238ec | 218 | * This parameter can be: HIGH or LOW. |
| Wolfgang Betz |
34:edda6a7238ec | 219 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 220 | OutputLevel SpiritGpioGetLevel(SpiritGpioPin xGpioX) |
| Wolfgang Betz |
34:edda6a7238ec | 221 | { |
| Wolfgang Betz |
34:edda6a7238ec | 222 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 223 | OutputLevel level; |
| Wolfgang Betz |
34:edda6a7238ec | 224 | |
| Wolfgang Betz |
34:edda6a7238ec | 225 | /* Check the parameters */ |
| Wolfgang Betz |
34:edda6a7238ec | 226 | s_assert_param(IS_SPIRIT_GPIO(xGpioX)); |
| Wolfgang Betz |
34:edda6a7238ec | 227 | |
| Wolfgang Betz |
34:edda6a7238ec | 228 | /* Reads the SPIRIT_GPIOx register */ |
| Wolfgang Betz |
34:edda6a7238ec | 229 | g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 230 | |
| Wolfgang Betz |
34:edda6a7238ec | 231 | /* Mask the GPIO_SELECT field and returns the value according */ |
| Wolfgang Betz |
34:edda6a7238ec | 232 | tempRegValue &= 0xF8; |
| Wolfgang Betz |
34:edda6a7238ec | 233 | if(tempRegValue == SPIRIT_GPIO_DIG_OUT_VDD) |
| Wolfgang Betz |
34:edda6a7238ec | 234 | { |
| Wolfgang Betz |
34:edda6a7238ec | 235 | level = HIGH; |
| Wolfgang Betz |
34:edda6a7238ec | 236 | } |
| Wolfgang Betz |
34:edda6a7238ec | 237 | else |
| Wolfgang Betz |
34:edda6a7238ec | 238 | { |
| Wolfgang Betz |
34:edda6a7238ec | 239 | level = LOW; |
| Wolfgang Betz |
34:edda6a7238ec | 240 | } |
| Wolfgang Betz |
34:edda6a7238ec | 241 | |
| Wolfgang Betz |
34:edda6a7238ec | 242 | return level; |
| Wolfgang Betz |
34:edda6a7238ec | 243 | |
| Wolfgang Betz |
34:edda6a7238ec | 244 | } |
| Wolfgang Betz |
34:edda6a7238ec | 245 | |
| Wolfgang Betz |
34:edda6a7238ec | 246 | |
| Wolfgang Betz |
34:edda6a7238ec | 247 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 248 | * @brief Enables or Disables the MCU clock output. |
| Wolfgang Betz |
34:edda6a7238ec | 249 | * @param xNewState new state for the MCU clock output. |
| Wolfgang Betz |
34:edda6a7238ec | 250 | * This parameter can be: S_ENABLE or S_DISABLE. |
| Wolfgang Betz |
34:edda6a7238ec | 251 | * @retval None. |
| Wolfgang Betz |
34:edda6a7238ec | 252 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 253 | void SpiritGpioClockOutput(SpiritFunctionalState xNewState) |
| Wolfgang Betz |
34:edda6a7238ec | 254 | { |
| Wolfgang Betz |
34:edda6a7238ec | 255 | uint8_t tempRegValue; |
| Wolfgang Betz |
34:edda6a7238ec | 256 | |
| Wolfgang Betz |
34:edda6a7238ec | 257 | /* Check the parameters */ |
| Wolfgang Betz |
34:edda6a7238ec | 258 | s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); |
| Wolfgang Betz |
34:edda6a7238ec | 259 | |
| Wolfgang Betz |
34:edda6a7238ec | 260 | /* Reads the MCU_CK_CONF register and mask the result to enable or disable the clock output */ |
| Wolfgang Betz |
34:edda6a7238ec | 261 | g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 262 | |
| Wolfgang Betz |
34:edda6a7238ec | 263 | if(xNewState) |
| Wolfgang Betz |
34:edda6a7238ec | 264 | { |
| Wolfgang Betz |
34:edda6a7238ec | 265 | tempRegValue |= MCU_CK_ENABLE; |
| Wolfgang Betz |
34:edda6a7238ec | 266 | } |
| Wolfgang Betz |
34:edda6a7238ec | 267 | else |
| Wolfgang Betz |
34:edda6a7238ec | 268 | { |
| Wolfgang Betz |
34:edda6a7238ec | 269 | tempRegValue &= (~MCU_CK_ENABLE); |
| Wolfgang Betz |
34:edda6a7238ec | 270 | } |
| Wolfgang Betz |
34:edda6a7238ec | 271 | |
| Wolfgang Betz |
34:edda6a7238ec | 272 | /* Writes the MCU_CK_CONF register */ |
| Wolfgang Betz |
34:edda6a7238ec | 273 | g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 274 | |
| Wolfgang Betz |
34:edda6a7238ec | 275 | } |
| Wolfgang Betz |
34:edda6a7238ec | 276 | |
| Wolfgang Betz |
34:edda6a7238ec | 277 | |
| Wolfgang Betz |
34:edda6a7238ec | 278 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 279 | * @brief Initializes the SPIRIT Clock Output according to the specified |
| Wolfgang Betz |
34:edda6a7238ec | 280 | * parameters in the xClockOutputInitStruct. |
| Wolfgang Betz |
34:edda6a7238ec | 281 | * @param pxClockOutputInitStruct pointer to a ClockOutputInit structure that |
| Wolfgang Betz |
34:edda6a7238ec | 282 | * contains the configuration information for the SPIRIT Clock Output. |
| Wolfgang Betz |
34:edda6a7238ec | 283 | * @retval None. |
| Wolfgang Betz |
34:edda6a7238ec | 284 | * @note The function SpiritGpioClockOutput() must be called in order to enable |
| Wolfgang Betz |
34:edda6a7238ec | 285 | * or disable the MCU clock dividers. |
| Wolfgang Betz |
34:edda6a7238ec | 286 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 287 | void SpiritGpioClockOutputInit(ClockOutputInit* pxClockOutputInitStruct) |
| Wolfgang Betz |
34:edda6a7238ec | 288 | { |
| Wolfgang Betz |
34:edda6a7238ec | 289 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 290 | |
| Wolfgang Betz |
34:edda6a7238ec | 291 | /* Check the parameters */ |
| Wolfgang Betz |
34:edda6a7238ec | 292 | s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_XO(pxClockOutputInitStruct->xClockOutputXOPrescaler)); |
| Wolfgang Betz |
34:edda6a7238ec | 293 | s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_RCO(pxClockOutputInitStruct->xClockOutputRCOPrescaler)); |
| Wolfgang Betz |
34:edda6a7238ec | 294 | s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_EXTRA_CYCLES(pxClockOutputInitStruct->xExtraClockCycles)); |
| Wolfgang Betz |
34:edda6a7238ec | 295 | |
| Wolfgang Betz |
34:edda6a7238ec | 296 | /* Calculates the register value to write according to the specified configuration */ |
| Wolfgang Betz |
34:edda6a7238ec | 297 | tempRegValue = ((uint8_t)(pxClockOutputInitStruct->xClockOutputXOPrescaler) | (uint8_t)(pxClockOutputInitStruct->xClockOutputRCOPrescaler) | \ |
| Wolfgang Betz |
34:edda6a7238ec | 298 | (uint8_t)(pxClockOutputInitStruct->xExtraClockCycles)); |
| Wolfgang Betz |
34:edda6a7238ec | 299 | |
| Wolfgang Betz |
34:edda6a7238ec | 300 | /* Writes the MCU_CLOCK register */ |
| Wolfgang Betz |
34:edda6a7238ec | 301 | g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 302 | |
| Wolfgang Betz |
34:edda6a7238ec | 303 | } |
| Wolfgang Betz |
34:edda6a7238ec | 304 | |
| Wolfgang Betz |
34:edda6a7238ec | 305 | |
| Wolfgang Betz |
34:edda6a7238ec | 306 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 307 | * @brief Sets the XO ratio as clock output. |
| Wolfgang Betz |
34:edda6a7238ec | 308 | * @param xXOPrescaler the XO prescaler to be used as clock output. |
| Wolfgang Betz |
34:edda6a7238ec | 309 | * This parameter can be any value of @ref ClockOutputXOPrescaler . |
| Wolfgang Betz |
34:edda6a7238ec | 310 | * @retval None |
| Wolfgang Betz |
34:edda6a7238ec | 311 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 312 | void SpiritGpioSetXOPrescaler(ClockOutputXOPrescaler xXOPrescaler) |
| Wolfgang Betz |
34:edda6a7238ec | 313 | { |
| Wolfgang Betz |
34:edda6a7238ec | 314 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 315 | |
| Wolfgang Betz |
34:edda6a7238ec | 316 | /* Check the parameters */ |
| Wolfgang Betz |
34:edda6a7238ec | 317 | s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_XO(xXOPrescaler)); |
| Wolfgang Betz |
34:edda6a7238ec | 318 | |
| Wolfgang Betz |
34:edda6a7238ec | 319 | /* Reads the MCU_CLK_CONFIG register */ |
| Wolfgang Betz |
34:edda6a7238ec | 320 | g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 321 | |
| Wolfgang Betz |
34:edda6a7238ec | 322 | /* Mask the XO_RATIO field and writes the new value */ |
| Wolfgang Betz |
34:edda6a7238ec | 323 | tempRegValue &= 0x61; |
| Wolfgang Betz |
34:edda6a7238ec | 324 | tempRegValue |= ((uint8_t)xXOPrescaler); |
| Wolfgang Betz |
34:edda6a7238ec | 325 | |
| Wolfgang Betz |
34:edda6a7238ec | 326 | /* Writes the new XO prescaler in the MCU_CLOCK register */ |
| Wolfgang Betz |
34:edda6a7238ec | 327 | g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 328 | |
| Wolfgang Betz |
34:edda6a7238ec | 329 | } |
| Wolfgang Betz |
34:edda6a7238ec | 330 | |
| Wolfgang Betz |
34:edda6a7238ec | 331 | |
| Wolfgang Betz |
34:edda6a7238ec | 332 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 333 | * @brief Returns the settled XO prescaler as clock output. |
| Wolfgang Betz |
34:edda6a7238ec | 334 | * @param None. |
| Wolfgang Betz |
34:edda6a7238ec | 335 | * @retval ClockOutputXOPrescaler Settled XO prescaler used for clock |
| Wolfgang Betz |
34:edda6a7238ec | 336 | * output. This parameter can be a value of @ref ClockOutputXOPrescaler . |
| Wolfgang Betz |
34:edda6a7238ec | 337 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 338 | ClockOutputXOPrescaler SpiritGpioGetXOPrescaler(void) |
| Wolfgang Betz |
34:edda6a7238ec | 339 | { |
| Wolfgang Betz |
34:edda6a7238ec | 340 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 341 | |
| Wolfgang Betz |
34:edda6a7238ec | 342 | /* Reads the MCU_CLK_CONFIG register */ |
| Wolfgang Betz |
34:edda6a7238ec | 343 | g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 344 | |
| Wolfgang Betz |
34:edda6a7238ec | 345 | /* Mask the XO_RATIO field and return the value */ |
| Wolfgang Betz |
34:edda6a7238ec | 346 | return ((ClockOutputXOPrescaler)(tempRegValue & 0x1E)); |
| Wolfgang Betz |
34:edda6a7238ec | 347 | |
| Wolfgang Betz |
34:edda6a7238ec | 348 | } |
| Wolfgang Betz |
34:edda6a7238ec | 349 | |
| Wolfgang Betz |
34:edda6a7238ec | 350 | |
| Wolfgang Betz |
34:edda6a7238ec | 351 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 352 | * @brief Sets the RCO ratio as clock output |
| Wolfgang Betz |
34:edda6a7238ec | 353 | * @param xRCOPrescaler the RCO prescaler to be used as clock output. |
| Wolfgang Betz |
34:edda6a7238ec | 354 | * This parameter can be any value of @ref ClockOutputRCOPrescaler . |
| Wolfgang Betz |
34:edda6a7238ec | 355 | * @retval None. |
| Wolfgang Betz |
34:edda6a7238ec | 356 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 357 | void SpiritGpioSetRCOPrescaler(ClockOutputRCOPrescaler xRCOPrescaler) |
| Wolfgang Betz |
34:edda6a7238ec | 358 | { |
| Wolfgang Betz |
34:edda6a7238ec | 359 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 360 | |
| Wolfgang Betz |
34:edda6a7238ec | 361 | /* Check the parameters */ |
| Wolfgang Betz |
34:edda6a7238ec | 362 | s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_RCO(xRCOPrescaler)); |
| Wolfgang Betz |
34:edda6a7238ec | 363 | |
| Wolfgang Betz |
34:edda6a7238ec | 364 | /* Reads the MCU_CLK_CONFIG register */ |
| Wolfgang Betz |
34:edda6a7238ec | 365 | g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 366 | |
| Wolfgang Betz |
34:edda6a7238ec | 367 | /* Mask the RCO_RATIO field and writes the new value */ |
| Wolfgang Betz |
34:edda6a7238ec | 368 | tempRegValue &= 0xFE; |
| Wolfgang Betz |
34:edda6a7238ec | 369 | tempRegValue |= ((uint8_t)xRCOPrescaler); |
| Wolfgang Betz |
34:edda6a7238ec | 370 | |
| Wolfgang Betz |
34:edda6a7238ec | 371 | /* Writes the new RCO prescaler in the MCU_CLOCK register */ |
| Wolfgang Betz |
34:edda6a7238ec | 372 | g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 373 | |
| Wolfgang Betz |
34:edda6a7238ec | 374 | } |
| Wolfgang Betz |
34:edda6a7238ec | 375 | |
| Wolfgang Betz |
34:edda6a7238ec | 376 | |
| Wolfgang Betz |
34:edda6a7238ec | 377 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 378 | * @brief Returns the settled RCO prescaler as clock output. |
| Wolfgang Betz |
34:edda6a7238ec | 379 | * @param None. |
| Wolfgang Betz |
34:edda6a7238ec | 380 | * @retval ClockOutputRCOPrescaler Settled RCO prescaler used for clock |
| Wolfgang Betz |
34:edda6a7238ec | 381 | * output. This parameter can be a value of @ref ClockOutputRCOPrescaler. |
| Wolfgang Betz |
34:edda6a7238ec | 382 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 383 | ClockOutputRCOPrescaler SpiritGpioGetRCOPrescaler(void) |
| Wolfgang Betz |
34:edda6a7238ec | 384 | { |
| Wolfgang Betz |
34:edda6a7238ec | 385 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 386 | |
| Wolfgang Betz |
34:edda6a7238ec | 387 | /* Reads the MCU_CLK_CONFIG register */ |
| Wolfgang Betz |
34:edda6a7238ec | 388 | g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 389 | |
| Wolfgang Betz |
34:edda6a7238ec | 390 | /* Mask the RCO_RATIO field and returns the value */ |
| Wolfgang Betz |
34:edda6a7238ec | 391 | return ((ClockOutputRCOPrescaler)(tempRegValue & 0x01)); |
| Wolfgang Betz |
34:edda6a7238ec | 392 | |
| Wolfgang Betz |
34:edda6a7238ec | 393 | } |
| Wolfgang Betz |
34:edda6a7238ec | 394 | |
| Wolfgang Betz |
34:edda6a7238ec | 395 | |
| Wolfgang Betz |
34:edda6a7238ec | 396 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 397 | * @brief Sets the RCO ratio as clock output. |
| Wolfgang Betz |
34:edda6a7238ec | 398 | * @param xExtraCycles the number of extra clock cycles provided before switching |
| Wolfgang Betz |
34:edda6a7238ec | 399 | * to STANDBY state. This parameter can be any value of @ref ExtraClockCycles . |
| Wolfgang Betz |
34:edda6a7238ec | 400 | * @retval None. |
| Wolfgang Betz |
34:edda6a7238ec | 401 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 402 | void SpiritGpioSetExtraClockCycles(ExtraClockCycles xExtraCycles) |
| Wolfgang Betz |
34:edda6a7238ec | 403 | { |
| Wolfgang Betz |
34:edda6a7238ec | 404 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 405 | |
| Wolfgang Betz |
34:edda6a7238ec | 406 | /* Check the parameters */ |
| Wolfgang Betz |
34:edda6a7238ec | 407 | s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_EXTRA_CYCLES(xExtraCycles)); |
| Wolfgang Betz |
34:edda6a7238ec | 408 | |
| Wolfgang Betz |
34:edda6a7238ec | 409 | /* Reads the MCU_CLK_CONFIG register */ |
| Wolfgang Betz |
34:edda6a7238ec | 410 | g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 411 | |
| Wolfgang Betz |
34:edda6a7238ec | 412 | /* Mask the CLOCK_TAIL field and writes the new value */ |
| Wolfgang Betz |
34:edda6a7238ec | 413 | tempRegValue &= 0x9F; |
| Wolfgang Betz |
34:edda6a7238ec | 414 | tempRegValue |= ((uint8_t)xExtraCycles); |
| Wolfgang Betz |
34:edda6a7238ec | 415 | |
| Wolfgang Betz |
34:edda6a7238ec | 416 | /* Writes the new number of extra clock cycles in the MCU_CLOCK register */ |
| Wolfgang Betz |
34:edda6a7238ec | 417 | g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 418 | |
| Wolfgang Betz |
34:edda6a7238ec | 419 | } |
| Wolfgang Betz |
34:edda6a7238ec | 420 | |
| Wolfgang Betz |
34:edda6a7238ec | 421 | |
| Wolfgang Betz |
34:edda6a7238ec | 422 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 423 | * @brief Returns the settled RCO prescaler as clock output. |
| Wolfgang Betz |
34:edda6a7238ec | 424 | * @param None. |
| Wolfgang Betz |
34:edda6a7238ec | 425 | * @retval ExtraClockCycles Settled number of extra clock cycles |
| Wolfgang Betz |
34:edda6a7238ec | 426 | * provided before switching to STANDBY state. This parameter can be |
| Wolfgang Betz |
34:edda6a7238ec | 427 | * any value of @ref ExtraClockCycles . |
| Wolfgang Betz |
34:edda6a7238ec | 428 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 429 | ExtraClockCycles SpiritGpioGetExtraClockCycles(void) |
| Wolfgang Betz |
34:edda6a7238ec | 430 | { |
| Wolfgang Betz |
34:edda6a7238ec | 431 | uint8_t tempRegValue = 0x00; |
| Wolfgang Betz |
34:edda6a7238ec | 432 | |
| Wolfgang Betz |
34:edda6a7238ec | 433 | /* Reads the MCU_CLK_CONFIG register */ |
| Wolfgang Betz |
34:edda6a7238ec | 434 | g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); |
| Wolfgang Betz |
34:edda6a7238ec | 435 | |
| Wolfgang Betz |
34:edda6a7238ec | 436 | /* Mask the CLOCK_TAIL field and returns the value */ |
| Wolfgang Betz |
34:edda6a7238ec | 437 | return ((ExtraClockCycles)(tempRegValue & 0x60)); |
| Wolfgang Betz |
34:edda6a7238ec | 438 | |
| Wolfgang Betz |
34:edda6a7238ec | 439 | } |
| Wolfgang Betz |
34:edda6a7238ec | 440 | |
| Wolfgang Betz |
34:edda6a7238ec | 441 | |
| Wolfgang Betz |
34:edda6a7238ec | 442 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 443 | * @} |
| Wolfgang Betz |
34:edda6a7238ec | 444 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 445 | |
| Wolfgang Betz |
34:edda6a7238ec | 446 | |
| Wolfgang Betz |
34:edda6a7238ec | 447 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 448 | * @} |
| Wolfgang Betz |
34:edda6a7238ec | 449 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 450 | |
| Wolfgang Betz |
34:edda6a7238ec | 451 | |
| Wolfgang Betz |
34:edda6a7238ec | 452 | /** |
| Wolfgang Betz |
34:edda6a7238ec | 453 | * @} |
| Wolfgang Betz |
34:edda6a7238ec | 454 | */ |
| Wolfgang Betz |
34:edda6a7238ec | 455 | |
| Wolfgang Betz |
34:edda6a7238ec | 456 | |
| Wolfgang Betz |
34:edda6a7238ec | 457 | |
| Wolfgang Betz |
34:edda6a7238ec | 458 | /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/ |
X-NUCLEO-IDS01A4 Sub-1GHz RF Expansion Board