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