change some io settings for TWR-K22F-120M

Dependents:   twr_helloworld

Committer:
Jasper_lee
Date:
Tue Dec 23 03:35:08 2014 +0000
Revision:
0:b16d94660a33
change some io setting used in TWR-K22F120M

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jasper_lee 0:b16d94660a33 1 /* mbed Microcontroller Library
Jasper_lee 0:b16d94660a33 2 * Copyright (c) 2006-2013 ARM Limited
Jasper_lee 0:b16d94660a33 3 *
Jasper_lee 0:b16d94660a33 4 * Licensed under the Apache License, Version 2.0 (the "License");
Jasper_lee 0:b16d94660a33 5 * you may not use this file except in compliance with the License.
Jasper_lee 0:b16d94660a33 6 * You may obtain a copy of the License at
Jasper_lee 0:b16d94660a33 7 *
Jasper_lee 0:b16d94660a33 8 * http://www.apache.org/licenses/LICENSE-2.0
Jasper_lee 0:b16d94660a33 9 *
Jasper_lee 0:b16d94660a33 10 * Unless required by applicable law or agreed to in writing, software
Jasper_lee 0:b16d94660a33 11 * distributed under the License is distributed on an "AS IS" BASIS,
Jasper_lee 0:b16d94660a33 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Jasper_lee 0:b16d94660a33 13 * See the License for the specific language governing permissions and
Jasper_lee 0:b16d94660a33 14 * limitations under the License.
Jasper_lee 0:b16d94660a33 15 */
Jasper_lee 0:b16d94660a33 16 #ifndef MBED_TICKER_H
Jasper_lee 0:b16d94660a33 17 #define MBED_TICKER_H
Jasper_lee 0:b16d94660a33 18
Jasper_lee 0:b16d94660a33 19 #include "TimerEvent.h"
Jasper_lee 0:b16d94660a33 20 #include "FunctionPointer.h"
Jasper_lee 0:b16d94660a33 21
Jasper_lee 0:b16d94660a33 22 namespace mbed {
Jasper_lee 0:b16d94660a33 23
Jasper_lee 0:b16d94660a33 24 /** A Ticker is used to call a function at a recurring interval
Jasper_lee 0:b16d94660a33 25 *
Jasper_lee 0:b16d94660a33 26 * You can use as many seperate Ticker objects as you require.
Jasper_lee 0:b16d94660a33 27 *
Jasper_lee 0:b16d94660a33 28 * Example:
Jasper_lee 0:b16d94660a33 29 * @code
Jasper_lee 0:b16d94660a33 30 * // Toggle the blinking led after 5 seconds
Jasper_lee 0:b16d94660a33 31 *
Jasper_lee 0:b16d94660a33 32 * #include "mbed.h"
Jasper_lee 0:b16d94660a33 33 *
Jasper_lee 0:b16d94660a33 34 * Ticker timer;
Jasper_lee 0:b16d94660a33 35 * DigitalOut led1(LED1);
Jasper_lee 0:b16d94660a33 36 * DigitalOut led2(LED2);
Jasper_lee 0:b16d94660a33 37 *
Jasper_lee 0:b16d94660a33 38 * int flip = 0;
Jasper_lee 0:b16d94660a33 39 *
Jasper_lee 0:b16d94660a33 40 * void attime() {
Jasper_lee 0:b16d94660a33 41 * flip = !flip;
Jasper_lee 0:b16d94660a33 42 * }
Jasper_lee 0:b16d94660a33 43 *
Jasper_lee 0:b16d94660a33 44 * int main() {
Jasper_lee 0:b16d94660a33 45 * timer.attach(&attime, 5);
Jasper_lee 0:b16d94660a33 46 * while(1) {
Jasper_lee 0:b16d94660a33 47 * if(flip == 0) {
Jasper_lee 0:b16d94660a33 48 * led1 = !led1;
Jasper_lee 0:b16d94660a33 49 * } else {
Jasper_lee 0:b16d94660a33 50 * led2 = !led2;
Jasper_lee 0:b16d94660a33 51 * }
Jasper_lee 0:b16d94660a33 52 * wait(0.2);
Jasper_lee 0:b16d94660a33 53 * }
Jasper_lee 0:b16d94660a33 54 * }
Jasper_lee 0:b16d94660a33 55 * @endcode
Jasper_lee 0:b16d94660a33 56 */
Jasper_lee 0:b16d94660a33 57 class Ticker : public TimerEvent {
Jasper_lee 0:b16d94660a33 58
Jasper_lee 0:b16d94660a33 59 public:
Jasper_lee 0:b16d94660a33 60
Jasper_lee 0:b16d94660a33 61 /** Attach a function to be called by the Ticker, specifiying the interval in seconds
Jasper_lee 0:b16d94660a33 62 *
Jasper_lee 0:b16d94660a33 63 * @param fptr pointer to the function to be called
Jasper_lee 0:b16d94660a33 64 * @param t the time between calls in seconds
Jasper_lee 0:b16d94660a33 65 */
Jasper_lee 0:b16d94660a33 66 void attach(void (*fptr)(void), float t) {
Jasper_lee 0:b16d94660a33 67 attach_us(fptr, t * 1000000.0f);
Jasper_lee 0:b16d94660a33 68 }
Jasper_lee 0:b16d94660a33 69
Jasper_lee 0:b16d94660a33 70 /** Attach a member function to be called by the Ticker, specifiying the interval in seconds
Jasper_lee 0:b16d94660a33 71 *
Jasper_lee 0:b16d94660a33 72 * @param tptr pointer to the object to call the member function on
Jasper_lee 0:b16d94660a33 73 * @param mptr pointer to the member function to be called
Jasper_lee 0:b16d94660a33 74 * @param t the time between calls in seconds
Jasper_lee 0:b16d94660a33 75 */
Jasper_lee 0:b16d94660a33 76 template<typename T>
Jasper_lee 0:b16d94660a33 77 void attach(T* tptr, void (T::*mptr)(void), float t) {
Jasper_lee 0:b16d94660a33 78 attach_us(tptr, mptr, t * 1000000.0f);
Jasper_lee 0:b16d94660a33 79 }
Jasper_lee 0:b16d94660a33 80
Jasper_lee 0:b16d94660a33 81 /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
Jasper_lee 0:b16d94660a33 82 *
Jasper_lee 0:b16d94660a33 83 * @param fptr pointer to the function to be called
Jasper_lee 0:b16d94660a33 84 * @param t the time between calls in micro-seconds
Jasper_lee 0:b16d94660a33 85 */
Jasper_lee 0:b16d94660a33 86 void attach_us(void (*fptr)(void), timestamp_t t) {
Jasper_lee 0:b16d94660a33 87 _function.attach(fptr);
Jasper_lee 0:b16d94660a33 88 setup(t);
Jasper_lee 0:b16d94660a33 89 }
Jasper_lee 0:b16d94660a33 90
Jasper_lee 0:b16d94660a33 91 /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
Jasper_lee 0:b16d94660a33 92 *
Jasper_lee 0:b16d94660a33 93 * @param tptr pointer to the object to call the member function on
Jasper_lee 0:b16d94660a33 94 * @param mptr pointer to the member function to be called
Jasper_lee 0:b16d94660a33 95 * @param t the time between calls in micro-seconds
Jasper_lee 0:b16d94660a33 96 */
Jasper_lee 0:b16d94660a33 97 template<typename T>
Jasper_lee 0:b16d94660a33 98 void attach_us(T* tptr, void (T::*mptr)(void), timestamp_t t) {
Jasper_lee 0:b16d94660a33 99 _function.attach(tptr, mptr);
Jasper_lee 0:b16d94660a33 100 setup(t);
Jasper_lee 0:b16d94660a33 101 }
Jasper_lee 0:b16d94660a33 102
Jasper_lee 0:b16d94660a33 103 virtual ~Ticker() {
Jasper_lee 0:b16d94660a33 104 detach();
Jasper_lee 0:b16d94660a33 105 }
Jasper_lee 0:b16d94660a33 106
Jasper_lee 0:b16d94660a33 107 /** Detach the function
Jasper_lee 0:b16d94660a33 108 */
Jasper_lee 0:b16d94660a33 109 void detach();
Jasper_lee 0:b16d94660a33 110
Jasper_lee 0:b16d94660a33 111 protected:
Jasper_lee 0:b16d94660a33 112 void setup(timestamp_t t);
Jasper_lee 0:b16d94660a33 113 virtual void handler();
Jasper_lee 0:b16d94660a33 114
Jasper_lee 0:b16d94660a33 115 protected:
Jasper_lee 0:b16d94660a33 116 timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
Jasper_lee 0:b16d94660a33 117 FunctionPointer _function; /**< Callback. */
Jasper_lee 0:b16d94660a33 118 };
Jasper_lee 0:b16d94660a33 119
Jasper_lee 0:b16d94660a33 120 } // namespace mbed
Jasper_lee 0:b16d94660a33 121
Jasper_lee 0:b16d94660a33 122 #endif