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