fix nrf51822 i2c & spi conflict

Dependencies:   BLE_API eMPL_MPU6050 nRF51822

Fork of Seeed_Tiny_BLE_Flash by Darren Huang

Committer:
yihui
Date:
Tue Nov 17 07:48:56 2015 +0000
Revision:
5:b8c02645e6af
fix i2c & spi conflict

Who changed what in which revision?

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