temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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