mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Nov 09 11:33:53 2012 +0000
Revision:
8:c14af7958ef5
Parent:
7:73c5efe92a6c
Child:
9:663789d7729f
SPI driver; ADC driver; DAC driver; microlib support; general bugfixing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 0:8024c367e29f 1 /* mbed Microcontroller Library - InterruptIn
emilmont 0:8024c367e29f 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
emilmont 7:73c5efe92a6c 3 */
emilmont 0:8024c367e29f 4 #ifndef MBED_INTERRUPTIN_H
emilmont 0:8024c367e29f 5 #define MBED_INTERRUPTIN_H
emilmont 0:8024c367e29f 6
emilmont 8:c14af7958ef5 7 #include "platform.h"
emilmont 0:8024c367e29f 8
emilmont 0:8024c367e29f 9 #if DEVICE_INTERRUPTIN
emilmont 0:8024c367e29f 10
emilmont 7:73c5efe92a6c 11 #include "gpio_api.h"
emilmont 7:73c5efe92a6c 12 #include "gpio_irq_api.h"
emilmont 7:73c5efe92a6c 13
emilmont 0:8024c367e29f 14 #include "FunctionPointer.h"
emilmont 0:8024c367e29f 15
emilmont 0:8024c367e29f 16 namespace mbed {
emilmont 0:8024c367e29f 17
emilmont 8:c14af7958ef5 18 /** A digital interrupt input, used to call a function on a rising or falling edge
emilmont 0:8024c367e29f 19 *
emilmont 0:8024c367e29f 20 * Example:
emilmont 8:c14af7958ef5 21 * @code
emilmont 8:c14af7958ef5 22 * // Flash an LED while waiting for events
emilmont 8:c14af7958ef5 23 *
emilmont 8:c14af7958ef5 24 * #include "mbed.h"
emilmont 8:c14af7958ef5 25 *
emilmont 8:c14af7958ef5 26 * InterruptIn event(p16);
emilmont 8:c14af7958ef5 27 * DigitalOut led(LED1);
emilmont 8:c14af7958ef5 28 *
emilmont 8:c14af7958ef5 29 * void trigger() {
emilmont 8:c14af7958ef5 30 * printf("triggered!\n");
emilmont 8:c14af7958ef5 31 * }
emilmont 8:c14af7958ef5 32 *
emilmont 8:c14af7958ef5 33 * int main() {
emilmont 8:c14af7958ef5 34 * event.rise(&trigger);
emilmont 8:c14af7958ef5 35 * while(1) {
emilmont 8:c14af7958ef5 36 * led = !led;
emilmont 8:c14af7958ef5 37 * wait(0.25);
emilmont 8:c14af7958ef5 38 * }
emilmont 8:c14af7958ef5 39 * }
emilmont 8:c14af7958ef5 40 * @endcode
emilmont 0:8024c367e29f 41 */
emilmont 8:c14af7958ef5 42 class InterruptIn {
emilmont 0:8024c367e29f 43
emilmont 0:8024c367e29f 44 public:
emilmont 0:8024c367e29f 45
emilmont 8:c14af7958ef5 46 /** Create an InterruptIn connected to the specified pin
emilmont 0:8024c367e29f 47 *
emilmont 8:c14af7958ef5 48 * @param pin InterruptIn pin to connect to
emilmont 8:c14af7958ef5 49 * @param name (optional) A string to identify the object
emilmont 0:8024c367e29f 50 */
emilmont 8:c14af7958ef5 51 InterruptIn(PinName pin);
emilmont 0:8024c367e29f 52 virtual ~InterruptIn();
emilmont 8:c14af7958ef5 53
emilmont 0:8024c367e29f 54 int read();
emilmont 0:8024c367e29f 55 #ifdef MBED_OPERATORS
emilmont 0:8024c367e29f 56 operator int();
emilmont 0:8024c367e29f 57
emilmont 0:8024c367e29f 58 #endif
emilmont 0:8024c367e29f 59
emilmont 8:c14af7958ef5 60 /** Attach a function to call when a rising edge occurs on the input
emilmont 0:8024c367e29f 61 *
emilmont 8:c14af7958ef5 62 * @param fptr A pointer to a void function, or 0 to set as none
emilmont 0:8024c367e29f 63 */
emilmont 0:8024c367e29f 64 void rise(void (*fptr)(void));
emilmont 0:8024c367e29f 65
emilmont 8:c14af7958ef5 66 /** Attach a member function to call when a rising edge occurs on the input
emilmont 0:8024c367e29f 67 *
emilmont 8:c14af7958ef5 68 * @param tptr pointer to the object to call the member function on
emilmont 8:c14af7958ef5 69 * @param mptr pointer to the member function to be called
emilmont 0:8024c367e29f 70 */
emilmont 0:8024c367e29f 71 template<typename T>
emilmont 0:8024c367e29f 72 void rise(T* tptr, void (T::*mptr)(void)) {
emilmont 0:8024c367e29f 73 _rise.attach(tptr, mptr);
emilmont 7:73c5efe92a6c 74 gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
emilmont 0:8024c367e29f 75 }
emilmont 0:8024c367e29f 76
emilmont 8:c14af7958ef5 77 /** Attach a function to call when a falling edge occurs on the input
emilmont 0:8024c367e29f 78 *
emilmont 8:c14af7958ef5 79 * @param fptr A pointer to a void function, or 0 to set as none
emilmont 0:8024c367e29f 80 */
emilmont 0:8024c367e29f 81 void fall(void (*fptr)(void));
emilmont 0:8024c367e29f 82
emilmont 8:c14af7958ef5 83 /** Attach a member function to call when a falling edge occurs on the input
emilmont 0:8024c367e29f 84 *
emilmont 8:c14af7958ef5 85 * @param tptr pointer to the object to call the member function on
emilmont 8:c14af7958ef5 86 * @param mptr pointer to the member function to be called
emilmont 0:8024c367e29f 87 */
emilmont 0:8024c367e29f 88 template<typename T>
emilmont 0:8024c367e29f 89 void fall(T* tptr, void (T::*mptr)(void)) {
emilmont 0:8024c367e29f 90 _fall.attach(tptr, mptr);
emilmont 7:73c5efe92a6c 91 gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
emilmont 0:8024c367e29f 92 }
emilmont 0:8024c367e29f 93
emilmont 8:c14af7958ef5 94 /** Set the input pin mode
emilmont 0:8024c367e29f 95 *
emilmont 8:c14af7958ef5 96 * @param mode PullUp, PullDown, PullNone
emilmont 0:8024c367e29f 97 */
emilmont 0:8024c367e29f 98 void mode(PinMode pull);
emilmont 0:8024c367e29f 99
emilmont 7:73c5efe92a6c 100 static void _irq_handler(uint32_t id, gpio_irq_event event);
emilmont 0:8024c367e29f 101
emilmont 0:8024c367e29f 102 protected:
emilmont 0:8024c367e29f 103 gpio_object gpio;
emilmont 7:73c5efe92a6c 104 gpio_irq_object gpio_irq;
emilmont 7:73c5efe92a6c 105
emilmont 0:8024c367e29f 106 FunctionPointer _rise;
emilmont 0:8024c367e29f 107 FunctionPointer _fall;
emilmont 0:8024c367e29f 108 };
emilmont 0:8024c367e29f 109
emilmont 0:8024c367e29f 110 } // namespace mbed
emilmont 0:8024c367e29f 111
emilmont 0:8024c367e29f 112 #endif
emilmont 0:8024c367e29f 113
emilmont 0:8024c367e29f 114 #endif