This is a repository for all my programs or modified programs.

Committer:
mturner5
Date:
Sun Sep 11 23:48:09 2016 +0000
Revision:
0:72480818e4a9
Made delays for the LEDS and button presses

Who changed what in which revision?

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