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