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