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-2013 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_CALLCHAIN_H
bryantaylor 0:eafc3fd41f75 17 #define MBED_CALLCHAIN_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
bryantaylor 0:eafc3fd41f75 23 namespace mbed {
bryantaylor 0:eafc3fd41f75 24
bryantaylor 0:eafc3fd41f75 25 /** Group one or more functions in an instance of a CallChain, then call them in
bryantaylor 0:eafc3fd41f75 26 * sequence using CallChain::call(). Used mostly by the interrupt chaining code,
bryantaylor 0:eafc3fd41f75 27 * but can be used for other purposes.
bryantaylor 0:eafc3fd41f75 28 *
bryantaylor 0:eafc3fd41f75 29 * @Note Synchronization level: Not protected
bryantaylor 0:eafc3fd41f75 30 *
bryantaylor 0:eafc3fd41f75 31 * Example:
bryantaylor 0:eafc3fd41f75 32 * @code
bryantaylor 0:eafc3fd41f75 33 * #include "mbed.h"
bryantaylor 0:eafc3fd41f75 34 *
bryantaylor 0:eafc3fd41f75 35 * CallChain chain;
bryantaylor 0:eafc3fd41f75 36 *
bryantaylor 0:eafc3fd41f75 37 * void first(void) {
bryantaylor 0:eafc3fd41f75 38 * printf("'first' function.\n");
bryantaylor 0:eafc3fd41f75 39 * }
bryantaylor 0:eafc3fd41f75 40 *
bryantaylor 0:eafc3fd41f75 41 * void second(void) {
bryantaylor 0:eafc3fd41f75 42 * printf("'second' function.\n");
bryantaylor 0:eafc3fd41f75 43 * }
bryantaylor 0:eafc3fd41f75 44 *
bryantaylor 0:eafc3fd41f75 45 * class Test {
bryantaylor 0:eafc3fd41f75 46 * public:
bryantaylor 0:eafc3fd41f75 47 * void f(void) {
bryantaylor 0:eafc3fd41f75 48 * printf("A::f (class member).\n");
bryantaylor 0:eafc3fd41f75 49 * }
bryantaylor 0:eafc3fd41f75 50 * };
bryantaylor 0:eafc3fd41f75 51 *
bryantaylor 0:eafc3fd41f75 52 * int main() {
bryantaylor 0:eafc3fd41f75 53 * Test test;
bryantaylor 0:eafc3fd41f75 54 *
bryantaylor 0:eafc3fd41f75 55 * chain.add(second);
bryantaylor 0:eafc3fd41f75 56 * chain.add_front(first);
bryantaylor 0:eafc3fd41f75 57 * chain.add(&test, &Test::f);
bryantaylor 0:eafc3fd41f75 58 * chain.call();
bryantaylor 0:eafc3fd41f75 59 * }
bryantaylor 0:eafc3fd41f75 60 * @endcode
bryantaylor 0:eafc3fd41f75 61 */
bryantaylor 0:eafc3fd41f75 62
bryantaylor 0:eafc3fd41f75 63 typedef Callback<void()> *pFunctionPointer_t;
bryantaylor 0:eafc3fd41f75 64 class CallChainLink;
bryantaylor 0:eafc3fd41f75 65
bryantaylor 0:eafc3fd41f75 66 class CallChain {
bryantaylor 0:eafc3fd41f75 67 public:
bryantaylor 0:eafc3fd41f75 68 /** Create an empty chain
bryantaylor 0:eafc3fd41f75 69 *
bryantaylor 0:eafc3fd41f75 70 * @param size (optional) Initial size of the chain
bryantaylor 0:eafc3fd41f75 71 */
bryantaylor 0:eafc3fd41f75 72 CallChain(int size = 4);
bryantaylor 0:eafc3fd41f75 73 virtual ~CallChain();
bryantaylor 0:eafc3fd41f75 74
bryantaylor 0:eafc3fd41f75 75 /** Add a function at the end of the chain
bryantaylor 0:eafc3fd41f75 76 *
bryantaylor 0:eafc3fd41f75 77 * @param func A pointer to a void function
bryantaylor 0:eafc3fd41f75 78 *
bryantaylor 0:eafc3fd41f75 79 * @returns
bryantaylor 0:eafc3fd41f75 80 * The function object created for 'func'
bryantaylor 0:eafc3fd41f75 81 */
bryantaylor 0:eafc3fd41f75 82 pFunctionPointer_t add(Callback<void()> func);
bryantaylor 0:eafc3fd41f75 83
bryantaylor 0:eafc3fd41f75 84 /** Add a function at the end of the chain
bryantaylor 0:eafc3fd41f75 85 *
bryantaylor 0:eafc3fd41f75 86 * @param obj pointer to the object to call the member function on
bryantaylor 0:eafc3fd41f75 87 * @param method pointer to the member function to be called
bryantaylor 0:eafc3fd41f75 88 *
bryantaylor 0:eafc3fd41f75 89 * @returns
bryantaylor 0:eafc3fd41f75 90 * The function object created for 'obj' and 'method'
bryantaylor 0:eafc3fd41f75 91 *
bryantaylor 0:eafc3fd41f75 92 * @deprecated
bryantaylor 0:eafc3fd41f75 93 * The add function does not support cv-qualifiers. Replaced by
bryantaylor 0:eafc3fd41f75 94 * add(callback(obj, method)).
bryantaylor 0:eafc3fd41f75 95 */
bryantaylor 0:eafc3fd41f75 96 template<typename T, typename M>
bryantaylor 0:eafc3fd41f75 97 MBED_DEPRECATED_SINCE("mbed-os-5.1",
bryantaylor 0:eafc3fd41f75 98 "The add function does not support cv-qualifiers. Replaced by "
bryantaylor 0:eafc3fd41f75 99 "add(callback(obj, method)).")
bryantaylor 0:eafc3fd41f75 100 pFunctionPointer_t add(T *obj, M method) {
bryantaylor 0:eafc3fd41f75 101 return add(callback(obj, method));
bryantaylor 0:eafc3fd41f75 102 }
bryantaylor 0:eafc3fd41f75 103
bryantaylor 0:eafc3fd41f75 104 /** Add a function at the beginning of the chain
bryantaylor 0:eafc3fd41f75 105 *
bryantaylor 0:eafc3fd41f75 106 * @param func A pointer to a void function
bryantaylor 0:eafc3fd41f75 107 *
bryantaylor 0:eafc3fd41f75 108 * @returns
bryantaylor 0:eafc3fd41f75 109 * The function object created for 'func'
bryantaylor 0:eafc3fd41f75 110 */
bryantaylor 0:eafc3fd41f75 111 pFunctionPointer_t add_front(Callback<void()> func);
bryantaylor 0:eafc3fd41f75 112
bryantaylor 0:eafc3fd41f75 113 /** Add a function at the beginning of the chain
bryantaylor 0:eafc3fd41f75 114 *
bryantaylor 0:eafc3fd41f75 115 * @param tptr pointer to the object to call the member function on
bryantaylor 0:eafc3fd41f75 116 * @param mptr pointer to the member function to be called
bryantaylor 0:eafc3fd41f75 117 *
bryantaylor 0:eafc3fd41f75 118 * @returns
bryantaylor 0:eafc3fd41f75 119 * The function object created for 'tptr' and 'mptr'
bryantaylor 0:eafc3fd41f75 120 *
bryantaylor 0:eafc3fd41f75 121 * @deprecated
bryantaylor 0:eafc3fd41f75 122 * The add_front function does not support cv-qualifiers. Replaced by
bryantaylor 0:eafc3fd41f75 123 * add_front(callback(obj, method)).
bryantaylor 0:eafc3fd41f75 124 */
bryantaylor 0:eafc3fd41f75 125 template<typename T, typename M>
bryantaylor 0:eafc3fd41f75 126 MBED_DEPRECATED_SINCE("mbed-os-5.1",
bryantaylor 0:eafc3fd41f75 127 "The add_front function does not support cv-qualifiers. Replaced by "
bryantaylor 0:eafc3fd41f75 128 "add_front(callback(obj, method)).")
bryantaylor 0:eafc3fd41f75 129 pFunctionPointer_t add_front(T *obj, M method) {
bryantaylor 0:eafc3fd41f75 130 return add_front(callback(obj, method));
bryantaylor 0:eafc3fd41f75 131 }
bryantaylor 0:eafc3fd41f75 132
bryantaylor 0:eafc3fd41f75 133 /** Get the number of functions in the chain
bryantaylor 0:eafc3fd41f75 134 */
bryantaylor 0:eafc3fd41f75 135 int size() const;
bryantaylor 0:eafc3fd41f75 136
bryantaylor 0:eafc3fd41f75 137 /** Get a function object from the chain
bryantaylor 0:eafc3fd41f75 138 *
bryantaylor 0:eafc3fd41f75 139 * @param i function object index
bryantaylor 0:eafc3fd41f75 140 *
bryantaylor 0:eafc3fd41f75 141 * @returns
bryantaylor 0:eafc3fd41f75 142 * The function object at position 'i' in the chain
bryantaylor 0:eafc3fd41f75 143 */
bryantaylor 0:eafc3fd41f75 144 pFunctionPointer_t get(int i) const;
bryantaylor 0:eafc3fd41f75 145
bryantaylor 0:eafc3fd41f75 146 /** Look for a function object in the call chain
bryantaylor 0:eafc3fd41f75 147 *
bryantaylor 0:eafc3fd41f75 148 * @param f the function object to search
bryantaylor 0:eafc3fd41f75 149 *
bryantaylor 0:eafc3fd41f75 150 * @returns
bryantaylor 0:eafc3fd41f75 151 * The index of the function object if found, -1 otherwise.
bryantaylor 0:eafc3fd41f75 152 */
bryantaylor 0:eafc3fd41f75 153 int find(pFunctionPointer_t f) const;
bryantaylor 0:eafc3fd41f75 154
bryantaylor 0:eafc3fd41f75 155 /** Clear the call chain (remove all functions in the chain).
bryantaylor 0:eafc3fd41f75 156 */
bryantaylor 0:eafc3fd41f75 157 void clear();
bryantaylor 0:eafc3fd41f75 158
bryantaylor 0:eafc3fd41f75 159 /** Remove a function object from the chain
bryantaylor 0:eafc3fd41f75 160 *
bryantaylor 0:eafc3fd41f75 161 * @arg f the function object to remove
bryantaylor 0:eafc3fd41f75 162 *
bryantaylor 0:eafc3fd41f75 163 * @returns
bryantaylor 0:eafc3fd41f75 164 * true if the function object was found and removed, false otherwise.
bryantaylor 0:eafc3fd41f75 165 */
bryantaylor 0:eafc3fd41f75 166 bool remove(pFunctionPointer_t f);
bryantaylor 0:eafc3fd41f75 167
bryantaylor 0:eafc3fd41f75 168 /** Call all the functions in the chain in sequence
bryantaylor 0:eafc3fd41f75 169 */
bryantaylor 0:eafc3fd41f75 170 void call();
bryantaylor 0:eafc3fd41f75 171
bryantaylor 0:eafc3fd41f75 172 void operator ()(void) {
bryantaylor 0:eafc3fd41f75 173 call();
bryantaylor 0:eafc3fd41f75 174 }
bryantaylor 0:eafc3fd41f75 175 pFunctionPointer_t operator [](int i) const {
bryantaylor 0:eafc3fd41f75 176 return get(i);
bryantaylor 0:eafc3fd41f75 177 }
bryantaylor 0:eafc3fd41f75 178
bryantaylor 0:eafc3fd41f75 179 /* disallow copy constructor and assignment operators */
bryantaylor 0:eafc3fd41f75 180 private:
bryantaylor 0:eafc3fd41f75 181 CallChain(const CallChain&);
bryantaylor 0:eafc3fd41f75 182 CallChain & operator = (const CallChain&);
bryantaylor 0:eafc3fd41f75 183 CallChainLink *_chain;
bryantaylor 0:eafc3fd41f75 184 };
bryantaylor 0:eafc3fd41f75 185
bryantaylor 0:eafc3fd41f75 186 } // namespace mbed
bryantaylor 0:eafc3fd41f75 187
bryantaylor 0:eafc3fd41f75 188 #endif