To get started with Seeed Tiny BLE, include detecting motion, button and battery level.

Dependencies:   BLE_API eMPL_MPU6050 mbed nRF51822

Committer:
yihui
Date:
Wed Apr 22 07:47:17 2015 +0000
Revision:
1:fc2f9d636751
update libraries; ; delete nRF51822/nordic-sdk/components/gpiote/app_gpiote.c to solve GPIOTE_IRQHandler multiply defined issue. temperarily change nRF51822 library to folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 1:fc2f9d636751 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
yihui 1:fc2f9d636751 2 *
yihui 1:fc2f9d636751 3 * The information contained herein is property of Nordic Semiconductor ASA.
yihui 1:fc2f9d636751 4 * Terms and conditions of usage are described in detail in NORDIC
yihui 1:fc2f9d636751 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
yihui 1:fc2f9d636751 6 *
yihui 1:fc2f9d636751 7 * Licensees are granted free, non-transferable use of the information. NO
yihui 1:fc2f9d636751 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
yihui 1:fc2f9d636751 9 * the file.
yihui 1:fc2f9d636751 10 *
yihui 1:fc2f9d636751 11 */
yihui 1:fc2f9d636751 12
yihui 1:fc2f9d636751 13 /** @file
yihui 1:fc2f9d636751 14 *
yihui 1:fc2f9d636751 15 * @defgroup app_gpiote GPIOTE Handler
yihui 1:fc2f9d636751 16 * @{
yihui 1:fc2f9d636751 17 * @ingroup app_common
yihui 1:fc2f9d636751 18 *
yihui 1:fc2f9d636751 19 * @brief GPIOTE handler module.
yihui 1:fc2f9d636751 20 *
yihui 1:fc2f9d636751 21 * @details The GPIOTE handler allows several modules ("users") to share the GPIOTE interrupt,
yihui 1:fc2f9d636751 22 * each user defining a set of pins able to generate events to the user.
yihui 1:fc2f9d636751 23 * When a GPIOTE interrupt occurs, the GPIOTE interrupt handler will call the event handler
yihui 1:fc2f9d636751 24 * of each user for which at least one of the pins generated an event.
yihui 1:fc2f9d636751 25 *
yihui 1:fc2f9d636751 26 * The GPIOTE users are responsible for configuring all their corresponding pins, except
yihui 1:fc2f9d636751 27 * the SENSE field, which should be initialized to GPIO_PIN_CNF_SENSE_Disabled.
yihui 1:fc2f9d636751 28 * The SENSE field will be updated by the GPIOTE module when it is enabled or disabled,
yihui 1:fc2f9d636751 29 * and also while it is enabled.
yihui 1:fc2f9d636751 30 *
yihui 1:fc2f9d636751 31 * The module specifies on which pins events should be generated if the pin(s) goes
yihui 1:fc2f9d636751 32 * from low->high or high->low or both directions.
yihui 1:fc2f9d636751 33 *
yihui 1:fc2f9d636751 34 * @note Even if the application is using the @ref app_scheduler, the GPIOTE event handlers will
yihui 1:fc2f9d636751 35 * be called directly from the GPIOTE interrupt handler.
yihui 1:fc2f9d636751 36 *
yihui 1:fc2f9d636751 37 * @warning If multiple users registers for the same pins the behavior for those pins are undefined.
yihui 1:fc2f9d636751 38 */
yihui 1:fc2f9d636751 39
yihui 1:fc2f9d636751 40 #ifndef APP_GPIOTE_H__
yihui 1:fc2f9d636751 41 #define APP_GPIOTE_H__
yihui 1:fc2f9d636751 42
yihui 1:fc2f9d636751 43 #include <stdint.h>
yihui 1:fc2f9d636751 44 #include <stdbool.h>
yihui 1:fc2f9d636751 45 #include "nrf.h"
yihui 1:fc2f9d636751 46 #include "app_error.h"
yihui 1:fc2f9d636751 47 #include "app_util.h"
yihui 1:fc2f9d636751 48
yihui 1:fc2f9d636751 49 #define GPIOTE_USER_NODE_SIZE 20 /**< Size of app_gpiote.gpiote_user_t (only for use inside APP_GPIOTE_BUF_SIZE()). */
yihui 1:fc2f9d636751 50 #define NO_OF_PINS 32 /**< Number of GPIO pins on the nRF51 chip. */
yihui 1:fc2f9d636751 51
yihui 1:fc2f9d636751 52 /**@brief Compute number of bytes required to hold the GPIOTE data structures.
yihui 1:fc2f9d636751 53 *
yihui 1:fc2f9d636751 54 * @param[in] MAX_USERS Maximum number of GPIOTE users.
yihui 1:fc2f9d636751 55 *
yihui 1:fc2f9d636751 56 * @return Required buffer size (in bytes).
yihui 1:fc2f9d636751 57 */
yihui 1:fc2f9d636751 58 #define APP_GPIOTE_BUF_SIZE(MAX_USERS) ((MAX_USERS) * GPIOTE_USER_NODE_SIZE)
yihui 1:fc2f9d636751 59
yihui 1:fc2f9d636751 60 typedef uint8_t app_gpiote_user_id_t;
yihui 1:fc2f9d636751 61
yihui 1:fc2f9d636751 62 /**@brief GPIOTE event handler type. */
yihui 1:fc2f9d636751 63 typedef void (*app_gpiote_event_handler_t)(uint32_t event_pins_low_to_high,
yihui 1:fc2f9d636751 64 uint32_t event_pins_high_to_low);
yihui 1:fc2f9d636751 65
yihui 1:fc2f9d636751 66 /**@brief GPIOTE input event handler type. */
yihui 1:fc2f9d636751 67 typedef void (*app_gpiote_input_event_handler_t)(void);
yihui 1:fc2f9d636751 68
yihui 1:fc2f9d636751 69 /**@brief Macro for initializing the GPIOTE module.
yihui 1:fc2f9d636751 70 *
yihui 1:fc2f9d636751 71 * @details It will handle dimensioning and allocation of the memory buffer required by the module,
yihui 1:fc2f9d636751 72 * making sure that the buffer is correctly aligned.
yihui 1:fc2f9d636751 73 *
yihui 1:fc2f9d636751 74 * @param[in] MAX_USERS Maximum number of GPIOTE users.
yihui 1:fc2f9d636751 75 *
yihui 1:fc2f9d636751 76 * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it
yihui 1:fc2f9d636751 77 * several times as long as it is from the same location, e.g. to do a reinitialization).
yihui 1:fc2f9d636751 78 */
yihui 1:fc2f9d636751 79 /*lint -emacro(506, APP_GPIOTE_INIT) */ /* Suppress "Constant value Boolean */
yihui 1:fc2f9d636751 80 #define APP_GPIOTE_INIT(MAX_USERS) \
yihui 1:fc2f9d636751 81 do \
yihui 1:fc2f9d636751 82 { \
yihui 1:fc2f9d636751 83 static uint32_t app_gpiote_buf[CEIL_DIV(APP_GPIOTE_BUF_SIZE(MAX_USERS), sizeof(uint32_t))];\
yihui 1:fc2f9d636751 84 uint32_t ERR_CODE = app_gpiote_init((MAX_USERS), app_gpiote_buf); \
yihui 1:fc2f9d636751 85 APP_ERROR_CHECK(ERR_CODE); \
yihui 1:fc2f9d636751 86 } while (0)
yihui 1:fc2f9d636751 87
yihui 1:fc2f9d636751 88 /**@brief Function for initializing the GPIOTE module.
yihui 1:fc2f9d636751 89 *
yihui 1:fc2f9d636751 90 * @note Normally initialization should be done using the APP_GPIOTE_INIT() macro, as that will
yihui 1:fc2f9d636751 91 * allocate the buffer needed by the GPIOTE module (including aligning the buffer correctly).
yihui 1:fc2f9d636751 92 *
yihui 1:fc2f9d636751 93 * @param[in] max_users Maximum number of GPIOTE users.
yihui 1:fc2f9d636751 94 * @param[in] p_buffer Pointer to memory buffer for internal use in the app_gpiote
yihui 1:fc2f9d636751 95 * module. The size of the buffer can be computed using the
yihui 1:fc2f9d636751 96 * APP_GPIOTE_BUF_SIZE() macro. The buffer must be aligned to
yihui 1:fc2f9d636751 97 * a 4 byte boundary.
yihui 1:fc2f9d636751 98 *
yihui 1:fc2f9d636751 99 * @retval NRF_SUCCESS Successful initialization.
yihui 1:fc2f9d636751 100 * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte
yihui 1:fc2f9d636751 101 * boundary).
yihui 1:fc2f9d636751 102 */
yihui 1:fc2f9d636751 103 uint32_t app_gpiote_init(uint8_t max_users, void * p_buffer);
yihui 1:fc2f9d636751 104
yihui 1:fc2f9d636751 105 /**@brief Function for registering a GPIOTE user.
yihui 1:fc2f9d636751 106 *
yihui 1:fc2f9d636751 107 * @param[out] p_user_id Id for the new GPIOTE user.
yihui 1:fc2f9d636751 108 * @param[in] pins_low_to_high_mask Mask defining which pins will generate events to this user
yihui 1:fc2f9d636751 109 * when state is changed from low->high.
yihui 1:fc2f9d636751 110 * @param[in] pins_high_to_low_mask Mask defining which pins will generate events to this user
yihui 1:fc2f9d636751 111 * when state is changed from high->low.
yihui 1:fc2f9d636751 112 * @param[in] event_handler Pointer to function to be executed when an event occurs.
yihui 1:fc2f9d636751 113 *
yihui 1:fc2f9d636751 114 * @retval NRF_SUCCESS Successful initialization.
yihui 1:fc2f9d636751 115 * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte boundary).
yihui 1:fc2f9d636751 116 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
yihui 1:fc2f9d636751 117 * module.
yihui 1:fc2f9d636751 118 * @retval NRF_ERROR_NO_MEM Returned if the application tries to register more users
yihui 1:fc2f9d636751 119 * than defined when the GPIOTE module was initialized in
yihui 1:fc2f9d636751 120 * @ref app_gpiote_init.
yihui 1:fc2f9d636751 121 */
yihui 1:fc2f9d636751 122 uint32_t app_gpiote_user_register(app_gpiote_user_id_t * p_user_id,
yihui 1:fc2f9d636751 123 uint32_t pins_low_to_high_mask,
yihui 1:fc2f9d636751 124 uint32_t pins_high_to_low_mask,
yihui 1:fc2f9d636751 125 app_gpiote_event_handler_t event_handler);
yihui 1:fc2f9d636751 126
yihui 1:fc2f9d636751 127 /**@brief Function for informing the GPIOTE module that the specified user wants to use the GPIOTE module.
yihui 1:fc2f9d636751 128 *
yihui 1:fc2f9d636751 129 * @param[in] user_id Id of user to enable.
yihui 1:fc2f9d636751 130 *
yihui 1:fc2f9d636751 131 * @retval NRF_SUCCESS On success.
yihui 1:fc2f9d636751 132 * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user.
yihui 1:fc2f9d636751 133 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
yihui 1:fc2f9d636751 134 * module.
yihui 1:fc2f9d636751 135 */
yihui 1:fc2f9d636751 136 uint32_t app_gpiote_user_enable(app_gpiote_user_id_t user_id);
yihui 1:fc2f9d636751 137
yihui 1:fc2f9d636751 138 /**@brief Function for informing the GPIOTE module that the specified user is done using the GPIOTE module.
yihui 1:fc2f9d636751 139 *
yihui 1:fc2f9d636751 140 * @param[in] user_id Id of user to enable.
yihui 1:fc2f9d636751 141 *
yihui 1:fc2f9d636751 142 * @return NRF_SUCCESS On success.
yihui 1:fc2f9d636751 143 * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user.
yihui 1:fc2f9d636751 144 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
yihui 1:fc2f9d636751 145 * module.
yihui 1:fc2f9d636751 146 */
yihui 1:fc2f9d636751 147 uint32_t app_gpiote_user_disable(app_gpiote_user_id_t user_id);
yihui 1:fc2f9d636751 148
yihui 1:fc2f9d636751 149 /**@brief Function for getting the state of the pins which are registered for the specified user.
yihui 1:fc2f9d636751 150 *
yihui 1:fc2f9d636751 151 * @param[in] user_id Id of user to check.
yihui 1:fc2f9d636751 152 * @param[out] p_pins Bit mask corresponding to the pins configured to generate events to
yihui 1:fc2f9d636751 153 * the specified user. All bits corresponding to pins in the state
yihui 1:fc2f9d636751 154 * 'high' will have value '1', all others will have value '0'.
yihui 1:fc2f9d636751 155 *
yihui 1:fc2f9d636751 156 * @return NRF_SUCCESS On success.
yihui 1:fc2f9d636751 157 * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user.
yihui 1:fc2f9d636751 158 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
yihui 1:fc2f9d636751 159 * module.
yihui 1:fc2f9d636751 160 */
yihui 1:fc2f9d636751 161 uint32_t app_gpiote_pins_state_get(app_gpiote_user_id_t user_id, uint32_t * p_pins);
yihui 1:fc2f9d636751 162
yihui 1:fc2f9d636751 163 /**@brief Function for registering event handlers for GPIOTE IN events.
yihui 1:fc2f9d636751 164 *
yihui 1:fc2f9d636751 165 * @param[in] channel GPIOTE channel [0..3].
yihui 1:fc2f9d636751 166 * @param[in] pin Pins associated with GPIOTE channel. Changes on following pins will generate events.
yihui 1:fc2f9d636751 167 * @param[in] polarity Specify operation on input that shall trigger IN event.
yihui 1:fc2f9d636751 168 * @param[in] event_handler Event handler invoked on the IN event in the GPIOTE interrupt.
yihui 1:fc2f9d636751 169 *
yihui 1:fc2f9d636751 170 * @return NRF_SUCCESS On success.
yihui 1:fc2f9d636751 171 * @retval NRF_ERROR_INVALID_PARAM Invalid channel or pin number.
yihui 1:fc2f9d636751 172 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
yihui 1:fc2f9d636751 173 */
yihui 1:fc2f9d636751 174 uint32_t app_gpiote_input_event_handler_register(const uint8_t channel,
yihui 1:fc2f9d636751 175 const uint32_t pin,
yihui 1:fc2f9d636751 176 const uint32_t polarity,
yihui 1:fc2f9d636751 177 app_gpiote_input_event_handler_t event_handler);
yihui 1:fc2f9d636751 178
yihui 1:fc2f9d636751 179 /**@brief Function for unregistering event handlers for GPIOTE IN events.
yihui 1:fc2f9d636751 180 *
yihui 1:fc2f9d636751 181 * @return NRF_SUCCESS On success.
yihui 1:fc2f9d636751 182 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
yihui 1:fc2f9d636751 183 */
yihui 1:fc2f9d636751 184 uint32_t app_gpiote_input_event_handler_unregister(const uint8_t channel);
yihui 1:fc2f9d636751 185
yihui 1:fc2f9d636751 186 /**@brief Function for registering event handler invoked at the end of a GPIOTE interrupt.
yihui 1:fc2f9d636751 187 *
yihui 1:fc2f9d636751 188 * @param[in] event_handler Event handler invoked at the end of the GPIOTE interrupt.
yihui 1:fc2f9d636751 189 *
yihui 1:fc2f9d636751 190 * @return NRF_SUCCESS On success.
yihui 1:fc2f9d636751 191 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
yihui 1:fc2f9d636751 192 */
yihui 1:fc2f9d636751 193 uint32_t app_gpiote_end_irq_event_handler_register(app_gpiote_input_event_handler_t event_handler);
yihui 1:fc2f9d636751 194
yihui 1:fc2f9d636751 195 /**@brief Function for unregistering event handler invoked at the end of a GPIOTE interrupt.
yihui 1:fc2f9d636751 196 *
yihui 1:fc2f9d636751 197 * @return NRF_SUCCESS On success.
yihui 1:fc2f9d636751 198 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
yihui 1:fc2f9d636751 199 */
yihui 1:fc2f9d636751 200 uint32_t app_gpiote_end_irq_event_handler_unregister(void);
yihui 1:fc2f9d636751 201
yihui 1:fc2f9d636751 202 /**@brief Function for enabling interrupts in the GPIOTE driver.
yihui 1:fc2f9d636751 203 *
yihui 1:fc2f9d636751 204 * @return NRF_SUCCESS On success.
yihui 1:fc2f9d636751 205 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support.
yihui 1:fc2f9d636751 206 */
yihui 1:fc2f9d636751 207 uint32_t app_gpiote_enable_interrupts(void);
yihui 1:fc2f9d636751 208
yihui 1:fc2f9d636751 209 /**@brief Function for disabling interrupts in the GPIOTE driver.
yihui 1:fc2f9d636751 210 *
yihui 1:fc2f9d636751 211 * @return NRF_SUCCESS On success.
yihui 1:fc2f9d636751 212 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support.
yihui 1:fc2f9d636751 213 */
yihui 1:fc2f9d636751 214 uint32_t app_gpiote_disable_interrupts(void);
yihui 1:fc2f9d636751 215
yihui 1:fc2f9d636751 216
yihui 1:fc2f9d636751 217 #endif // APP_GPIOTE_H__
yihui 1:fc2f9d636751 218
yihui 1:fc2f9d636751 219 /** @} */