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_button.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_button Button Handler
jksoft 1:48f6e08a3ac2 16 * @{
jksoft 1:48f6e08a3ac2 17 * @ingroup app_common
jksoft 1:48f6e08a3ac2 18 *
jksoft 1:48f6e08a3ac2 19 * @brief Buttons handling module.
jksoft 1:48f6e08a3ac2 20 *
jksoft 1:48f6e08a3ac2 21 * @details The button handler uses the @ref app_gpiote to detect that a button has been
jksoft 1:48f6e08a3ac2 22 * pushed. To handle debouncing, it will start a timer in the GPIOTE event handler.
jksoft 1:48f6e08a3ac2 23 * The button will only be reported as pushed if the corresponding pin is still active when
jksoft 1:48f6e08a3ac2 24 * the timer expires. If there is a new GPIOTE event while the timer is running, the timer
jksoft 1:48f6e08a3ac2 25 * is restarted.
jksoft 1:48f6e08a3ac2 26 * Use the USE_SCHEDULER parameter of the APP_BUTTON_INIT() macro to select if the
jksoft 1:48f6e08a3ac2 27 * @ref app_scheduler is to be used or not.
jksoft 1:48f6e08a3ac2 28 *
jksoft 1:48f6e08a3ac2 29 * @note The app_button module uses the app_timer module. The user must ensure that the queue in
jksoft 1:48f6e08a3ac2 30 * app_timer is large enough to hold the app_timer_stop() / app_timer_start() operations
jksoft 1:48f6e08a3ac2 31 * which will be executed on each event from GPIOTE module (2 operations), as well as other
jksoft 1:48f6e08a3ac2 32 * app_timer operations queued simultaneously in the application.
jksoft 1:48f6e08a3ac2 33 *
jksoft 1:48f6e08a3ac2 34 * @note Even if the scheduler is not used, app_button.h will include app_scheduler.h, so when
jksoft 1:48f6e08a3ac2 35 * compiling, app_scheduler.h must be available in one of the compiler include paths.
jksoft 1:48f6e08a3ac2 36 */
jksoft 1:48f6e08a3ac2 37
jksoft 1:48f6e08a3ac2 38 #ifndef APP_BUTTON_H__
jksoft 1:48f6e08a3ac2 39 #define APP_BUTTON_H__
jksoft 1:48f6e08a3ac2 40
jksoft 1:48f6e08a3ac2 41 #include <stdint.h>
jksoft 1:48f6e08a3ac2 42 #include <stdbool.h>
jksoft 1:48f6e08a3ac2 43 #include "app_error.h"
jksoft 1:48f6e08a3ac2 44 #include "app_scheduler.h"
jksoft 1:48f6e08a3ac2 45 #include "nrf_gpio.h"
jksoft 1:48f6e08a3ac2 46
jksoft 1:48f6e08a3ac2 47 #define APP_BUTTON_SCHED_EVT_SIZE sizeof(app_button_event_t) /**< Size of button events being passed through the scheduler (is to be used for computing the maximum size of scheduler events). */
jksoft 1:48f6e08a3ac2 48 #define APP_BUTTON_PUSH 1 /**< Indicates that a button is pushed. */
jksoft 1:48f6e08a3ac2 49 #define APP_BUTTON_RELEASE 0 /**< Indicates that a button is released. */
jksoft 1:48f6e08a3ac2 50 #define APP_BUTTON_ACTIVE_HIGH 1 /**< Indicates that a button is active high. */
jksoft 1:48f6e08a3ac2 51 #define APP_BUTTON_ACTIVE_LOW 0 /**< Indicates that a button is active low. */
jksoft 1:48f6e08a3ac2 52
jksoft 1:48f6e08a3ac2 53 /**@brief Button event handler type. */
jksoft 1:48f6e08a3ac2 54 typedef void (*app_button_handler_t)(uint8_t pin_no, uint8_t button_action);
jksoft 1:48f6e08a3ac2 55
jksoft 1:48f6e08a3ac2 56 /**@brief Type of function for passing events from the Button Handler module to the scheduler. */
jksoft 1:48f6e08a3ac2 57 typedef uint32_t (*app_button_evt_schedule_func_t) (app_button_handler_t button_handler,
jksoft 1:48f6e08a3ac2 58 uint8_t pin_no,
jksoft 1:48f6e08a3ac2 59 uint8_t button_action);
jksoft 1:48f6e08a3ac2 60
jksoft 1:48f6e08a3ac2 61 /**@brief Button configuration structure. */
jksoft 1:48f6e08a3ac2 62 typedef struct
jksoft 1:48f6e08a3ac2 63 {
jksoft 1:48f6e08a3ac2 64 uint8_t pin_no; /**< Pin to be used as a button. */
jksoft 1:48f6e08a3ac2 65 uint8_t active_state; /**< APP_BUTTON_ACTIVE_HIGH or APP_BUTTON_ACTIVE_LOW. */
jksoft 1:48f6e08a3ac2 66 nrf_gpio_pin_pull_t pull_cfg; /**< Pull-up or -down configuration. */
jksoft 1:48f6e08a3ac2 67 app_button_handler_t button_handler; /**< Handler to be called when button is pushed. */
jksoft 1:48f6e08a3ac2 68 } app_button_cfg_t;
jksoft 1:48f6e08a3ac2 69
jksoft 1:48f6e08a3ac2 70 /**@brief Pin transition direction struct. */
jksoft 1:48f6e08a3ac2 71 typedef struct
jksoft 1:48f6e08a3ac2 72 {
jksoft 1:48f6e08a3ac2 73 uint32_t high_to_low; /**Pin went from high to low */
jksoft 1:48f6e08a3ac2 74 uint32_t low_to_high; /**Pin went from low to high */
jksoft 1:48f6e08a3ac2 75 } pin_transition_t;
jksoft 1:48f6e08a3ac2 76
jksoft 1:48f6e08a3ac2 77 /**@brief Macro for initializing the Button Handler module.
jksoft 1:48f6e08a3ac2 78 *
jksoft 1:48f6e08a3ac2 79 * @details It will initialize the specified pins as buttons, and configure the Button Handler
jksoft 1:48f6e08a3ac2 80 * module as a GPIOTE user (but it will not enable button detection). It will also connect
jksoft 1:48f6e08a3ac2 81 * the Button Handler module to the scheduler (if specified).
jksoft 1:48f6e08a3ac2 82 *
jksoft 1:48f6e08a3ac2 83 * @param[in] BUTTONS Array of buttons to be used (type app_button_cfg_t, must be
jksoft 1:48f6e08a3ac2 84 * static!).
jksoft 1:48f6e08a3ac2 85 * @param[in] BUTTON_COUNT Number of buttons.
jksoft 1:48f6e08a3ac2 86 * @param[in] DETECTION_DELAY Delay from a GPIOTE event until a button is reported as pushed.
jksoft 1:48f6e08a3ac2 87 * @param[in] USE_SCHEDULER TRUE if the application is using the event scheduler,
jksoft 1:48f6e08a3ac2 88 * FALSE otherwise.
jksoft 1:48f6e08a3ac2 89 */
jksoft 1:48f6e08a3ac2 90 /*lint -emacro(506, APP_BUTTON_INIT) */ /* Suppress "Constant value Boolean */
jksoft 1:48f6e08a3ac2 91 #define APP_BUTTON_INIT(BUTTONS, BUTTON_COUNT, DETECTION_DELAY, USE_SCHEDULER) \
jksoft 1:48f6e08a3ac2 92 do \
jksoft 1:48f6e08a3ac2 93 { \
jksoft 1:48f6e08a3ac2 94 uint32_t ERR_CODE = app_button_init((BUTTONS), \
jksoft 1:48f6e08a3ac2 95 (BUTTON_COUNT), \
jksoft 1:48f6e08a3ac2 96 (DETECTION_DELAY), \
jksoft 1:48f6e08a3ac2 97 (USE_SCHEDULER) ? app_button_evt_schedule : NULL); \
jksoft 1:48f6e08a3ac2 98 APP_ERROR_CHECK(ERR_CODE); \
jksoft 1:48f6e08a3ac2 99 } while (0)
jksoft 1:48f6e08a3ac2 100
jksoft 1:48f6e08a3ac2 101 /**@brief Function for initializing the Buttons.
jksoft 1:48f6e08a3ac2 102 *
jksoft 1:48f6e08a3ac2 103 * @details This function will initialize the specified pins as buttons, and configure the Button
jksoft 1:48f6e08a3ac2 104 * Handler module as a GPIOTE user (but it will not enable button detection).
jksoft 1:48f6e08a3ac2 105 *
jksoft 1:48f6e08a3ac2 106 * @note Normally initialization should be done using the APP_BUTTON_INIT() macro, as that will take
jksoft 1:48f6e08a3ac2 107 * care of connecting the Buttons module to the scheduler (if specified).
jksoft 1:48f6e08a3ac2 108 *
jksoft 1:48f6e08a3ac2 109 * @note app_button_enable() function must be called in order to enable the button detection.
jksoft 1:48f6e08a3ac2 110 *
jksoft 1:48f6e08a3ac2 111 * @param[in] p_buttons Array of buttons to be used (NOTE: Must be static!).
jksoft 1:48f6e08a3ac2 112 * @param[in] button_count Number of buttons.
jksoft 1:48f6e08a3ac2 113 * @param[in] detection_delay Delay from a GPIOTE event until a button is reported as pushed.
jksoft 1:48f6e08a3ac2 114 * @param[in] evt_schedule_func Function for passing button events to the scheduler. Point to
jksoft 1:48f6e08a3ac2 115 * app_button_evt_schedule() to connect to the scheduler. Set to
jksoft 1:48f6e08a3ac2 116 * NULL to make the Buttons module call the event handler directly
jksoft 1:48f6e08a3ac2 117 * from the delayed button push detection timeout handler.
jksoft 1:48f6e08a3ac2 118 *
jksoft 1:48f6e08a3ac2 119 * @return NRF_SUCCESS on success, otherwise an error code.
jksoft 1:48f6e08a3ac2 120 */
jksoft 1:48f6e08a3ac2 121 uint32_t app_button_init(app_button_cfg_t * p_buttons,
jksoft 1:48f6e08a3ac2 122 uint8_t button_count,
jksoft 1:48f6e08a3ac2 123 uint32_t detection_delay,
jksoft 1:48f6e08a3ac2 124 app_button_evt_schedule_func_t evt_schedule_func);
jksoft 1:48f6e08a3ac2 125
jksoft 1:48f6e08a3ac2 126 /**@brief Function for enabling button detection.
jksoft 1:48f6e08a3ac2 127 *
jksoft 1:48f6e08a3ac2 128 * @retval NRF_ERROR_INVALID_PARAM GPIOTE has to many users.
jksoft 1:48f6e08a3ac2 129 * @retval NRF_ERROR_INVALID_STATE Button or GPIOTE not initialized.
jksoft 1:48f6e08a3ac2 130 * @retval NRF_SUCCESS Button detection successfully enabled.
jksoft 1:48f6e08a3ac2 131 */
jksoft 1:48f6e08a3ac2 132 uint32_t app_button_enable(void);
jksoft 1:48f6e08a3ac2 133
jksoft 1:48f6e08a3ac2 134 /**@brief Function for disabling button detection.
jksoft 1:48f6e08a3ac2 135 *
jksoft 1:48f6e08a3ac2 136 * @retval NRF_ERROR_INVALID_PARAM GPIOTE has to many users.
jksoft 1:48f6e08a3ac2 137 * @retval NRF_ERROR_INVALID_STATE Button or GPIOTE not initialized.
jksoft 1:48f6e08a3ac2 138 * @retval NRF_SUCCESS Button detection successfully enabled.
jksoft 1:48f6e08a3ac2 139 */
jksoft 1:48f6e08a3ac2 140 uint32_t app_button_disable(void);
jksoft 1:48f6e08a3ac2 141
jksoft 1:48f6e08a3ac2 142 /**@brief Function for checking if a button is currently being pushed.
jksoft 1:48f6e08a3ac2 143 *
jksoft 1:48f6e08a3ac2 144 * @param[in] pin_no Button pin to be checked.
jksoft 1:48f6e08a3ac2 145 * @param[out] p_is_pushed Button state.
jksoft 1:48f6e08a3ac2 146 *
jksoft 1:48f6e08a3ac2 147 * @retval NRF_SUCCESS State successfully read.
jksoft 1:48f6e08a3ac2 148 * @retval NRF_ERROR_INVALID_PARAM Invalid pin_no.
jksoft 1:48f6e08a3ac2 149 */
jksoft 1:48f6e08a3ac2 150 uint32_t app_button_is_pushed(uint8_t pin_no, bool * p_is_pushed);
jksoft 1:48f6e08a3ac2 151
jksoft 1:48f6e08a3ac2 152
jksoft 1:48f6e08a3ac2 153 // Type and functions for connecting the Buttons module to the scheduler:
jksoft 1:48f6e08a3ac2 154
jksoft 1:48f6e08a3ac2 155 /**@cond NO_DOXYGEN */
jksoft 1:48f6e08a3ac2 156 typedef struct
jksoft 1:48f6e08a3ac2 157 {
jksoft 1:48f6e08a3ac2 158 app_button_handler_t button_handler;
jksoft 1:48f6e08a3ac2 159 uint8_t pin_no;
jksoft 1:48f6e08a3ac2 160 uint8_t button_action;
jksoft 1:48f6e08a3ac2 161 } app_button_event_t;
jksoft 1:48f6e08a3ac2 162
jksoft 1:48f6e08a3ac2 163 static __INLINE void app_button_evt_get(void * p_event_data, uint16_t event_size)
jksoft 1:48f6e08a3ac2 164 {
jksoft 1:48f6e08a3ac2 165 app_button_event_t * p_buttons_event = (app_button_event_t *)p_event_data;
jksoft 1:48f6e08a3ac2 166
jksoft 1:48f6e08a3ac2 167 APP_ERROR_CHECK_BOOL(event_size == sizeof(app_button_event_t));
jksoft 1:48f6e08a3ac2 168 p_buttons_event->button_handler(p_buttons_event->pin_no, p_buttons_event->button_action);
jksoft 1:48f6e08a3ac2 169 }
jksoft 1:48f6e08a3ac2 170
jksoft 1:48f6e08a3ac2 171 static __INLINE uint32_t app_button_evt_schedule(app_button_handler_t button_handler,
jksoft 1:48f6e08a3ac2 172 uint8_t pin_no,
jksoft 1:48f6e08a3ac2 173 uint8_t button_action)
jksoft 1:48f6e08a3ac2 174 {
jksoft 1:48f6e08a3ac2 175 app_button_event_t buttons_event;
jksoft 1:48f6e08a3ac2 176
jksoft 1:48f6e08a3ac2 177 buttons_event.button_handler = button_handler;
jksoft 1:48f6e08a3ac2 178 buttons_event.pin_no = pin_no;
jksoft 1:48f6e08a3ac2 179 buttons_event.button_action = button_action;
jksoft 1:48f6e08a3ac2 180
jksoft 1:48f6e08a3ac2 181 return app_sched_event_put(&buttons_event, sizeof(buttons_event), app_button_evt_get);
jksoft 1:48f6e08a3ac2 182 }
jksoft 1:48f6e08a3ac2 183 /**@endcond */
jksoft 1:48f6e08a3ac2 184
jksoft 1:48f6e08a3ac2 185 #endif // APP_BUTTON_H__
jksoft 1:48f6e08a3ac2 186
jksoft 1:48f6e08a3ac2 187 /** @} */