MPU6050 library

Dependents:   CSSE4011_BLE_IMU_Project_rev2 Seeed_Tiny_BLE_Get_Started nrf51822_fix_i2c_spi_conflict balanceboard ... more

Committer:
yihui
Date:
Thu Nov 05 01:38:50 2015 +0000
Revision:
1:6aedb937cb38
Parent:
0:1b6dab73c06b
add mbed_i2c_clear() function; ; use mbed_i2c_clear to recover i2c bus when i2c is stuck

Who changed what in which revision?

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