Use MPU9250 with nRF51822

Dependencies:   eMPL_MPU

Fork of Seeed_Tiny_BLE_Flash by Darren Huang

Committer:
yihui
Date:
Thu Dec 10 08:00:18 2015 +0000
Revision:
5:9b240c1d5251
get 9dof data from mpu9250

Who changed what in which revision?

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