mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Mon Feb 18 09:41:56 2013 +0000
Revision:
9:663789d7729f
Parent:
8:c14af7958ef5
Update mbed-KL25Z to latest build

Who changed what in which revision?

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