mbed libraries for KL25Z
InterruptIn.h@7:73c5efe92a6c, 2012-10-23 (annotated)
- Committer:
- emilmont
- Date:
- Tue Oct 23 09:20:18 2012 +0000
- Revision:
- 7:73c5efe92a6c
- Parent:
- 0:8024c367e29f
- Child:
- 8:c14af7958ef5
Make the C++ library completely TARGET independent.; Implement "gpio_irq_api" and "port_api" to 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 | 7:73c5efe92a6c | 3 | */ |
emilmont | 0:8024c367e29f | 4 | #ifndef MBED_INTERRUPTIN_H |
emilmont | 0:8024c367e29f | 5 | #define MBED_INTERRUPTIN_H |
emilmont | 0:8024c367e29f | 6 | |
emilmont | 0:8024c367e29f | 7 | #include "device.h" |
emilmont | 0:8024c367e29f | 8 | |
emilmont | 0:8024c367e29f | 9 | #if DEVICE_INTERRUPTIN |
emilmont | 0:8024c367e29f | 10 | |
emilmont | 7:73c5efe92a6c | 11 | #include "gpio_api.h" |
emilmont | 7:73c5efe92a6c | 12 | #include "gpio_irq_api.h" |
emilmont | 7:73c5efe92a6c | 13 | |
emilmont | 0:8024c367e29f | 14 | #include "platform.h" |
emilmont | 0:8024c367e29f | 15 | #include "Base.h" |
emilmont | 0:8024c367e29f | 16 | #include "FunctionPointer.h" |
emilmont | 0:8024c367e29f | 17 | |
emilmont | 0:8024c367e29f | 18 | namespace mbed { |
emilmont | 0:8024c367e29f | 19 | |
emilmont | 0:8024c367e29f | 20 | /* Class: InterruptIn |
emilmont | 0:8024c367e29f | 21 | * A digital interrupt input, used to call a function on a rising or falling edge |
emilmont | 0:8024c367e29f | 22 | * |
emilmont | 0:8024c367e29f | 23 | * Example: |
emilmont | 0:8024c367e29f | 24 | * > // Flash an LED while waiting for events |
emilmont | 0:8024c367e29f | 25 | * > |
emilmont | 0:8024c367e29f | 26 | * > #include "mbed.h" |
emilmont | 0:8024c367e29f | 27 | * > |
emilmont | 0:8024c367e29f | 28 | * > InterruptIn event(p16); |
emilmont | 0:8024c367e29f | 29 | * > DigitalOut led(LED1); |
emilmont | 0:8024c367e29f | 30 | * > |
emilmont | 0:8024c367e29f | 31 | * > void trigger() { |
emilmont | 0:8024c367e29f | 32 | * > printf("triggered!\n"); |
emilmont | 0:8024c367e29f | 33 | * > } |
emilmont | 0:8024c367e29f | 34 | * > |
emilmont | 0:8024c367e29f | 35 | * > int main() { |
emilmont | 0:8024c367e29f | 36 | * > event.rise(&trigger); |
emilmont | 0:8024c367e29f | 37 | * > while(1) { |
emilmont | 0:8024c367e29f | 38 | * > led = !led; |
emilmont | 0:8024c367e29f | 39 | * > wait(0.25); |
emilmont | 0:8024c367e29f | 40 | * > } |
emilmont | 0:8024c367e29f | 41 | * > } |
emilmont | 0:8024c367e29f | 42 | */ |
emilmont | 0:8024c367e29f | 43 | class InterruptIn : public Base { |
emilmont | 0:8024c367e29f | 44 | |
emilmont | 0:8024c367e29f | 45 | public: |
emilmont | 0:8024c367e29f | 46 | |
emilmont | 0:8024c367e29f | 47 | /* Constructor: InterruptIn |
emilmont | 0:8024c367e29f | 48 | * Create an InterruptIn connected to the specified pin |
emilmont | 0:8024c367e29f | 49 | * |
emilmont | 0:8024c367e29f | 50 | * Variables: |
emilmont | 0:8024c367e29f | 51 | * pin - InterruptIn pin to connect to |
emilmont | 0:8024c367e29f | 52 | * name - (optional) A string to identify the object |
emilmont | 0:8024c367e29f | 53 | */ |
emilmont | 0:8024c367e29f | 54 | InterruptIn(PinName pin, const char *name = NULL); |
emilmont | 0:8024c367e29f | 55 | virtual ~InterruptIn(); |
emilmont | 0:8024c367e29f | 56 | |
emilmont | 0:8024c367e29f | 57 | int read(); |
emilmont | 0:8024c367e29f | 58 | #ifdef MBED_OPERATORS |
emilmont | 0:8024c367e29f | 59 | operator int(); |
emilmont | 0:8024c367e29f | 60 | |
emilmont | 0:8024c367e29f | 61 | #endif |
emilmont | 0:8024c367e29f | 62 | |
emilmont | 0:8024c367e29f | 63 | /* Function: rise |
emilmont | 0:8024c367e29f | 64 | * Attach a function to call when a rising edge occurs on the input |
emilmont | 0:8024c367e29f | 65 | * |
emilmont | 0:8024c367e29f | 66 | * Variables: |
emilmont | 0:8024c367e29f | 67 | * fptr - A pointer to a void function, or 0 to set as none |
emilmont | 0:8024c367e29f | 68 | */ |
emilmont | 0:8024c367e29f | 69 | void rise(void (*fptr)(void)); |
emilmont | 0:8024c367e29f | 70 | |
emilmont | 0:8024c367e29f | 71 | /* Function: rise |
emilmont | 0:8024c367e29f | 72 | * Attach a member function to call when a rising edge occurs on the input |
emilmont | 0:8024c367e29f | 73 | * |
emilmont | 0:8024c367e29f | 74 | * Variables: |
emilmont | 0:8024c367e29f | 75 | * tptr - pointer to the object to call the member function on |
emilmont | 0:8024c367e29f | 76 | * mptr - pointer to the member function to be called |
emilmont | 0:8024c367e29f | 77 | */ |
emilmont | 0:8024c367e29f | 78 | template<typename T> |
emilmont | 0:8024c367e29f | 79 | void rise(T* tptr, void (T::*mptr)(void)) { |
emilmont | 0:8024c367e29f | 80 | _rise.attach(tptr, mptr); |
emilmont | 7:73c5efe92a6c | 81 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
emilmont | 0:8024c367e29f | 82 | } |
emilmont | 0:8024c367e29f | 83 | |
emilmont | 0:8024c367e29f | 84 | /* Function: fall |
emilmont | 0:8024c367e29f | 85 | * Attach a function to call when a falling edge occurs on the input |
emilmont | 0:8024c367e29f | 86 | * |
emilmont | 0:8024c367e29f | 87 | * Variables: |
emilmont | 0:8024c367e29f | 88 | * fptr - A pointer to a void function, or 0 to set as none |
emilmont | 0:8024c367e29f | 89 | */ |
emilmont | 0:8024c367e29f | 90 | void fall(void (*fptr)(void)); |
emilmont | 0:8024c367e29f | 91 | |
emilmont | 0:8024c367e29f | 92 | /* Function: fall |
emilmont | 0:8024c367e29f | 93 | * Attach a member function to call when a falling edge occurs on the input |
emilmont | 0:8024c367e29f | 94 | * |
emilmont | 0:8024c367e29f | 95 | * Variables: |
emilmont | 0:8024c367e29f | 96 | * tptr - pointer to the object to call the member function on |
emilmont | 0:8024c367e29f | 97 | * mptr - pointer to the member function to be called |
emilmont | 0:8024c367e29f | 98 | */ |
emilmont | 0:8024c367e29f | 99 | template<typename T> |
emilmont | 0:8024c367e29f | 100 | void fall(T* tptr, void (T::*mptr)(void)) { |
emilmont | 0:8024c367e29f | 101 | _fall.attach(tptr, mptr); |
emilmont | 7:73c5efe92a6c | 102 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
emilmont | 0:8024c367e29f | 103 | } |
emilmont | 0:8024c367e29f | 104 | |
emilmont | 0:8024c367e29f | 105 | /* Function: mode |
emilmont | 0:8024c367e29f | 106 | * Set the input pin mode |
emilmont | 0:8024c367e29f | 107 | * |
emilmont | 0:8024c367e29f | 108 | * Variables: |
emilmont | 0:8024c367e29f | 109 | * mode - PullUp, PullDown, PullNone |
emilmont | 0:8024c367e29f | 110 | */ |
emilmont | 0:8024c367e29f | 111 | void mode(PinMode pull); |
emilmont | 0:8024c367e29f | 112 | |
emilmont | 7:73c5efe92a6c | 113 | static void _irq_handler(uint32_t id, gpio_irq_event event); |
emilmont | 0:8024c367e29f | 114 | |
emilmont | 0:8024c367e29f | 115 | protected: |
emilmont | 0:8024c367e29f | 116 | gpio_object gpio; |
emilmont | 7:73c5efe92a6c | 117 | gpio_irq_object gpio_irq; |
emilmont | 7:73c5efe92a6c | 118 | |
emilmont | 0:8024c367e29f | 119 | FunctionPointer _rise; |
emilmont | 0:8024c367e29f | 120 | FunctionPointer _fall; |
emilmont | 0:8024c367e29f | 121 | }; |
emilmont | 0:8024c367e29f | 122 | |
emilmont | 0:8024c367e29f | 123 | } // namespace mbed |
emilmont | 0:8024c367e29f | 124 | |
emilmont | 0:8024c367e29f | 125 | #endif |
emilmont | 0:8024c367e29f | 126 | |
emilmont | 0:8024c367e29f | 127 | #endif |