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
app_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 00013 /** @file 00014 * 00015 * @defgroup app_gpiote GPIOTE Handler 00016 * @{ 00017 * @ingroup app_common 00018 * 00019 * @brief GPIOTE handler module. 00020 * 00021 * @details The GPIOTE handler allows several modules ("users") to share the GPIOTE interrupt, 00022 * each user defining a set of pins able to generate events to the user. 00023 * When a GPIOTE interrupt occurs, the GPIOTE interrupt handler will call the event handler 00024 * of each user for which at least one of the pins generated an event. 00025 * 00026 * The GPIOTE users are responsible for configuring all their corresponding pins, except 00027 * the SENSE field, which should be initialized to GPIO_PIN_CNF_SENSE_Disabled. 00028 * The SENSE field will be updated by the GPIOTE module when it is enabled or disabled, 00029 * and also while it is enabled. 00030 * 00031 * The module specifies on which pins events should be generated if the pin(s) goes 00032 * from low->high or high->low or both directions. 00033 * 00034 * @note Even if the application is using the @ref app_scheduler, the GPIOTE event handlers will 00035 * be called directly from the GPIOTE interrupt handler. 00036 */ 00037 00038 #ifndef APP_GPIOTE_H__ 00039 #define APP_GPIOTE_H__ 00040 00041 #include <stdint.h> 00042 #include <stdbool.h> 00043 #include "nordic_global.h" 00044 #include "nrf.h" 00045 #include "app_error.h " 00046 #include "app_util.h " 00047 00048 #define GPIOTE_USER_NODE_SIZE 20 /**< Size of app_gpiote.gpiote_user_t (only for use inside APP_GPIOTE_BUF_SIZE()). */ 00049 #define NO_OF_PINS 32 /**< Number of GPIO pins on the nRF51 chip. */ 00050 00051 /**@brief Compute number of bytes required to hold the GPIOTE data structures. 00052 * 00053 * @param[in] MAX_USERS Maximum number of GPIOTE users. 00054 * 00055 * @return Required buffer size (in bytes). 00056 */ 00057 #define APP_GPIOTE_BUF_SIZE(MAX_USERS) ((MAX_USERS) * GPIOTE_USER_NODE_SIZE) 00058 00059 typedef uint8_t app_gpiote_user_id_t; 00060 00061 /**@brief GPIOTE event handler type. */ 00062 typedef void (*app_gpiote_event_handler_t)(uint32_t event_pins_low_to_high, 00063 uint32_t event_pins_high_to_low); 00064 00065 /**@brief Macro for initializing the GPIOTE module. 00066 * 00067 * @details It will handle dimensioning and allocation of the memory buffer required by the module, 00068 * making sure that the buffer is correctly aligned. 00069 * 00070 * @param[in] MAX_USERS Maximum number of GPIOTE users. 00071 * 00072 * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it 00073 * several times as long as it is from the same location, e.g. to do a reinitialization). 00074 */ 00075 /*lint -emacro(506, APP_GPIOTE_INIT) */ /* Suppress "Constant value Boolean */ 00076 #define APP_GPIOTE_INIT(MAX_USERS) \ 00077 do \ 00078 { \ 00079 static uint32_t app_gpiote_buf[CEIL_DIV(APP_GPIOTE_BUF_SIZE(MAX_USERS), sizeof(uint32_t))];\ 00080 uint32_t ERR_CODE = app_gpiote_init((MAX_USERS), app_gpiote_buf); \ 00081 APP_ERROR_CHECK(ERR_CODE); \ 00082 } while (0) 00083 00084 /**@brief Function for initializing the GPIOTE module. 00085 * 00086 * @note Normally initialization should be done using the APP_GPIOTE_INIT() macro, as that will 00087 * allocate the buffer needed by the GPIOTE module (including aligning the buffer correctly). 00088 * 00089 * @param[in] max_users Maximum number of GPIOTE users. 00090 * @param[in] p_buffer Pointer to memory buffer for internal use in the app_gpiote 00091 * module. The size of the buffer can be computed using the 00092 * APP_GPIOTE_BUF_SIZE() macro. The buffer must be aligned to 00093 * a 4 byte boundary. 00094 * 00095 * @retval NRF_SUCCESS Successful initialization. 00096 * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte 00097 * boundary). 00098 */ 00099 uint32_t app_gpiote_init(uint8_t max_users, void * p_buffer); 00100 00101 /**@brief Function for registering a GPIOTE user. 00102 * 00103 * @param[out] p_user_id Id for the new GPIOTE user. 00104 * @param[in] pins_low_to_high_mask Mask defining which pins will generate events to this user 00105 * when state is changed from low->high. 00106 * @param[in] pins_high_to_low_mask Mask defining which pins will generate events to this user 00107 * when state is changed from high->low. 00108 * @param[in] event_handler Pointer to function to be executed when an event occurs. 00109 * 00110 * @retval NRF_SUCCESS Successful initialization. 00111 * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte boundary). 00112 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE 00113 * module. 00114 * @retval NRF_ERROR_NO_MEM Returned if the application tries to register more users 00115 * than defined when the GPIOTE module was initialized in 00116 * @ref app_gpiote_init. 00117 */ 00118 uint32_t app_gpiote_user_register(app_gpiote_user_id_t * p_user_id, 00119 uint32_t pins_low_to_high_mask, 00120 uint32_t pins_high_to_low_mask, 00121 app_gpiote_event_handler_t event_handler); 00122 00123 /**@brief Function for informing the GPIOTE module that the specified user wants to use the GPIOTE module. 00124 * 00125 * @param[in] user_id Id of user to enable. 00126 * 00127 * @retval NRF_SUCCESS On success. 00128 * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user. 00129 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE 00130 * module. 00131 */ 00132 uint32_t app_gpiote_user_enable(app_gpiote_user_id_t user_id); 00133 00134 /**@brief Function for informing the GPIOTE module that the specified user is done using the GPIOTE module. 00135 * 00136 * @param[in] user_id Id of user to enable. 00137 * 00138 * @return NRF_SUCCESS On success. 00139 * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user. 00140 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE 00141 * module. 00142 */ 00143 uint32_t app_gpiote_user_disable(app_gpiote_user_id_t user_id); 00144 00145 /**@brief Function for getting the state of the pins which are registered for the specified user. 00146 * 00147 * @param[in] user_id Id of user to check. 00148 * @param[out] p_pins Bit mask corresponding to the pins configured to generate events to 00149 * the specified user. All bits corresponding to pins in the state 00150 * 'high' will have value '1', all others will have value '0'. 00151 * 00152 * @return NRF_SUCCESS On success. 00153 * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user. 00154 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE 00155 * module. 00156 */ 00157 uint32_t app_gpiote_pins_state_get(app_gpiote_user_id_t user_id, uint32_t * p_pins); 00158 00159 #endif // APP_GPIOTE_H__ 00160 00161 /** @} */
Generated on Tue Jul 12 2022 19:00:51 by
