Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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