AndroidのBLEラジコンプロポアプリ「BLEPropo」と接続し、RCサーボとDCモータを制御するプログラムです。 BLE Nanoで動作を確認しています。 BLEPropo → https://github.com/lipoyang/BLEPropo
BLEを使ったAndroid用ラジコンプロポアプリ「BLEPropo」に対応するBLE Nano用ファームウェアです。
BLEPropoは、GitHubにて公開中。
https://github.com/lipoyang/BLEPropo
ラジコンは、mbed HRM1017とRCサーボやDCモータを組み合わせて作ります。
回路図
/media/uploads/lipoyang/ministeer3.pdf
nRF51822/btle/btle_gap.cpp@5:7f89fca19a9e, 2015-03-14 (annotated)
- Committer:
- lipoyang
- Date:
- Sat Mar 14 12:02:48 2015 +0000
- Revision:
- 5:7f89fca19a9e
-convert nRF51822 library to a folder
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lipoyang | 5:7f89fca19a9e | 1 | /* mbed Microcontroller Library |
lipoyang | 5:7f89fca19a9e | 2 | * Copyright (c) 2006-2013 ARM Limited |
lipoyang | 5:7f89fca19a9e | 3 | * |
lipoyang | 5:7f89fca19a9e | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
lipoyang | 5:7f89fca19a9e | 5 | * you may not use this file except in compliance with the License. |
lipoyang | 5:7f89fca19a9e | 6 | * You may obtain a copy of the License at |
lipoyang | 5:7f89fca19a9e | 7 | * |
lipoyang | 5:7f89fca19a9e | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
lipoyang | 5:7f89fca19a9e | 9 | * |
lipoyang | 5:7f89fca19a9e | 10 | * Unless required by applicable law or agreed to in writing, software |
lipoyang | 5:7f89fca19a9e | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
lipoyang | 5:7f89fca19a9e | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
lipoyang | 5:7f89fca19a9e | 13 | * See the License for the specific language governing permissions and |
lipoyang | 5:7f89fca19a9e | 14 | * limitations under the License. |
lipoyang | 5:7f89fca19a9e | 15 | */ |
lipoyang | 5:7f89fca19a9e | 16 | #include "common/common.h" |
lipoyang | 5:7f89fca19a9e | 17 | |
lipoyang | 5:7f89fca19a9e | 18 | #include "app_timer.h" |
lipoyang | 5:7f89fca19a9e | 19 | #include "ble_gap.h" |
lipoyang | 5:7f89fca19a9e | 20 | #include "ble_conn_params.h" |
lipoyang | 5:7f89fca19a9e | 21 | |
lipoyang | 5:7f89fca19a9e | 22 | static inline uint32_t msec_to_1_25msec(uint32_t interval_ms) ATTR_ALWAYS_INLINE ATTR_CONST; |
lipoyang | 5:7f89fca19a9e | 23 | #if SDK_CONN_PARAMS_MODULE_ENABLE |
lipoyang | 5:7f89fca19a9e | 24 | static void error_callback(uint32_t nrf_error); |
lipoyang | 5:7f89fca19a9e | 25 | #endif // SDK_CONN_PARAMS_MODULE_ENABLE |
lipoyang | 5:7f89fca19a9e | 26 | |
lipoyang | 5:7f89fca19a9e | 27 | /**************************************************************************/ |
lipoyang | 5:7f89fca19a9e | 28 | /*! |
lipoyang | 5:7f89fca19a9e | 29 | @brief Initialise GAP in the underlying SoftDevice |
lipoyang | 5:7f89fca19a9e | 30 | |
lipoyang | 5:7f89fca19a9e | 31 | @returns |
lipoyang | 5:7f89fca19a9e | 32 | */ |
lipoyang | 5:7f89fca19a9e | 33 | /**************************************************************************/ |
lipoyang | 5:7f89fca19a9e | 34 | error_t btle_gap_init(void) |
lipoyang | 5:7f89fca19a9e | 35 | { |
lipoyang | 5:7f89fca19a9e | 36 | ble_gap_conn_params_t gap_conn_params = {0}; |
lipoyang | 5:7f89fca19a9e | 37 | |
lipoyang | 5:7f89fca19a9e | 38 | gap_conn_params.min_conn_interval = msec_to_1_25msec(CFG_GAP_CONNECTION_MIN_INTERVAL_MS); // in 1.25ms units |
lipoyang | 5:7f89fca19a9e | 39 | gap_conn_params.max_conn_interval = msec_to_1_25msec(CFG_GAP_CONNECTION_MAX_INTERVAL_MS); // in 1.25ms unit |
lipoyang | 5:7f89fca19a9e | 40 | gap_conn_params.slave_latency = CFG_GAP_CONNECTION_SLAVE_LATENCY; |
lipoyang | 5:7f89fca19a9e | 41 | gap_conn_params.conn_sup_timeout = CFG_GAP_CONNECTION_SUPERVISION_TIMEOUT_MS / 10; // in 10ms unit |
lipoyang | 5:7f89fca19a9e | 42 | |
lipoyang | 5:7f89fca19a9e | 43 | ble_gap_conn_sec_mode_t sec_mode; |
lipoyang | 5:7f89fca19a9e | 44 | BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed |
lipoyang | 5:7f89fca19a9e | 45 | |
lipoyang | 5:7f89fca19a9e | 46 | ASSERT_STATUS( sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *) CFG_GAP_LOCAL_NAME, strlen(CFG_GAP_LOCAL_NAME))); |
lipoyang | 5:7f89fca19a9e | 47 | ASSERT_STATUS( sd_ble_gap_appearance_set(CFG_GAP_APPEARANCE)); |
lipoyang | 5:7f89fca19a9e | 48 | ASSERT_STATUS( sd_ble_gap_ppcp_set(&gap_conn_params)); |
lipoyang | 5:7f89fca19a9e | 49 | ASSERT_STATUS( sd_ble_gap_tx_power_set(CFG_BLE_TX_POWER_LEVEL)); |
lipoyang | 5:7f89fca19a9e | 50 | |
lipoyang | 5:7f89fca19a9e | 51 | /** |
lipoyang | 5:7f89fca19a9e | 52 | * Call to conn_params_init() is not necessary; and so is disabled by default. |
lipoyang | 5:7f89fca19a9e | 53 | * This API should be exposed to the user to be invoked when necessary. |
lipoyang | 5:7f89fca19a9e | 54 | */ |
lipoyang | 5:7f89fca19a9e | 55 | #if SDK_CONN_PARAMS_MODULE_ENABLE |
lipoyang | 5:7f89fca19a9e | 56 | /* Connection Parameters */ |
lipoyang | 5:7f89fca19a9e | 57 | enum { |
lipoyang | 5:7f89fca19a9e | 58 | FIRST_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER), |
lipoyang | 5:7f89fca19a9e | 59 | NEXT_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER), |
lipoyang | 5:7f89fca19a9e | 60 | MAX_UPDATE_COUNT = 3 |
lipoyang | 5:7f89fca19a9e | 61 | }; |
lipoyang | 5:7f89fca19a9e | 62 | |
lipoyang | 5:7f89fca19a9e | 63 | ble_conn_params_init_t cp_init = {0}; |
lipoyang | 5:7f89fca19a9e | 64 | |
lipoyang | 5:7f89fca19a9e | 65 | cp_init.p_conn_params = NULL; |
lipoyang | 5:7f89fca19a9e | 66 | cp_init.first_conn_params_update_delay = FIRST_UPDATE_DELAY; |
lipoyang | 5:7f89fca19a9e | 67 | cp_init.next_conn_params_update_delay = NEXT_UPDATE_DELAY; |
lipoyang | 5:7f89fca19a9e | 68 | cp_init.max_conn_params_update_count = MAX_UPDATE_COUNT; |
lipoyang | 5:7f89fca19a9e | 69 | cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID; |
lipoyang | 5:7f89fca19a9e | 70 | cp_init.disconnect_on_fail = true; |
lipoyang | 5:7f89fca19a9e | 71 | cp_init.evt_handler = NULL; |
lipoyang | 5:7f89fca19a9e | 72 | cp_init.error_handler = error_callback; |
lipoyang | 5:7f89fca19a9e | 73 | |
lipoyang | 5:7f89fca19a9e | 74 | ASSERT_STATUS ( ble_conn_params_init(&cp_init)); |
lipoyang | 5:7f89fca19a9e | 75 | #endif // SDK_CONN_PARAMS_MODULE_ENABLE |
lipoyang | 5:7f89fca19a9e | 76 | |
lipoyang | 5:7f89fca19a9e | 77 | return ERROR_NONE; |
lipoyang | 5:7f89fca19a9e | 78 | } |
lipoyang | 5:7f89fca19a9e | 79 | |
lipoyang | 5:7f89fca19a9e | 80 | /**************************************************************************/ |
lipoyang | 5:7f89fca19a9e | 81 | /*! |
lipoyang | 5:7f89fca19a9e | 82 | @brief Converts msecs to an integer representing 1.25ms units |
lipoyang | 5:7f89fca19a9e | 83 | |
lipoyang | 5:7f89fca19a9e | 84 | @param[in] ms |
lipoyang | 5:7f89fca19a9e | 85 | The number of milliseconds to conver to 1.25ms units |
lipoyang | 5:7f89fca19a9e | 86 | |
lipoyang | 5:7f89fca19a9e | 87 | @returns The number of 1.25ms units in the supplied number of ms |
lipoyang | 5:7f89fca19a9e | 88 | */ |
lipoyang | 5:7f89fca19a9e | 89 | /**************************************************************************/ |
lipoyang | 5:7f89fca19a9e | 90 | static inline uint32_t msec_to_1_25msec(uint32_t interval_ms) |
lipoyang | 5:7f89fca19a9e | 91 | { |
lipoyang | 5:7f89fca19a9e | 92 | return (interval_ms * 4) / 5; |
lipoyang | 5:7f89fca19a9e | 93 | } |
lipoyang | 5:7f89fca19a9e | 94 | |
lipoyang | 5:7f89fca19a9e | 95 | #if SDK_CONN_PARAMS_MODULE_ENABLE |
lipoyang | 5:7f89fca19a9e | 96 | static void error_callback(uint32_t nrf_error) |
lipoyang | 5:7f89fca19a9e | 97 | { |
lipoyang | 5:7f89fca19a9e | 98 | ASSERT_STATUS_RET_VOID( nrf_error ); |
lipoyang | 5:7f89fca19a9e | 99 | } |
lipoyang | 5:7f89fca19a9e | 100 | #endif // SDK_CONN_PARAMS_MODULE_ENABLE |