Audio singal input and output example for DISCO-F746. Input: MEMS mic, Output: CN10 OUT, Acoustic effect: echo and frequency shift. DISCO-F746 によるオーディオ信号入出力.入力:MEMS マイク,出力:CN10 OUT,音響効果:エコー,周波数変換.
Dependencies: F746_GUI F746_SAI_IO
mbed_src_STM32F7/api/InterruptIn.h@10:56f2f01df983, 2017-04-10 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Apr 10 13:44:13 2017 +0000
- Revision:
- 10:56f2f01df983
- Parent:
- 6:38f7dce055d0
11
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 6:38f7dce055d0 | 1 | /* mbed Microcontroller Library |
MikamiUitOpen | 6:38f7dce055d0 | 2 | * Copyright (c) 2006-2013 ARM Limited |
MikamiUitOpen | 6:38f7dce055d0 | 3 | * |
MikamiUitOpen | 6:38f7dce055d0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
MikamiUitOpen | 6:38f7dce055d0 | 5 | * you may not use this file except in compliance with the License. |
MikamiUitOpen | 6:38f7dce055d0 | 6 | * You may obtain a copy of the License at |
MikamiUitOpen | 6:38f7dce055d0 | 7 | * |
MikamiUitOpen | 6:38f7dce055d0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
MikamiUitOpen | 6:38f7dce055d0 | 9 | * |
MikamiUitOpen | 6:38f7dce055d0 | 10 | * Unless required by applicable law or agreed to in writing, software |
MikamiUitOpen | 6:38f7dce055d0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
MikamiUitOpen | 6:38f7dce055d0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MikamiUitOpen | 6:38f7dce055d0 | 13 | * See the License for the specific language governing permissions and |
MikamiUitOpen | 6:38f7dce055d0 | 14 | * limitations under the License. |
MikamiUitOpen | 6:38f7dce055d0 | 15 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 16 | #ifndef MBED_INTERRUPTIN_H |
MikamiUitOpen | 6:38f7dce055d0 | 17 | #define MBED_INTERRUPTIN_H |
MikamiUitOpen | 6:38f7dce055d0 | 18 | |
MikamiUitOpen | 6:38f7dce055d0 | 19 | #include "platform.h" |
MikamiUitOpen | 6:38f7dce055d0 | 20 | |
MikamiUitOpen | 6:38f7dce055d0 | 21 | #if DEVICE_INTERRUPTIN |
MikamiUitOpen | 6:38f7dce055d0 | 22 | |
MikamiUitOpen | 6:38f7dce055d0 | 23 | #include "gpio_api.h" |
MikamiUitOpen | 6:38f7dce055d0 | 24 | #include "gpio_irq_api.h" |
MikamiUitOpen | 6:38f7dce055d0 | 25 | #include "FunctionPointer.h" |
MikamiUitOpen | 6:38f7dce055d0 | 26 | |
MikamiUitOpen | 6:38f7dce055d0 | 27 | namespace mbed { |
MikamiUitOpen | 6:38f7dce055d0 | 28 | |
MikamiUitOpen | 6:38f7dce055d0 | 29 | /** A digital interrupt input, used to call a function on a rising or falling edge |
MikamiUitOpen | 6:38f7dce055d0 | 30 | * |
MikamiUitOpen | 6:38f7dce055d0 | 31 | * Example: |
MikamiUitOpen | 6:38f7dce055d0 | 32 | * @code |
MikamiUitOpen | 6:38f7dce055d0 | 33 | * // Flash an LED while waiting for events |
MikamiUitOpen | 6:38f7dce055d0 | 34 | * |
MikamiUitOpen | 6:38f7dce055d0 | 35 | * #include "mbed.h" |
MikamiUitOpen | 6:38f7dce055d0 | 36 | * |
MikamiUitOpen | 6:38f7dce055d0 | 37 | * InterruptIn event(p16); |
MikamiUitOpen | 6:38f7dce055d0 | 38 | * DigitalOut led(LED1); |
MikamiUitOpen | 6:38f7dce055d0 | 39 | * |
MikamiUitOpen | 6:38f7dce055d0 | 40 | * void trigger() { |
MikamiUitOpen | 6:38f7dce055d0 | 41 | * printf("triggered!\n"); |
MikamiUitOpen | 6:38f7dce055d0 | 42 | * } |
MikamiUitOpen | 6:38f7dce055d0 | 43 | * |
MikamiUitOpen | 6:38f7dce055d0 | 44 | * int main() { |
MikamiUitOpen | 6:38f7dce055d0 | 45 | * event.rise(&trigger); |
MikamiUitOpen | 6:38f7dce055d0 | 46 | * while(1) { |
MikamiUitOpen | 6:38f7dce055d0 | 47 | * led = !led; |
MikamiUitOpen | 6:38f7dce055d0 | 48 | * wait(0.25); |
MikamiUitOpen | 6:38f7dce055d0 | 49 | * } |
MikamiUitOpen | 6:38f7dce055d0 | 50 | * } |
MikamiUitOpen | 6:38f7dce055d0 | 51 | * @endcode |
MikamiUitOpen | 6:38f7dce055d0 | 52 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 53 | class InterruptIn { |
MikamiUitOpen | 6:38f7dce055d0 | 54 | |
MikamiUitOpen | 6:38f7dce055d0 | 55 | public: |
MikamiUitOpen | 6:38f7dce055d0 | 56 | |
MikamiUitOpen | 6:38f7dce055d0 | 57 | /** Create an InterruptIn connected to the specified pin |
MikamiUitOpen | 6:38f7dce055d0 | 58 | * |
MikamiUitOpen | 6:38f7dce055d0 | 59 | * @param pin InterruptIn pin to connect to |
MikamiUitOpen | 6:38f7dce055d0 | 60 | * @param name (optional) A string to identify the object |
MikamiUitOpen | 6:38f7dce055d0 | 61 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 62 | InterruptIn(PinName pin); |
MikamiUitOpen | 6:38f7dce055d0 | 63 | virtual ~InterruptIn(); |
MikamiUitOpen | 6:38f7dce055d0 | 64 | |
MikamiUitOpen | 6:38f7dce055d0 | 65 | int read(); |
MikamiUitOpen | 6:38f7dce055d0 | 66 | #ifdef MBED_OPERATORS |
MikamiUitOpen | 6:38f7dce055d0 | 67 | operator int(); |
MikamiUitOpen | 6:38f7dce055d0 | 68 | |
MikamiUitOpen | 6:38f7dce055d0 | 69 | #endif |
MikamiUitOpen | 6:38f7dce055d0 | 70 | |
MikamiUitOpen | 6:38f7dce055d0 | 71 | /** Attach a function to call when a rising edge occurs on the input |
MikamiUitOpen | 6:38f7dce055d0 | 72 | * |
MikamiUitOpen | 6:38f7dce055d0 | 73 | * @param fptr A pointer to a void function, or 0 to set as none |
MikamiUitOpen | 6:38f7dce055d0 | 74 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 75 | void rise(void (*fptr)(void)); |
MikamiUitOpen | 6:38f7dce055d0 | 76 | |
MikamiUitOpen | 6:38f7dce055d0 | 77 | /** Attach a member function to call when a rising edge occurs on the input |
MikamiUitOpen | 6:38f7dce055d0 | 78 | * |
MikamiUitOpen | 6:38f7dce055d0 | 79 | * @param tptr pointer to the object to call the member function on |
MikamiUitOpen | 6:38f7dce055d0 | 80 | * @param mptr pointer to the member function to be called |
MikamiUitOpen | 6:38f7dce055d0 | 81 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 82 | template<typename T> |
MikamiUitOpen | 6:38f7dce055d0 | 83 | void rise(T* tptr, void (T::*mptr)(void)) { |
MikamiUitOpen | 6:38f7dce055d0 | 84 | _rise.attach(tptr, mptr); |
MikamiUitOpen | 6:38f7dce055d0 | 85 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
MikamiUitOpen | 6:38f7dce055d0 | 86 | } |
MikamiUitOpen | 6:38f7dce055d0 | 87 | |
MikamiUitOpen | 6:38f7dce055d0 | 88 | /** Attach a function to call when a falling edge occurs on the input |
MikamiUitOpen | 6:38f7dce055d0 | 89 | * |
MikamiUitOpen | 6:38f7dce055d0 | 90 | * @param fptr A pointer to a void function, or 0 to set as none |
MikamiUitOpen | 6:38f7dce055d0 | 91 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 92 | void fall(void (*fptr)(void)); |
MikamiUitOpen | 6:38f7dce055d0 | 93 | |
MikamiUitOpen | 6:38f7dce055d0 | 94 | /** Attach a member function to call when a falling edge occurs on the input |
MikamiUitOpen | 6:38f7dce055d0 | 95 | * |
MikamiUitOpen | 6:38f7dce055d0 | 96 | * @param tptr pointer to the object to call the member function on |
MikamiUitOpen | 6:38f7dce055d0 | 97 | * @param mptr pointer to the member function to be called |
MikamiUitOpen | 6:38f7dce055d0 | 98 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 99 | template<typename T> |
MikamiUitOpen | 6:38f7dce055d0 | 100 | void fall(T* tptr, void (T::*mptr)(void)) { |
MikamiUitOpen | 6:38f7dce055d0 | 101 | _fall.attach(tptr, mptr); |
MikamiUitOpen | 6:38f7dce055d0 | 102 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
MikamiUitOpen | 6:38f7dce055d0 | 103 | } |
MikamiUitOpen | 6:38f7dce055d0 | 104 | |
MikamiUitOpen | 6:38f7dce055d0 | 105 | /** Set the input pin mode |
MikamiUitOpen | 6:38f7dce055d0 | 106 | * |
MikamiUitOpen | 6:38f7dce055d0 | 107 | * @param mode PullUp, PullDown, PullNone |
MikamiUitOpen | 6:38f7dce055d0 | 108 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 109 | void mode(PinMode pull); |
MikamiUitOpen | 6:38f7dce055d0 | 110 | |
MikamiUitOpen | 6:38f7dce055d0 | 111 | /** Enable IRQ. This method depends on hw implementation, might enable one |
MikamiUitOpen | 6:38f7dce055d0 | 112 | * port interrupts. For further information, check gpio_irq_enable(). |
MikamiUitOpen | 6:38f7dce055d0 | 113 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 114 | void enable_irq(); |
MikamiUitOpen | 6:38f7dce055d0 | 115 | |
MikamiUitOpen | 6:38f7dce055d0 | 116 | /** Disable IRQ. This method depends on hw implementation, might disable one |
MikamiUitOpen | 6:38f7dce055d0 | 117 | * port interrupts. For further information, check gpio_irq_disable(). |
MikamiUitOpen | 6:38f7dce055d0 | 118 | */ |
MikamiUitOpen | 6:38f7dce055d0 | 119 | void disable_irq(); |
MikamiUitOpen | 6:38f7dce055d0 | 120 | |
MikamiUitOpen | 6:38f7dce055d0 | 121 | static void _irq_handler(uint32_t id, gpio_irq_event event); |
MikamiUitOpen | 6:38f7dce055d0 | 122 | |
MikamiUitOpen | 6:38f7dce055d0 | 123 | protected: |
MikamiUitOpen | 6:38f7dce055d0 | 124 | gpio_t gpio; |
MikamiUitOpen | 6:38f7dce055d0 | 125 | gpio_irq_t gpio_irq; |
MikamiUitOpen | 6:38f7dce055d0 | 126 | |
MikamiUitOpen | 6:38f7dce055d0 | 127 | FunctionPointer _rise; |
MikamiUitOpen | 6:38f7dce055d0 | 128 | FunctionPointer _fall; |
MikamiUitOpen | 6:38f7dce055d0 | 129 | }; |
MikamiUitOpen | 6:38f7dce055d0 | 130 | |
MikamiUitOpen | 6:38f7dce055d0 | 131 | } // namespace mbed |
MikamiUitOpen | 6:38f7dce055d0 | 132 | |
MikamiUitOpen | 6:38f7dce055d0 | 133 | #endif |
MikamiUitOpen | 6:38f7dce055d0 | 134 | |
MikamiUitOpen | 6:38f7dce055d0 | 135 | #endif |