FRDM-K64F, Avnet M14A2A, Grove Shield, to create smart home system. In use with AT&Ts M2x & Flow.

Dependencies:   mbed FXOS8700CQ MODSERIAL

Committer:
jwhammel
Date:
Mon Apr 29 04:24:38 2019 +0000
Revision:
85:0cf65ceb4492
Parent:
84:fc8c9b39723a
We have added an alarm trigger that gets sent to AT&T Flow.

Who changed what in which revision?

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