Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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