mbed-drivers
InterruptIn.h
1 /*
2  * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * 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, WITHOUT
13  * 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.h"
21 
22 #if DEVICE_INTERRUPTIN
23 
24 #include "gpio_api.h"
25 #include "gpio_irq_api.h"
26 #include "core-util/FunctionPointer.h"
27 
28 namespace mbed {
29 
54 class InterruptIn {
55 
56 public:
57 
63  InterruptIn(PinName pin);
64  virtual ~InterruptIn();
65 
66  int read();
67 #ifdef MBED_OPERATORS
68  operator int();
69 
70 #endif
71 
76  void rise(void (*fptr)(void));
77 
83  template<typename T>
84  void rise(T* tptr, void (T::*mptr)(void)) {
85  _rise.attach(tptr, mptr);
86  gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
87  }
88 
93  void fall(void (*fptr)(void));
94 
100  template<typename T>
101  void fall(T* tptr, void (T::*mptr)(void)) {
102  _fall.attach(tptr, mptr);
103  gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
104  }
105 
110  void mode(PinMode pull);
111 
115  void enable_irq();
116 
120  void disable_irq();
121 
122  static void _irq_handler(uint32_t id, gpio_irq_event event);
123 
124 protected:
125  gpio_t gpio;
126  gpio_irq_t gpio_irq;
127 
128  mbed::util::FunctionPointer _rise;
129  mbed::util::FunctionPointer _fall;
130 };
131 
132 } // namespace mbed
133 
134 #endif
135 
136 #endif
void enable_irq()
Definition: InterruptIn.cpp:81
void rise(void(*fptr)(void))
Definition: InterruptIn.cpp:43
void fall(void(*fptr)(void))
Definition: InterruptIn.cpp:53
void fall(T *tptr, void(T::*mptr)(void))
Definition: InterruptIn.h:101
void disable_irq()
Definition: InterruptIn.cpp:85
void mode(PinMode pull)
Definition: InterruptIn.cpp:39
void rise(T *tptr, void(T::*mptr)(void))
Definition: InterruptIn.h:84
InterruptIn(PinName pin)
Definition: InterruptIn.cpp:23
Definition: InterruptIn.h:54
Definition: BusIn.cpp:19