change some io settings for TWR-K22F-120M

Dependents:   twr_helloworld

Committer:
Jasper_lee
Date:
Tue Dec 23 03:35:08 2014 +0000
Revision:
0:b16d94660a33
change some io setting used in TWR-K22F120M

Who changed what in which revision?

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