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
nrf_gpiote.h
00001 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * Terms and conditions of usage are described in detail in NORDIC 00005 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 */ 00012 #ifndef NRF_GPIOTE_H__ 00013 #define NRF_GPIOTE_H__ 00014 00015 #include "nrf.h" 00016 00017 /** 00018 * @defgroup nrf_gpiote GPIOTE abstraction 00019 * @{ 00020 * @ingroup nrf_drivers 00021 * @brief GPIOTE abstraction for configuration of channels. 00022 */ 00023 00024 00025 /** 00026 * @enum nrf_gpiote_polarity_t 00027 * @brief Polarity for GPIOTE channel enumerator. 00028 */ 00029 typedef enum 00030 { 00031 NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi, ///< Low to high 00032 NRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo, ///< High to low 00033 NRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle ///< Toggle 00034 } nrf_gpiote_polarity_t; 00035 00036 00037 /** 00038 * @enum nrf_gpiote_outinit_t 00039 * @brief Initial output value for GPIOTE channel enumerator. 00040 */ 00041 typedef enum 00042 { 00043 NRF_GPIOTE_INITIAL_VALUE_LOW = GPIOTE_CONFIG_OUTINIT_Low, ///< Low to high 00044 NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High ///< High to low 00045 } nrf_gpiote_outinit_t; 00046 00047 00048 /** 00049 * @brief Function for configuring GPIOTE channel as output, setting the properly desired output level. 00050 * 00051 * 00052 * @param channel_number specifies the GPIOTE channel [0:3] to configure as an output channel. 00053 * @param pin_number specifies the pin number [0:30] to use in the GPIOTE channel. 00054 * @param polarity specifies the desired polarity in the output GPIOTE channel. 00055 * @param initial_value specifies the initial value of the GPIOTE channel input after the channel configuration. 00056 */ 00057 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) 00058 { 00059 /* Check if the output desired is high or low */ 00060 if (initial_value == NRF_GPIOTE_INITIAL_VALUE_LOW) 00061 { 00062 /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens 00063 on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the 00064 correct state in GPIOTE but not in the OUT register. */ 00065 NRF_GPIO->OUTCLR = (1 << pin_number); 00066 00067 /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */ 00068 NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | 00069 (31UL << GPIOTE_CONFIG_PSEL_Pos) | 00070 (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos); 00071 } 00072 else 00073 { 00074 /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens 00075 on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the 00076 correct state in GPIOTE but not in the OUT register. */ 00077 NRF_GPIO->OUTSET = (1 << pin_number); 00078 00079 /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */ 00080 NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | 00081 (31UL << GPIOTE_CONFIG_PSEL_Pos) | 00082 (GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos); 00083 } 00084 00085 /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ 00086 __NOP(); 00087 __NOP(); 00088 __NOP(); 00089 00090 /* Launch the task to take the GPIOTE channel output to the desired level */ 00091 NRF_GPIOTE->TASKS_OUT[channel_number] = 1; 00092 00093 00094 /* Finally configure the channel as the caller expects. If OUTINIT works, the channel is configured properly. 00095 If it does not, the channel output inheritance sets the proper level. */ 00096 NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | 00097 ((uint32_t)pin_number << GPIOTE_CONFIG_PSEL_Pos) | 00098 ((uint32_t)polarity << GPIOTE_CONFIG_POLARITY_Pos) | 00099 ((uint32_t)initial_value << GPIOTE_CONFIG_OUTINIT_Pos); 00100 00101 /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ 00102 __NOP(); 00103 __NOP(); 00104 __NOP(); 00105 } 00106 00107 /** 00108 * @brief Function for configuring GPIOTE channel as input, automatically clearing an event that appears in some cases under configuration. 00109 * 00110 * Note that when configuring the channel as input an event might be triggered. Care of disabling interrupts 00111 * for that channel is left to the user. 00112 * 00113 * @param channel_number specifies the GPIOTE channel [0:3] to configure as an input channel. 00114 * @param pin_number specifies the pin number [0:30] to use in the GPIOTE channel. 00115 * @param polarity specifies the desired polarity in the output GPIOTE channel. 00116 */ 00117 static __INLINE void nrf_gpiote_event_config(uint32_t channel_number, uint32_t pin_number, nrf_gpiote_polarity_t polarity) 00118 { 00119 /* Configure the channel as the caller expects */ 00120 NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos) | 00121 ((uint32_t)pin_number << GPIOTE_CONFIG_PSEL_Pos) | 00122 ((uint32_t)polarity << GPIOTE_CONFIG_POLARITY_Pos); 00123 00124 /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ 00125 __NOP(); 00126 __NOP(); 00127 __NOP(); 00128 00129 /* Clear the event that appears in some cases */ 00130 NRF_GPIOTE->EVENTS_IN[channel_number] = 0; 00131 } 00132 00133 00134 /** 00135 * @brief Function for unconfiguring GPIOTE channel. 00136 * 00137 * 00138 * Note that when unconfiguring the channel, the pin is configured as GPIO PIN_CNF configuration. 00139 * 00140 * @param channel_number specifies the GPIOTE channel [0:3] to unconfigure. 00141 */ 00142 static __INLINE void nrf_gpiote_unconfig(uint32_t channel_number) 00143 { 00144 /* Unonfigure the channel as the caller expects */ 00145 NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Disabled << GPIOTE_CONFIG_MODE_Pos) | 00146 (31UL << GPIOTE_CONFIG_PSEL_Pos) | 00147 (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos); 00148 } 00149 00150 00151 /** @} */ 00152 00153 #endif
Generated on Tue Jul 12 2022 16:21:03 by
