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-2013 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_CALLCHAIN_H
lypinator 0:bb348c97df44 17 #define MBED_CALLCHAIN_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 "platform/NonCopyable.h"
lypinator 0:bb348c97df44 22 #include <string.h>
lypinator 0:bb348c97df44 23
lypinator 0:bb348c97df44 24 namespace mbed {
lypinator 0:bb348c97df44 25
lypinator 0:bb348c97df44 26
lypinator 0:bb348c97df44 27 typedef Callback<void()> *pFunctionPointer_t;
lypinator 0:bb348c97df44 28 class CallChainLink;
lypinator 0:bb348c97df44 29
lypinator 0:bb348c97df44 30 /** \addtogroup platform */
lypinator 0:bb348c97df44 31 /** @{*/
lypinator 0:bb348c97df44 32 /**
lypinator 0:bb348c97df44 33 * \defgroup platform_CallChain CallChain class
lypinator 0:bb348c97df44 34 * @{
lypinator 0:bb348c97df44 35 */
lypinator 0:bb348c97df44 36
lypinator 0:bb348c97df44 37 /** Group one or more functions in an instance of a CallChain, then call them in
lypinator 0:bb348c97df44 38 * sequence using CallChain::call(). Used mostly by the interrupt chaining code,
lypinator 0:bb348c97df44 39 * but can be used for other purposes.
lypinator 0:bb348c97df44 40 *
lypinator 0:bb348c97df44 41 * @deprecated Do not use this class. This class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 42 * @note Synchronization level: Not protected
lypinator 0:bb348c97df44 43 *
lypinator 0:bb348c97df44 44 * Example:
lypinator 0:bb348c97df44 45 * @code
lypinator 0:bb348c97df44 46 * #include "mbed.h"
lypinator 0:bb348c97df44 47 *
lypinator 0:bb348c97df44 48 * CallChain chain;
lypinator 0:bb348c97df44 49 *
lypinator 0:bb348c97df44 50 * void first(void) {
lypinator 0:bb348c97df44 51 * printf("'first' function.\n");
lypinator 0:bb348c97df44 52 * }
lypinator 0:bb348c97df44 53 *
lypinator 0:bb348c97df44 54 * void second(void) {
lypinator 0:bb348c97df44 55 * printf("'second' function.\n");
lypinator 0:bb348c97df44 56 * }
lypinator 0:bb348c97df44 57 *
lypinator 0:bb348c97df44 58 * class Test {
lypinator 0:bb348c97df44 59 * public:
lypinator 0:bb348c97df44 60 * void f(void) {
lypinator 0:bb348c97df44 61 * printf("A::f (class member).\n");
lypinator 0:bb348c97df44 62 * }
lypinator 0:bb348c97df44 63 * };
lypinator 0:bb348c97df44 64 *
lypinator 0:bb348c97df44 65 * int main() {
lypinator 0:bb348c97df44 66 * Test test;
lypinator 0:bb348c97df44 67 *
lypinator 0:bb348c97df44 68 * chain.add(second);
lypinator 0:bb348c97df44 69 * chain.add_front(first);
lypinator 0:bb348c97df44 70 * chain.add(&test, &Test::f);
lypinator 0:bb348c97df44 71 * chain.call();
lypinator 0:bb348c97df44 72 * }
lypinator 0:bb348c97df44 73 * @endcode
lypinator 0:bb348c97df44 74 */
lypinator 0:bb348c97df44 75 class CallChain : private NonCopyable<CallChain> {
lypinator 0:bb348c97df44 76 public:
lypinator 0:bb348c97df44 77 /** Create an empty chain
lypinator 0:bb348c97df44 78 * @deprecated
lypinator 0:bb348c97df44 79 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 80 *
lypinator 0:bb348c97df44 81 * @param size (optional) Initial size of the chain
lypinator 0:bb348c97df44 82 */
lypinator 0:bb348c97df44 83 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 84 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 85 CallChain(int size = 4);
lypinator 0:bb348c97df44 86
lypinator 0:bb348c97df44 87 /** Create an empty chain
lypinator 0:bb348c97df44 88 * @deprecated
lypinator 0:bb348c97df44 89 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 90 */
lypinator 0:bb348c97df44 91 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 92 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 93 virtual ~CallChain();
lypinator 0:bb348c97df44 94
lypinator 0:bb348c97df44 95 /** Add a function at the end of the chain
lypinator 0:bb348c97df44 96 *
lypinator 0:bb348c97df44 97 * @deprecated
lypinator 0:bb348c97df44 98 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 99 *
lypinator 0:bb348c97df44 100 * @param func A pointer to a void function
lypinator 0:bb348c97df44 101 *
lypinator 0:bb348c97df44 102 * @returns
lypinator 0:bb348c97df44 103 * The function object created for 'func'
lypinator 0:bb348c97df44 104 */
lypinator 0:bb348c97df44 105 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 106 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 107 pFunctionPointer_t add(Callback<void()> func);
lypinator 0:bb348c97df44 108
lypinator 0:bb348c97df44 109 /** Add a function at the end of the chain
lypinator 0:bb348c97df44 110 *
lypinator 0:bb348c97df44 111 * @param obj pointer to the object to call the member function on
lypinator 0:bb348c97df44 112 * @param method pointer to the member function to be called
lypinator 0:bb348c97df44 113 *
lypinator 0:bb348c97df44 114 * @returns
lypinator 0:bb348c97df44 115 * The function object created for 'obj' and 'method'
lypinator 0:bb348c97df44 116 *
lypinator 0:bb348c97df44 117 * @deprecated
lypinator 0:bb348c97df44 118 * The add function does not support cv-qualifiers. Replaced by
lypinator 0:bb348c97df44 119 * add(callback(obj, method)).
lypinator 0:bb348c97df44 120 */
lypinator 0:bb348c97df44 121 template<typename T, typename M>
lypinator 0:bb348c97df44 122 MBED_DEPRECATED_SINCE("mbed-os-5.1",
lypinator 0:bb348c97df44 123 "The add function does not support cv-qualifiers. Replaced by "
lypinator 0:bb348c97df44 124 "add(callback(obj, method)).")
lypinator 0:bb348c97df44 125 pFunctionPointer_t add(T *obj, M method)
lypinator 0:bb348c97df44 126 {
lypinator 0:bb348c97df44 127 return add(callback(obj, method));
lypinator 0:bb348c97df44 128 }
lypinator 0:bb348c97df44 129
lypinator 0:bb348c97df44 130 /** Add a function at the beginning of the chain
lypinator 0:bb348c97df44 131 * @deprecated
lypinator 0:bb348c97df44 132 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 133 *
lypinator 0:bb348c97df44 134 *
lypinator 0:bb348c97df44 135 * @param func A pointer to a void function
lypinator 0:bb348c97df44 136 *
lypinator 0:bb348c97df44 137 * @returns
lypinator 0:bb348c97df44 138 * The function object created for 'func'
lypinator 0:bb348c97df44 139 */
lypinator 0:bb348c97df44 140 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 141 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 142 pFunctionPointer_t add_front(Callback<void()> func);
lypinator 0:bb348c97df44 143
lypinator 0:bb348c97df44 144 /** Add a function at the beginning of the chain
lypinator 0:bb348c97df44 145 *
lypinator 0:bb348c97df44 146 * @param obj pointer to the object to call the member function on
lypinator 0:bb348c97df44 147 * @param method pointer to the member function to be called
lypinator 0:bb348c97df44 148 *
lypinator 0:bb348c97df44 149 * @returns
lypinator 0:bb348c97df44 150 * The function object created for 'tptr' and 'mptr'
lypinator 0:bb348c97df44 151 *
lypinator 0:bb348c97df44 152 * @deprecated
lypinator 0:bb348c97df44 153 * The add_front function does not support cv-qualifiers. Replaced by
lypinator 0:bb348c97df44 154 * add_front(callback(obj, method)).
lypinator 0:bb348c97df44 155 */
lypinator 0:bb348c97df44 156 template<typename T, typename M>
lypinator 0:bb348c97df44 157 MBED_DEPRECATED_SINCE("mbed-os-5.1",
lypinator 0:bb348c97df44 158 "The add_front function does not support cv-qualifiers. Replaced by "
lypinator 0:bb348c97df44 159 "add_front(callback(obj, method)).")
lypinator 0:bb348c97df44 160 pFunctionPointer_t add_front(T *obj, M method)
lypinator 0:bb348c97df44 161 {
lypinator 0:bb348c97df44 162 return add_front(callback(obj, method));
lypinator 0:bb348c97df44 163 }
lypinator 0:bb348c97df44 164
lypinator 0:bb348c97df44 165 /** Get the number of functions in the chain
lypinator 0:bb348c97df44 166 * @deprecated
lypinator 0:bb348c97df44 167 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 168 *
lypinator 0:bb348c97df44 169 */
lypinator 0:bb348c97df44 170 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 171 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 172 int size() const;
lypinator 0:bb348c97df44 173
lypinator 0:bb348c97df44 174 /** Get a function object from the chain
lypinator 0:bb348c97df44 175 * @deprecated
lypinator 0:bb348c97df44 176 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 177 *
lypinator 0:bb348c97df44 178 * @param i function object index
lypinator 0:bb348c97df44 179 *
lypinator 0:bb348c97df44 180 * @returns
lypinator 0:bb348c97df44 181 * The function object at position 'i' in the chain
lypinator 0:bb348c97df44 182 */
lypinator 0:bb348c97df44 183 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 184 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 185 pFunctionPointer_t get(int i) const;
lypinator 0:bb348c97df44 186
lypinator 0:bb348c97df44 187 /** Look for a function object in the call chain
lypinator 0:bb348c97df44 188 * @deprecated
lypinator 0:bb348c97df44 189 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 190 *
lypinator 0:bb348c97df44 191 * @param f the function object to search
lypinator 0:bb348c97df44 192 *
lypinator 0:bb348c97df44 193 * @returns
lypinator 0:bb348c97df44 194 * The index of the function object if found, -1 otherwise.
lypinator 0:bb348c97df44 195 */
lypinator 0:bb348c97df44 196 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 197 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 198 int find(pFunctionPointer_t f) const;
lypinator 0:bb348c97df44 199
lypinator 0:bb348c97df44 200 /** Clear the call chain (remove all functions in the chain).
lypinator 0:bb348c97df44 201 * @deprecated Do not use this function. This class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 202 */
lypinator 0:bb348c97df44 203 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 204 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 205 void clear();
lypinator 0:bb348c97df44 206
lypinator 0:bb348c97df44 207 /** Remove a function object from the chain
lypinator 0:bb348c97df44 208 * @deprecated
lypinator 0:bb348c97df44 209 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 210 *
lypinator 0:bb348c97df44 211 * @arg f the function object to remove
lypinator 0:bb348c97df44 212 *
lypinator 0:bb348c97df44 213 * @returns
lypinator 0:bb348c97df44 214 * true if the function object was found and removed, false otherwise.
lypinator 0:bb348c97df44 215 */
lypinator 0:bb348c97df44 216 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 217 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 218 bool remove(pFunctionPointer_t f);
lypinator 0:bb348c97df44 219
lypinator 0:bb348c97df44 220 /** Call all the functions in the chain in sequence
lypinator 0:bb348c97df44 221 * @deprecated
lypinator 0:bb348c97df44 222 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 223 *
lypinator 0:bb348c97df44 224 */
lypinator 0:bb348c97df44 225 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 226 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 227 void call();
lypinator 0:bb348c97df44 228
lypinator 0:bb348c97df44 229 /**
lypinator 0:bb348c97df44 230 * @deprecated
lypinator 0:bb348c97df44 231 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 232 *
lypinator 0:bb348c97df44 233 */
lypinator 0:bb348c97df44 234 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 235 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 236 void operator()(void)
lypinator 0:bb348c97df44 237 {
lypinator 0:bb348c97df44 238 call();
lypinator 0:bb348c97df44 239 }
lypinator 0:bb348c97df44 240
lypinator 0:bb348c97df44 241 /**
lypinator 0:bb348c97df44 242 * @deprecated
lypinator 0:bb348c97df44 243 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
lypinator 0:bb348c97df44 244 *
lypinator 0:bb348c97df44 245 */
lypinator 0:bb348c97df44 246 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
lypinator 0:bb348c97df44 247 "public API of mbed-os and is being removed in the future.")
lypinator 0:bb348c97df44 248 pFunctionPointer_t operator [](int i) const
lypinator 0:bb348c97df44 249 {
lypinator 0:bb348c97df44 250 return get(i);
lypinator 0:bb348c97df44 251 }
lypinator 0:bb348c97df44 252
lypinator 0:bb348c97df44 253 private:
lypinator 0:bb348c97df44 254 CallChainLink *_chain;
lypinator 0:bb348c97df44 255 };
lypinator 0:bb348c97df44 256
lypinator 0:bb348c97df44 257 /**@}*/
lypinator 0:bb348c97df44 258
lypinator 0:bb348c97df44 259 /**@}*/
lypinator 0:bb348c97df44 260
lypinator 0:bb348c97df44 261 } // namespace mbed
lypinator 0:bb348c97df44 262
lypinator 0:bb348c97df44 263 #endif
lypinator 0:bb348c97df44 264