test

Dependents:   robotic_fish_6

Committer:
juansal12
Date:
Fri Dec 03 23:00:34 2021 +0000
Revision:
0:c792b17d9f78
uploaded sofi code ;

Who changed what in which revision?

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