ads1115 only

Fork of mbed by mbed official

Committer:
kaoshen
Date:
Tue Jan 17 23:27:32 2017 +0000
Revision:
135:fce8a9387ed1
Parent:
128:9bcdf88f62b0
333 ADS1115 ADC1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 128:9bcdf88f62b0 1 /* mbed Microcontroller Library
<> 128:9bcdf88f62b0 2 * Copyright (c) 2006-2013 ARM Limited
<> 128:9bcdf88f62b0 3 *
<> 128:9bcdf88f62b0 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 128:9bcdf88f62b0 5 * you may not use this file except in compliance with the License.
<> 128:9bcdf88f62b0 6 * You may obtain a copy of the License at
<> 128:9bcdf88f62b0 7 *
<> 128:9bcdf88f62b0 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 128:9bcdf88f62b0 9 *
<> 128:9bcdf88f62b0 10 * Unless required by applicable law or agreed to in writing, software
<> 128:9bcdf88f62b0 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 128:9bcdf88f62b0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 128:9bcdf88f62b0 13 * See the License for the specific language governing permissions and
<> 128:9bcdf88f62b0 14 * limitations under the License.
<> 128:9bcdf88f62b0 15 */
<> 128:9bcdf88f62b0 16 #ifndef MBED_CALLCHAIN_H
<> 128:9bcdf88f62b0 17 #define MBED_CALLCHAIN_H
<> 128:9bcdf88f62b0 18
<> 128:9bcdf88f62b0 19 #include "platform/Callback.h"
<> 128:9bcdf88f62b0 20 #include "platform/toolchain.h"
<> 128:9bcdf88f62b0 21 #include <string.h>
<> 128:9bcdf88f62b0 22
<> 128:9bcdf88f62b0 23 namespace mbed {
<> 128:9bcdf88f62b0 24 /** \addtogroup platform */
<> 128:9bcdf88f62b0 25 /** @{*/
<> 128:9bcdf88f62b0 26
<> 128:9bcdf88f62b0 27 /** Group one or more functions in an instance of a CallChain, then call them in
<> 128:9bcdf88f62b0 28 * sequence using CallChain::call(). Used mostly by the interrupt chaining code,
<> 128:9bcdf88f62b0 29 * but can be used for other purposes.
<> 128:9bcdf88f62b0 30 *
<> 128:9bcdf88f62b0 31 * @Note Synchronization level: Not protected
<> 128:9bcdf88f62b0 32 *
<> 128:9bcdf88f62b0 33 * Example:
<> 128:9bcdf88f62b0 34 * @code
<> 128:9bcdf88f62b0 35 * #include "mbed.h"
<> 128:9bcdf88f62b0 36 *
<> 128:9bcdf88f62b0 37 * CallChain chain;
<> 128:9bcdf88f62b0 38 *
<> 128:9bcdf88f62b0 39 * void first(void) {
<> 128:9bcdf88f62b0 40 * printf("'first' function.\n");
<> 128:9bcdf88f62b0 41 * }
<> 128:9bcdf88f62b0 42 *
<> 128:9bcdf88f62b0 43 * void second(void) {
<> 128:9bcdf88f62b0 44 * printf("'second' function.\n");
<> 128:9bcdf88f62b0 45 * }
<> 128:9bcdf88f62b0 46 *
<> 128:9bcdf88f62b0 47 * class Test {
<> 128:9bcdf88f62b0 48 * public:
<> 128:9bcdf88f62b0 49 * void f(void) {
<> 128:9bcdf88f62b0 50 * printf("A::f (class member).\n");
<> 128:9bcdf88f62b0 51 * }
<> 128:9bcdf88f62b0 52 * };
<> 128:9bcdf88f62b0 53 *
<> 128:9bcdf88f62b0 54 * int main() {
<> 128:9bcdf88f62b0 55 * Test test;
<> 128:9bcdf88f62b0 56 *
<> 128:9bcdf88f62b0 57 * chain.add(second);
<> 128:9bcdf88f62b0 58 * chain.add_front(first);
<> 128:9bcdf88f62b0 59 * chain.add(&test, &Test::f);
<> 128:9bcdf88f62b0 60 * chain.call();
<> 128:9bcdf88f62b0 61 * }
<> 128:9bcdf88f62b0 62 * @endcode
<> 128:9bcdf88f62b0 63 */
<> 128:9bcdf88f62b0 64
<> 128:9bcdf88f62b0 65 typedef Callback<void()> *pFunctionPointer_t;
<> 128:9bcdf88f62b0 66 class CallChainLink;
<> 128:9bcdf88f62b0 67
<> 128:9bcdf88f62b0 68 class CallChain {
<> 128:9bcdf88f62b0 69 public:
<> 128:9bcdf88f62b0 70 /** Create an empty chain
<> 128:9bcdf88f62b0 71 *
<> 128:9bcdf88f62b0 72 * @param size (optional) Initial size of the chain
<> 128:9bcdf88f62b0 73 */
<> 128:9bcdf88f62b0 74 CallChain(int size = 4);
<> 128:9bcdf88f62b0 75 virtual ~CallChain();
<> 128:9bcdf88f62b0 76
<> 128:9bcdf88f62b0 77 /** Add a function at the end of the chain
<> 128:9bcdf88f62b0 78 *
<> 128:9bcdf88f62b0 79 * @param func A pointer to a void function
<> 128:9bcdf88f62b0 80 *
<> 128:9bcdf88f62b0 81 * @returns
<> 128:9bcdf88f62b0 82 * The function object created for 'func'
<> 128:9bcdf88f62b0 83 */
<> 128:9bcdf88f62b0 84 pFunctionPointer_t add(Callback<void()> func);
<> 128:9bcdf88f62b0 85
<> 128:9bcdf88f62b0 86 /** Add a function at the end of the chain
<> 128:9bcdf88f62b0 87 *
<> 128:9bcdf88f62b0 88 * @param obj pointer to the object to call the member function on
<> 128:9bcdf88f62b0 89 * @param method pointer to the member function to be called
<> 128:9bcdf88f62b0 90 *
<> 128:9bcdf88f62b0 91 * @returns
<> 128:9bcdf88f62b0 92 * The function object created for 'obj' and 'method'
<> 128:9bcdf88f62b0 93 *
<> 128:9bcdf88f62b0 94 * @deprecated
<> 128:9bcdf88f62b0 95 * The add function does not support cv-qualifiers. Replaced by
<> 128:9bcdf88f62b0 96 * add(callback(obj, method)).
<> 128:9bcdf88f62b0 97 */
<> 128:9bcdf88f62b0 98 template<typename T, typename M>
<> 128:9bcdf88f62b0 99 MBED_DEPRECATED_SINCE("mbed-os-5.1",
<> 128:9bcdf88f62b0 100 "The add function does not support cv-qualifiers. Replaced by "
<> 128:9bcdf88f62b0 101 "add(callback(obj, method)).")
<> 128:9bcdf88f62b0 102 pFunctionPointer_t add(T *obj, M method) {
<> 128:9bcdf88f62b0 103 return add(callback(obj, method));
<> 128:9bcdf88f62b0 104 }
<> 128:9bcdf88f62b0 105
<> 128:9bcdf88f62b0 106 /** Add a function at the beginning of the chain
<> 128:9bcdf88f62b0 107 *
<> 128:9bcdf88f62b0 108 * @param func A pointer to a void function
<> 128:9bcdf88f62b0 109 *
<> 128:9bcdf88f62b0 110 * @returns
<> 128:9bcdf88f62b0 111 * The function object created for 'func'
<> 128:9bcdf88f62b0 112 */
<> 128:9bcdf88f62b0 113 pFunctionPointer_t add_front(Callback<void()> func);
<> 128:9bcdf88f62b0 114
<> 128:9bcdf88f62b0 115 /** Add a function at the beginning of the chain
<> 128:9bcdf88f62b0 116 *
<> 128:9bcdf88f62b0 117 * @param tptr pointer to the object to call the member function on
<> 128:9bcdf88f62b0 118 * @param mptr pointer to the member function to be called
<> 128:9bcdf88f62b0 119 *
<> 128:9bcdf88f62b0 120 * @returns
<> 128:9bcdf88f62b0 121 * The function object created for 'tptr' and 'mptr'
<> 128:9bcdf88f62b0 122 *
<> 128:9bcdf88f62b0 123 * @deprecated
<> 128:9bcdf88f62b0 124 * The add_front function does not support cv-qualifiers. Replaced by
<> 128:9bcdf88f62b0 125 * add_front(callback(obj, method)).
<> 128:9bcdf88f62b0 126 */
<> 128:9bcdf88f62b0 127 template<typename T, typename M>
<> 128:9bcdf88f62b0 128 MBED_DEPRECATED_SINCE("mbed-os-5.1",
<> 128:9bcdf88f62b0 129 "The add_front function does not support cv-qualifiers. Replaced by "
<> 128:9bcdf88f62b0 130 "add_front(callback(obj, method)).")
<> 128:9bcdf88f62b0 131 pFunctionPointer_t add_front(T *obj, M method) {
<> 128:9bcdf88f62b0 132 return add_front(callback(obj, method));
<> 128:9bcdf88f62b0 133 }
<> 128:9bcdf88f62b0 134
<> 128:9bcdf88f62b0 135 /** Get the number of functions in the chain
<> 128:9bcdf88f62b0 136 */
<> 128:9bcdf88f62b0 137 int size() const;
<> 128:9bcdf88f62b0 138
<> 128:9bcdf88f62b0 139 /** Get a function object from the chain
<> 128:9bcdf88f62b0 140 *
<> 128:9bcdf88f62b0 141 * @param i function object index
<> 128:9bcdf88f62b0 142 *
<> 128:9bcdf88f62b0 143 * @returns
<> 128:9bcdf88f62b0 144 * The function object at position 'i' in the chain
<> 128:9bcdf88f62b0 145 */
<> 128:9bcdf88f62b0 146 pFunctionPointer_t get(int i) const;
<> 128:9bcdf88f62b0 147
<> 128:9bcdf88f62b0 148 /** Look for a function object in the call chain
<> 128:9bcdf88f62b0 149 *
<> 128:9bcdf88f62b0 150 * @param f the function object to search
<> 128:9bcdf88f62b0 151 *
<> 128:9bcdf88f62b0 152 * @returns
<> 128:9bcdf88f62b0 153 * The index of the function object if found, -1 otherwise.
<> 128:9bcdf88f62b0 154 */
<> 128:9bcdf88f62b0 155 int find(pFunctionPointer_t f) const;
<> 128:9bcdf88f62b0 156
<> 128:9bcdf88f62b0 157 /** Clear the call chain (remove all functions in the chain).
<> 128:9bcdf88f62b0 158 */
<> 128:9bcdf88f62b0 159 void clear();
<> 128:9bcdf88f62b0 160
<> 128:9bcdf88f62b0 161 /** Remove a function object from the chain
<> 128:9bcdf88f62b0 162 *
<> 128:9bcdf88f62b0 163 * @arg f the function object to remove
<> 128:9bcdf88f62b0 164 *
<> 128:9bcdf88f62b0 165 * @returns
<> 128:9bcdf88f62b0 166 * true if the function object was found and removed, false otherwise.
<> 128:9bcdf88f62b0 167 */
<> 128:9bcdf88f62b0 168 bool remove(pFunctionPointer_t f);
<> 128:9bcdf88f62b0 169
<> 128:9bcdf88f62b0 170 /** Call all the functions in the chain in sequence
<> 128:9bcdf88f62b0 171 */
<> 128:9bcdf88f62b0 172 void call();
<> 128:9bcdf88f62b0 173
<> 128:9bcdf88f62b0 174 void operator ()(void) {
<> 128:9bcdf88f62b0 175 call();
<> 128:9bcdf88f62b0 176 }
<> 128:9bcdf88f62b0 177 pFunctionPointer_t operator [](int i) const {
<> 128:9bcdf88f62b0 178 return get(i);
<> 128:9bcdf88f62b0 179 }
<> 128:9bcdf88f62b0 180
<> 128:9bcdf88f62b0 181 /* disallow copy constructor and assignment operators */
<> 128:9bcdf88f62b0 182 private:
<> 128:9bcdf88f62b0 183 CallChain(const CallChain&);
<> 128:9bcdf88f62b0 184 CallChain & operator = (const CallChain&);
<> 128:9bcdf88f62b0 185 CallChainLink *_chain;
<> 128:9bcdf88f62b0 186 };
<> 128:9bcdf88f62b0 187
<> 128:9bcdf88f62b0 188 } // namespace mbed
<> 128:9bcdf88f62b0 189
<> 128:9bcdf88f62b0 190 #endif
<> 128:9bcdf88f62b0 191
<> 128:9bcdf88f62b0 192 /** @}*/