Tried to initialize the buttons and slider but couldn't get it to work.

Dependencies:   mbed

Committer:
mturner5
Date:
Mon Sep 19 03:28:41 2016 +0000
Revision:
0:0d6b77c9ae01
basic v2;

Who changed what in which revision?

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