fix nrf51822 i2c & spi conflict

Dependencies:   BLE_API eMPL_MPU6050 nRF51822

Fork of Seeed_Tiny_BLE_Flash by Darren Huang

Committer:
yihui
Date:
Tue Nov 17 07:48:56 2015 +0000
Revision:
5:b8c02645e6af
fix i2c & spi conflict

Who changed what in which revision?

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