mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /* mbed Microcontroller Library
elessair 0:f269e3021894 2 * Copyright (c) 2006-2015 ARM Limited
elessair 0:f269e3021894 3 *
elessair 0:f269e3021894 4 * Licensed under the Apache License, Version 2.0 (the "License");
elessair 0:f269e3021894 5 * you may not use this file except in compliance with the License.
elessair 0:f269e3021894 6 * You may obtain a copy of the License at
elessair 0:f269e3021894 7 *
elessair 0:f269e3021894 8 * http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 9 *
elessair 0:f269e3021894 10 * Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 11 * distributed under the License is distributed on an "AS IS" BASIS,
elessair 0:f269e3021894 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 13 * See the License for the specific language governing permissions and
elessair 0:f269e3021894 14 * limitations under the License.
elessair 0:f269e3021894 15 */
elessair 0:f269e3021894 16 #ifndef MBED_FUNCTIONPOINTER_H
elessair 0:f269e3021894 17 #define MBED_FUNCTIONPOINTER_H
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 #include "platform/Callback.h"
elessair 0:f269e3021894 20 #include "platform/toolchain.h"
elessair 0:f269e3021894 21 #include <string.h>
elessair 0:f269e3021894 22 #include <stdint.h>
elessair 0:f269e3021894 23
elessair 0:f269e3021894 24 namespace mbed {
elessair 0:f269e3021894 25 /** \addtogroup platform */
elessair 0:f269e3021894 26 /** @{*/
elessair 0:f269e3021894 27
elessair 0:f269e3021894 28
elessair 0:f269e3021894 29 // Declarations for backwards compatibility
elessair 0:f269e3021894 30 // To be foward compatible, code should adopt the Callback class
elessair 0:f269e3021894 31 template <typename R, typename A1>
elessair 0:f269e3021894 32 class FunctionPointerArg1 : public Callback<R(A1)> {
elessair 0:f269e3021894 33 public:
elessair 0:f269e3021894 34 MBED_DEPRECATED_SINCE("mbed-os-5.1",
elessair 0:f269e3021894 35 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
elessair 0:f269e3021894 36 FunctionPointerArg1(R (*function)(A1) = 0)
elessair 0:f269e3021894 37 : Callback<R(A1)>(function) {}
elessair 0:f269e3021894 38
elessair 0:f269e3021894 39 template<typename T>
elessair 0:f269e3021894 40 MBED_DEPRECATED_SINCE("mbed-os-5.1",
elessair 0:f269e3021894 41 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
elessair 0:f269e3021894 42 FunctionPointerArg1(T *object, R (T::*member)(A1))
elessair 0:f269e3021894 43 : Callback<R(A1)>(object, member) {}
elessair 0:f269e3021894 44
elessair 0:f269e3021894 45 R (*get_function())(A1) {
elessair 0:f269e3021894 46 return *reinterpret_cast<R (**)(A1)>(this);
elessair 0:f269e3021894 47 }
elessair 0:f269e3021894 48
elessair 0:f269e3021894 49 R call(A1 a1) const {
elessair 0:f269e3021894 50 if (!Callback<R(A1)>::operator bool()) {
elessair 0:f269e3021894 51 return (R)0;
elessair 0:f269e3021894 52 }
elessair 0:f269e3021894 53
elessair 0:f269e3021894 54 return Callback<R(A1)>::call(a1);
elessair 0:f269e3021894 55 }
elessair 0:f269e3021894 56
elessair 0:f269e3021894 57 R operator()(A1 a1) const {
elessair 0:f269e3021894 58 return Callback<R(A1)>::call(a1);
elessair 0:f269e3021894 59 }
elessair 0:f269e3021894 60 };
elessair 0:f269e3021894 61
elessair 0:f269e3021894 62 template <typename R>
elessair 0:f269e3021894 63 class FunctionPointerArg1<R, void> : public Callback<R()> {
elessair 0:f269e3021894 64 public:
elessair 0:f269e3021894 65 MBED_DEPRECATED_SINCE("mbed-os-5.1",
elessair 0:f269e3021894 66 "FunctionPointer has been replaced by Callback<void()>")
elessair 0:f269e3021894 67 FunctionPointerArg1(R (*function)() = 0)
elessair 0:f269e3021894 68 : Callback<R()>(function) {}
elessair 0:f269e3021894 69
elessair 0:f269e3021894 70 template<typename T>
elessair 0:f269e3021894 71 MBED_DEPRECATED_SINCE("mbed-os-5.1",
elessair 0:f269e3021894 72 "FunctionPointer has been replaced by Callback<void()>")
elessair 0:f269e3021894 73 FunctionPointerArg1(T *object, R (T::*member)())
elessair 0:f269e3021894 74 : Callback<R()>(object, member) {}
elessair 0:f269e3021894 75
elessair 0:f269e3021894 76 R (*get_function())() {
elessair 0:f269e3021894 77 return *reinterpret_cast<R (**)()>(this);
elessair 0:f269e3021894 78 }
elessair 0:f269e3021894 79
elessair 0:f269e3021894 80 R call() const {
elessair 0:f269e3021894 81 if (!Callback<R()>::operator bool()) {
elessair 0:f269e3021894 82 return (R)0;
elessair 0:f269e3021894 83 }
elessair 0:f269e3021894 84
elessair 0:f269e3021894 85 return Callback<R()>::call();
elessair 0:f269e3021894 86 }
elessair 0:f269e3021894 87
elessair 0:f269e3021894 88 R operator()() const {
elessair 0:f269e3021894 89 return Callback<R()>::call();
elessair 0:f269e3021894 90 }
elessair 0:f269e3021894 91 };
elessair 0:f269e3021894 92
elessair 0:f269e3021894 93 typedef FunctionPointerArg1<void, void> FunctionPointer;
elessair 0:f269e3021894 94
elessair 0:f269e3021894 95
elessair 0:f269e3021894 96 } // namespace mbed
elessair 0:f269e3021894 97
elessair 0:f269e3021894 98 #endif
elessair 0:f269e3021894 99
elessair 0:f269e3021894 100 /** @}*/