Mistake on this page?
Report an issue in GitHub or email us
InterruptIn.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_INTERRUPTIN_H
18 #define MBED_INTERRUPTIN_H
19 
20 #include "platform/platform.h"
21 
22 #if DEVICE_INTERRUPTIN || defined(DOXYGEN_ONLY)
23 
24 #include "hal/gpio_api.h"
25 #include "hal/gpio_irq_api.h"
26 #include "platform/Callback.h"
27 #include "platform/mbed_critical.h"
28 #include "platform/mbed_toolchain.h"
29 #include "platform/NonCopyable.h"
30 
31 namespace mbed {
32 /**
33  * \defgroup drivers_InterruptIn InterruptIn class
34  * \ingroup drivers-public-api-gpio
35  * @{
36  */
37 
38 /** A digital interrupt input, used to call a function on a rising or falling edge
39  *
40  * @note Synchronization level: Interrupt safe
41  *
42  * Example:
43  * @code
44  * // Flash an LED while waiting for events
45  *
46  * #include "mbed.h"
47  *
48  * InterruptIn event(p16);
49  * DigitalOut led(LED1);
50  *
51  * void trigger() {
52  * printf("triggered!\n");
53  * }
54  *
55  * int main() {
56  * // register trigger() to be called upon the rising edge of event
57  * event.rise(&trigger);
58  * while(1) {
59  * led = !led;
60  * ThisThread::sleep_for(250);
61  * }
62  * }
63  * @endcode
64  */
65 class InterruptIn : private NonCopyable<InterruptIn> {
66 
67 public:
68 
69  /** Create an InterruptIn connected to the specified pin
70  *
71  * @param pin InterruptIn pin to connect to
72  */
73  InterruptIn(PinName pin);
74 
75  /** Create an InterruptIn connected to the specified pin,
76  * and the pin configured to the specified mode.
77  *
78  * @param pin InterruptIn pin to connect to
79  * @param mode Desired Pin mode configuration.
80  * (Valid values could be PullNone, PullDown, PullUp and PullDefault.
81  * See PinNames.h for your target for definitions)
82  *
83  */
84  InterruptIn(PinName pin, PinMode mode);
85 
86  virtual ~InterruptIn();
87 
88  /** Read the input, represented as 0 or 1 (int)
89  *
90  * @returns
91  * An integer representing the state of the input pin,
92  * 0 for logical 0, 1 for logical 1
93  */
94  int read();
95 
96  /** An operator shorthand for read()
97  */
98  operator int();
99 
100 
101  /** Attach a function to call when a rising edge occurs on the input
102  * Interrupts are enabled for the pin
103  *
104  * @param func A pointer to a void function, or 0 to set as none
105  */
106  void rise(Callback<void()> func);
107 
108  /** Attach a function to call when a falling edge occurs on the input
109  * Interrupts are enabled for the pin
110  *
111  * @param func A pointer to a void function, or 0 to set as none
112  */
113  void fall(Callback<void()> func);
114 
115  /** Set the input pin mode
116  *
117  * @param pull PullUp, PullDown, PullNone, PullDefault
118  * See PinNames.h for your target for definitions)
119  */
120  void mode(PinMode pull);
121 
122  /** Enable IRQ. This method depends on hardware implementation, might enable one
123  * port interrupts. For further information, check gpio_irq_enable().
124  */
125  void enable_irq();
126 
127  /** Disable IRQ. This method depends on hardware implementation, might disable one
128  * port interrupts. For further information, check gpio_irq_disable().
129  */
130  void disable_irq();
131 
132  static void _irq_handler(uintptr_t context, gpio_irq_event event);
133 #if !defined(DOXYGEN_ONLY)
134 protected:
135  gpio_t gpio;
136  gpio_irq_t gpio_irq;
137 
138  Callback<void()> _rise;
139  Callback<void()> _fall;
140 
141  void irq_init(PinName pin);
142 #endif
143 };
144 
145 /** @}*/
146 
147 } // namespace mbed
148 
149 #endif
150 
151 #endif
void fall(Callback< void()> func)
Attach a function to call when a falling edge occurs on the input Interrupts are enabled for the pin...
void mode(PinMode pull)
Set the input pin mode.
void disable_irq()
Disable IRQ.
void enable_irq()
Enable IRQ.
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:162
gpio_irq_event
GPIO IRQ events.
Definition: gpio_irq_api.h:34
struct gpio_irq_s gpio_irq_t
GPIO IRQ HAL structure.
Definition: gpio_irq_api.h:42
InterruptIn(PinName pin)
Create an InterruptIn connected to the specified pin.
int read()
Read the input, represented as 0 or 1 (int)
A digital interrupt input, used to call a function on a rising or falling edge.
Definition: InterruptIn.h:65
void rise(Callback< void()> func)
Attach a function to call when a rising edge occurs on the input Interrupts are enabled for the pin...
Callback class based on template specialization.
Definition: Callback.h:53
Definition: ATHandler.h:46
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.