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 #include <stdio.h>
yihui 5:9b240c1d5251 17 #include "mbed_interface.h"
yihui 5:9b240c1d5251 18
yihui 5:9b240c1d5251 19 #include "gpio_api.h"
yihui 5:9b240c1d5251 20 #include "wait_api.h"
yihui 5:9b240c1d5251 21 #include "semihost_api.h"
yihui 5:9b240c1d5251 22 #include "mbed_error.h"
yihui 5:9b240c1d5251 23 #include "toolchain.h"
yihui 5:9b240c1d5251 24
yihui 5:9b240c1d5251 25 #if DEVICE_SEMIHOST
yihui 5:9b240c1d5251 26
yihui 5:9b240c1d5251 27 // return true if a debugger is attached, indicating mbed interface is connected
yihui 5:9b240c1d5251 28 int mbed_interface_connected(void) {
yihui 5:9b240c1d5251 29 return semihost_connected();
yihui 5:9b240c1d5251 30 }
yihui 5:9b240c1d5251 31
yihui 5:9b240c1d5251 32 int mbed_interface_reset(void) {
yihui 5:9b240c1d5251 33 if (mbed_interface_connected()) {
yihui 5:9b240c1d5251 34 semihost_reset();
yihui 5:9b240c1d5251 35 return 0;
yihui 5:9b240c1d5251 36 } else {
yihui 5:9b240c1d5251 37 return -1;
yihui 5:9b240c1d5251 38 }
yihui 5:9b240c1d5251 39 }
yihui 5:9b240c1d5251 40
yihui 5:9b240c1d5251 41 WEAK int mbed_interface_uid(char *uid) {
yihui 5:9b240c1d5251 42 if (mbed_interface_connected()) {
yihui 5:9b240c1d5251 43 return semihost_uid(uid); // Returns 0 if successful, -1 on failure
yihui 5:9b240c1d5251 44 } else {
yihui 5:9b240c1d5251 45 uid[0] = 0;
yihui 5:9b240c1d5251 46 return -1;
yihui 5:9b240c1d5251 47 }
yihui 5:9b240c1d5251 48 }
yihui 5:9b240c1d5251 49
yihui 5:9b240c1d5251 50 int mbed_interface_disconnect(void) {
yihui 5:9b240c1d5251 51 int res;
yihui 5:9b240c1d5251 52 if (mbed_interface_connected()) {
yihui 5:9b240c1d5251 53 if ((res = semihost_disabledebug()) != 0)
yihui 5:9b240c1d5251 54 return res;
yihui 5:9b240c1d5251 55 while (mbed_interface_connected());
yihui 5:9b240c1d5251 56 return 0;
yihui 5:9b240c1d5251 57 } else {
yihui 5:9b240c1d5251 58 return -1;
yihui 5:9b240c1d5251 59 }
yihui 5:9b240c1d5251 60 }
yihui 5:9b240c1d5251 61
yihui 5:9b240c1d5251 62 int mbed_interface_powerdown(void) {
yihui 5:9b240c1d5251 63 int res;
yihui 5:9b240c1d5251 64 if (mbed_interface_connected()) {
yihui 5:9b240c1d5251 65 if ((res = semihost_powerdown()) != 0)
yihui 5:9b240c1d5251 66 return res;
yihui 5:9b240c1d5251 67 while (mbed_interface_connected());
yihui 5:9b240c1d5251 68 return 0;
yihui 5:9b240c1d5251 69 } else {
yihui 5:9b240c1d5251 70 return -1;
yihui 5:9b240c1d5251 71 }
yihui 5:9b240c1d5251 72 }
yihui 5:9b240c1d5251 73
yihui 5:9b240c1d5251 74 // for backward compatibility
yihui 5:9b240c1d5251 75 void mbed_reset(void) {
yihui 5:9b240c1d5251 76 mbed_interface_reset();
yihui 5:9b240c1d5251 77 }
yihui 5:9b240c1d5251 78
yihui 5:9b240c1d5251 79 WEAK int mbed_uid(char *uid) {
yihui 5:9b240c1d5251 80 return mbed_interface_uid(uid);
yihui 5:9b240c1d5251 81 }
yihui 5:9b240c1d5251 82 #endif
yihui 5:9b240c1d5251 83
yihui 5:9b240c1d5251 84 WEAK void mbed_mac_address(char *mac) {
yihui 5:9b240c1d5251 85 #if DEVICE_SEMIHOST
yihui 5:9b240c1d5251 86 char uid[DEVICE_ID_LENGTH + 1];
yihui 5:9b240c1d5251 87 int i;
yihui 5:9b240c1d5251 88
yihui 5:9b240c1d5251 89 // if we have a UID, extract the MAC
yihui 5:9b240c1d5251 90 if (mbed_interface_uid(uid) == 0) {
yihui 5:9b240c1d5251 91 char *p = uid;
yihui 5:9b240c1d5251 92 #if defined(DEVICE_MAC_OFFSET)
yihui 5:9b240c1d5251 93 p += DEVICE_MAC_OFFSET;
yihui 5:9b240c1d5251 94 #endif
yihui 5:9b240c1d5251 95 for (i=0; i<6; i++) {
yihui 5:9b240c1d5251 96 int byte;
yihui 5:9b240c1d5251 97 sscanf(p, "%2x", &byte);
yihui 5:9b240c1d5251 98 mac[i] = byte;
yihui 5:9b240c1d5251 99 p += 2;
yihui 5:9b240c1d5251 100 }
yihui 5:9b240c1d5251 101 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
yihui 5:9b240c1d5251 102 } else { // else return a default MAC
yihui 5:9b240c1d5251 103 #endif
yihui 5:9b240c1d5251 104 mac[0] = 0x00;
yihui 5:9b240c1d5251 105 mac[1] = 0x02;
yihui 5:9b240c1d5251 106 mac[2] = 0xF7;
yihui 5:9b240c1d5251 107 mac[3] = 0xF0;
yihui 5:9b240c1d5251 108 mac[4] = 0x00;
yihui 5:9b240c1d5251 109 mac[5] = 0x00;
yihui 5:9b240c1d5251 110 #if DEVICE_SEMIHOST
yihui 5:9b240c1d5251 111 }
yihui 5:9b240c1d5251 112 #endif
yihui 5:9b240c1d5251 113 }