Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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