mbed library sources(for async_print)

Dependents:   AsyncPrint

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Nov 20 17:24:08 2012 +0000
Revision:
0:fd0d7bdfcdc2
Child:
2:143cac498751
mbed sources

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:fd0d7bdfcdc2 1 /* mbed Microcontroller Library
mbed_official 0:fd0d7bdfcdc2 2 * Copyright (c) 2006-2012 ARM Limited
mbed_official 0:fd0d7bdfcdc2 3 *
mbed_official 0:fd0d7bdfcdc2 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mbed_official 0:fd0d7bdfcdc2 5 * of this software and associated documentation files (the "Software"), to deal
mbed_official 0:fd0d7bdfcdc2 6 * in the Software without restriction, including without limitation the rights
mbed_official 0:fd0d7bdfcdc2 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbed_official 0:fd0d7bdfcdc2 8 * copies of the Software, and to permit persons to whom the Software is
mbed_official 0:fd0d7bdfcdc2 9 * furnished to do so, subject to the following conditions:
mbed_official 0:fd0d7bdfcdc2 10 *
mbed_official 0:fd0d7bdfcdc2 11 * The above copyright notice and this permission notice shall be included in
mbed_official 0:fd0d7bdfcdc2 12 * all copies or substantial portions of the Software.
mbed_official 0:fd0d7bdfcdc2 13 *
mbed_official 0:fd0d7bdfcdc2 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbed_official 0:fd0d7bdfcdc2 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbed_official 0:fd0d7bdfcdc2 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbed_official 0:fd0d7bdfcdc2 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbed_official 0:fd0d7bdfcdc2 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 0:fd0d7bdfcdc2 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
mbed_official 0:fd0d7bdfcdc2 20 * SOFTWARE.
mbed_official 0:fd0d7bdfcdc2 21 */
mbed_official 0:fd0d7bdfcdc2 22 #ifndef MBED_INTERRUPTIN_H
mbed_official 0:fd0d7bdfcdc2 23 #define MBED_INTERRUPTIN_H
mbed_official 0:fd0d7bdfcdc2 24
mbed_official 0:fd0d7bdfcdc2 25 #include "platform.h"
mbed_official 0:fd0d7bdfcdc2 26
mbed_official 0:fd0d7bdfcdc2 27 #if DEVICE_INTERRUPTIN
mbed_official 0:fd0d7bdfcdc2 28
mbed_official 0:fd0d7bdfcdc2 29 #include "gpio_api.h"
mbed_official 0:fd0d7bdfcdc2 30 #include "gpio_irq_api.h"
mbed_official 0:fd0d7bdfcdc2 31
mbed_official 0:fd0d7bdfcdc2 32 #include "FunctionPointer.h"
mbed_official 0:fd0d7bdfcdc2 33
mbed_official 0:fd0d7bdfcdc2 34 namespace mbed {
mbed_official 0:fd0d7bdfcdc2 35
mbed_official 0:fd0d7bdfcdc2 36 /** A digital interrupt input, used to call a function on a rising or falling edge
mbed_official 0:fd0d7bdfcdc2 37 *
mbed_official 0:fd0d7bdfcdc2 38 * Example:
mbed_official 0:fd0d7bdfcdc2 39 * @code
mbed_official 0:fd0d7bdfcdc2 40 * // Flash an LED while waiting for events
mbed_official 0:fd0d7bdfcdc2 41 *
mbed_official 0:fd0d7bdfcdc2 42 * #include "mbed.h"
mbed_official 0:fd0d7bdfcdc2 43 *
mbed_official 0:fd0d7bdfcdc2 44 * InterruptIn event(p16);
mbed_official 0:fd0d7bdfcdc2 45 * DigitalOut led(LED1);
mbed_official 0:fd0d7bdfcdc2 46 *
mbed_official 0:fd0d7bdfcdc2 47 * void trigger() {
mbed_official 0:fd0d7bdfcdc2 48 * printf("triggered!\n");
mbed_official 0:fd0d7bdfcdc2 49 * }
mbed_official 0:fd0d7bdfcdc2 50 *
mbed_official 0:fd0d7bdfcdc2 51 * int main() {
mbed_official 0:fd0d7bdfcdc2 52 * event.rise(&trigger);
mbed_official 0:fd0d7bdfcdc2 53 * while(1) {
mbed_official 0:fd0d7bdfcdc2 54 * led = !led;
mbed_official 0:fd0d7bdfcdc2 55 * wait(0.25);
mbed_official 0:fd0d7bdfcdc2 56 * }
mbed_official 0:fd0d7bdfcdc2 57 * }
mbed_official 0:fd0d7bdfcdc2 58 * @endcode
mbed_official 0:fd0d7bdfcdc2 59 */
mbed_official 0:fd0d7bdfcdc2 60 class InterruptIn {
mbed_official 0:fd0d7bdfcdc2 61
mbed_official 0:fd0d7bdfcdc2 62 public:
mbed_official 0:fd0d7bdfcdc2 63
mbed_official 0:fd0d7bdfcdc2 64 /** Create an InterruptIn connected to the specified pin
mbed_official 0:fd0d7bdfcdc2 65 *
mbed_official 0:fd0d7bdfcdc2 66 * @param pin InterruptIn pin to connect to
mbed_official 0:fd0d7bdfcdc2 67 * @param name (optional) A string to identify the object
mbed_official 0:fd0d7bdfcdc2 68 */
mbed_official 0:fd0d7bdfcdc2 69 InterruptIn(PinName pin);
mbed_official 0:fd0d7bdfcdc2 70 virtual ~InterruptIn();
mbed_official 0:fd0d7bdfcdc2 71
mbed_official 0:fd0d7bdfcdc2 72 int read();
mbed_official 0:fd0d7bdfcdc2 73 #ifdef MBED_OPERATORS
mbed_official 0:fd0d7bdfcdc2 74 operator int();
mbed_official 0:fd0d7bdfcdc2 75
mbed_official 0:fd0d7bdfcdc2 76 #endif
mbed_official 0:fd0d7bdfcdc2 77
mbed_official 0:fd0d7bdfcdc2 78 /** Attach a function to call when a rising edge occurs on the input
mbed_official 0:fd0d7bdfcdc2 79 *
mbed_official 0:fd0d7bdfcdc2 80 * @param fptr A pointer to a void function, or 0 to set as none
mbed_official 0:fd0d7bdfcdc2 81 */
mbed_official 0:fd0d7bdfcdc2 82 void rise(void (*fptr)(void));
mbed_official 0:fd0d7bdfcdc2 83
mbed_official 0:fd0d7bdfcdc2 84 /** Attach a member function to call when a rising edge occurs on the input
mbed_official 0:fd0d7bdfcdc2 85 *
mbed_official 0:fd0d7bdfcdc2 86 * @param tptr pointer to the object to call the member function on
mbed_official 0:fd0d7bdfcdc2 87 * @param mptr pointer to the member function to be called
mbed_official 0:fd0d7bdfcdc2 88 */
mbed_official 0:fd0d7bdfcdc2 89 template<typename T>
mbed_official 0:fd0d7bdfcdc2 90 void rise(T* tptr, void (T::*mptr)(void)) {
mbed_official 0:fd0d7bdfcdc2 91 _rise.attach(tptr, mptr);
mbed_official 0:fd0d7bdfcdc2 92 gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
mbed_official 0:fd0d7bdfcdc2 93 }
mbed_official 0:fd0d7bdfcdc2 94
mbed_official 0:fd0d7bdfcdc2 95 /** Attach a function to call when a falling edge occurs on the input
mbed_official 0:fd0d7bdfcdc2 96 *
mbed_official 0:fd0d7bdfcdc2 97 * @param fptr A pointer to a void function, or 0 to set as none
mbed_official 0:fd0d7bdfcdc2 98 */
mbed_official 0:fd0d7bdfcdc2 99 void fall(void (*fptr)(void));
mbed_official 0:fd0d7bdfcdc2 100
mbed_official 0:fd0d7bdfcdc2 101 /** Attach a member function to call when a falling edge occurs on the input
mbed_official 0:fd0d7bdfcdc2 102 *
mbed_official 0:fd0d7bdfcdc2 103 * @param tptr pointer to the object to call the member function on
mbed_official 0:fd0d7bdfcdc2 104 * @param mptr pointer to the member function to be called
mbed_official 0:fd0d7bdfcdc2 105 */
mbed_official 0:fd0d7bdfcdc2 106 template<typename T>
mbed_official 0:fd0d7bdfcdc2 107 void fall(T* tptr, void (T::*mptr)(void)) {
mbed_official 0:fd0d7bdfcdc2 108 _fall.attach(tptr, mptr);
mbed_official 0:fd0d7bdfcdc2 109 gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
mbed_official 0:fd0d7bdfcdc2 110 }
mbed_official 0:fd0d7bdfcdc2 111
mbed_official 0:fd0d7bdfcdc2 112 /** Set the input pin mode
mbed_official 0:fd0d7bdfcdc2 113 *
mbed_official 0:fd0d7bdfcdc2 114 * @param mode PullUp, PullDown, PullNone
mbed_official 0:fd0d7bdfcdc2 115 */
mbed_official 0:fd0d7bdfcdc2 116 void mode(PinMode pull);
mbed_official 0:fd0d7bdfcdc2 117
mbed_official 0:fd0d7bdfcdc2 118 static void _irq_handler(uint32_t id, gpio_irq_event event);
mbed_official 0:fd0d7bdfcdc2 119
mbed_official 0:fd0d7bdfcdc2 120 protected:
mbed_official 0:fd0d7bdfcdc2 121 gpio_t gpio;
mbed_official 0:fd0d7bdfcdc2 122 gpio_irq_t gpio_irq;
mbed_official 0:fd0d7bdfcdc2 123
mbed_official 0:fd0d7bdfcdc2 124 FunctionPointer _rise;
mbed_official 0:fd0d7bdfcdc2 125 FunctionPointer _fall;
mbed_official 0:fd0d7bdfcdc2 126 };
mbed_official 0:fd0d7bdfcdc2 127
mbed_official 0:fd0d7bdfcdc2 128 } // namespace mbed
mbed_official 0:fd0d7bdfcdc2 129
mbed_official 0:fd0d7bdfcdc2 130 #endif
mbed_official 0:fd0d7bdfcdc2 131
mbed_official 0:fd0d7bdfcdc2 132 #endif