Please use mbed-src instead of this library.mbed-src supports GR-PEACH rev.C. mbed-srcライブラリをご利用ください。mbed-srcはGR-PEACH rev.Cに対応しています。

Fork of mbed-src_GR-PEACH_rev_c by GR-PEACH_producer_meeting

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers InterruptIn.cpp Source File

InterruptIn.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "InterruptIn.h"
00017 
00018 #if DEVICE_INTERRUPTIN
00019 
00020 namespace mbed {
00021 
00022 InterruptIn::InterruptIn(PinName pin) : gpio(),
00023                                         gpio_irq(),
00024                                         _rise(),
00025                                         _fall() {
00026     gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
00027     gpio_init_in(&gpio, pin);
00028 }
00029 
00030 InterruptIn::~InterruptIn() {
00031     gpio_irq_free(&gpio_irq);
00032 }
00033 
00034 int InterruptIn::read() {
00035     return gpio_read(&gpio);
00036 }
00037 
00038 void InterruptIn::mode(PinMode pull) {
00039     gpio_mode(&gpio, pull);
00040 }
00041 
00042 void InterruptIn::rise(void (*fptr)(void)) {
00043     if (fptr) {
00044         _rise.attach(fptr);
00045         gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
00046     } else {
00047         gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
00048     }
00049 }
00050 
00051 void InterruptIn::fall(void (*fptr)(void)) {
00052     if (fptr) {
00053         _fall.attach(fptr);
00054         gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
00055     } else {
00056         gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
00057     }
00058 }
00059 
00060 void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
00061     InterruptIn *handler = (InterruptIn*)id;
00062     switch (event) {
00063         case IRQ_RISE: handler->_rise.call(); break;
00064         case IRQ_FALL: handler->_fall.call(); break;
00065         case IRQ_NONE: break;
00066     }
00067 }
00068 
00069 void InterruptIn::enable_irq() {
00070     gpio_irq_enable(&gpio_irq);
00071 }
00072 
00073 void InterruptIn::disable_irq() {
00074     gpio_irq_disable(&gpio_irq);
00075 }
00076 
00077 #ifdef MBED_OPERATORS
00078 InterruptIn::operator int() {
00079     return read();
00080 }
00081 #endif
00082 
00083 } // namespace mbed
00084 
00085 #endif