mbed-dev library fork for STM32F100R6 microcontroller (LQFP64, 24MHz, 32kB flash, 4kB ram, 2-channel DAC, HDMI CEC, very cheap) . Use in online compiler (instead mbed library) with selected platform Nucleo F103RB.

Fork of mbed-dev by mbed official

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         _rise.attach(NULL);
00048         gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
00049     }
00050 }
00051 
00052 void InterruptIn::fall(void (*fptr)(void)) {
00053     if (fptr) {
00054         _fall.attach(fptr);
00055         gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
00056     } else {
00057         _fall.attach(NULL);
00058         gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
00059     }
00060 }
00061 
00062 void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
00063     InterruptIn *handler = (InterruptIn*)id;
00064     switch (event) {
00065         case IRQ_RISE: handler->_rise.call(); break;
00066         case IRQ_FALL: handler->_fall.call(); break;
00067         case IRQ_NONE: break;
00068     }
00069 }
00070 
00071 void InterruptIn::enable_irq() {
00072     gpio_irq_enable(&gpio_irq);
00073 }
00074 
00075 void InterruptIn::disable_irq() {
00076     gpio_irq_disable(&gpio_irq);
00077 }
00078 
00079 #ifdef MBED_OPERATORS
00080 InterruptIn::operator int() {
00081     return read();
00082 }
00083 #endif
00084 
00085 } // namespace mbed
00086 
00087 #endif