iOSのBLEコントローラアプリ「RCBController」とmbed HRM1017を接続し、RCサーボモータを操作するテストプログラムです。

Dependencies:   BLE_API_Native_IRC Servo mbed

Fork of BLE_RCBController by Junichi Katsu

  • 古いBLEライブラリを使っているのでプラットフォームは”Nordic nRF51822”を選択してください。
  • ライブラリ類はUpdateしないでください。コンパイルエラーになります。

うまく接続できない時は、iPhone/iPadのBluetoothをOFF->ONしてキャッシュをクリアしてみてください。

/media/uploads/robo8080/img_1560.jpg

Committer:
jksoft
Date:
Thu Jul 10 14:21:52 2014 +0000
Revision:
0:8c643bfe55b7
??

Who changed what in which revision?

UserRevisionLine numberNew 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 ble_flash_module Flash Manager
jksoft 0:8c643bfe55b7 16 * @{
jksoft 0:8c643bfe55b7 17 * @ingroup ble_sdk_lib
jksoft 0:8c643bfe55b7 18 * @brief Module for accessing flash memory.
jksoft 0:8c643bfe55b7 19 *
jksoft 0:8c643bfe55b7 20 * @details It contains functions for reading, writing and erasing one page in flash.
jksoft 0:8c643bfe55b7 21 *
jksoft 0:8c643bfe55b7 22 * The module uses the first 32 bits of the flash page to write a magic number in order to
jksoft 0:8c643bfe55b7 23 * determine if the page has been written or not.
jksoft 0:8c643bfe55b7 24 *
jksoft 0:8c643bfe55b7 25 * @note Be careful not to use a page number in the SoftDevice area (which currently occupies the
jksoft 0:8c643bfe55b7 26 * range 0 to 127), or in your application space! In both cases, this would end up
jksoft 0:8c643bfe55b7 27 * with a hard fault.
jksoft 0:8c643bfe55b7 28 */
jksoft 0:8c643bfe55b7 29
jksoft 0:8c643bfe55b7 30 #ifndef BLE_FLASH_H__
jksoft 0:8c643bfe55b7 31 #define BLE_FLASH_H__
jksoft 0:8c643bfe55b7 32
jksoft 0:8c643bfe55b7 33 #include <stdint.h>
jksoft 0:8c643bfe55b7 34 #include <stdbool.h>
jksoft 0:8c643bfe55b7 35 #include <nrf51.h>
jksoft 0:8c643bfe55b7 36 #include "nordic_global.h"
jksoft 0:8c643bfe55b7 37
jksoft 0:8c643bfe55b7 38 #define BLE_FLASH_PAGE_SIZE ((uint16_t)NRF_FICR->CODEPAGESIZE) /**< Size of one flash page. */
jksoft 0:8c643bfe55b7 39 #define BLE_FLASH_MAGIC_NUMBER 0x45DE0000 /**< Magic value to identify if flash contains valid data. */
jksoft 0:8c643bfe55b7 40 #define BLE_FLASH_EMPTY_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */
jksoft 0:8c643bfe55b7 41
jksoft 0:8c643bfe55b7 42
jksoft 0:8c643bfe55b7 43 /**@brief Macro for getting the end of the flash available for application.
jksoft 0:8c643bfe55b7 44 *
jksoft 0:8c643bfe55b7 45 * @details The result flash page number indicates the end boundary of the flash available
jksoft 0:8c643bfe55b7 46 * to the application. If a bootloader is used, the end will be the start of the
jksoft 0:8c643bfe55b7 47 * bootloader region. Otherwise, the end will be the size of the flash.
jksoft 0:8c643bfe55b7 48 */
jksoft 0:8c643bfe55b7 49 #define BLE_FLASH_PAGE_END \
jksoft 0:8c643bfe55b7 50 ((NRF_UICR->BOOTLOADERADDR != BLE_FLASH_EMPTY_MASK) \
jksoft 0:8c643bfe55b7 51 ? (NRF_UICR->BOOTLOADERADDR / BLE_FLASH_PAGE_SIZE) \
jksoft 0:8c643bfe55b7 52 : NRF_FICR->CODESIZE)
jksoft 0:8c643bfe55b7 53
jksoft 0:8c643bfe55b7 54 /**@brief Function for erasing the specified flash page, and then writes the given data to this page.
jksoft 0:8c643bfe55b7 55 *
jksoft 0:8c643bfe55b7 56 * @warning This operation blocks the CPU. DO NOT use while in a connection!
jksoft 0:8c643bfe55b7 57 *
jksoft 0:8c643bfe55b7 58 * @param[in] page_num Page number to update.
jksoft 0:8c643bfe55b7 59 * @param[in] p_in_array Pointer to a RAM area containing the elements to write in flash.
jksoft 0:8c643bfe55b7 60 * This area has to be 32 bits aligned.
jksoft 0:8c643bfe55b7 61 * @param[in] word_count Number of 32 bits words to write in flash.
jksoft 0:8c643bfe55b7 62 *
jksoft 0:8c643bfe55b7 63 * @return NRF_SUCCESS on successful flash write, otherwise an error code.
jksoft 0:8c643bfe55b7 64 */
jksoft 0:8c643bfe55b7 65 uint32_t ble_flash_page_write(uint8_t page_num, uint32_t * p_in_array, uint8_t word_count);
jksoft 0:8c643bfe55b7 66
jksoft 0:8c643bfe55b7 67 /**@brief Function for reading data from flash to RAM.
jksoft 0:8c643bfe55b7 68 *
jksoft 0:8c643bfe55b7 69 * @param[in] page_num Page number to read.
jksoft 0:8c643bfe55b7 70 * @param[out] p_out_array Pointer to a RAM area where the found data will be written.
jksoft 0:8c643bfe55b7 71 * This area has to be 32 bits aligned.
jksoft 0:8c643bfe55b7 72 * @param[out] p_word_count Number of 32 bits words read.
jksoft 0:8c643bfe55b7 73 *
jksoft 0:8c643bfe55b7 74 * @return NRF_SUCCESS on successful upload, NRF_ERROR_NOT_FOUND if no valid data has been found
jksoft 0:8c643bfe55b7 75 * in flash (first 32 bits not equal to the MAGIC_NUMBER+CRC).
jksoft 0:8c643bfe55b7 76 */
jksoft 0:8c643bfe55b7 77 uint32_t ble_flash_page_read(uint8_t page_num, uint32_t * p_out_array, uint8_t * p_word_count);
jksoft 0:8c643bfe55b7 78
jksoft 0:8c643bfe55b7 79 /**@brief Function for erasing a flash page.
jksoft 0:8c643bfe55b7 80 *
jksoft 0:8c643bfe55b7 81 * @note This operation blocks the CPU, so it should not be done while the radio is running!
jksoft 0:8c643bfe55b7 82 *
jksoft 0:8c643bfe55b7 83 * @param[in] page_num Page number to erase.
jksoft 0:8c643bfe55b7 84 *
jksoft 0:8c643bfe55b7 85 * @return NRF_SUCCESS on success, an error_code otherwise.
jksoft 0:8c643bfe55b7 86 */
jksoft 0:8c643bfe55b7 87 uint32_t ble_flash_page_erase(uint8_t page_num);
jksoft 0:8c643bfe55b7 88
jksoft 0:8c643bfe55b7 89 /**@brief Function for writing one word to flash.
jksoft 0:8c643bfe55b7 90 *
jksoft 0:8c643bfe55b7 91 * @note Flash location to be written must have been erased previously.
jksoft 0:8c643bfe55b7 92 *
jksoft 0:8c643bfe55b7 93 * @param[in] p_address Pointer to flash location to be written.
jksoft 0:8c643bfe55b7 94 * @param[in] value Value to write to flash.
jksoft 0:8c643bfe55b7 95 *
jksoft 0:8c643bfe55b7 96 * @return NRF_SUCCESS.
jksoft 0:8c643bfe55b7 97 */
jksoft 0:8c643bfe55b7 98 uint32_t ble_flash_word_write(uint32_t * p_address, uint32_t value);
jksoft 0:8c643bfe55b7 99
jksoft 0:8c643bfe55b7 100 /**@brief Function for writing a data block to flash.
jksoft 0:8c643bfe55b7 101 *
jksoft 0:8c643bfe55b7 102 * @note Flash locations to be written must have been erased previously.
jksoft 0:8c643bfe55b7 103 *
jksoft 0:8c643bfe55b7 104 * @param[in] p_address Pointer to start of flash location to be written.
jksoft 0:8c643bfe55b7 105 * @param[in] p_in_array Pointer to start of flash block to be written.
jksoft 0:8c643bfe55b7 106 * @param[in] word_count Number of words to be written.
jksoft 0:8c643bfe55b7 107 *
jksoft 0:8c643bfe55b7 108 * @return NRF_SUCCESS.
jksoft 0:8c643bfe55b7 109 */
jksoft 0:8c643bfe55b7 110 uint32_t ble_flash_block_write(uint32_t * p_address, uint32_t * p_in_array, uint16_t word_count);
jksoft 0:8c643bfe55b7 111
jksoft 0:8c643bfe55b7 112 /**@brief Function for computing pointer to start of specified flash page.
jksoft 0:8c643bfe55b7 113 *
jksoft 0:8c643bfe55b7 114 * @param[in] page_num Page number.
jksoft 0:8c643bfe55b7 115 * @param[out] pp_page_addr Pointer to start of flash page.
jksoft 0:8c643bfe55b7 116 *
jksoft 0:8c643bfe55b7 117 * @return NRF_SUCCESS.
jksoft 0:8c643bfe55b7 118 */
jksoft 0:8c643bfe55b7 119 uint32_t ble_flash_page_addr(uint8_t page_num, uint32_t ** pp_page_addr);
jksoft 0:8c643bfe55b7 120
jksoft 0:8c643bfe55b7 121 /**@brief Function for calculating a 16 bit CRC using the CRC-16-CCITT scheme.
jksoft 0:8c643bfe55b7 122 *
jksoft 0:8c643bfe55b7 123 * @param[in] p_data Pointer to data on which the CRC is to be calulated.
jksoft 0:8c643bfe55b7 124 * @param[in] size Number of bytes on which the CRC is to be calulated.
jksoft 0:8c643bfe55b7 125 * @param[in] p_crc Initial CRC value (if NULL, a preset value is used as the initial value).
jksoft 0:8c643bfe55b7 126 *
jksoft 0:8c643bfe55b7 127 * @return Calculated CRC.
jksoft 0:8c643bfe55b7 128 */
jksoft 0:8c643bfe55b7 129 uint16_t ble_flash_crc16_compute(uint8_t * p_data, uint16_t size, uint16_t * p_crc);
jksoft 0:8c643bfe55b7 130
jksoft 0:8c643bfe55b7 131 /**@brief Function for handling flashing module Radio Notification event.
jksoft 0:8c643bfe55b7 132 *
jksoft 0:8c643bfe55b7 133 * @note For flash writing to work safely while in a connection or while advertising, this function
jksoft 0:8c643bfe55b7 134 * MUST be called from the Radio Notification module's event handler (see
jksoft 0:8c643bfe55b7 135 * @ref ble_radio_notification for details).
jksoft 0:8c643bfe55b7 136 *
jksoft 0:8c643bfe55b7 137 * @param[in] radio_active TRUE if radio is active (or about to become active), FALSE otherwise.
jksoft 0:8c643bfe55b7 138 */
jksoft 0:8c643bfe55b7 139 void ble_flash_on_radio_active_evt(bool radio_active);
jksoft 0:8c643bfe55b7 140
jksoft 0:8c643bfe55b7 141 #endif // BLE_FLASH_H__
jksoft 0:8c643bfe55b7 142
jksoft 0:8c643bfe55b7 143 /** @} */