This is the final version of Mini Gateway for Automation and Security desgined for Renesas GR Peach Design Contest

Dependencies:   GR-PEACH_video GraphicsFramework HTTPServer R_BSP mbed-rpc mbed-rtos Socket lwip-eth lwip-sys lwip FATFileSystem

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers InterruptIn.h Source File

InterruptIn.h

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 #ifndef MBED_INTERRUPTIN_H
00017 #define MBED_INTERRUPTIN_H
00018 
00019 #include "platform/platform.h"
00020 
00021 #if DEVICE_INTERRUPTIN
00022 
00023 #include "hal/gpio_api.h"
00024 #include "hal/gpio_irq_api.h"
00025 #include "platform/Callback.h"
00026 #include "platform/critical.h"
00027 #include "platform/toolchain.h"
00028 
00029 namespace mbed {
00030 /** \addtogroup drivers */
00031 /** @{*/
00032 
00033 /** A digital interrupt input, used to call a function on a rising or falling edge
00034  *
00035  * @Note Synchronization level: Interrupt safe
00036  *
00037  * Example:
00038  * @code
00039  * // Flash an LED while waiting for events
00040  *
00041  * #include "mbed.h"
00042  *
00043  * InterruptIn event(p16);
00044  * DigitalOut led(LED1);
00045  *
00046  * void trigger() {
00047  *     printf("triggered!\n");
00048  * }
00049  *
00050  * int main() {
00051  *     event.rise(&trigger);
00052  *     while(1) {
00053  *         led = !led;
00054  *         wait(0.25);
00055  *     }
00056  * }
00057  * @endcode
00058  */
00059 class InterruptIn {
00060 
00061 public:
00062 
00063     /** Create an InterruptIn connected to the specified pin
00064      *
00065      *  @param pin InterruptIn pin to connect to
00066      *  @param name (optional) A string to identify the object
00067      */
00068     InterruptIn(PinName pin);
00069     virtual ~InterruptIn();
00070 
00071     /** Read the input, represented as 0 or 1 (int)
00072      *
00073      *  @returns
00074      *    An integer representing the state of the input pin,
00075      *    0 for logical 0, 1 for logical 1
00076      */
00077     int read();
00078 
00079     /** An operator shorthand for read()
00080      */
00081     operator int();
00082 
00083 
00084     /** Attach a function to call when a rising edge occurs on the input
00085      *
00086      *  @param func A pointer to a void function, or 0 to set as none
00087      */
00088     void rise(Callback<void()> func);
00089 
00090     /** Attach a member function to call when a rising edge occurs on the input
00091      *
00092      *  @param obj pointer to the object to call the member function on
00093      *  @param method pointer to the member function to be called
00094      *  @deprecated
00095      *      The rise function does not support cv-qualifiers. Replaced by
00096      *      rise(callback(obj, method)).
00097      */
00098     template<typename T, typename M>
00099     MBED_DEPRECATED_SINCE("mbed-os-5.1",
00100         "The rise function does not support cv-qualifiers. Replaced by "
00101         "rise(callback(obj, method)).")
00102     void rise(T *obj, M method) {
00103         core_util_critical_section_enter();
00104         rise(callback(obj, method));
00105         core_util_critical_section_exit();
00106     }
00107 
00108     /** Attach a function to call when a falling edge occurs on the input
00109      *
00110      *  @param func A pointer to a void function, or 0 to set as none
00111      */
00112     void fall(Callback<void()> func);
00113 
00114     /** Attach a member function to call when a falling edge occurs on the input
00115      *
00116      *  @param obj pointer to the object to call the member function on
00117      *  @param method pointer to the member function to be called
00118      *  @deprecated
00119      *      The rise function does not support cv-qualifiers. Replaced by
00120      *      rise(callback(obj, method)).
00121      */
00122     template<typename T, typename M>
00123     MBED_DEPRECATED_SINCE("mbed-os-5.1",
00124         "The fall function does not support cv-qualifiers. Replaced by "
00125         "fall(callback(obj, method)).")
00126     void fall(T *obj, M method) {
00127         core_util_critical_section_enter();
00128         fall(callback(obj, method));
00129         core_util_critical_section_exit();
00130     }
00131 
00132     /** Set the input pin mode
00133      *
00134      *  @param mode PullUp, PullDown, PullNone
00135      */
00136     void mode(PinMode pull);
00137 
00138     /** Enable IRQ. This method depends on hw implementation, might enable one
00139      *  port interrupts. For further information, check gpio_irq_enable().
00140      */
00141     void enable_irq();
00142 
00143     /** Disable IRQ. This method depends on hw implementation, might disable one
00144      *  port interrupts. For further information, check gpio_irq_disable().
00145      */
00146     void disable_irq();
00147 
00148     static void _irq_handler(uint32_t id, gpio_irq_event event);
00149 
00150 protected:
00151     gpio_t gpio;
00152     gpio_irq_t gpio_irq;
00153 
00154     Callback<void()> _rise;
00155     Callback<void()> _fall;
00156 };
00157 
00158 } // namespace mbed
00159 
00160 #endif
00161 
00162 #endif
00163 
00164 /** @}*/