Final version.

Dependencies:   F746_GUI F746_SAI_IO UIT_FFT_Real

Fork of F746_Spectrogram by 不韋 呂

Committer:
mladjo1993
Date:
Wed Aug 30 07:47:58 2017 +0000
Revision:
9:444e58089d09
Parent:
4:c1beacfc42c7
Final version.

Who changed what in which revision?

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