Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

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