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