USB Serial application

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
Zaitsev
Date:
Sat Dec 16 10:26:48 2017 +0000
Revision:
11:b3f2a8bdac4d
Parent:
10:41552d038a69
A copy for D.S;

Who changed what in which revision?

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