Library

Dependents:   OSCTest_2

Fork of mbed by gokmen ascioglu

Committer:
gokmenascioglu
Date:
Sat Sep 22 10:32:07 2012 +0000
Revision:
0:a8fa94490a0a
alican library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gokmenascioglu 0:a8fa94490a0a 1 /* mbed Microcontroller Library - InterruptIn
gokmenascioglu 0:a8fa94490a0a 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
gokmenascioglu 0:a8fa94490a0a 3 */
gokmenascioglu 0:a8fa94490a0a 4
gokmenascioglu 0:a8fa94490a0a 5 #ifndef MBED_INTERRUPTIN_H
gokmenascioglu 0:a8fa94490a0a 6 #define MBED_INTERRUPTIN_H
gokmenascioglu 0:a8fa94490a0a 7
gokmenascioglu 0:a8fa94490a0a 8 #include "device.h"
gokmenascioglu 0:a8fa94490a0a 9
gokmenascioglu 0:a8fa94490a0a 10 #if DEVICE_INTERRUPTIN
gokmenascioglu 0:a8fa94490a0a 11
gokmenascioglu 0:a8fa94490a0a 12 #include "platform.h"
gokmenascioglu 0:a8fa94490a0a 13 #include "PinNames.h"
gokmenascioglu 0:a8fa94490a0a 14 #include "PeripheralNames.h"
gokmenascioglu 0:a8fa94490a0a 15 #include "Base.h"
gokmenascioglu 0:a8fa94490a0a 16 #include "FunctionPointer.h"
gokmenascioglu 0:a8fa94490a0a 17
gokmenascioglu 0:a8fa94490a0a 18 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
gokmenascioglu 0:a8fa94490a0a 19 #define CHANNEL_NUM 48
gokmenascioglu 0:a8fa94490a0a 20 #elif defined(TARGET_LPC11U24)
gokmenascioglu 0:a8fa94490a0a 21 #define CHANNEL_NUM 8
gokmenascioglu 0:a8fa94490a0a 22 #endif
gokmenascioglu 0:a8fa94490a0a 23
gokmenascioglu 0:a8fa94490a0a 24 namespace mbed {
gokmenascioglu 0:a8fa94490a0a 25
gokmenascioglu 0:a8fa94490a0a 26 /* Class: InterruptIn
gokmenascioglu 0:a8fa94490a0a 27 * A digital interrupt input, used to call a function on a rising or falling edge
gokmenascioglu 0:a8fa94490a0a 28 *
gokmenascioglu 0:a8fa94490a0a 29 * Example:
gokmenascioglu 0:a8fa94490a0a 30 * > // Flash an LED while waiting for events
gokmenascioglu 0:a8fa94490a0a 31 * >
gokmenascioglu 0:a8fa94490a0a 32 * > #include "mbed.h"
gokmenascioglu 0:a8fa94490a0a 33 * >
gokmenascioglu 0:a8fa94490a0a 34 * > InterruptIn event(p16);
gokmenascioglu 0:a8fa94490a0a 35 * > DigitalOut led(LED1);
gokmenascioglu 0:a8fa94490a0a 36 * >
gokmenascioglu 0:a8fa94490a0a 37 * > void trigger() {
gokmenascioglu 0:a8fa94490a0a 38 * > printf("triggered!\n");
gokmenascioglu 0:a8fa94490a0a 39 * > }
gokmenascioglu 0:a8fa94490a0a 40 * >
gokmenascioglu 0:a8fa94490a0a 41 * > int main() {
gokmenascioglu 0:a8fa94490a0a 42 * > event.rise(&trigger);
gokmenascioglu 0:a8fa94490a0a 43 * > while(1) {
gokmenascioglu 0:a8fa94490a0a 44 * > led = !led;
gokmenascioglu 0:a8fa94490a0a 45 * > wait(0.25);
gokmenascioglu 0:a8fa94490a0a 46 * > }
gokmenascioglu 0:a8fa94490a0a 47 * > }
gokmenascioglu 0:a8fa94490a0a 48 */
gokmenascioglu 0:a8fa94490a0a 49 class InterruptIn : public Base {
gokmenascioglu 0:a8fa94490a0a 50
gokmenascioglu 0:a8fa94490a0a 51 public:
gokmenascioglu 0:a8fa94490a0a 52
gokmenascioglu 0:a8fa94490a0a 53 /* Constructor: InterruptIn
gokmenascioglu 0:a8fa94490a0a 54 * Create an InterruptIn connected to the specified pin
gokmenascioglu 0:a8fa94490a0a 55 *
gokmenascioglu 0:a8fa94490a0a 56 * Variables:
gokmenascioglu 0:a8fa94490a0a 57 * pin - InterruptIn pin to connect to
gokmenascioglu 0:a8fa94490a0a 58 * name - (optional) A string to identify the object
gokmenascioglu 0:a8fa94490a0a 59 */
gokmenascioglu 0:a8fa94490a0a 60 InterruptIn(PinName pin, const char *name = NULL);
gokmenascioglu 0:a8fa94490a0a 61 #if defined(TARGET_LPC11U24)
gokmenascioglu 0:a8fa94490a0a 62 virtual ~InterruptIn();
gokmenascioglu 0:a8fa94490a0a 63 #endif
gokmenascioglu 0:a8fa94490a0a 64
gokmenascioglu 0:a8fa94490a0a 65 int read();
gokmenascioglu 0:a8fa94490a0a 66 #ifdef MBED_OPERATORS
gokmenascioglu 0:a8fa94490a0a 67 operator int();
gokmenascioglu 0:a8fa94490a0a 68
gokmenascioglu 0:a8fa94490a0a 69 #endif
gokmenascioglu 0:a8fa94490a0a 70
gokmenascioglu 0:a8fa94490a0a 71 /* Function: rise
gokmenascioglu 0:a8fa94490a0a 72 * Attach a function to call when a rising edge occurs on the input
gokmenascioglu 0:a8fa94490a0a 73 *
gokmenascioglu 0:a8fa94490a0a 74 * Variables:
gokmenascioglu 0:a8fa94490a0a 75 * fptr - A pointer to a void function, or 0 to set as none
gokmenascioglu 0:a8fa94490a0a 76 */
gokmenascioglu 0:a8fa94490a0a 77 void rise(void (*fptr)(void));
gokmenascioglu 0:a8fa94490a0a 78
gokmenascioglu 0:a8fa94490a0a 79 /* Function: rise
gokmenascioglu 0:a8fa94490a0a 80 * Attach a member function to call when a rising edge occurs on the input
gokmenascioglu 0:a8fa94490a0a 81 *
gokmenascioglu 0:a8fa94490a0a 82 * Variables:
gokmenascioglu 0:a8fa94490a0a 83 * tptr - pointer to the object to call the member function on
gokmenascioglu 0:a8fa94490a0a 84 * mptr - pointer to the member function to be called
gokmenascioglu 0:a8fa94490a0a 85 */
gokmenascioglu 0:a8fa94490a0a 86 template<typename T>
gokmenascioglu 0:a8fa94490a0a 87 void rise(T* tptr, void (T::*mptr)(void)) {
gokmenascioglu 0:a8fa94490a0a 88 _rise.attach(tptr, mptr);
gokmenascioglu 0:a8fa94490a0a 89 setup_interrupt(1, 1);
gokmenascioglu 0:a8fa94490a0a 90 }
gokmenascioglu 0:a8fa94490a0a 91
gokmenascioglu 0:a8fa94490a0a 92 /* Function: fall
gokmenascioglu 0:a8fa94490a0a 93 * Attach a function to call when a falling edge occurs on the input
gokmenascioglu 0:a8fa94490a0a 94 *
gokmenascioglu 0:a8fa94490a0a 95 * Variables:
gokmenascioglu 0:a8fa94490a0a 96 * fptr - A pointer to a void function, or 0 to set as none
gokmenascioglu 0:a8fa94490a0a 97 */
gokmenascioglu 0:a8fa94490a0a 98 void fall(void (*fptr)(void));
gokmenascioglu 0:a8fa94490a0a 99
gokmenascioglu 0:a8fa94490a0a 100 /* Function: fall
gokmenascioglu 0:a8fa94490a0a 101 * Attach a member function to call when a falling edge occurs on the input
gokmenascioglu 0:a8fa94490a0a 102 *
gokmenascioglu 0:a8fa94490a0a 103 * Variables:
gokmenascioglu 0:a8fa94490a0a 104 * tptr - pointer to the object to call the member function on
gokmenascioglu 0:a8fa94490a0a 105 * mptr - pointer to the member function to be called
gokmenascioglu 0:a8fa94490a0a 106 */
gokmenascioglu 0:a8fa94490a0a 107 template<typename T>
gokmenascioglu 0:a8fa94490a0a 108 void fall(T* tptr, void (T::*mptr)(void)) {
gokmenascioglu 0:a8fa94490a0a 109 _fall.attach(tptr, mptr);
gokmenascioglu 0:a8fa94490a0a 110 setup_interrupt(0, 1);
gokmenascioglu 0:a8fa94490a0a 111 }
gokmenascioglu 0:a8fa94490a0a 112
gokmenascioglu 0:a8fa94490a0a 113 /* Function: mode
gokmenascioglu 0:a8fa94490a0a 114 * Set the input pin mode
gokmenascioglu 0:a8fa94490a0a 115 *
gokmenascioglu 0:a8fa94490a0a 116 * Variables:
gokmenascioglu 0:a8fa94490a0a 117 * mode - PullUp, PullDown, PullNone
gokmenascioglu 0:a8fa94490a0a 118 */
gokmenascioglu 0:a8fa94490a0a 119 void mode(PinMode pull);
gokmenascioglu 0:a8fa94490a0a 120
gokmenascioglu 0:a8fa94490a0a 121 static InterruptIn *_irq_objects[CHANNEL_NUM];
gokmenascioglu 0:a8fa94490a0a 122
gokmenascioglu 0:a8fa94490a0a 123 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
gokmenascioglu 0:a8fa94490a0a 124 static void _irq();
gokmenascioglu 0:a8fa94490a0a 125 #elif defined(TARGET_LPC11U24)
gokmenascioglu 0:a8fa94490a0a 126 static void handle_interrupt_in(unsigned int channel);
gokmenascioglu 0:a8fa94490a0a 127 static void _irq0(); static void _irq1();
gokmenascioglu 0:a8fa94490a0a 128 static void _irq2(); static void _irq3();
gokmenascioglu 0:a8fa94490a0a 129 static void _irq4(); static void _irq5();
gokmenascioglu 0:a8fa94490a0a 130 static void _irq6(); static void _irq7();
gokmenascioglu 0:a8fa94490a0a 131 #endif
gokmenascioglu 0:a8fa94490a0a 132
gokmenascioglu 0:a8fa94490a0a 133 protected:
gokmenascioglu 0:a8fa94490a0a 134 PinName _pin;
gokmenascioglu 0:a8fa94490a0a 135 #if defined(TARGET_LPC11U24)
gokmenascioglu 0:a8fa94490a0a 136 Channel _channel;
gokmenascioglu 0:a8fa94490a0a 137 #endif
gokmenascioglu 0:a8fa94490a0a 138 FunctionPointer _rise;
gokmenascioglu 0:a8fa94490a0a 139 FunctionPointer _fall;
gokmenascioglu 0:a8fa94490a0a 140
gokmenascioglu 0:a8fa94490a0a 141 void setup_interrupt(int rising, int enable);
gokmenascioglu 0:a8fa94490a0a 142
gokmenascioglu 0:a8fa94490a0a 143 };
gokmenascioglu 0:a8fa94490a0a 144
gokmenascioglu 0:a8fa94490a0a 145 } // namespace mbed
gokmenascioglu 0:a8fa94490a0a 146
gokmenascioglu 0:a8fa94490a0a 147 #endif
gokmenascioglu 0:a8fa94490a0a 148
gokmenascioglu 0:a8fa94490a0a 149 #endif