Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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