library for MPU6050 and MPU9250, supports both I2C and SPI

Dependents:   Seeed_nRF51822_MPU9250

Committer:
yihui
Date:
Thu Dec 10 07:39:48 2015 +0000
Revision:
0:972f3778c19c
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:972f3778c19c 1
yihui 0:972f3778c19c 2 /******************************************************************************
yihui 0:972f3778c19c 3 * $Id: mbed_spi.h $
yihui 0:972f3778c19c 4 *****************************************************************************/
yihui 0:972f3778c19c 5 /**
yihui 0:972f3778c19c 6 * @defgroup MBED_System_Layer MBED System Layer
yihui 0:972f3778c19c 7 * @brief MBED System Layer APIs.
yihui 0:972f3778c19c 8 * To interface with any platform, eMPL needs access to various
yihui 0:972f3778c19c 9 * system layer functions.
yihui 0:972f3778c19c 10 *
yihui 0:972f3778c19c 11 * @{
yihui 0:972f3778c19c 12 * @file mbed_spi.h
yihui 0:972f3778c19c 13 * @brief Serial communication functions needed by eMPL to
yihui 0:972f3778c19c 14 * communicate to the MPU devices.
yihui 0:972f3778c19c 15 * @details This driver assumes that eMPL is with a sub-master clock set
yihui 0:972f3778c19c 16 * to 20MHz. The following MBEDs are supported:
yihui 0:972f3778c19c 17 */
yihui 0:972f3778c19c 18 #ifndef _MBED_SPI_H_
yihui 0:972f3778c19c 19 #define _MBED_SPI_H_
yihui 0:972f3778c19c 20
yihui 0:972f3778c19c 21 #ifdef __cplusplus
yihui 0:972f3778c19c 22 extern "C" {
yihui 0:972f3778c19c 23 #endif
yihui 0:972f3778c19c 24
yihui 0:972f3778c19c 25 #include "spi_api.h"
yihui 0:972f3778c19c 26
yihui 0:972f3778c19c 27 /**
yihui 0:972f3778c19c 28 * @brief Set up the SPI port and configure the MBED as the master.
yihui 0:972f3778c19c 29 */
yihui 0:972f3778c19c 30 void mbed_spi_init(PinName mosi, PinName miso, PinName sclk, PinName cs);
yihui 0:972f3778c19c 31
yihui 0:972f3778c19c 32 /**
yihui 0:972f3778c19c 33 * @brief Enable SPI port.
yihui 0:972f3778c19c 34 */
yihui 0:972f3778c19c 35 void mbed_spi_enable(void);
yihui 0:972f3778c19c 36
yihui 0:972f3778c19c 37 /**
yihui 0:972f3778c19c 38 * @brief Disable SPI communication.
yihui 0:972f3778c19c 39 * This function will disable the SPI hardware and should be called prior to
yihui 0:972f3778c19c 40 * entering low-power mode.
yihui 0:972f3778c19c 41 */
yihui 0:972f3778c19c 42 void mbed_spi_disable(void);
yihui 0:972f3778c19c 43
yihui 0:972f3778c19c 44 /**
yihui 0:972f3778c19c 45 * @brief Write to a device register.
yihui 0:972f3778c19c 46 *
yihui 0:972f3778c19c 47 * @param[in] reg_addr Slave register to be written to.
yihui 0:972f3778c19c 48 * @param[in] length Number of bytes to write.
yihui 0:972f3778c19c 49 * @param[out] data Data to be written to register.
yihui 0:972f3778c19c 50 *
yihui 0:972f3778c19c 51 * @return 0 if successful.
yihui 0:972f3778c19c 52 */
yihui 0:972f3778c19c 53 int mbed_spi_write(unsigned char reg_addr,
yihui 0:972f3778c19c 54 unsigned char length,
yihui 0:972f3778c19c 55 unsigned char const *data);
yihui 0:972f3778c19c 56 /**
yihui 0:972f3778c19c 57 * @brief Read from a device.
yihui 0:972f3778c19c 58 *
yihui 0:972f3778c19c 59 * @param[in] reg_addr Slave register to be read from.
yihui 0:972f3778c19c 60 * @param[in] length Number of bytes to read.
yihui 0:972f3778c19c 61 * @param[out] data Data from register.
yihui 0:972f3778c19c 62 *
yihui 0:972f3778c19c 63 * @return 0 if successful.
yihui 0:972f3778c19c 64 */
yihui 0:972f3778c19c 65 int mbed_spi_read(unsigned char reg_addr,
yihui 0:972f3778c19c 66 unsigned char length,
yihui 0:972f3778c19c 67 unsigned char *data);
yihui 0:972f3778c19c 68
yihui 0:972f3778c19c 69 #ifdef __cplusplus
yihui 0:972f3778c19c 70 }
yihui 0:972f3778c19c 71 #endif
yihui 0:972f3778c19c 72
yihui 0:972f3778c19c 73 #endif /* _MBED_I2C_H_ */
yihui 0:972f3778c19c 74
yihui 0:972f3778c19c 75 /**
yihui 0:972f3778c19c 76 * @}
yihui 0:972f3778c19c 77 */