dev01 Brautlecht / mbed-STM32F030F4

Dependents:   STM32F031_Blink_Aug17

Fork of mbed-STM32F030F4 by Nothing Special

Committer:
mega64
Date:
Sat Oct 18 02:40:17 2014 +0000
Revision:
0:38ccae254a29
only for STM32F030F4

Who changed what in which revision?

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