iOSのBLEコントローラアプリ「RCBController」とmbed HRM1017を接続し、RCサーボモータを操作するテストプログラムです。
Dependencies: BLE_API_Native_IRC Servo mbed
Fork of BLE_RCBController by
- 古いBLEライブラリを使っているのでプラットフォームは”Nordic nRF51822”を選択してください。
- ライブラリ類はUpdateしないでください。コンパイルエラーになります。
うまく接続できない時は、iPhone/iPadのBluetoothをOFF->ONしてキャッシュをクリアしてみてください。
BLE_API_Native_IRC/hw/nRF51822n/nordic/nrf-sdk/app_common/app_gpiote.h@0:8c643bfe55b7, 2014-07-10 (annotated)
- Committer:
- jksoft
- Date:
- Thu Jul 10 14:21:52 2014 +0000
- Revision:
- 0:8c643bfe55b7
??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:8c643bfe55b7 | 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. |
jksoft | 0:8c643bfe55b7 | 2 | * |
jksoft | 0:8c643bfe55b7 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
jksoft | 0:8c643bfe55b7 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
jksoft | 0:8c643bfe55b7 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
jksoft | 0:8c643bfe55b7 | 6 | * |
jksoft | 0:8c643bfe55b7 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
jksoft | 0:8c643bfe55b7 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jksoft | 0:8c643bfe55b7 | 9 | * the file. |
jksoft | 0:8c643bfe55b7 | 10 | * |
jksoft | 0:8c643bfe55b7 | 11 | */ |
jksoft | 0:8c643bfe55b7 | 12 | |
jksoft | 0:8c643bfe55b7 | 13 | /** @file |
jksoft | 0:8c643bfe55b7 | 14 | * |
jksoft | 0:8c643bfe55b7 | 15 | * @defgroup app_gpiote GPIOTE Handler |
jksoft | 0:8c643bfe55b7 | 16 | * @{ |
jksoft | 0:8c643bfe55b7 | 17 | * @ingroup app_common |
jksoft | 0:8c643bfe55b7 | 18 | * |
jksoft | 0:8c643bfe55b7 | 19 | * @brief GPIOTE handler module. |
jksoft | 0:8c643bfe55b7 | 20 | * |
jksoft | 0:8c643bfe55b7 | 21 | * @details The GPIOTE handler allows several modules ("users") to share the GPIOTE interrupt, |
jksoft | 0:8c643bfe55b7 | 22 | * each user defining a set of pins able to generate events to the user. |
jksoft | 0:8c643bfe55b7 | 23 | * When a GPIOTE interrupt occurs, the GPIOTE interrupt handler will call the event handler |
jksoft | 0:8c643bfe55b7 | 24 | * of each user for which at least one of the pins generated an event. |
jksoft | 0:8c643bfe55b7 | 25 | * |
jksoft | 0:8c643bfe55b7 | 26 | * The GPIOTE users are responsible for configuring all their corresponding pins, except |
jksoft | 0:8c643bfe55b7 | 27 | * the SENSE field, which should be initialized to GPIO_PIN_CNF_SENSE_Disabled. |
jksoft | 0:8c643bfe55b7 | 28 | * The SENSE field will be updated by the GPIOTE module when it is enabled or disabled, |
jksoft | 0:8c643bfe55b7 | 29 | * and also while it is enabled. |
jksoft | 0:8c643bfe55b7 | 30 | * |
jksoft | 0:8c643bfe55b7 | 31 | * The module specifies on which pins events should be generated if the pin(s) goes |
jksoft | 0:8c643bfe55b7 | 32 | * from low->high or high->low or both directions. |
jksoft | 0:8c643bfe55b7 | 33 | * |
jksoft | 0:8c643bfe55b7 | 34 | * @note Even if the application is using the @ref app_scheduler, the GPIOTE event handlers will |
jksoft | 0:8c643bfe55b7 | 35 | * be called directly from the GPIOTE interrupt handler. |
jksoft | 0:8c643bfe55b7 | 36 | */ |
jksoft | 0:8c643bfe55b7 | 37 | |
jksoft | 0:8c643bfe55b7 | 38 | #ifndef APP_GPIOTE_H__ |
jksoft | 0:8c643bfe55b7 | 39 | #define APP_GPIOTE_H__ |
jksoft | 0:8c643bfe55b7 | 40 | |
jksoft | 0:8c643bfe55b7 | 41 | #include <stdint.h> |
jksoft | 0:8c643bfe55b7 | 42 | #include <stdbool.h> |
jksoft | 0:8c643bfe55b7 | 43 | #include "nordic_global.h" |
jksoft | 0:8c643bfe55b7 | 44 | #include "nrf.h" |
jksoft | 0:8c643bfe55b7 | 45 | #include "app_error.h" |
jksoft | 0:8c643bfe55b7 | 46 | #include "app_util.h" |
jksoft | 0:8c643bfe55b7 | 47 | |
jksoft | 0:8c643bfe55b7 | 48 | #define GPIOTE_USER_NODE_SIZE 20 /**< Size of app_gpiote.gpiote_user_t (only for use inside APP_GPIOTE_BUF_SIZE()). */ |
jksoft | 0:8c643bfe55b7 | 49 | #define NO_OF_PINS 32 /**< Number of GPIO pins on the nRF51 chip. */ |
jksoft | 0:8c643bfe55b7 | 50 | |
jksoft | 0:8c643bfe55b7 | 51 | /**@brief Compute number of bytes required to hold the GPIOTE data structures. |
jksoft | 0:8c643bfe55b7 | 52 | * |
jksoft | 0:8c643bfe55b7 | 53 | * @param[in] MAX_USERS Maximum number of GPIOTE users. |
jksoft | 0:8c643bfe55b7 | 54 | * |
jksoft | 0:8c643bfe55b7 | 55 | * @return Required buffer size (in bytes). |
jksoft | 0:8c643bfe55b7 | 56 | */ |
jksoft | 0:8c643bfe55b7 | 57 | #define APP_GPIOTE_BUF_SIZE(MAX_USERS) ((MAX_USERS) * GPIOTE_USER_NODE_SIZE) |
jksoft | 0:8c643bfe55b7 | 58 | |
jksoft | 0:8c643bfe55b7 | 59 | typedef uint8_t app_gpiote_user_id_t; |
jksoft | 0:8c643bfe55b7 | 60 | |
jksoft | 0:8c643bfe55b7 | 61 | /**@brief GPIOTE event handler type. */ |
jksoft | 0:8c643bfe55b7 | 62 | typedef void (*app_gpiote_event_handler_t)(uint32_t event_pins_low_to_high, |
jksoft | 0:8c643bfe55b7 | 63 | uint32_t event_pins_high_to_low); |
jksoft | 0:8c643bfe55b7 | 64 | |
jksoft | 0:8c643bfe55b7 | 65 | /**@brief Macro for initializing the GPIOTE module. |
jksoft | 0:8c643bfe55b7 | 66 | * |
jksoft | 0:8c643bfe55b7 | 67 | * @details It will handle dimensioning and allocation of the memory buffer required by the module, |
jksoft | 0:8c643bfe55b7 | 68 | * making sure that the buffer is correctly aligned. |
jksoft | 0:8c643bfe55b7 | 69 | * |
jksoft | 0:8c643bfe55b7 | 70 | * @param[in] MAX_USERS Maximum number of GPIOTE users. |
jksoft | 0:8c643bfe55b7 | 71 | * |
jksoft | 0:8c643bfe55b7 | 72 | * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it |
jksoft | 0:8c643bfe55b7 | 73 | * several times as long as it is from the same location, e.g. to do a reinitialization). |
jksoft | 0:8c643bfe55b7 | 74 | */ |
jksoft | 0:8c643bfe55b7 | 75 | /*lint -emacro(506, APP_GPIOTE_INIT) */ /* Suppress "Constant value Boolean */ |
jksoft | 0:8c643bfe55b7 | 76 | #define APP_GPIOTE_INIT(MAX_USERS) \ |
jksoft | 0:8c643bfe55b7 | 77 | do \ |
jksoft | 0:8c643bfe55b7 | 78 | { \ |
jksoft | 0:8c643bfe55b7 | 79 | static uint32_t app_gpiote_buf[CEIL_DIV(APP_GPIOTE_BUF_SIZE(MAX_USERS), sizeof(uint32_t))];\ |
jksoft | 0:8c643bfe55b7 | 80 | uint32_t ERR_CODE = app_gpiote_init((MAX_USERS), app_gpiote_buf); \ |
jksoft | 0:8c643bfe55b7 | 81 | APP_ERROR_CHECK(ERR_CODE); \ |
jksoft | 0:8c643bfe55b7 | 82 | } while (0) |
jksoft | 0:8c643bfe55b7 | 83 | |
jksoft | 0:8c643bfe55b7 | 84 | /**@brief Function for initializing the GPIOTE module. |
jksoft | 0:8c643bfe55b7 | 85 | * |
jksoft | 0:8c643bfe55b7 | 86 | * @note Normally initialization should be done using the APP_GPIOTE_INIT() macro, as that will |
jksoft | 0:8c643bfe55b7 | 87 | * allocate the buffer needed by the GPIOTE module (including aligning the buffer correctly). |
jksoft | 0:8c643bfe55b7 | 88 | * |
jksoft | 0:8c643bfe55b7 | 89 | * @param[in] max_users Maximum number of GPIOTE users. |
jksoft | 0:8c643bfe55b7 | 90 | * @param[in] p_buffer Pointer to memory buffer for internal use in the app_gpiote |
jksoft | 0:8c643bfe55b7 | 91 | * module. The size of the buffer can be computed using the |
jksoft | 0:8c643bfe55b7 | 92 | * APP_GPIOTE_BUF_SIZE() macro. The buffer must be aligned to |
jksoft | 0:8c643bfe55b7 | 93 | * a 4 byte boundary. |
jksoft | 0:8c643bfe55b7 | 94 | * |
jksoft | 0:8c643bfe55b7 | 95 | * @retval NRF_SUCCESS Successful initialization. |
jksoft | 0:8c643bfe55b7 | 96 | * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte |
jksoft | 0:8c643bfe55b7 | 97 | * boundary). |
jksoft | 0:8c643bfe55b7 | 98 | */ |
jksoft | 0:8c643bfe55b7 | 99 | uint32_t app_gpiote_init(uint8_t max_users, void * p_buffer); |
jksoft | 0:8c643bfe55b7 | 100 | |
jksoft | 0:8c643bfe55b7 | 101 | /**@brief Function for registering a GPIOTE user. |
jksoft | 0:8c643bfe55b7 | 102 | * |
jksoft | 0:8c643bfe55b7 | 103 | * @param[out] p_user_id Id for the new GPIOTE user. |
jksoft | 0:8c643bfe55b7 | 104 | * @param[in] pins_low_to_high_mask Mask defining which pins will generate events to this user |
jksoft | 0:8c643bfe55b7 | 105 | * when state is changed from low->high. |
jksoft | 0:8c643bfe55b7 | 106 | * @param[in] pins_high_to_low_mask Mask defining which pins will generate events to this user |
jksoft | 0:8c643bfe55b7 | 107 | * when state is changed from high->low. |
jksoft | 0:8c643bfe55b7 | 108 | * @param[in] event_handler Pointer to function to be executed when an event occurs. |
jksoft | 0:8c643bfe55b7 | 109 | * |
jksoft | 0:8c643bfe55b7 | 110 | * @retval NRF_SUCCESS Successful initialization. |
jksoft | 0:8c643bfe55b7 | 111 | * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte boundary). |
jksoft | 0:8c643bfe55b7 | 112 | * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE |
jksoft | 0:8c643bfe55b7 | 113 | * module. |
jksoft | 0:8c643bfe55b7 | 114 | * @retval NRF_ERROR_NO_MEM Returned if the application tries to register more users |
jksoft | 0:8c643bfe55b7 | 115 | * than defined when the GPIOTE module was initialized in |
jksoft | 0:8c643bfe55b7 | 116 | * @ref app_gpiote_init. |
jksoft | 0:8c643bfe55b7 | 117 | */ |
jksoft | 0:8c643bfe55b7 | 118 | uint32_t app_gpiote_user_register(app_gpiote_user_id_t * p_user_id, |
jksoft | 0:8c643bfe55b7 | 119 | uint32_t pins_low_to_high_mask, |
jksoft | 0:8c643bfe55b7 | 120 | uint32_t pins_high_to_low_mask, |
jksoft | 0:8c643bfe55b7 | 121 | app_gpiote_event_handler_t event_handler); |
jksoft | 0:8c643bfe55b7 | 122 | |
jksoft | 0:8c643bfe55b7 | 123 | /**@brief Function for informing the GPIOTE module that the specified user wants to use the GPIOTE module. |
jksoft | 0:8c643bfe55b7 | 124 | * |
jksoft | 0:8c643bfe55b7 | 125 | * @param[in] user_id Id of user to enable. |
jksoft | 0:8c643bfe55b7 | 126 | * |
jksoft | 0:8c643bfe55b7 | 127 | * @retval NRF_SUCCESS On success. |
jksoft | 0:8c643bfe55b7 | 128 | * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user. |
jksoft | 0:8c643bfe55b7 | 129 | * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE |
jksoft | 0:8c643bfe55b7 | 130 | * module. |
jksoft | 0:8c643bfe55b7 | 131 | */ |
jksoft | 0:8c643bfe55b7 | 132 | uint32_t app_gpiote_user_enable(app_gpiote_user_id_t user_id); |
jksoft | 0:8c643bfe55b7 | 133 | |
jksoft | 0:8c643bfe55b7 | 134 | /**@brief Function for informing the GPIOTE module that the specified user is done using the GPIOTE module. |
jksoft | 0:8c643bfe55b7 | 135 | * |
jksoft | 0:8c643bfe55b7 | 136 | * @param[in] user_id Id of user to enable. |
jksoft | 0:8c643bfe55b7 | 137 | * |
jksoft | 0:8c643bfe55b7 | 138 | * @return NRF_SUCCESS On success. |
jksoft | 0:8c643bfe55b7 | 139 | * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user. |
jksoft | 0:8c643bfe55b7 | 140 | * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE |
jksoft | 0:8c643bfe55b7 | 141 | * module. |
jksoft | 0:8c643bfe55b7 | 142 | */ |
jksoft | 0:8c643bfe55b7 | 143 | uint32_t app_gpiote_user_disable(app_gpiote_user_id_t user_id); |
jksoft | 0:8c643bfe55b7 | 144 | |
jksoft | 0:8c643bfe55b7 | 145 | /**@brief Function for getting the state of the pins which are registered for the specified user. |
jksoft | 0:8c643bfe55b7 | 146 | * |
jksoft | 0:8c643bfe55b7 | 147 | * @param[in] user_id Id of user to check. |
jksoft | 0:8c643bfe55b7 | 148 | * @param[out] p_pins Bit mask corresponding to the pins configured to generate events to |
jksoft | 0:8c643bfe55b7 | 149 | * the specified user. All bits corresponding to pins in the state |
jksoft | 0:8c643bfe55b7 | 150 | * 'high' will have value '1', all others will have value '0'. |
jksoft | 0:8c643bfe55b7 | 151 | * |
jksoft | 0:8c643bfe55b7 | 152 | * @return NRF_SUCCESS On success. |
jksoft | 0:8c643bfe55b7 | 153 | * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user. |
jksoft | 0:8c643bfe55b7 | 154 | * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE |
jksoft | 0:8c643bfe55b7 | 155 | * module. |
jksoft | 0:8c643bfe55b7 | 156 | */ |
jksoft | 0:8c643bfe55b7 | 157 | uint32_t app_gpiote_pins_state_get(app_gpiote_user_id_t user_id, uint32_t * p_pins); |
jksoft | 0:8c643bfe55b7 | 158 | |
jksoft | 0:8c643bfe55b7 | 159 | #endif // APP_GPIOTE_H__ |
jksoft | 0:8c643bfe55b7 | 160 | |
jksoft | 0:8c643bfe55b7 | 161 | /** @} */ |