PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Committer:
Pokitto
Date:
Wed Oct 11 20:35:27 2017 +0000
Revision:
5:ea7377f3d1af
Fixed PokittoLib. Includes a working custom mbed-src

Who changed what in which revision?

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