1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "InterruptIn.h"
18 #if DEVICE_INTERRUPTIN
22 InterruptIn::InterruptIn(PinName pin) : gpio(),
26 gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
27 gpio_init_in(&gpio, pin);
30 InterruptIn::~InterruptIn() {
31 gpio_irq_free(&gpio_irq);
34 int InterruptIn::read() {
35 return gpio_read(&gpio);
38 void InterruptIn::mode(PinMode pull) {
39 gpio_mode(&gpio, pull);
42 void InterruptIn::rise(void (*fptr)(void)) {
45 gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
47 gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
51 void InterruptIn::fall(void (*fptr)(void)) {
54 gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
56 gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
60 void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
61 InterruptIn *handler = (InterruptIn*)id;
63 case IRQ_RISE: handler->_rise.call(); break;
64 case IRQ_FALL: handler->_fall.call(); break;
69 void InterruptIn::enable_irq() {
70 gpio_irq_enable(&gpio_irq);
73 void InterruptIn::disable_irq() {
74 gpio_irq_disable(&gpio_irq);
78 InterruptIn::operator int() {