Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
ethaderu
Date:
Tue Mar 05 02:34:44 2019 +0000
Revision:
3:78f223d34f36
Publish 1

Who changed what in which revision?

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