mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Committer:
Kojto
Date:
Fri Aug 12 13:04:35 2016 +0200
Revision:
123:b0220dba8be7
Parent:
122:f9eeca106725
Release 123 of the mbed library

Changes:
- new targets: nucleo_f207zg, beetle, nrf51_dk, hexiwear,
nuvoton nuc472, vk rz a1h
- ST - fix timer interrupt handler, sleep api fix
- NXP - lpc15xx us ticker fix
- Nordic - analogin fixes, LF clock init addition, enable i2c async

Who changed what in which revision?

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