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