iOSのBLEコントローラアプリ「RCBController」と接続し、コントローラの操作を取得するサンプルプログラムです。 mbed HRM1017で動作を確認しています。 2014.08.20時点でのBLEライブラリに対応しました。

Dependencies:   BLE_API mbed

Fork of BLE_RCBController by Junichi Katsu

Committer:
jksoft
Date:
Wed Aug 20 13:41:01 2014 +0000
Revision:
4:ebda47d22091
Parent:
nRF51822/nordic/nrf-sdk/app_common/app_gpiote.h@1:48f6e08a3ac2
?????????

Who changed what in which revision?

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