SD card interface

Committer:
lharoon
Date:
Mon Oct 08 11:14:07 2012 +0000
Revision:
0:22612ae617a0
1st edition

Who changed what in which revision?

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