SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 09:08:29 2019 +0000
Revision:
0:aa3fc5ad02f7
SPKT

Who changed what in which revision?

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