mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

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