mbed.h library with any bug fixes AV finds.
Dependents: micromouse4_encoder_testing PID_Test Lab1_Test WorkingPID ... more
api/InterruptIn.h@0:ba7650f404af, 2015-11-02 (annotated)
- Committer:
- aravindsv
- Date:
- Mon Nov 02 02:26:59 2015 +0000
- Revision:
- 0:ba7650f404af
Reduced HSE_STARTUP_TIMEOUT to 500 ms, fixed some compiler warnings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aravindsv | 0:ba7650f404af | 1 | /* mbed Microcontroller Library |
aravindsv | 0:ba7650f404af | 2 | * Copyright (c) 2006-2013 ARM Limited |
aravindsv | 0:ba7650f404af | 3 | * |
aravindsv | 0:ba7650f404af | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
aravindsv | 0:ba7650f404af | 5 | * you may not use this file except in compliance with the License. |
aravindsv | 0:ba7650f404af | 6 | * You may obtain a copy of the License at |
aravindsv | 0:ba7650f404af | 7 | * |
aravindsv | 0:ba7650f404af | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
aravindsv | 0:ba7650f404af | 9 | * |
aravindsv | 0:ba7650f404af | 10 | * Unless required by applicable law or agreed to in writing, software |
aravindsv | 0:ba7650f404af | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
aravindsv | 0:ba7650f404af | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
aravindsv | 0:ba7650f404af | 13 | * See the License for the specific language governing permissions and |
aravindsv | 0:ba7650f404af | 14 | * limitations under the License. |
aravindsv | 0:ba7650f404af | 15 | */ |
aravindsv | 0:ba7650f404af | 16 | #ifndef MBED_INTERRUPTIN_H |
aravindsv | 0:ba7650f404af | 17 | #define MBED_INTERRUPTIN_H |
aravindsv | 0:ba7650f404af | 18 | |
aravindsv | 0:ba7650f404af | 19 | #include "platform.h" |
aravindsv | 0:ba7650f404af | 20 | |
aravindsv | 0:ba7650f404af | 21 | #if DEVICE_INTERRUPTIN |
aravindsv | 0:ba7650f404af | 22 | |
aravindsv | 0:ba7650f404af | 23 | #include "gpio_api.h" |
aravindsv | 0:ba7650f404af | 24 | #include "gpio_irq_api.h" |
aravindsv | 0:ba7650f404af | 25 | #include "FunctionPointer.h" |
aravindsv | 0:ba7650f404af | 26 | |
aravindsv | 0:ba7650f404af | 27 | namespace mbed { |
aravindsv | 0:ba7650f404af | 28 | |
aravindsv | 0:ba7650f404af | 29 | /** A digital interrupt input, used to call a function on a rising or falling edge |
aravindsv | 0:ba7650f404af | 30 | * |
aravindsv | 0:ba7650f404af | 31 | * Example: |
aravindsv | 0:ba7650f404af | 32 | * @code |
aravindsv | 0:ba7650f404af | 33 | * // Flash an LED while waiting for events |
aravindsv | 0:ba7650f404af | 34 | * |
aravindsv | 0:ba7650f404af | 35 | * #include "mbed.h" |
aravindsv | 0:ba7650f404af | 36 | * |
aravindsv | 0:ba7650f404af | 37 | * InterruptIn event(p16); |
aravindsv | 0:ba7650f404af | 38 | * DigitalOut led(LED1); |
aravindsv | 0:ba7650f404af | 39 | * |
aravindsv | 0:ba7650f404af | 40 | * void trigger() { |
aravindsv | 0:ba7650f404af | 41 | * printf("triggered!\n"); |
aravindsv | 0:ba7650f404af | 42 | * } |
aravindsv | 0:ba7650f404af | 43 | * |
aravindsv | 0:ba7650f404af | 44 | * int main() { |
aravindsv | 0:ba7650f404af | 45 | * event.rise(&trigger); |
aravindsv | 0:ba7650f404af | 46 | * while(1) { |
aravindsv | 0:ba7650f404af | 47 | * led = !led; |
aravindsv | 0:ba7650f404af | 48 | * wait(0.25); |
aravindsv | 0:ba7650f404af | 49 | * } |
aravindsv | 0:ba7650f404af | 50 | * } |
aravindsv | 0:ba7650f404af | 51 | * @endcode |
aravindsv | 0:ba7650f404af | 52 | */ |
aravindsv | 0:ba7650f404af | 53 | class InterruptIn { |
aravindsv | 0:ba7650f404af | 54 | |
aravindsv | 0:ba7650f404af | 55 | public: |
aravindsv | 0:ba7650f404af | 56 | |
aravindsv | 0:ba7650f404af | 57 | /** Create an InterruptIn connected to the specified pin |
aravindsv | 0:ba7650f404af | 58 | * |
aravindsv | 0:ba7650f404af | 59 | * @param pin InterruptIn pin to connect to |
aravindsv | 0:ba7650f404af | 60 | * @param name (optional) A string to identify the object |
aravindsv | 0:ba7650f404af | 61 | */ |
aravindsv | 0:ba7650f404af | 62 | InterruptIn(PinName pin); |
aravindsv | 0:ba7650f404af | 63 | virtual ~InterruptIn(); |
aravindsv | 0:ba7650f404af | 64 | |
aravindsv | 0:ba7650f404af | 65 | int read(); |
aravindsv | 0:ba7650f404af | 66 | #ifdef MBED_OPERATORS |
aravindsv | 0:ba7650f404af | 67 | operator int(); |
aravindsv | 0:ba7650f404af | 68 | |
aravindsv | 0:ba7650f404af | 69 | #endif |
aravindsv | 0:ba7650f404af | 70 | |
aravindsv | 0:ba7650f404af | 71 | /** Attach a function to call when a rising edge occurs on the input |
aravindsv | 0:ba7650f404af | 72 | * |
aravindsv | 0:ba7650f404af | 73 | * @param fptr A pointer to a void function, or 0 to set as none |
aravindsv | 0:ba7650f404af | 74 | */ |
aravindsv | 0:ba7650f404af | 75 | void rise(void (*fptr)(void)); |
aravindsv | 0:ba7650f404af | 76 | |
aravindsv | 0:ba7650f404af | 77 | /** Attach a member function to call when a rising edge occurs on the input |
aravindsv | 0:ba7650f404af | 78 | * |
aravindsv | 0:ba7650f404af | 79 | * @param tptr pointer to the object to call the member function on |
aravindsv | 0:ba7650f404af | 80 | * @param mptr pointer to the member function to be called |
aravindsv | 0:ba7650f404af | 81 | */ |
aravindsv | 0:ba7650f404af | 82 | template<typename T> |
aravindsv | 0:ba7650f404af | 83 | void rise(T* tptr, void (T::*mptr)(void)) { |
aravindsv | 0:ba7650f404af | 84 | _rise.attach(tptr, mptr); |
aravindsv | 0:ba7650f404af | 85 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
aravindsv | 0:ba7650f404af | 86 | } |
aravindsv | 0:ba7650f404af | 87 | |
aravindsv | 0:ba7650f404af | 88 | /** Attach a function to call when a falling edge occurs on the input |
aravindsv | 0:ba7650f404af | 89 | * |
aravindsv | 0:ba7650f404af | 90 | * @param fptr A pointer to a void function, or 0 to set as none |
aravindsv | 0:ba7650f404af | 91 | */ |
aravindsv | 0:ba7650f404af | 92 | void fall(void (*fptr)(void)); |
aravindsv | 0:ba7650f404af | 93 | |
aravindsv | 0:ba7650f404af | 94 | /** Attach a member function to call when a falling edge occurs on the input |
aravindsv | 0:ba7650f404af | 95 | * |
aravindsv | 0:ba7650f404af | 96 | * @param tptr pointer to the object to call the member function on |
aravindsv | 0:ba7650f404af | 97 | * @param mptr pointer to the member function to be called |
aravindsv | 0:ba7650f404af | 98 | */ |
aravindsv | 0:ba7650f404af | 99 | template<typename T> |
aravindsv | 0:ba7650f404af | 100 | void fall(T* tptr, void (T::*mptr)(void)) { |
aravindsv | 0:ba7650f404af | 101 | _fall.attach(tptr, mptr); |
aravindsv | 0:ba7650f404af | 102 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
aravindsv | 0:ba7650f404af | 103 | } |
aravindsv | 0:ba7650f404af | 104 | |
aravindsv | 0:ba7650f404af | 105 | /** Set the input pin mode |
aravindsv | 0:ba7650f404af | 106 | * |
aravindsv | 0:ba7650f404af | 107 | * @param mode PullUp, PullDown, PullNone |
aravindsv | 0:ba7650f404af | 108 | */ |
aravindsv | 0:ba7650f404af | 109 | void mode(PinMode pull); |
aravindsv | 0:ba7650f404af | 110 | |
aravindsv | 0:ba7650f404af | 111 | /** Enable IRQ. This method depends on hw implementation, might enable one |
aravindsv | 0:ba7650f404af | 112 | * port interrupts. For further information, check gpio_irq_enable(). |
aravindsv | 0:ba7650f404af | 113 | */ |
aravindsv | 0:ba7650f404af | 114 | void enable_irq(); |
aravindsv | 0:ba7650f404af | 115 | |
aravindsv | 0:ba7650f404af | 116 | /** Disable IRQ. This method depends on hw implementation, might disable one |
aravindsv | 0:ba7650f404af | 117 | * port interrupts. For further information, check gpio_irq_disable(). |
aravindsv | 0:ba7650f404af | 118 | */ |
aravindsv | 0:ba7650f404af | 119 | void disable_irq(); |
aravindsv | 0:ba7650f404af | 120 | |
aravindsv | 0:ba7650f404af | 121 | static void _irq_handler(uint32_t id, gpio_irq_event event); |
aravindsv | 0:ba7650f404af | 122 | |
aravindsv | 0:ba7650f404af | 123 | protected: |
aravindsv | 0:ba7650f404af | 124 | gpio_t gpio; |
aravindsv | 0:ba7650f404af | 125 | gpio_irq_t gpio_irq; |
aravindsv | 0:ba7650f404af | 126 | |
aravindsv | 0:ba7650f404af | 127 | FunctionPointer _rise; |
aravindsv | 0:ba7650f404af | 128 | FunctionPointer _fall; |
aravindsv | 0:ba7650f404af | 129 | }; |
aravindsv | 0:ba7650f404af | 130 | |
aravindsv | 0:ba7650f404af | 131 | } // namespace mbed |
aravindsv | 0:ba7650f404af | 132 | |
aravindsv | 0:ba7650f404af | 133 | #endif |
aravindsv | 0:ba7650f404af | 134 | |
aravindsv | 0:ba7650f404af | 135 | #endif |