test

Dependents:   robotic_fish_7

Committer:
juansal12
Date:
Tue Jan 14 19:14:29 2020 +0000
Revision:
0:44931ff4a3ed
Sofi 7 code;

Who changed what in which revision?

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