mbed library sources for GR-PEACH rev.B.

Fork of mbed-src by mbed official

Committer:
bogdanm
Date:
Mon Aug 05 14:12:34 2013 +0300
Revision:
13:0645d8841f51
Parent:
10:3bc89ef62ce7
Child:
15:4892fe388435
Update mbed sources to revision 64

Who changed what in which revision?

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