This fork of the MBED Library allows you to use counters on the external counter pins (15/16 for Timer 3, 29/30 for Timer 2) by switching internal timing functions in MBED to utilize Timer 0

Fork of mbed-src by mbed official

Committer:
emilmont
Date:
Fri Jun 14 17:49:17 2013 +0100
Revision:
10:3bc89ef62ce7
Parent:
9:0ce32e54c9a7
Child:
13:0645d8841f51
Unify mbed library sources

Who changed what in which revision?

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