The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Thu Jul 07 14:34:11 2016 +0100
Revision:
122:f9eeca106725
Parent:
76:824293ae5e43
Child:
123:b0220dba8be7
Release 122 of the mbed library

Changes:
- new targets - Nucleo L432KC, Beetle, Nucleo F446ZE, Nucleo L011K4
- Thread safety addition - mbed API should contain a statement about thread safety
- critical section API addition
- CAS API (core_util_atomic_incr/decr)
- DEVICE_ are generated from targets.json file, device.h deprecated
- Callback replaces FunctionPointer to provide std like interface
- mbed HAL API docs improvements
- toolchain - prexif attributes with MBED_
- add new attributes - packed, weak, forcedinline, align
- target.json - contains targets definitions
- ST - L1XX - Cube update to 1.5
- SPI clock selection fix (clock from APB domain)
- F7 - Cube update v1.4.0
- L0 - baudrate init fix
- L1 - Cube update v1.5
- F3 - baudrate init fix, 3 targets CAN support
- F4 - Cube update v1.12.0, 3 targets CAN support
- L4XX - Cube update v1.5.1
- F0 - update Cube to v1.5.0
- L4 - 2 targets (L476RG/VG) CAN support
- NXP - pwm clock fix for KSDK2 MCU
- LPC2368 - remove ARM toolchain support - due to regression
- KSDK2 - fix SPI , I2C address and repeat start
- Silabs - some fixes backported from mbed 3
- Renesas - RZ_A1H - SystemCoreClockUpdate addition

Who changed what in which revision?

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