mbed SDK library sources

Fork of mbed-src by mbed official

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

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

Committer:
emilmont
Date:
Mon Feb 18 11:44:18 2013 +0000
Revision:
2:143cac498751
Parent:
0:fd0d7bdfcdc2
Update mbed sources to Rev 59

Who changed what in which revision?

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