RCBControllerでモータを制御します。うおーるぼっとも動かせました。

Dependencies:   BLE_API_Native_IRC TB6612FNG2 mbed

Fork of BLE_RCBController by Junichi Katsu

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

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

RCBControllerでうおーるぼっとを操縦する例 /media/uploads/robo8080/img_1671.jpg

RCBControllerでの操縦は次の4種類あります。 それぞれうおーるぼっとの動きが異なりますので試してみてください。

  • 左十字ボタン
  • 左のみアナログ
  • 右のみアナログ
  • 両方アナログ

うおーるぼっと(LPC1768のソケット)とHRM1017の接続はこれです。

LPC1768 ー HRM1017

p11 ーーー P0_0

p12 ーーー P0_1

p13 ーーー P0_28

p14 ーーー P0_29

p21 ーーー P0_30

p22 ーーー P0_25

GND ーーー GND

HRM1017の電源はうおーるぼっとのUSBコネクタからとります。 /media/uploads/robo8080/img_1674.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 app_util Utility Functions and Definitions
jksoft 0:8c643bfe55b7 16 * @{
jksoft 0:8c643bfe55b7 17 * @ingroup app_common
jksoft 0:8c643bfe55b7 18 *
jksoft 0:8c643bfe55b7 19 * @brief Various types and definitions available to all applications.
jksoft 0:8c643bfe55b7 20 */
jksoft 0:8c643bfe55b7 21
jksoft 0:8c643bfe55b7 22 #ifndef APP_UTIL_H__
jksoft 0:8c643bfe55b7 23 #define APP_UTIL_H__
jksoft 0:8c643bfe55b7 24
jksoft 0:8c643bfe55b7 25 #include <stdint.h>
jksoft 0:8c643bfe55b7 26 #include "nordic_global.h"
jksoft 0:8c643bfe55b7 27 #include "compiler_abstraction.h"
jksoft 0:8c643bfe55b7 28 #include "nrf51.h"
jksoft 0:8c643bfe55b7 29 #include "app_error.h"
jksoft 0:8c643bfe55b7 30
jksoft 0:8c643bfe55b7 31 /**@brief The interrupt priorities available to the application while the softdevice is active. */
jksoft 0:8c643bfe55b7 32 typedef enum
jksoft 0:8c643bfe55b7 33 {
jksoft 0:8c643bfe55b7 34 APP_IRQ_PRIORITY_HIGH = 1,
jksoft 0:8c643bfe55b7 35 APP_IRQ_PRIORITY_LOW = 3
jksoft 0:8c643bfe55b7 36 } app_irq_priority_t;
jksoft 0:8c643bfe55b7 37
jksoft 0:8c643bfe55b7 38 enum
jksoft 0:8c643bfe55b7 39 {
jksoft 0:8c643bfe55b7 40 UNIT_0_625_MS = 625, /**< Number of microseconds in 0.625 milliseconds. */
jksoft 0:8c643bfe55b7 41 UNIT_1_25_MS = 1250, /**< Number of microseconds in 1.25 milliseconds. */
jksoft 0:8c643bfe55b7 42 UNIT_10_MS = 10000 /**< Number of microseconds in 10 milliseconds. */
jksoft 0:8c643bfe55b7 43 };
jksoft 0:8c643bfe55b7 44
jksoft 0:8c643bfe55b7 45 #define NRF_APP_PRIORITY_THREAD 4 /**< "Interrupt level" when running in Thread Mode. */
jksoft 0:8c643bfe55b7 46
jksoft 0:8c643bfe55b7 47 /**@cond NO_DOXYGEN */
jksoft 0:8c643bfe55b7 48 #define EXTERNAL_INT_VECTOR_OFFSET 16
jksoft 0:8c643bfe55b7 49 /**@endcond */
jksoft 0:8c643bfe55b7 50
jksoft 0:8c643bfe55b7 51 #define PACKED(TYPE) __packed TYPE
jksoft 0:8c643bfe55b7 52
jksoft 0:8c643bfe55b7 53 /**@brief Macro for doing static (i.e. compile time) assertion.
jksoft 0:8c643bfe55b7 54 *
jksoft 0:8c643bfe55b7 55 * @note If the assertion fails when compiling using Keil, the compiler will report error message
jksoft 0:8c643bfe55b7 56 * "error: #94: the size of an array must be greater than zero" (while gcc will list the
jksoft 0:8c643bfe55b7 57 * symbol static_assert_failed, making the error message more readable).
jksoft 0:8c643bfe55b7 58 * If the supplied expression can not be evaluated at compile time, Keil will report
jksoft 0:8c643bfe55b7 59 * "error: #28: expression must have a constant value".
jksoft 0:8c643bfe55b7 60 *
jksoft 0:8c643bfe55b7 61 * @note The macro is intentionally implemented not using do while(0), allowing it to be used
jksoft 0:8c643bfe55b7 62 * outside function blocks (e.g. close to global type- and variable declarations).
jksoft 0:8c643bfe55b7 63 * If used in a code block, it must be used before any executable code in this block.
jksoft 0:8c643bfe55b7 64 *
jksoft 0:8c643bfe55b7 65 * @param[in] EXPR Constant expression to be verified.
jksoft 0:8c643bfe55b7 66 */
jksoft 0:8c643bfe55b7 67
jksoft 0:8c643bfe55b7 68 #define STATIC_ASSERT(EXPR) typedef char static_assert_failed[(EXPR) ? 1 : -1]
jksoft 0:8c643bfe55b7 69
jksoft 0:8c643bfe55b7 70 /**@brief type for holding an encoded (i.e. little endian) 16 bit unsigned integer. */
jksoft 0:8c643bfe55b7 71 typedef uint8_t uint16_le_t[2];
jksoft 0:8c643bfe55b7 72
jksoft 0:8c643bfe55b7 73 /**@brief type for holding an encoded (i.e. little endian) 32 bit unsigned integer. */
jksoft 0:8c643bfe55b7 74 typedef uint8_t uint32_le_t[4];
jksoft 0:8c643bfe55b7 75
jksoft 0:8c643bfe55b7 76 /**@brief Byte array type. */
jksoft 0:8c643bfe55b7 77 typedef struct
jksoft 0:8c643bfe55b7 78 {
jksoft 0:8c643bfe55b7 79 uint16_t size; /**< Number of array entries. */
jksoft 0:8c643bfe55b7 80 uint8_t * p_data; /**< Pointer to array entries. */
jksoft 0:8c643bfe55b7 81 } uint8_array_t;
jksoft 0:8c643bfe55b7 82
jksoft 0:8c643bfe55b7 83 /**@brief Macro for entering a critical region.
jksoft 0:8c643bfe55b7 84 *
jksoft 0:8c643bfe55b7 85 * @note Due to implementation details, there must exist one and only one call to
jksoft 0:8c643bfe55b7 86 * CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
jksoft 0:8c643bfe55b7 87 * in the same scope.
jksoft 0:8c643bfe55b7 88 */
jksoft 0:8c643bfe55b7 89 #define CRITICAL_REGION_ENTER() \
jksoft 0:8c643bfe55b7 90 { \
jksoft 0:8c643bfe55b7 91 uint8_t IS_NESTED_CRITICAL_REGION = 0; \
jksoft 0:8c643bfe55b7 92 uint32_t CURRENT_INT_PRI = current_int_priority_get(); \
jksoft 0:8c643bfe55b7 93 if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH) \
jksoft 0:8c643bfe55b7 94 { \
jksoft 0:8c643bfe55b7 95 uint32_t ERR_CODE = sd_nvic_critical_region_enter(&IS_NESTED_CRITICAL_REGION); \
jksoft 0:8c643bfe55b7 96 if (ERR_CODE == NRF_ERROR_SOFTDEVICE_NOT_ENABLED) \
jksoft 0:8c643bfe55b7 97 { \
jksoft 0:8c643bfe55b7 98 __disable_irq(); \
jksoft 0:8c643bfe55b7 99 } \
jksoft 0:8c643bfe55b7 100 else \
jksoft 0:8c643bfe55b7 101 { \
jksoft 0:8c643bfe55b7 102 APP_ERROR_CHECK(ERR_CODE); \
jksoft 0:8c643bfe55b7 103 } \
jksoft 0:8c643bfe55b7 104 }
jksoft 0:8c643bfe55b7 105
jksoft 0:8c643bfe55b7 106 /**@brief Macro for leaving a critical region.
jksoft 0:8c643bfe55b7 107 *
jksoft 0:8c643bfe55b7 108 * @note Due to implementation details, there must exist one and only one call to
jksoft 0:8c643bfe55b7 109 * CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
jksoft 0:8c643bfe55b7 110 * in the same scope.
jksoft 0:8c643bfe55b7 111 */
jksoft 0:8c643bfe55b7 112 #define CRITICAL_REGION_EXIT() \
jksoft 0:8c643bfe55b7 113 if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH) \
jksoft 0:8c643bfe55b7 114 { \
jksoft 0:8c643bfe55b7 115 uint32_t ERR_CODE; \
jksoft 0:8c643bfe55b7 116 __enable_irq(); \
jksoft 0:8c643bfe55b7 117 ERR_CODE = sd_nvic_critical_region_exit(IS_NESTED_CRITICAL_REGION); \
jksoft 0:8c643bfe55b7 118 if (ERR_CODE != NRF_ERROR_SOFTDEVICE_NOT_ENABLED) \
jksoft 0:8c643bfe55b7 119 { \
jksoft 0:8c643bfe55b7 120 APP_ERROR_CHECK(ERR_CODE); \
jksoft 0:8c643bfe55b7 121 } \
jksoft 0:8c643bfe55b7 122 } \
jksoft 0:8c643bfe55b7 123 }
jksoft 0:8c643bfe55b7 124
jksoft 0:8c643bfe55b7 125 /**@brief Perform rounded integer division (as opposed to truncating the result).
jksoft 0:8c643bfe55b7 126 *
jksoft 0:8c643bfe55b7 127 * @param[in] A Numerator.
jksoft 0:8c643bfe55b7 128 * @param[in] B Denominator.
jksoft 0:8c643bfe55b7 129 *
jksoft 0:8c643bfe55b7 130 * @return Rounded (integer) result of dividing A by B.
jksoft 0:8c643bfe55b7 131 */
jksoft 0:8c643bfe55b7 132 #define ROUNDED_DIV(A, B) (((A) + ((B) / 2)) / (B))
jksoft 0:8c643bfe55b7 133
jksoft 0:8c643bfe55b7 134 /**@brief Check if the integer provided is a power of two.
jksoft 0:8c643bfe55b7 135 *
jksoft 0:8c643bfe55b7 136 * @param[in] A Number to be tested.
jksoft 0:8c643bfe55b7 137 *
jksoft 0:8c643bfe55b7 138 * @return true if value is power of two.
jksoft 0:8c643bfe55b7 139 * @return false if value not power of two.
jksoft 0:8c643bfe55b7 140 */
jksoft 0:8c643bfe55b7 141 #define IS_POWER_OF_TWO(A) ( ((A) != 0) && ((((A) - 1) & (A)) == 0) )
jksoft 0:8c643bfe55b7 142
jksoft 0:8c643bfe55b7 143 /**@brief To convert ticks to millisecond
jksoft 0:8c643bfe55b7 144 * @param[in] time Number of millseconds that needs to be converted.
jksoft 0:8c643bfe55b7 145 * @param[in] resolution Units to be converted.
jksoft 0:8c643bfe55b7 146 */
jksoft 0:8c643bfe55b7 147 #define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
jksoft 0:8c643bfe55b7 148
jksoft 0:8c643bfe55b7 149
jksoft 0:8c643bfe55b7 150 /**@brief Perform integer division, making sure the result is rounded up.
jksoft 0:8c643bfe55b7 151 *
jksoft 0:8c643bfe55b7 152 * @details One typical use for this is to compute the number of objects with size B is needed to
jksoft 0:8c643bfe55b7 153 * hold A number of bytes.
jksoft 0:8c643bfe55b7 154 *
jksoft 0:8c643bfe55b7 155 * @param[in] A Numerator.
jksoft 0:8c643bfe55b7 156 * @param[in] B Denominator.
jksoft 0:8c643bfe55b7 157 *
jksoft 0:8c643bfe55b7 158 * @return Integer result of dividing A by B, rounded up.
jksoft 0:8c643bfe55b7 159 */
jksoft 0:8c643bfe55b7 160 #define CEIL_DIV(A, B) \
jksoft 0:8c643bfe55b7 161 /*lint -save -e573 */ \
jksoft 0:8c643bfe55b7 162 ((((A) - 1) / (B)) + 1) \
jksoft 0:8c643bfe55b7 163 /*lint -restore */
jksoft 0:8c643bfe55b7 164
jksoft 0:8c643bfe55b7 165 /**@brief Function for encoding a uint16 value.
jksoft 0:8c643bfe55b7 166 *
jksoft 0:8c643bfe55b7 167 * @param[in] value Value to be encoded.
jksoft 0:8c643bfe55b7 168 * @param[out] p_encoded_data Buffer where the encoded data is to be written.
jksoft 0:8c643bfe55b7 169 *
jksoft 0:8c643bfe55b7 170 * @return Number of bytes written.
jksoft 0:8c643bfe55b7 171 */
jksoft 0:8c643bfe55b7 172 static __INLINE uint8_t uint16_encode(uint16_t value, uint8_t * p_encoded_data)
jksoft 0:8c643bfe55b7 173 {
jksoft 0:8c643bfe55b7 174 p_encoded_data[0] = (uint8_t) ((value & 0x00FF) >> 0);
jksoft 0:8c643bfe55b7 175 p_encoded_data[1] = (uint8_t) ((value & 0xFF00) >> 8);
jksoft 0:8c643bfe55b7 176 return sizeof(uint16_t);
jksoft 0:8c643bfe55b7 177 }
jksoft 0:8c643bfe55b7 178
jksoft 0:8c643bfe55b7 179 /**@brief Function for encoding a uint32 value.
jksoft 0:8c643bfe55b7 180 *
jksoft 0:8c643bfe55b7 181 * @param[in] value Value to be encoded.
jksoft 0:8c643bfe55b7 182 * @param[out] p_encoded_data Buffer where the encoded data is to be written.
jksoft 0:8c643bfe55b7 183 *
jksoft 0:8c643bfe55b7 184 * @return Number of bytes written.
jksoft 0:8c643bfe55b7 185 */
jksoft 0:8c643bfe55b7 186 static __INLINE uint8_t uint32_encode(uint32_t value, uint8_t * p_encoded_data)
jksoft 0:8c643bfe55b7 187 {
jksoft 0:8c643bfe55b7 188 p_encoded_data[0] = (uint8_t) ((value & 0x000000FF) >> 0);
jksoft 0:8c643bfe55b7 189 p_encoded_data[1] = (uint8_t) ((value & 0x0000FF00) >> 8);
jksoft 0:8c643bfe55b7 190 p_encoded_data[2] = (uint8_t) ((value & 0x00FF0000) >> 16);
jksoft 0:8c643bfe55b7 191 p_encoded_data[3] = (uint8_t) ((value & 0xFF000000) >> 24);
jksoft 0:8c643bfe55b7 192 return sizeof(uint32_t);
jksoft 0:8c643bfe55b7 193 }
jksoft 0:8c643bfe55b7 194
jksoft 0:8c643bfe55b7 195 /**@brief Function for decoding a uint16 value.
jksoft 0:8c643bfe55b7 196 *
jksoft 0:8c643bfe55b7 197 * @param[in] p_encoded_data Buffer where the encoded data is stored.
jksoft 0:8c643bfe55b7 198 *
jksoft 0:8c643bfe55b7 199 * @return Decoded value.
jksoft 0:8c643bfe55b7 200 */
jksoft 0:8c643bfe55b7 201 static __INLINE uint16_t uint16_decode(const uint8_t * p_encoded_data)
jksoft 0:8c643bfe55b7 202 {
jksoft 0:8c643bfe55b7 203 return ( (((uint16_t)((uint8_t *)p_encoded_data)[0])) |
jksoft 0:8c643bfe55b7 204 (((uint16_t)((uint8_t *)p_encoded_data)[1]) << 8 ));
jksoft 0:8c643bfe55b7 205 }
jksoft 0:8c643bfe55b7 206
jksoft 0:8c643bfe55b7 207 /**@brief Function for decoding a uint32 value.
jksoft 0:8c643bfe55b7 208 *
jksoft 0:8c643bfe55b7 209 * @param[in] p_encoded_data Buffer where the encoded data is stored.
jksoft 0:8c643bfe55b7 210 *
jksoft 0:8c643bfe55b7 211 * @return Decoded value.
jksoft 0:8c643bfe55b7 212 */
jksoft 0:8c643bfe55b7 213 static __INLINE uint32_t uint32_decode(const uint8_t * p_encoded_data)
jksoft 0:8c643bfe55b7 214 {
jksoft 0:8c643bfe55b7 215 return ( (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0) |
jksoft 0:8c643bfe55b7 216 (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8) |
jksoft 0:8c643bfe55b7 217 (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16) |
jksoft 0:8c643bfe55b7 218 (((uint32_t)((uint8_t *)p_encoded_data)[3]) << 24 ));
jksoft 0:8c643bfe55b7 219 }
jksoft 0:8c643bfe55b7 220
jksoft 0:8c643bfe55b7 221
jksoft 0:8c643bfe55b7 222 /**@brief Function for finding the current interrupt level.
jksoft 0:8c643bfe55b7 223 *
jksoft 0:8c643bfe55b7 224 * @return Current interrupt level.
jksoft 0:8c643bfe55b7 225 * @retval APP_IRQ_PRIORITY_HIGH We are running in Application High interrupt level.
jksoft 0:8c643bfe55b7 226 * @retval APP_IRQ_PRIORITY_LOW We are running in Application Low interrupt level.
jksoft 0:8c643bfe55b7 227 * @retval APP_IRQ_PRIORITY_THREAD We are running in Thread Mode.
jksoft 0:8c643bfe55b7 228 */
jksoft 0:8c643bfe55b7 229 static __INLINE uint8_t current_int_priority_get(void)
jksoft 0:8c643bfe55b7 230 {
jksoft 0:8c643bfe55b7 231 uint32_t isr_vector_num = (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk);
jksoft 0:8c643bfe55b7 232 if (isr_vector_num > 0)
jksoft 0:8c643bfe55b7 233 {
jksoft 0:8c643bfe55b7 234 int32_t irq_type = ((int32_t)isr_vector_num - EXTERNAL_INT_VECTOR_OFFSET);
jksoft 0:8c643bfe55b7 235 return (NVIC_GetPriority((IRQn_Type)irq_type) & 0xFF);
jksoft 0:8c643bfe55b7 236 }
jksoft 0:8c643bfe55b7 237 else
jksoft 0:8c643bfe55b7 238 {
jksoft 0:8c643bfe55b7 239 return NRF_APP_PRIORITY_THREAD;
jksoft 0:8c643bfe55b7 240 }
jksoft 0:8c643bfe55b7 241 }
jksoft 0:8c643bfe55b7 242
jksoft 0:8c643bfe55b7 243 /** @brief Function for converting the input voltage (in milli volts) into percentage of 3.0 Volts.
jksoft 0:8c643bfe55b7 244 *
jksoft 0:8c643bfe55b7 245 * @details The calculation is based on a linearized version of the battery's discharge
jksoft 0:8c643bfe55b7 246 * curve. 3.0V returns 100% battery level. The limit for power failure is 2.1V and
jksoft 0:8c643bfe55b7 247 * is considered to be the lower boundary.
jksoft 0:8c643bfe55b7 248 *
jksoft 0:8c643bfe55b7 249 * The discharge curve for CR2032 is non-linear. In this model it is split into
jksoft 0:8c643bfe55b7 250 * 4 linear sections:
jksoft 0:8c643bfe55b7 251 * - Section 1: 3.0V - 2.9V = 100% - 42% (58% drop on 100 mV)
jksoft 0:8c643bfe55b7 252 * - Section 2: 2.9V - 2.74V = 42% - 18% (24% drop on 160 mV)
jksoft 0:8c643bfe55b7 253 * - Section 3: 2.74V - 2.44V = 18% - 6% (12% drop on 300 mV)
jksoft 0:8c643bfe55b7 254 * - Section 4: 2.44V - 2.1V = 6% - 0% (6% drop on 340 mV)
jksoft 0:8c643bfe55b7 255 *
jksoft 0:8c643bfe55b7 256 * These numbers are by no means accurate. Temperature and
jksoft 0:8c643bfe55b7 257 * load in the actual application is not accounted for!
jksoft 0:8c643bfe55b7 258 *
jksoft 0:8c643bfe55b7 259 * @param[in] mvolts The voltage in mV
jksoft 0:8c643bfe55b7 260 *
jksoft 0:8c643bfe55b7 261 * @return Battery level in percent.
jksoft 0:8c643bfe55b7 262 */
jksoft 0:8c643bfe55b7 263 static __INLINE uint8_t battery_level_in_percent(const uint16_t mvolts)
jksoft 0:8c643bfe55b7 264 {
jksoft 0:8c643bfe55b7 265 uint8_t battery_level;
jksoft 0:8c643bfe55b7 266
jksoft 0:8c643bfe55b7 267 if (mvolts >= 3000)
jksoft 0:8c643bfe55b7 268 {
jksoft 0:8c643bfe55b7 269 battery_level = 100;
jksoft 0:8c643bfe55b7 270 }
jksoft 0:8c643bfe55b7 271 else if (mvolts > 2900)
jksoft 0:8c643bfe55b7 272 {
jksoft 0:8c643bfe55b7 273 battery_level = 100 - ((3000 - mvolts) * 58) / 100;
jksoft 0:8c643bfe55b7 274 }
jksoft 0:8c643bfe55b7 275 else if (mvolts > 2740)
jksoft 0:8c643bfe55b7 276 {
jksoft 0:8c643bfe55b7 277 battery_level = 42 - ((2900 - mvolts) * 24) / 160;
jksoft 0:8c643bfe55b7 278 }
jksoft 0:8c643bfe55b7 279 else if (mvolts > 2440)
jksoft 0:8c643bfe55b7 280 {
jksoft 0:8c643bfe55b7 281 battery_level = 18 - ((2740 - mvolts) * 12) / 300;
jksoft 0:8c643bfe55b7 282 }
jksoft 0:8c643bfe55b7 283 else if (mvolts > 2100)
jksoft 0:8c643bfe55b7 284 {
jksoft 0:8c643bfe55b7 285 battery_level = 6 - ((2440 - mvolts) * 6) / 340;
jksoft 0:8c643bfe55b7 286 }
jksoft 0:8c643bfe55b7 287 else
jksoft 0:8c643bfe55b7 288 {
jksoft 0:8c643bfe55b7 289 battery_level = 0;
jksoft 0:8c643bfe55b7 290 }
jksoft 0:8c643bfe55b7 291
jksoft 0:8c643bfe55b7 292 return battery_level;
jksoft 0:8c643bfe55b7 293 }
jksoft 0:8c643bfe55b7 294
jksoft 0:8c643bfe55b7 295 /**@brief Function for checking if a pointer value is aligned to a 4 byte boundary.
jksoft 0:8c643bfe55b7 296 *
jksoft 0:8c643bfe55b7 297 * @param[in] p Pointer value to be checked.
jksoft 0:8c643bfe55b7 298 *
jksoft 0:8c643bfe55b7 299 * @return TRUE if pointer is aligned to a 4 byte boundary, FALSE otherwise.
jksoft 0:8c643bfe55b7 300 */
jksoft 0:8c643bfe55b7 301 static __INLINE bool is_word_aligned(void * p)
jksoft 0:8c643bfe55b7 302 {
jksoft 0:8c643bfe55b7 303 return (((uint32_t)p & 0x00000003) == 0);
jksoft 0:8c643bfe55b7 304 }
jksoft 0:8c643bfe55b7 305
jksoft 0:8c643bfe55b7 306 #endif // APP_UTIL_H__
jksoft 0:8c643bfe55b7 307
jksoft 0:8c643bfe55b7 308 /** @} */