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_ETHERNET_H
yihui 5:9b240c1d5251 17 #define MBED_ETHERNET_H
yihui 5:9b240c1d5251 18
yihui 5:9b240c1d5251 19 #include "platform.h"
yihui 5:9b240c1d5251 20
yihui 5:9b240c1d5251 21 #if DEVICE_ETHERNET
yihui 5:9b240c1d5251 22
yihui 5:9b240c1d5251 23 namespace mbed {
yihui 5:9b240c1d5251 24
yihui 5:9b240c1d5251 25 /** An ethernet interface, to use with the ethernet pins.
yihui 5:9b240c1d5251 26 *
yihui 5:9b240c1d5251 27 * Example:
yihui 5:9b240c1d5251 28 * @code
yihui 5:9b240c1d5251 29 * // Read destination and source from every ethernet packet
yihui 5:9b240c1d5251 30 *
yihui 5:9b240c1d5251 31 * #include "mbed.h"
yihui 5:9b240c1d5251 32 *
yihui 5:9b240c1d5251 33 * Ethernet eth;
yihui 5:9b240c1d5251 34 *
yihui 5:9b240c1d5251 35 * int main() {
yihui 5:9b240c1d5251 36 * char buf[0x600];
yihui 5:9b240c1d5251 37 *
yihui 5:9b240c1d5251 38 * while(1) {
yihui 5:9b240c1d5251 39 * int size = eth.receive();
yihui 5:9b240c1d5251 40 * if(size > 0) {
yihui 5:9b240c1d5251 41 * eth.read(buf, size);
yihui 5:9b240c1d5251 42 * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
yihui 5:9b240c1d5251 43 * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
yihui 5:9b240c1d5251 44 * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
yihui 5:9b240c1d5251 45 * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
yihui 5:9b240c1d5251 46 * }
yihui 5:9b240c1d5251 47 *
yihui 5:9b240c1d5251 48 * wait(1);
yihui 5:9b240c1d5251 49 * }
yihui 5:9b240c1d5251 50 * }
yihui 5:9b240c1d5251 51 * @endcode
yihui 5:9b240c1d5251 52 */
yihui 5:9b240c1d5251 53 class Ethernet {
yihui 5:9b240c1d5251 54
yihui 5:9b240c1d5251 55 public:
yihui 5:9b240c1d5251 56
yihui 5:9b240c1d5251 57 /** Initialise the ethernet interface.
yihui 5:9b240c1d5251 58 */
yihui 5:9b240c1d5251 59 Ethernet();
yihui 5:9b240c1d5251 60
yihui 5:9b240c1d5251 61 /** Powers the hardware down.
yihui 5:9b240c1d5251 62 */
yihui 5:9b240c1d5251 63 virtual ~Ethernet();
yihui 5:9b240c1d5251 64
yihui 5:9b240c1d5251 65 enum Mode {
yihui 5:9b240c1d5251 66 AutoNegotiate,
yihui 5:9b240c1d5251 67 HalfDuplex10,
yihui 5:9b240c1d5251 68 FullDuplex10,
yihui 5:9b240c1d5251 69 HalfDuplex100,
yihui 5:9b240c1d5251 70 FullDuplex100
yihui 5:9b240c1d5251 71 };
yihui 5:9b240c1d5251 72
yihui 5:9b240c1d5251 73 /** Writes into an outgoing ethernet packet.
yihui 5:9b240c1d5251 74 *
yihui 5:9b240c1d5251 75 * It will append size bytes of data to the previously written bytes.
yihui 5:9b240c1d5251 76 *
yihui 5:9b240c1d5251 77 * @param data An array to write.
yihui 5:9b240c1d5251 78 * @param size The size of data.
yihui 5:9b240c1d5251 79 *
yihui 5:9b240c1d5251 80 * @returns
yihui 5:9b240c1d5251 81 * The number of written bytes.
yihui 5:9b240c1d5251 82 */
yihui 5:9b240c1d5251 83 int write(const char *data, int size);
yihui 5:9b240c1d5251 84
yihui 5:9b240c1d5251 85 /** Send an outgoing ethernet packet.
yihui 5:9b240c1d5251 86 *
yihui 5:9b240c1d5251 87 * After filling in the data in an ethernet packet it must be send.
yihui 5:9b240c1d5251 88 * Send will provide a new packet to write to.
yihui 5:9b240c1d5251 89 *
yihui 5:9b240c1d5251 90 * @returns
yihui 5:9b240c1d5251 91 * 0 if the sending was failed,
yihui 5:9b240c1d5251 92 * or the size of the packet successfully sent.
yihui 5:9b240c1d5251 93 */
yihui 5:9b240c1d5251 94 int send();
yihui 5:9b240c1d5251 95
yihui 5:9b240c1d5251 96 /** Recevies an arrived ethernet packet.
yihui 5:9b240c1d5251 97 *
yihui 5:9b240c1d5251 98 * Receiving an ethernet packet will drop the last received ethernet packet
yihui 5:9b240c1d5251 99 * and make a new ethernet packet ready to read.
yihui 5:9b240c1d5251 100 * If no ethernet packet is arrived it will return 0.
yihui 5:9b240c1d5251 101 *
yihui 5:9b240c1d5251 102 * @returns
yihui 5:9b240c1d5251 103 * 0 if no ethernet packet is arrived,
yihui 5:9b240c1d5251 104 * or the size of the arrived packet.
yihui 5:9b240c1d5251 105 */
yihui 5:9b240c1d5251 106 int receive();
yihui 5:9b240c1d5251 107
yihui 5:9b240c1d5251 108 /** Read from an recevied ethernet packet.
yihui 5:9b240c1d5251 109 *
yihui 5:9b240c1d5251 110 * After receive returnd a number bigger than 0it is
yihui 5:9b240c1d5251 111 * possible to read bytes from this packet.
yihui 5:9b240c1d5251 112 * Read will write up to size bytes into data.
yihui 5:9b240c1d5251 113 *
yihui 5:9b240c1d5251 114 * It is possible to use read multible times.
yihui 5:9b240c1d5251 115 * Each time read will start reading after the last read byte before.
yihui 5:9b240c1d5251 116 *
yihui 5:9b240c1d5251 117 * @returns
yihui 5:9b240c1d5251 118 * The number of byte read.
yihui 5:9b240c1d5251 119 */
yihui 5:9b240c1d5251 120 int read(char *data, int size);
yihui 5:9b240c1d5251 121
yihui 5:9b240c1d5251 122 /** Gives the ethernet address of the mbed.
yihui 5:9b240c1d5251 123 *
yihui 5:9b240c1d5251 124 * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
yihui 5:9b240c1d5251 125 */
yihui 5:9b240c1d5251 126 void address(char *mac);
yihui 5:9b240c1d5251 127
yihui 5:9b240c1d5251 128 /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
yihui 5:9b240c1d5251 129 *
yihui 5:9b240c1d5251 130 * @returns
yihui 5:9b240c1d5251 131 * 0 if no ethernet link is pressent,
yihui 5:9b240c1d5251 132 * 1 if an ethernet link is pressent.
yihui 5:9b240c1d5251 133 *
yihui 5:9b240c1d5251 134 * Example:
yihui 5:9b240c1d5251 135 * @code
yihui 5:9b240c1d5251 136 * // Using the Ethernet link function
yihui 5:9b240c1d5251 137 * #include "mbed.h"
yihui 5:9b240c1d5251 138 *
yihui 5:9b240c1d5251 139 * Ethernet eth;
yihui 5:9b240c1d5251 140 *
yihui 5:9b240c1d5251 141 * int main() {
yihui 5:9b240c1d5251 142 * wait(1); // Needed after startup.
yihui 5:9b240c1d5251 143 * if (eth.link()) {
yihui 5:9b240c1d5251 144 * printf("online\n");
yihui 5:9b240c1d5251 145 * } else {
yihui 5:9b240c1d5251 146 * printf("offline\n");
yihui 5:9b240c1d5251 147 * }
yihui 5:9b240c1d5251 148 * }
yihui 5:9b240c1d5251 149 * @endcode
yihui 5:9b240c1d5251 150 */
yihui 5:9b240c1d5251 151 int link();
yihui 5:9b240c1d5251 152
yihui 5:9b240c1d5251 153 /** Sets the speed and duplex parameters of an ethernet link
yihui 5:9b240c1d5251 154 *
yihui 5:9b240c1d5251 155 * - AutoNegotiate Auto negotiate speed and duplex
yihui 5:9b240c1d5251 156 * - HalfDuplex10 10 Mbit, half duplex
yihui 5:9b240c1d5251 157 * - FullDuplex10 10 Mbit, full duplex
yihui 5:9b240c1d5251 158 * - HalfDuplex100 100 Mbit, half duplex
yihui 5:9b240c1d5251 159 * - FullDuplex100 100 Mbit, full duplex
yihui 5:9b240c1d5251 160 *
yihui 5:9b240c1d5251 161 * @param mode the speed and duplex mode to set the link to:
yihui 5:9b240c1d5251 162 */
yihui 5:9b240c1d5251 163 void set_link(Mode mode);
yihui 5:9b240c1d5251 164 };
yihui 5:9b240c1d5251 165
yihui 5:9b240c1d5251 166 } // namespace mbed
yihui 5:9b240c1d5251 167
yihui 5:9b240c1d5251 168 #endif
yihui 5:9b240c1d5251 169
yihui 5:9b240c1d5251 170 #endif