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