This fork captures the mbed lib v125 for ease of integration into older projects.

Fork of mbed-dev by mbed official

Committer:
apluscw
Date:
Fri Jul 20 21:24:42 2018 +0000
Revision:
187:92cbb9eec47b
Mbed library with source code from mbed lib v125. Posted to ease integration with some older projects.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
apluscw 187:92cbb9eec47b 1 /* mbed Microcontroller Library
apluscw 187:92cbb9eec47b 2 * Copyright (c) 2006-2013 ARM Limited
apluscw 187:92cbb9eec47b 3 *
apluscw 187:92cbb9eec47b 4 * Licensed under the Apache License, Version 2.0 (the "License");
apluscw 187:92cbb9eec47b 5 * you may not use this file except in compliance with the License.
apluscw 187:92cbb9eec47b 6 * You may obtain a copy of the License at
apluscw 187:92cbb9eec47b 7 *
apluscw 187:92cbb9eec47b 8 * http://www.apache.org/licenses/LICENSE-2.0
apluscw 187:92cbb9eec47b 9 *
apluscw 187:92cbb9eec47b 10 * Unless required by applicable law or agreed to in writing, software
apluscw 187:92cbb9eec47b 11 * distributed under the License is distributed on an "AS IS" BASIS,
apluscw 187:92cbb9eec47b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
apluscw 187:92cbb9eec47b 13 * See the License for the specific language governing permissions and
apluscw 187:92cbb9eec47b 14 * limitations under the License.
apluscw 187:92cbb9eec47b 15 */
apluscw 187:92cbb9eec47b 16 #ifndef MBED_INTERRUPTIN_H
apluscw 187:92cbb9eec47b 17 #define MBED_INTERRUPTIN_H
apluscw 187:92cbb9eec47b 18
apluscw 187:92cbb9eec47b 19 #include "platform.h"
apluscw 187:92cbb9eec47b 20
apluscw 187:92cbb9eec47b 21 #if DEVICE_INTERRUPTIN
apluscw 187:92cbb9eec47b 22
apluscw 187:92cbb9eec47b 23 #include "gpio_api.h"
apluscw 187:92cbb9eec47b 24 #include "gpio_irq_api.h"
apluscw 187:92cbb9eec47b 25 #include "Callback.h"
apluscw 187:92cbb9eec47b 26 #include "critical.h"
apluscw 187:92cbb9eec47b 27
apluscw 187:92cbb9eec47b 28 namespace mbed {
apluscw 187:92cbb9eec47b 29
apluscw 187:92cbb9eec47b 30 /** A digital interrupt input, used to call a function on a rising or falling edge
apluscw 187:92cbb9eec47b 31 *
apluscw 187:92cbb9eec47b 32 * @Note Synchronization level: Interrupt safe
apluscw 187:92cbb9eec47b 33 *
apluscw 187:92cbb9eec47b 34 * Example:
apluscw 187:92cbb9eec47b 35 * @code
apluscw 187:92cbb9eec47b 36 * // Flash an LED while waiting for events
apluscw 187:92cbb9eec47b 37 *
apluscw 187:92cbb9eec47b 38 * #include "mbed.h"
apluscw 187:92cbb9eec47b 39 *
apluscw 187:92cbb9eec47b 40 * InterruptIn event(p16);
apluscw 187:92cbb9eec47b 41 * DigitalOut led(LED1);
apluscw 187:92cbb9eec47b 42 *
apluscw 187:92cbb9eec47b 43 * void trigger() {
apluscw 187:92cbb9eec47b 44 * printf("triggered!\n");
apluscw 187:92cbb9eec47b 45 * }
apluscw 187:92cbb9eec47b 46 *
apluscw 187:92cbb9eec47b 47 * int main() {
apluscw 187:92cbb9eec47b 48 * event.rise(&trigger);
apluscw 187:92cbb9eec47b 49 * while(1) {
apluscw 187:92cbb9eec47b 50 * led = !led;
apluscw 187:92cbb9eec47b 51 * wait(0.25);
apluscw 187:92cbb9eec47b 52 * }
apluscw 187:92cbb9eec47b 53 * }
apluscw 187:92cbb9eec47b 54 * @endcode
apluscw 187:92cbb9eec47b 55 */
apluscw 187:92cbb9eec47b 56 class InterruptIn {
apluscw 187:92cbb9eec47b 57
apluscw 187:92cbb9eec47b 58 public:
apluscw 187:92cbb9eec47b 59
apluscw 187:92cbb9eec47b 60 /** Create an InterruptIn connected to the specified pin
apluscw 187:92cbb9eec47b 61 *
apluscw 187:92cbb9eec47b 62 * @param pin InterruptIn pin to connect to
apluscw 187:92cbb9eec47b 63 * @param name (optional) A string to identify the object
apluscw 187:92cbb9eec47b 64 */
apluscw 187:92cbb9eec47b 65 InterruptIn(PinName pin);
apluscw 187:92cbb9eec47b 66 virtual ~InterruptIn();
apluscw 187:92cbb9eec47b 67
apluscw 187:92cbb9eec47b 68 /** Read the input, represented as 0 or 1 (int)
apluscw 187:92cbb9eec47b 69 *
apluscw 187:92cbb9eec47b 70 * @returns
apluscw 187:92cbb9eec47b 71 * An integer representing the state of the input pin,
apluscw 187:92cbb9eec47b 72 * 0 for logical 0, 1 for logical 1
apluscw 187:92cbb9eec47b 73 */
apluscw 187:92cbb9eec47b 74 int read();
apluscw 187:92cbb9eec47b 75
apluscw 187:92cbb9eec47b 76 /** An operator shorthand for read()
apluscw 187:92cbb9eec47b 77 */
apluscw 187:92cbb9eec47b 78 operator int();
apluscw 187:92cbb9eec47b 79
apluscw 187:92cbb9eec47b 80
apluscw 187:92cbb9eec47b 81 /** Attach a function to call when a rising edge occurs on the input
apluscw 187:92cbb9eec47b 82 *
apluscw 187:92cbb9eec47b 83 * @param func A pointer to a void function, or 0 to set as none
apluscw 187:92cbb9eec47b 84 */
apluscw 187:92cbb9eec47b 85 void rise(Callback<void()> func);
apluscw 187:92cbb9eec47b 86
apluscw 187:92cbb9eec47b 87 /** Attach a member function to call when a rising edge occurs on the input
apluscw 187:92cbb9eec47b 88 *
apluscw 187:92cbb9eec47b 89 * @param obj pointer to the object to call the member function on
apluscw 187:92cbb9eec47b 90 * @param method pointer to the member function to be called
apluscw 187:92cbb9eec47b 91 */
apluscw 187:92cbb9eec47b 92 template<typename T, typename M>
apluscw 187:92cbb9eec47b 93 void rise(T *obj, M method) {
apluscw 187:92cbb9eec47b 94 core_util_critical_section_enter();
apluscw 187:92cbb9eec47b 95 rise(Callback<void()>(obj, method));
apluscw 187:92cbb9eec47b 96 core_util_critical_section_exit();
apluscw 187:92cbb9eec47b 97 }
apluscw 187:92cbb9eec47b 98
apluscw 187:92cbb9eec47b 99 /** Attach a function to call when a falling edge occurs on the input
apluscw 187:92cbb9eec47b 100 *
apluscw 187:92cbb9eec47b 101 * @param func A pointer to a void function, or 0 to set as none
apluscw 187:92cbb9eec47b 102 */
apluscw 187:92cbb9eec47b 103 void fall(Callback<void()> func);
apluscw 187:92cbb9eec47b 104
apluscw 187:92cbb9eec47b 105 /** Attach a member function to call when a falling edge occurs on the input
apluscw 187:92cbb9eec47b 106 *
apluscw 187:92cbb9eec47b 107 * @param obj pointer to the object to call the member function on
apluscw 187:92cbb9eec47b 108 * @param method pointer to the member function to be called
apluscw 187:92cbb9eec47b 109 */
apluscw 187:92cbb9eec47b 110 template<typename T, typename M>
apluscw 187:92cbb9eec47b 111 void fall(T *obj, M method) {
apluscw 187:92cbb9eec47b 112 core_util_critical_section_enter();
apluscw 187:92cbb9eec47b 113 fall(Callback<void()>(obj, method));
apluscw 187:92cbb9eec47b 114 core_util_critical_section_exit();
apluscw 187:92cbb9eec47b 115 }
apluscw 187:92cbb9eec47b 116
apluscw 187:92cbb9eec47b 117 /** Set the input pin mode
apluscw 187:92cbb9eec47b 118 *
apluscw 187:92cbb9eec47b 119 * @param mode PullUp, PullDown, PullNone
apluscw 187:92cbb9eec47b 120 */
apluscw 187:92cbb9eec47b 121 void mode(PinMode pull);
apluscw 187:92cbb9eec47b 122
apluscw 187:92cbb9eec47b 123 /** Enable IRQ. This method depends on hw implementation, might enable one
apluscw 187:92cbb9eec47b 124 * port interrupts. For further information, check gpio_irq_enable().
apluscw 187:92cbb9eec47b 125 */
apluscw 187:92cbb9eec47b 126 void enable_irq();
apluscw 187:92cbb9eec47b 127
apluscw 187:92cbb9eec47b 128 /** Disable IRQ. This method depends on hw implementation, might disable one
apluscw 187:92cbb9eec47b 129 * port interrupts. For further information, check gpio_irq_disable().
apluscw 187:92cbb9eec47b 130 */
apluscw 187:92cbb9eec47b 131 void disable_irq();
apluscw 187:92cbb9eec47b 132
apluscw 187:92cbb9eec47b 133 static void _irq_handler(uint32_t id, gpio_irq_event event);
apluscw 187:92cbb9eec47b 134
apluscw 187:92cbb9eec47b 135 protected:
apluscw 187:92cbb9eec47b 136 gpio_t gpio;
apluscw 187:92cbb9eec47b 137 gpio_irq_t gpio_irq;
apluscw 187:92cbb9eec47b 138
apluscw 187:92cbb9eec47b 139 Callback<void()> _rise;
apluscw 187:92cbb9eec47b 140 Callback<void()> _fall;
apluscw 187:92cbb9eec47b 141 };
apluscw 187:92cbb9eec47b 142
apluscw 187:92cbb9eec47b 143 } // namespace mbed
apluscw 187:92cbb9eec47b 144
apluscw 187:92cbb9eec47b 145 #endif
apluscw 187:92cbb9eec47b 146
apluscw 187:92cbb9eec47b 147 #endif