fix nrf51822 i2c & spi conflict
Dependencies: BLE_API eMPL_MPU6050 nRF51822
Fork of Seeed_Tiny_BLE_Flash by
mbed-src/api/Ticker.h@5:b8c02645e6af, 2015-11-17 (annotated)
- Committer:
- yihui
- Date:
- Tue Nov 17 07:48:56 2015 +0000
- Revision:
- 5:b8c02645e6af
fix i2c & spi conflict
Who changed what in which revision?
User | Revision | Line number | New 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_TICKER_H |
yihui | 5:b8c02645e6af | 17 | #define MBED_TICKER_H |
yihui | 5:b8c02645e6af | 18 | |
yihui | 5:b8c02645e6af | 19 | #include "TimerEvent.h" |
yihui | 5:b8c02645e6af | 20 | #include "FunctionPointer.h" |
yihui | 5:b8c02645e6af | 21 | |
yihui | 5:b8c02645e6af | 22 | namespace mbed { |
yihui | 5:b8c02645e6af | 23 | |
yihui | 5:b8c02645e6af | 24 | /** A Ticker is used to call a function at a recurring interval |
yihui | 5:b8c02645e6af | 25 | * |
yihui | 5:b8c02645e6af | 26 | * You can use as many seperate Ticker objects as you require. |
yihui | 5:b8c02645e6af | 27 | * |
yihui | 5:b8c02645e6af | 28 | * Example: |
yihui | 5:b8c02645e6af | 29 | * @code |
yihui | 5:b8c02645e6af | 30 | * // Toggle the blinking led after 5 seconds |
yihui | 5:b8c02645e6af | 31 | * |
yihui | 5:b8c02645e6af | 32 | * #include "mbed.h" |
yihui | 5:b8c02645e6af | 33 | * |
yihui | 5:b8c02645e6af | 34 | * Ticker timer; |
yihui | 5:b8c02645e6af | 35 | * DigitalOut led1(LED1); |
yihui | 5:b8c02645e6af | 36 | * DigitalOut led2(LED2); |
yihui | 5:b8c02645e6af | 37 | * |
yihui | 5:b8c02645e6af | 38 | * int flip = 0; |
yihui | 5:b8c02645e6af | 39 | * |
yihui | 5:b8c02645e6af | 40 | * void attime() { |
yihui | 5:b8c02645e6af | 41 | * flip = !flip; |
yihui | 5:b8c02645e6af | 42 | * } |
yihui | 5:b8c02645e6af | 43 | * |
yihui | 5:b8c02645e6af | 44 | * int main() { |
yihui | 5:b8c02645e6af | 45 | * timer.attach(&attime, 5); |
yihui | 5:b8c02645e6af | 46 | * while(1) { |
yihui | 5:b8c02645e6af | 47 | * if(flip == 0) { |
yihui | 5:b8c02645e6af | 48 | * led1 = !led1; |
yihui | 5:b8c02645e6af | 49 | * } else { |
yihui | 5:b8c02645e6af | 50 | * led2 = !led2; |
yihui | 5:b8c02645e6af | 51 | * } |
yihui | 5:b8c02645e6af | 52 | * wait(0.2); |
yihui | 5:b8c02645e6af | 53 | * } |
yihui | 5:b8c02645e6af | 54 | * } |
yihui | 5:b8c02645e6af | 55 | * @endcode |
yihui | 5:b8c02645e6af | 56 | */ |
yihui | 5:b8c02645e6af | 57 | class Ticker : public TimerEvent { |
yihui | 5:b8c02645e6af | 58 | |
yihui | 5:b8c02645e6af | 59 | public: |
yihui | 5:b8c02645e6af | 60 | Ticker() : TimerEvent() { |
yihui | 5:b8c02645e6af | 61 | } |
yihui | 5:b8c02645e6af | 62 | |
yihui | 5:b8c02645e6af | 63 | Ticker(const ticker_data_t *data) : TimerEvent(data) { |
yihui | 5:b8c02645e6af | 64 | } |
yihui | 5:b8c02645e6af | 65 | |
yihui | 5:b8c02645e6af | 66 | /** Attach a function to be called by the Ticker, specifiying the interval in seconds |
yihui | 5:b8c02645e6af | 67 | * |
yihui | 5:b8c02645e6af | 68 | * @param fptr pointer to the function to be called |
yihui | 5:b8c02645e6af | 69 | * @param t the time between calls in seconds |
yihui | 5:b8c02645e6af | 70 | */ |
yihui | 5:b8c02645e6af | 71 | void attach(void (*fptr)(void), float t) { |
yihui | 5:b8c02645e6af | 72 | attach_us(fptr, t * 1000000.0f); |
yihui | 5:b8c02645e6af | 73 | } |
yihui | 5:b8c02645e6af | 74 | |
yihui | 5:b8c02645e6af | 75 | /** Attach a member function to be called by the Ticker, specifiying the interval in seconds |
yihui | 5:b8c02645e6af | 76 | * |
yihui | 5:b8c02645e6af | 77 | * @param tptr pointer to the object to call the member function on |
yihui | 5:b8c02645e6af | 78 | * @param mptr pointer to the member function to be called |
yihui | 5:b8c02645e6af | 79 | * @param t the time between calls in seconds |
yihui | 5:b8c02645e6af | 80 | */ |
yihui | 5:b8c02645e6af | 81 | template<typename T> |
yihui | 5:b8c02645e6af | 82 | void attach(T* tptr, void (T::*mptr)(void), float t) { |
yihui | 5:b8c02645e6af | 83 | attach_us(tptr, mptr, t * 1000000.0f); |
yihui | 5:b8c02645e6af | 84 | } |
yihui | 5:b8c02645e6af | 85 | |
yihui | 5:b8c02645e6af | 86 | /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds |
yihui | 5:b8c02645e6af | 87 | * |
yihui | 5:b8c02645e6af | 88 | * @param fptr pointer to the function to be called |
yihui | 5:b8c02645e6af | 89 | * @param t the time between calls in micro-seconds |
yihui | 5:b8c02645e6af | 90 | */ |
yihui | 5:b8c02645e6af | 91 | void attach_us(void (*fptr)(void), timestamp_t t) { |
yihui | 5:b8c02645e6af | 92 | _function.attach(fptr); |
yihui | 5:b8c02645e6af | 93 | setup(t); |
yihui | 5:b8c02645e6af | 94 | } |
yihui | 5:b8c02645e6af | 95 | |
yihui | 5:b8c02645e6af | 96 | /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds |
yihui | 5:b8c02645e6af | 97 | * |
yihui | 5:b8c02645e6af | 98 | * @param tptr pointer to the object to call the member function on |
yihui | 5:b8c02645e6af | 99 | * @param mptr pointer to the member function to be called |
yihui | 5:b8c02645e6af | 100 | * @param t the time between calls in micro-seconds |
yihui | 5:b8c02645e6af | 101 | */ |
yihui | 5:b8c02645e6af | 102 | template<typename T> |
yihui | 5:b8c02645e6af | 103 | void attach_us(T* tptr, void (T::*mptr)(void), timestamp_t t) { |
yihui | 5:b8c02645e6af | 104 | _function.attach(tptr, mptr); |
yihui | 5:b8c02645e6af | 105 | setup(t); |
yihui | 5:b8c02645e6af | 106 | } |
yihui | 5:b8c02645e6af | 107 | |
yihui | 5:b8c02645e6af | 108 | virtual ~Ticker() { |
yihui | 5:b8c02645e6af | 109 | detach(); |
yihui | 5:b8c02645e6af | 110 | } |
yihui | 5:b8c02645e6af | 111 | |
yihui | 5:b8c02645e6af | 112 | /** Detach the function |
yihui | 5:b8c02645e6af | 113 | */ |
yihui | 5:b8c02645e6af | 114 | void detach(); |
yihui | 5:b8c02645e6af | 115 | |
yihui | 5:b8c02645e6af | 116 | protected: |
yihui | 5:b8c02645e6af | 117 | void setup(timestamp_t t); |
yihui | 5:b8c02645e6af | 118 | virtual void handler(); |
yihui | 5:b8c02645e6af | 119 | |
yihui | 5:b8c02645e6af | 120 | protected: |
yihui | 5:b8c02645e6af | 121 | timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */ |
yihui | 5:b8c02645e6af | 122 | FunctionPointer _function; /**< Callback. */ |
yihui | 5:b8c02645e6af | 123 | }; |
yihui | 5:b8c02645e6af | 124 | |
yihui | 5:b8c02645e6af | 125 | } // namespace mbed |
yihui | 5:b8c02645e6af | 126 | |
yihui | 5:b8c02645e6af | 127 | #endif |