mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
Anna Bridge
Date:
Fri Jun 22 16:45:37 2018 +0100
Revision:
186:707f6e361f3e
Parent:
168:9672193075cf
mbed-dev library. Release version 162

Who changed what in which revision?

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