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.
Fork of nRF51822 by
nordic-sdk/components/drivers_nrf/hal/nrf_gpiote.h@386:3253b512fb24, 2015-07-21 (annotated)
- Committer:
- rgrover1
- Date:
- Tue Jul 21 13:23:43 2015 +0100
- Revision:
- 386:3253b512fb24
- Parent:
- source/nordic-sdk/components/drivers_nrf/hal/nrf_gpiote.h@381:c997e9717fb7
Synchronized with git rev 928a5e63
Author: Rohit Grover
Release 0.4.1
=============
This is a minor release.
Enhancements
~~~~~~~~~~~~
* Hide duplicate symbol definitions in ble_types.h. These have already been
brought into ble/blecommon.h.
* Replace DiscoveredCharacteristic::setupOnDataRead() with
GattClient::onDataRead().
* Implement new API GattServer::areUpdatesEnabled() to determine notification
status for a characteristic.
Bugfixes
~~~~~~~~
* fix for #20: GattServer::addService() incorrectly initialized value
attribute-handles. These were getting confused with characteristicIndex.
Event handlers also return attribute handles correctly now; they were also
previously returning characteristic indices.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 371:8f7d2137727a | 1 | /* |
rgrover1 | 371:8f7d2137727a | 2 | * Copyright (c) Nordic Semiconductor ASA |
rgrover1 | 371:8f7d2137727a | 3 | * All rights reserved. |
rgrover1 | 371:8f7d2137727a | 4 | * |
rgrover1 | 371:8f7d2137727a | 5 | * Redistribution and use in source and binary forms, with or without modification, |
rgrover1 | 371:8f7d2137727a | 6 | * are permitted provided that the following conditions are met: |
rgrover1 | 371:8f7d2137727a | 7 | * |
rgrover1 | 371:8f7d2137727a | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
rgrover1 | 371:8f7d2137727a | 9 | * list of conditions and the following disclaimer. |
rgrover1 | 371:8f7d2137727a | 10 | * |
rgrover1 | 371:8f7d2137727a | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
rgrover1 | 371:8f7d2137727a | 12 | * list of conditions and the following disclaimer in the documentation and/or |
rgrover1 | 371:8f7d2137727a | 13 | * other materials provided with the distribution. |
rgrover1 | 371:8f7d2137727a | 14 | * |
rgrover1 | 371:8f7d2137727a | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
rgrover1 | 371:8f7d2137727a | 16 | * contributors to this software may be used to endorse or promote products |
rgrover1 | 371:8f7d2137727a | 17 | * derived from this software without specific prior written permission. |
rgrover1 | 371:8f7d2137727a | 18 | * |
rgrover1 | 371:8f7d2137727a | 19 | * |
rgrover1 | 371:8f7d2137727a | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
rgrover1 | 371:8f7d2137727a | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
rgrover1 | 371:8f7d2137727a | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
rgrover1 | 371:8f7d2137727a | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
rgrover1 | 371:8f7d2137727a | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
rgrover1 | 371:8f7d2137727a | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
rgrover1 | 371:8f7d2137727a | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
rgrover1 | 371:8f7d2137727a | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
rgrover1 | 371:8f7d2137727a | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
rgrover1 | 371:8f7d2137727a | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
rgrover1 | 371:8f7d2137727a | 30 | * |
rgrover1 | 371:8f7d2137727a | 31 | */ |
rgrover1 | 371:8f7d2137727a | 32 | #ifndef NRF_GPIOTE_H__ |
rgrover1 | 371:8f7d2137727a | 33 | #define NRF_GPIOTE_H__ |
rgrover1 | 371:8f7d2137727a | 34 | |
rgrover1 | 371:8f7d2137727a | 35 | #include "nrf.h" |
rgrover1 | 371:8f7d2137727a | 36 | |
rgrover1 | 371:8f7d2137727a | 37 | /** |
rgrover1 | 371:8f7d2137727a | 38 | * @defgroup nrf_gpiote GPIOTE abstraction |
rgrover1 | 371:8f7d2137727a | 39 | * @{ |
rgrover1 | 371:8f7d2137727a | 40 | * @ingroup nrf_drivers |
rgrover1 | 371:8f7d2137727a | 41 | * @brief GPIOTE abstraction for configuration of channels. |
rgrover1 | 371:8f7d2137727a | 42 | */ |
rgrover1 | 371:8f7d2137727a | 43 | |
rgrover1 | 371:8f7d2137727a | 44 | |
rgrover1 | 371:8f7d2137727a | 45 | /** |
rgrover1 | 371:8f7d2137727a | 46 | * @enum nrf_gpiote_polarity_t |
rgrover1 | 371:8f7d2137727a | 47 | * @brief Polarity for GPIOTE channel enumerator. |
rgrover1 | 371:8f7d2137727a | 48 | */ |
rgrover1 | 371:8f7d2137727a | 49 | typedef enum |
rgrover1 | 371:8f7d2137727a | 50 | { |
rgrover1 | 371:8f7d2137727a | 51 | NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi, ///< Low to high |
rgrover1 | 371:8f7d2137727a | 52 | NRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo, ///< High to low |
rgrover1 | 371:8f7d2137727a | 53 | NRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle ///< Toggle |
rgrover1 | 371:8f7d2137727a | 54 | } nrf_gpiote_polarity_t; |
rgrover1 | 371:8f7d2137727a | 55 | |
rgrover1 | 371:8f7d2137727a | 56 | |
rgrover1 | 371:8f7d2137727a | 57 | /** |
rgrover1 | 371:8f7d2137727a | 58 | * @enum nrf_gpiote_outinit_t |
rgrover1 | 371:8f7d2137727a | 59 | * @brief Initial output value for GPIOTE channel enumerator. |
rgrover1 | 371:8f7d2137727a | 60 | */ |
rgrover1 | 371:8f7d2137727a | 61 | typedef enum |
rgrover1 | 371:8f7d2137727a | 62 | { |
rgrover1 | 371:8f7d2137727a | 63 | NRF_GPIOTE_INITIAL_VALUE_LOW = GPIOTE_CONFIG_OUTINIT_Low, ///< Low to high |
rgrover1 | 371:8f7d2137727a | 64 | NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High ///< High to low |
rgrover1 | 371:8f7d2137727a | 65 | } nrf_gpiote_outinit_t; |
rgrover1 | 371:8f7d2137727a | 66 | |
rgrover1 | 371:8f7d2137727a | 67 | |
rgrover1 | 371:8f7d2137727a | 68 | /** |
rgrover1 | 371:8f7d2137727a | 69 | * @brief Function for configuring GPIOTE channel as output, setting the properly desired output level. |
rgrover1 | 371:8f7d2137727a | 70 | * |
rgrover1 | 371:8f7d2137727a | 71 | * |
rgrover1 | 371:8f7d2137727a | 72 | * @param channel_number specifies the GPIOTE channel [0:3] to configure as an output channel. |
rgrover1 | 371:8f7d2137727a | 73 | * @param pin_number specifies the pin number [0:30] to use in the GPIOTE channel. |
rgrover1 | 371:8f7d2137727a | 74 | * @param polarity specifies the desired polarity in the output GPIOTE channel. |
rgrover1 | 371:8f7d2137727a | 75 | * @param initial_value specifies the initial value of the GPIOTE channel input after the channel configuration. |
rgrover1 | 371:8f7d2137727a | 76 | */ |
rgrover1 | 371:8f7d2137727a | 77 | static __INLINE void nrf_gpiote_task_config(uint32_t channel_number, uint32_t pin_number, nrf_gpiote_polarity_t polarity, nrf_gpiote_outinit_t initial_value) |
rgrover1 | 371:8f7d2137727a | 78 | { |
rgrover1 | 371:8f7d2137727a | 79 | /* Check if the output desired is high or low */ |
rgrover1 | 371:8f7d2137727a | 80 | if (initial_value == NRF_GPIOTE_INITIAL_VALUE_LOW) |
rgrover1 | 371:8f7d2137727a | 81 | { |
rgrover1 | 371:8f7d2137727a | 82 | /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens |
rgrover1 | 371:8f7d2137727a | 83 | on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the |
rgrover1 | 371:8f7d2137727a | 84 | correct state in GPIOTE but not in the OUT register. */ |
rgrover1 | 371:8f7d2137727a | 85 | NRF_GPIO->OUTCLR = (1 << pin_number); |
rgrover1 | 371:8f7d2137727a | 86 | |
rgrover1 | 371:8f7d2137727a | 87 | /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */ |
rgrover1 | 371:8f7d2137727a | 88 | NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | |
rgrover1 | 371:8f7d2137727a | 89 | (31UL << GPIOTE_CONFIG_PSEL_Pos) | |
rgrover1 | 371:8f7d2137727a | 90 | (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos); |
rgrover1 | 371:8f7d2137727a | 91 | } |
rgrover1 | 371:8f7d2137727a | 92 | else |
rgrover1 | 371:8f7d2137727a | 93 | { |
rgrover1 | 371:8f7d2137727a | 94 | /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens |
rgrover1 | 371:8f7d2137727a | 95 | on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the |
rgrover1 | 371:8f7d2137727a | 96 | correct state in GPIOTE but not in the OUT register. */ |
rgrover1 | 371:8f7d2137727a | 97 | NRF_GPIO->OUTSET = (1 << pin_number); |
rgrover1 | 371:8f7d2137727a | 98 | |
rgrover1 | 371:8f7d2137727a | 99 | /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */ |
rgrover1 | 371:8f7d2137727a | 100 | NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | |
rgrover1 | 371:8f7d2137727a | 101 | (31UL << GPIOTE_CONFIG_PSEL_Pos) | |
rgrover1 | 371:8f7d2137727a | 102 | (GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos); |
rgrover1 | 371:8f7d2137727a | 103 | } |
rgrover1 | 371:8f7d2137727a | 104 | |
rgrover1 | 371:8f7d2137727a | 105 | /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ |
rgrover1 | 371:8f7d2137727a | 106 | __NOP(); |
rgrover1 | 371:8f7d2137727a | 107 | __NOP(); |
rgrover1 | 371:8f7d2137727a | 108 | __NOP(); |
rgrover1 | 371:8f7d2137727a | 109 | |
rgrover1 | 371:8f7d2137727a | 110 | /* Launch the task to take the GPIOTE channel output to the desired level */ |
rgrover1 | 371:8f7d2137727a | 111 | NRF_GPIOTE->TASKS_OUT[channel_number] = 1; |
rgrover1 | 371:8f7d2137727a | 112 | |
rgrover1 | 371:8f7d2137727a | 113 | |
rgrover1 | 371:8f7d2137727a | 114 | /* Finally configure the channel as the caller expects. If OUTINIT works, the channel is configured properly. |
rgrover1 | 371:8f7d2137727a | 115 | If it does not, the channel output inheritance sets the proper level. */ |
rgrover1 | 371:8f7d2137727a | 116 | NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | |
rgrover1 | 371:8f7d2137727a | 117 | ((uint32_t)pin_number << GPIOTE_CONFIG_PSEL_Pos) | |
rgrover1 | 371:8f7d2137727a | 118 | ((uint32_t)polarity << GPIOTE_CONFIG_POLARITY_Pos) | |
rgrover1 | 371:8f7d2137727a | 119 | ((uint32_t)initial_value << GPIOTE_CONFIG_OUTINIT_Pos); |
rgrover1 | 371:8f7d2137727a | 120 | |
rgrover1 | 371:8f7d2137727a | 121 | /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ |
rgrover1 | 371:8f7d2137727a | 122 | __NOP(); |
rgrover1 | 371:8f7d2137727a | 123 | __NOP(); |
rgrover1 | 371:8f7d2137727a | 124 | __NOP(); |
rgrover1 | 371:8f7d2137727a | 125 | } |
rgrover1 | 371:8f7d2137727a | 126 | |
rgrover1 | 371:8f7d2137727a | 127 | /** |
rgrover1 | 371:8f7d2137727a | 128 | * @brief Function for configuring GPIOTE channel as input, automatically clearing an event that appears in some cases under configuration. |
rgrover1 | 371:8f7d2137727a | 129 | * |
rgrover1 | 371:8f7d2137727a | 130 | * Note that when configuring the channel as input an event might be triggered. Care of disabling interrupts |
rgrover1 | 371:8f7d2137727a | 131 | * for that channel is left to the user. |
rgrover1 | 371:8f7d2137727a | 132 | * |
rgrover1 | 371:8f7d2137727a | 133 | * @param channel_number specifies the GPIOTE channel [0:3] to configure as an input channel. |
rgrover1 | 371:8f7d2137727a | 134 | * @param pin_number specifies the pin number [0:30] to use in the GPIOTE channel. |
rgrover1 | 371:8f7d2137727a | 135 | * @param polarity specifies the desired polarity in the output GPIOTE channel. |
rgrover1 | 371:8f7d2137727a | 136 | */ |
rgrover1 | 371:8f7d2137727a | 137 | static __INLINE void nrf_gpiote_event_config(uint32_t channel_number, uint32_t pin_number, nrf_gpiote_polarity_t polarity) |
rgrover1 | 371:8f7d2137727a | 138 | { |
rgrover1 | 371:8f7d2137727a | 139 | /* Configure the channel as the caller expects */ |
rgrover1 | 371:8f7d2137727a | 140 | NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos) | |
rgrover1 | 371:8f7d2137727a | 141 | ((uint32_t)pin_number << GPIOTE_CONFIG_PSEL_Pos) | |
rgrover1 | 371:8f7d2137727a | 142 | ((uint32_t)polarity << GPIOTE_CONFIG_POLARITY_Pos); |
rgrover1 | 371:8f7d2137727a | 143 | |
rgrover1 | 371:8f7d2137727a | 144 | /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ |
rgrover1 | 371:8f7d2137727a | 145 | __NOP(); |
rgrover1 | 371:8f7d2137727a | 146 | __NOP(); |
rgrover1 | 371:8f7d2137727a | 147 | __NOP(); |
rgrover1 | 371:8f7d2137727a | 148 | |
rgrover1 | 371:8f7d2137727a | 149 | /* Clear the event that appears in some cases */ |
rgrover1 | 371:8f7d2137727a | 150 | NRF_GPIOTE->EVENTS_IN[channel_number] = 0; |
rgrover1 | 371:8f7d2137727a | 151 | } |
rgrover1 | 371:8f7d2137727a | 152 | |
rgrover1 | 371:8f7d2137727a | 153 | |
rgrover1 | 371:8f7d2137727a | 154 | /** |
rgrover1 | 371:8f7d2137727a | 155 | * @brief Function for unconfiguring GPIOTE channel. |
rgrover1 | 371:8f7d2137727a | 156 | * |
rgrover1 | 371:8f7d2137727a | 157 | * |
rgrover1 | 371:8f7d2137727a | 158 | * Note that when unconfiguring the channel, the pin is configured as GPIO PIN_CNF configuration. |
rgrover1 | 371:8f7d2137727a | 159 | * |
rgrover1 | 371:8f7d2137727a | 160 | * @param channel_number specifies the GPIOTE channel [0:3] to unconfigure. |
rgrover1 | 371:8f7d2137727a | 161 | */ |
rgrover1 | 371:8f7d2137727a | 162 | static __INLINE void nrf_gpiote_unconfig(uint32_t channel_number) |
rgrover1 | 371:8f7d2137727a | 163 | { |
rgrover1 | 371:8f7d2137727a | 164 | /* Unonfigure the channel as the caller expects */ |
rgrover1 | 371:8f7d2137727a | 165 | NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Disabled << GPIOTE_CONFIG_MODE_Pos) | |
rgrover1 | 371:8f7d2137727a | 166 | (31UL << GPIOTE_CONFIG_PSEL_Pos) | |
rgrover1 | 371:8f7d2137727a | 167 | (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos); |
rgrover1 | 371:8f7d2137727a | 168 | } |
rgrover1 | 371:8f7d2137727a | 169 | |
rgrover1 | 371:8f7d2137727a | 170 | |
rgrover1 | 371:8f7d2137727a | 171 | /** @} */ |
rgrover1 | 371:8f7d2137727a | 172 | |
rgrover1 | 371:8f7d2137727a | 173 | #endif |