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_PORTOUT_H
yihui 5:9b240c1d5251 17 #define MBED_PORTOUT_H
yihui 5:9b240c1d5251 18
yihui 5:9b240c1d5251 19 #include "platform.h"
yihui 5:9b240c1d5251 20
yihui 5:9b240c1d5251 21 #if DEVICE_PORTOUT
yihui 5:9b240c1d5251 22
yihui 5:9b240c1d5251 23 #include "port_api.h"
yihui 5:9b240c1d5251 24
yihui 5:9b240c1d5251 25 namespace mbed {
yihui 5:9b240c1d5251 26 /** A multiple pin digital out
yihui 5:9b240c1d5251 27 *
yihui 5:9b240c1d5251 28 * Example:
yihui 5:9b240c1d5251 29 * @code
yihui 5:9b240c1d5251 30 * // Toggle all four LEDs
yihui 5:9b240c1d5251 31 *
yihui 5:9b240c1d5251 32 * #include "mbed.h"
yihui 5:9b240c1d5251 33 *
yihui 5:9b240c1d5251 34 * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
yihui 5:9b240c1d5251 35 * #define LED_MASK 0x00B40000
yihui 5:9b240c1d5251 36 *
yihui 5:9b240c1d5251 37 * PortOut ledport(Port1, LED_MASK);
yihui 5:9b240c1d5251 38 *
yihui 5:9b240c1d5251 39 * int main() {
yihui 5:9b240c1d5251 40 * while(1) {
yihui 5:9b240c1d5251 41 * ledport = LED_MASK;
yihui 5:9b240c1d5251 42 * wait(1);
yihui 5:9b240c1d5251 43 * ledport = 0;
yihui 5:9b240c1d5251 44 * wait(1);
yihui 5:9b240c1d5251 45 * }
yihui 5:9b240c1d5251 46 * }
yihui 5:9b240c1d5251 47 * @endcode
yihui 5:9b240c1d5251 48 */
yihui 5:9b240c1d5251 49 class PortOut {
yihui 5:9b240c1d5251 50 public:
yihui 5:9b240c1d5251 51
yihui 5:9b240c1d5251 52 /** Create an PortOut, connected to the specified port
yihui 5:9b240c1d5251 53 *
yihui 5:9b240c1d5251 54 * @param port Port to connect to (Port0-Port5)
yihui 5:9b240c1d5251 55 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
yihui 5:9b240c1d5251 56 */
yihui 5:9b240c1d5251 57 PortOut(PortName port, int mask = 0xFFFFFFFF) {
yihui 5:9b240c1d5251 58 port_init(&_port, port, mask, PIN_OUTPUT);
yihui 5:9b240c1d5251 59 }
yihui 5:9b240c1d5251 60
yihui 5:9b240c1d5251 61 /** Write the value to the output port
yihui 5:9b240c1d5251 62 *
yihui 5:9b240c1d5251 63 * @param value An integer specifying a bit to write for every corresponding PortOut pin
yihui 5:9b240c1d5251 64 */
yihui 5:9b240c1d5251 65 void write(int value) {
yihui 5:9b240c1d5251 66 port_write(&_port, value);
yihui 5:9b240c1d5251 67 }
yihui 5:9b240c1d5251 68
yihui 5:9b240c1d5251 69 /** Read the value currently output on the port
yihui 5:9b240c1d5251 70 *
yihui 5:9b240c1d5251 71 * @returns
yihui 5:9b240c1d5251 72 * An integer with each bit corresponding to associated PortOut pin setting
yihui 5:9b240c1d5251 73 */
yihui 5:9b240c1d5251 74 int read() {
yihui 5:9b240c1d5251 75 return port_read(&_port);
yihui 5:9b240c1d5251 76 }
yihui 5:9b240c1d5251 77
yihui 5:9b240c1d5251 78 /** A shorthand for write()
yihui 5:9b240c1d5251 79 */
yihui 5:9b240c1d5251 80 PortOut& operator= (int value) {
yihui 5:9b240c1d5251 81 write(value);
yihui 5:9b240c1d5251 82 return *this;
yihui 5:9b240c1d5251 83 }
yihui 5:9b240c1d5251 84
yihui 5:9b240c1d5251 85 PortOut& operator= (PortOut& rhs) {
yihui 5:9b240c1d5251 86 write(rhs.read());
yihui 5:9b240c1d5251 87 return *this;
yihui 5:9b240c1d5251 88 }
yihui 5:9b240c1d5251 89
yihui 5:9b240c1d5251 90 /** A shorthand for read()
yihui 5:9b240c1d5251 91 */
yihui 5:9b240c1d5251 92 operator int() {
yihui 5:9b240c1d5251 93 return read();
yihui 5:9b240c1d5251 94 }
yihui 5:9b240c1d5251 95
yihui 5:9b240c1d5251 96 private:
yihui 5:9b240c1d5251 97 port_t _port;
yihui 5:9b240c1d5251 98 };
yihui 5:9b240c1d5251 99
yihui 5:9b240c1d5251 100 } // namespace mbed
yihui 5:9b240c1d5251 101
yihui 5:9b240c1d5251 102 #endif
yihui 5:9b240c1d5251 103
yihui 5:9b240c1d5251 104 #endif