mbed library sources. Supersedes mbed-src.

Dependents:   LPCXpresso1769_blinky

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Sep 02 15:07:44 2016 +0100
Revision:
144:ef7eb2e8f9f7
Parent:
0:9b334a45a8ff
This updates the lib to the mbed lib v125

Who changed what in which revision?

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