initial

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:49:25 2016 +0000
Revision:
1:9d3b497333c0
Parent:
0:638edba3adf6
use mbed lib

Who changed what in which revision?

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