This is my quadcopter prototype software, still in development!

Committer:
Anaesthetix
Date:
Tue Jul 23 14:01:42 2013 +0000
Revision:
1:ac68f0368a77
Parent:
0:978110f7f027
Other accelerometer added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anaesthetix 0:978110f7f027 1 /* mbed Microcontroller Library - InterruptIn
Anaesthetix 0:978110f7f027 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
Anaesthetix 0:978110f7f027 3 */
Anaesthetix 0:978110f7f027 4
Anaesthetix 0:978110f7f027 5 #ifndef MBED_INTERRUPTIN_H
Anaesthetix 0:978110f7f027 6 #define MBED_INTERRUPTIN_H
Anaesthetix 0:978110f7f027 7
Anaesthetix 0:978110f7f027 8 #include "device.h"
Anaesthetix 0:978110f7f027 9
Anaesthetix 0:978110f7f027 10 #if DEVICE_INTERRUPTIN
Anaesthetix 0:978110f7f027 11
Anaesthetix 0:978110f7f027 12 #include "platform.h"
Anaesthetix 0:978110f7f027 13 #include "PinNames.h"
Anaesthetix 0:978110f7f027 14 #include "PeripheralNames.h"
Anaesthetix 0:978110f7f027 15 #include "Base.h"
Anaesthetix 0:978110f7f027 16 #include "FunctionPointer.h"
Anaesthetix 0:978110f7f027 17
Anaesthetix 0:978110f7f027 18 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
Anaesthetix 0:978110f7f027 19 #define CHANNEL_NUM 48
Anaesthetix 0:978110f7f027 20 #elif defined(TARGET_LPC11U24)
Anaesthetix 0:978110f7f027 21 #define CHANNEL_NUM 8
Anaesthetix 0:978110f7f027 22 #endif
Anaesthetix 0:978110f7f027 23
Anaesthetix 0:978110f7f027 24 namespace mbed {
Anaesthetix 0:978110f7f027 25
Anaesthetix 0:978110f7f027 26 /* Class: InterruptIn
Anaesthetix 0:978110f7f027 27 * A digital interrupt input, used to call a function on a rising or falling edge
Anaesthetix 0:978110f7f027 28 *
Anaesthetix 0:978110f7f027 29 * Example:
Anaesthetix 0:978110f7f027 30 * > // Flash an LED while waiting for events
Anaesthetix 0:978110f7f027 31 * >
Anaesthetix 0:978110f7f027 32 * > #include "mbed.h"
Anaesthetix 0:978110f7f027 33 * >
Anaesthetix 0:978110f7f027 34 * > InterruptIn event(p16);
Anaesthetix 0:978110f7f027 35 * > DigitalOut led(LED1);
Anaesthetix 0:978110f7f027 36 * >
Anaesthetix 0:978110f7f027 37 * > void trigger() {
Anaesthetix 0:978110f7f027 38 * > printf("triggered!\n");
Anaesthetix 0:978110f7f027 39 * > }
Anaesthetix 0:978110f7f027 40 * >
Anaesthetix 0:978110f7f027 41 * > int main() {
Anaesthetix 0:978110f7f027 42 * > event.rise(&trigger);
Anaesthetix 0:978110f7f027 43 * > while(1) {
Anaesthetix 0:978110f7f027 44 * > led = !led;
Anaesthetix 0:978110f7f027 45 * > wait(0.25);
Anaesthetix 0:978110f7f027 46 * > }
Anaesthetix 0:978110f7f027 47 * > }
Anaesthetix 0:978110f7f027 48 */
Anaesthetix 0:978110f7f027 49 class InterruptIn : public Base {
Anaesthetix 0:978110f7f027 50
Anaesthetix 0:978110f7f027 51 public:
Anaesthetix 0:978110f7f027 52
Anaesthetix 0:978110f7f027 53 /* Constructor: InterruptIn
Anaesthetix 0:978110f7f027 54 * Create an InterruptIn connected to the specified pin
Anaesthetix 0:978110f7f027 55 *
Anaesthetix 0:978110f7f027 56 * Variables:
Anaesthetix 0:978110f7f027 57 * pin - InterruptIn pin to connect to
Anaesthetix 0:978110f7f027 58 * name - (optional) A string to identify the object
Anaesthetix 0:978110f7f027 59 */
Anaesthetix 0:978110f7f027 60 InterruptIn(PinName pin, const char *name = NULL);
Anaesthetix 0:978110f7f027 61 #if defined(TARGET_LPC11U24)
Anaesthetix 0:978110f7f027 62 virtual ~InterruptIn();
Anaesthetix 0:978110f7f027 63 #endif
Anaesthetix 0:978110f7f027 64
Anaesthetix 0:978110f7f027 65 int read();
Anaesthetix 0:978110f7f027 66 #ifdef MBED_OPERATORS
Anaesthetix 0:978110f7f027 67 operator int();
Anaesthetix 0:978110f7f027 68
Anaesthetix 0:978110f7f027 69 #endif
Anaesthetix 0:978110f7f027 70
Anaesthetix 0:978110f7f027 71 /* Function: rise
Anaesthetix 0:978110f7f027 72 * Attach a function to call when a rising edge occurs on the input
Anaesthetix 0:978110f7f027 73 *
Anaesthetix 0:978110f7f027 74 * Variables:
Anaesthetix 0:978110f7f027 75 * fptr - A pointer to a void function, or 0 to set as none
Anaesthetix 0:978110f7f027 76 */
Anaesthetix 0:978110f7f027 77 void rise(void (*fptr)(void));
Anaesthetix 0:978110f7f027 78
Anaesthetix 0:978110f7f027 79 /* Function: rise
Anaesthetix 0:978110f7f027 80 * Attach a member function to call when a rising edge occurs on the input
Anaesthetix 0:978110f7f027 81 *
Anaesthetix 0:978110f7f027 82 * Variables:
Anaesthetix 0:978110f7f027 83 * tptr - pointer to the object to call the member function on
Anaesthetix 0:978110f7f027 84 * mptr - pointer to the member function to be called
Anaesthetix 0:978110f7f027 85 */
Anaesthetix 0:978110f7f027 86 template<typename T>
Anaesthetix 0:978110f7f027 87 void rise(T* tptr, void (T::*mptr)(void)) {
Anaesthetix 0:978110f7f027 88 _rise.attach(tptr, mptr);
Anaesthetix 0:978110f7f027 89 setup_interrupt(1, 1);
Anaesthetix 0:978110f7f027 90 }
Anaesthetix 0:978110f7f027 91
Anaesthetix 0:978110f7f027 92 /* Function: fall
Anaesthetix 0:978110f7f027 93 * Attach a function to call when a falling edge occurs on the input
Anaesthetix 0:978110f7f027 94 *
Anaesthetix 0:978110f7f027 95 * Variables:
Anaesthetix 0:978110f7f027 96 * fptr - A pointer to a void function, or 0 to set as none
Anaesthetix 0:978110f7f027 97 */
Anaesthetix 0:978110f7f027 98 void fall(void (*fptr)(void));
Anaesthetix 0:978110f7f027 99
Anaesthetix 0:978110f7f027 100 /* Function: fall
Anaesthetix 0:978110f7f027 101 * Attach a member function to call when a falling edge occurs on the input
Anaesthetix 0:978110f7f027 102 *
Anaesthetix 0:978110f7f027 103 * Variables:
Anaesthetix 0:978110f7f027 104 * tptr - pointer to the object to call the member function on
Anaesthetix 0:978110f7f027 105 * mptr - pointer to the member function to be called
Anaesthetix 0:978110f7f027 106 */
Anaesthetix 0:978110f7f027 107 template<typename T>
Anaesthetix 0:978110f7f027 108 void fall(T* tptr, void (T::*mptr)(void)) {
Anaesthetix 0:978110f7f027 109 _fall.attach(tptr, mptr);
Anaesthetix 0:978110f7f027 110 setup_interrupt(0, 1);
Anaesthetix 0:978110f7f027 111 }
Anaesthetix 0:978110f7f027 112
Anaesthetix 0:978110f7f027 113 /* Function: mode
Anaesthetix 0:978110f7f027 114 * Set the input pin mode
Anaesthetix 0:978110f7f027 115 *
Anaesthetix 0:978110f7f027 116 * Variables:
Anaesthetix 0:978110f7f027 117 * mode - PullUp, PullDown, PullNone
Anaesthetix 0:978110f7f027 118 */
Anaesthetix 0:978110f7f027 119 void mode(PinMode pull);
Anaesthetix 0:978110f7f027 120
Anaesthetix 0:978110f7f027 121 static InterruptIn *_irq_objects[CHANNEL_NUM];
Anaesthetix 0:978110f7f027 122
Anaesthetix 0:978110f7f027 123 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
Anaesthetix 0:978110f7f027 124 static void _irq();
Anaesthetix 0:978110f7f027 125 #elif defined(TARGET_LPC11U24)
Anaesthetix 0:978110f7f027 126 static void handle_interrupt_in(unsigned int channel);
Anaesthetix 0:978110f7f027 127 static void _irq0(); static void _irq1();
Anaesthetix 0:978110f7f027 128 static void _irq2(); static void _irq3();
Anaesthetix 0:978110f7f027 129 static void _irq4(); static void _irq5();
Anaesthetix 0:978110f7f027 130 static void _irq6(); static void _irq7();
Anaesthetix 0:978110f7f027 131 #endif
Anaesthetix 0:978110f7f027 132
Anaesthetix 0:978110f7f027 133 protected:
Anaesthetix 0:978110f7f027 134 PinName _pin;
Anaesthetix 0:978110f7f027 135 #if defined(TARGET_LPC11U24)
Anaesthetix 0:978110f7f027 136 Channel _channel;
Anaesthetix 0:978110f7f027 137 #endif
Anaesthetix 0:978110f7f027 138 FunctionPointer _rise;
Anaesthetix 0:978110f7f027 139 FunctionPointer _fall;
Anaesthetix 0:978110f7f027 140
Anaesthetix 0:978110f7f027 141 void setup_interrupt(int rising, int enable);
Anaesthetix 0:978110f7f027 142
Anaesthetix 0:978110f7f027 143 };
Anaesthetix 0:978110f7f027 144
Anaesthetix 0:978110f7f027 145 } // namespace mbed
Anaesthetix 0:978110f7f027 146
Anaesthetix 0:978110f7f027 147 #endif
Anaesthetix 0:978110f7f027 148
Anaesthetix 0:978110f7f027 149 #endif