Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
drivers/InterruptIn.h@170:54ff26da7eb6, 2017-07-04 (annotated)
- Committer:
- thedo
- Date:
- Tue Jul 04 06:23:13 2017 +0000
- Revision:
- 170:54ff26da7eb6
- Parent:
- 167:1657b442184c
project opencv 3.1 on GR PEACH board, no use SD card.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thedo | 167:1657b442184c | 1 | /* mbed Microcontroller Library |
thedo | 167:1657b442184c | 2 | * Copyright (c) 2006-2013 ARM Limited |
thedo | 167:1657b442184c | 3 | * |
thedo | 167:1657b442184c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
thedo | 167:1657b442184c | 5 | * you may not use this file except in compliance with the License. |
thedo | 167:1657b442184c | 6 | * You may obtain a copy of the License at |
thedo | 167:1657b442184c | 7 | * |
thedo | 167:1657b442184c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
thedo | 167:1657b442184c | 9 | * |
thedo | 167:1657b442184c | 10 | * Unless required by applicable law or agreed to in writing, software |
thedo | 167:1657b442184c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
thedo | 167:1657b442184c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
thedo | 167:1657b442184c | 13 | * See the License for the specific language governing permissions and |
thedo | 167:1657b442184c | 14 | * limitations under the License. |
thedo | 167:1657b442184c | 15 | */ |
thedo | 167:1657b442184c | 16 | #ifndef MBED_INTERRUPTIN_H |
thedo | 167:1657b442184c | 17 | #define MBED_INTERRUPTIN_H |
thedo | 167:1657b442184c | 18 | |
thedo | 167:1657b442184c | 19 | #include "platform/platform.h" |
thedo | 167:1657b442184c | 20 | |
thedo | 167:1657b442184c | 21 | #if defined (DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) |
thedo | 167:1657b442184c | 22 | |
thedo | 167:1657b442184c | 23 | #include "hal/gpio_api.h" |
thedo | 167:1657b442184c | 24 | #include "hal/gpio_irq_api.h" |
thedo | 167:1657b442184c | 25 | #include "platform/Callback.h" |
thedo | 167:1657b442184c | 26 | #include "platform/mbed_critical.h" |
thedo | 167:1657b442184c | 27 | #include "platform/mbed_toolchain.h" |
thedo | 167:1657b442184c | 28 | |
thedo | 167:1657b442184c | 29 | namespace mbed { |
thedo | 167:1657b442184c | 30 | /** \addtogroup drivers */ |
thedo | 167:1657b442184c | 31 | |
thedo | 167:1657b442184c | 32 | /** A digital interrupt input, used to call a function on a rising or falling edge |
thedo | 167:1657b442184c | 33 | * |
thedo | 167:1657b442184c | 34 | * @note Synchronization level: Interrupt safe |
thedo | 167:1657b442184c | 35 | * |
thedo | 167:1657b442184c | 36 | * Example: |
thedo | 167:1657b442184c | 37 | * @code |
thedo | 167:1657b442184c | 38 | * // Flash an LED while waiting for events |
thedo | 167:1657b442184c | 39 | * |
thedo | 167:1657b442184c | 40 | * #include "mbed.h" |
thedo | 167:1657b442184c | 41 | * |
thedo | 167:1657b442184c | 42 | * InterruptIn event(p16); |
thedo | 167:1657b442184c | 43 | * DigitalOut led(LED1); |
thedo | 167:1657b442184c | 44 | * |
thedo | 167:1657b442184c | 45 | * void trigger() { |
thedo | 167:1657b442184c | 46 | * printf("triggered!\n"); |
thedo | 167:1657b442184c | 47 | * } |
thedo | 167:1657b442184c | 48 | * |
thedo | 167:1657b442184c | 49 | * int main() { |
thedo | 167:1657b442184c | 50 | * event.rise(&trigger); |
thedo | 167:1657b442184c | 51 | * while(1) { |
thedo | 167:1657b442184c | 52 | * led = !led; |
thedo | 167:1657b442184c | 53 | * wait(0.25); |
thedo | 167:1657b442184c | 54 | * } |
thedo | 167:1657b442184c | 55 | * } |
thedo | 167:1657b442184c | 56 | * @endcode |
thedo | 167:1657b442184c | 57 | * @ingroup drivers |
thedo | 167:1657b442184c | 58 | */ |
thedo | 167:1657b442184c | 59 | class InterruptIn { |
thedo | 167:1657b442184c | 60 | |
thedo | 167:1657b442184c | 61 | public: |
thedo | 167:1657b442184c | 62 | |
thedo | 167:1657b442184c | 63 | /** Create an InterruptIn connected to the specified pin |
thedo | 167:1657b442184c | 64 | * |
thedo | 167:1657b442184c | 65 | * @param pin InterruptIn pin to connect to |
thedo | 167:1657b442184c | 66 | */ |
thedo | 167:1657b442184c | 67 | InterruptIn(PinName pin); |
thedo | 167:1657b442184c | 68 | virtual ~InterruptIn(); |
thedo | 167:1657b442184c | 69 | |
thedo | 167:1657b442184c | 70 | /** Read the input, represented as 0 or 1 (int) |
thedo | 167:1657b442184c | 71 | * |
thedo | 167:1657b442184c | 72 | * @returns |
thedo | 167:1657b442184c | 73 | * An integer representing the state of the input pin, |
thedo | 167:1657b442184c | 74 | * 0 for logical 0, 1 for logical 1 |
thedo | 167:1657b442184c | 75 | */ |
thedo | 167:1657b442184c | 76 | int read(); |
thedo | 167:1657b442184c | 77 | |
thedo | 167:1657b442184c | 78 | /** An operator shorthand for read() |
thedo | 167:1657b442184c | 79 | */ |
thedo | 167:1657b442184c | 80 | operator int(); |
thedo | 167:1657b442184c | 81 | |
thedo | 167:1657b442184c | 82 | |
thedo | 167:1657b442184c | 83 | /** Attach a function to call when a rising edge occurs on the input |
thedo | 167:1657b442184c | 84 | * |
thedo | 167:1657b442184c | 85 | * @param func A pointer to a void function, or 0 to set as none |
thedo | 167:1657b442184c | 86 | */ |
thedo | 167:1657b442184c | 87 | void rise(Callback<void()> func); |
thedo | 167:1657b442184c | 88 | |
thedo | 167:1657b442184c | 89 | /** Attach a member function to call when a rising edge occurs on the input |
thedo | 167:1657b442184c | 90 | * |
thedo | 167:1657b442184c | 91 | * @param obj pointer to the object to call the member function on |
thedo | 167:1657b442184c | 92 | * @param method pointer to the member function to be called |
thedo | 167:1657b442184c | 93 | * @deprecated |
thedo | 167:1657b442184c | 94 | * The rise function does not support cv-qualifiers. Replaced by |
thedo | 167:1657b442184c | 95 | * rise(callback(obj, method)). |
thedo | 167:1657b442184c | 96 | */ |
thedo | 167:1657b442184c | 97 | template<typename T, typename M> |
thedo | 167:1657b442184c | 98 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
thedo | 167:1657b442184c | 99 | "The rise function does not support cv-qualifiers. Replaced by " |
thedo | 167:1657b442184c | 100 | "rise(callback(obj, method)).") |
thedo | 167:1657b442184c | 101 | void rise(T *obj, M method) { |
thedo | 167:1657b442184c | 102 | core_util_critical_section_enter(); |
thedo | 167:1657b442184c | 103 | rise(callback(obj, method)); |
thedo | 167:1657b442184c | 104 | core_util_critical_section_exit(); |
thedo | 167:1657b442184c | 105 | } |
thedo | 167:1657b442184c | 106 | |
thedo | 167:1657b442184c | 107 | /** Attach a function to call when a falling edge occurs on the input |
thedo | 167:1657b442184c | 108 | * |
thedo | 167:1657b442184c | 109 | * @param func A pointer to a void function, or 0 to set as none |
thedo | 167:1657b442184c | 110 | */ |
thedo | 167:1657b442184c | 111 | void fall(Callback<void()> func); |
thedo | 167:1657b442184c | 112 | |
thedo | 167:1657b442184c | 113 | /** Attach a member function to call when a falling edge occurs on the input |
thedo | 167:1657b442184c | 114 | * |
thedo | 167:1657b442184c | 115 | * @param obj pointer to the object to call the member function on |
thedo | 167:1657b442184c | 116 | * @param method pointer to the member function to be called |
thedo | 167:1657b442184c | 117 | * @deprecated |
thedo | 167:1657b442184c | 118 | * The rise function does not support cv-qualifiers. Replaced by |
thedo | 167:1657b442184c | 119 | * rise(callback(obj, method)). |
thedo | 167:1657b442184c | 120 | */ |
thedo | 167:1657b442184c | 121 | template<typename T, typename M> |
thedo | 167:1657b442184c | 122 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
thedo | 167:1657b442184c | 123 | "The fall function does not support cv-qualifiers. Replaced by " |
thedo | 167:1657b442184c | 124 | "fall(callback(obj, method)).") |
thedo | 167:1657b442184c | 125 | void fall(T *obj, M method) { |
thedo | 167:1657b442184c | 126 | core_util_critical_section_enter(); |
thedo | 167:1657b442184c | 127 | fall(callback(obj, method)); |
thedo | 167:1657b442184c | 128 | core_util_critical_section_exit(); |
thedo | 167:1657b442184c | 129 | } |
thedo | 167:1657b442184c | 130 | |
thedo | 167:1657b442184c | 131 | /** Set the input pin mode |
thedo | 167:1657b442184c | 132 | * |
thedo | 167:1657b442184c | 133 | * @param pull PullUp, PullDown, PullNone |
thedo | 167:1657b442184c | 134 | */ |
thedo | 167:1657b442184c | 135 | void mode(PinMode pull); |
thedo | 167:1657b442184c | 136 | |
thedo | 167:1657b442184c | 137 | /** Enable IRQ. This method depends on hw implementation, might enable one |
thedo | 167:1657b442184c | 138 | * port interrupts. For further information, check gpio_irq_enable(). |
thedo | 167:1657b442184c | 139 | */ |
thedo | 167:1657b442184c | 140 | void enable_irq(); |
thedo | 167:1657b442184c | 141 | |
thedo | 167:1657b442184c | 142 | /** Disable IRQ. This method depends on hw implementation, might disable one |
thedo | 167:1657b442184c | 143 | * port interrupts. For further information, check gpio_irq_disable(). |
thedo | 167:1657b442184c | 144 | */ |
thedo | 167:1657b442184c | 145 | void disable_irq(); |
thedo | 167:1657b442184c | 146 | |
thedo | 167:1657b442184c | 147 | static void _irq_handler(uint32_t id, gpio_irq_event event); |
thedo | 167:1657b442184c | 148 | |
thedo | 167:1657b442184c | 149 | protected: |
thedo | 167:1657b442184c | 150 | gpio_t gpio; |
thedo | 167:1657b442184c | 151 | gpio_irq_t gpio_irq; |
thedo | 167:1657b442184c | 152 | |
thedo | 167:1657b442184c | 153 | Callback<void()> _rise; |
thedo | 167:1657b442184c | 154 | Callback<void()> _fall; |
thedo | 167:1657b442184c | 155 | }; |
thedo | 167:1657b442184c | 156 | |
thedo | 167:1657b442184c | 157 | } // namespace mbed |
thedo | 167:1657b442184c | 158 | |
thedo | 167:1657b442184c | 159 | #endif |
thedo | 167:1657b442184c | 160 | |
thedo | 167:1657b442184c | 161 | #endif |
thedo | 167:1657b442184c | 162 |