Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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