IOTIO

Dependencies:   Nucleo_BLE_API_IOTIO Nucleo_BLE_BlueNRG Nucleo_BLE_DemoApp Nucleo_Sensor_Shield mbed

Dependents:   Nucleo_BLE_Demo_IOTIO

Fork of Nucleo_BLE_Demo by Cortex Challenge Team

Committer:
16038618
Date:
Sat Oct 29 15:11:28 2016 +0000
Revision:
1:4bdfa7d7e8bf
IOTIO

Who changed what in which revision?

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