2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
25 #include "drivers/io_types.h"
26 #include "drivers/rcc_types.h"
29 #define I2C_DEVICE I2CINVALID
32 typedef enum I2CDevice
{
40 #if defined(STM32F4) || defined(APM32F4)
41 #define I2CDEV_COUNT 3
42 #elif defined(STM32F7)
43 #define I2CDEV_COUNT 4
45 #define I2CDEV_COUNT 4
48 // Macros to convert between CLI bus number and I2CDevice.
49 #define I2C_CFG_TO_DEV(x) ((x) - 1)
50 #define I2C_DEV_TO_CFG(x) ((x) + 1)
52 // I2C device address range in 7-bit address mode
53 #define I2C_ADDR7_MIN 8
54 #define I2C_ADDR7_MAX 119
57 void i2cHardwareConfigure(const struct i2cConfig_s
*i2cConfig
);
58 void i2cInit(I2CDevice device
);
59 bool i2cWriteBuffer(I2CDevice device
, uint8_t addr_
, uint8_t reg_
, uint8_t len_
, uint8_t *data
);
60 bool i2cWrite(I2CDevice device
, uint8_t addr_
, uint8_t reg
, uint8_t data
);
61 bool i2cReadBuffer(I2CDevice device
, uint8_t addr_
, uint8_t reg
, uint8_t len
, uint8_t* buf
);
62 bool i2cRead(I2CDevice device
, uint8_t addr_
, uint8_t reg
, uint8_t len
, uint8_t* buf
);
63 bool i2cBusy(I2CDevice device
, bool *error
);
65 uint16_t i2cGetErrorCounter(void);
66 uint8_t i2cGetRegisteredDeviceCount(void);