mbed library sources with internal temperature sensor for nucleo f401

Committer:
elessair
Date:
Sat Jan 17 18:03:58 2015 +0000
Revision:
0:7e2bd16f80af
nucleo f401re internal temperature added

Who changed what in which revision?

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