2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
21 #define I2C_SHORT_TIMEOUT ((uint32_t)0x1000)
22 #define I2C_LONG_TIMEOUT ((uint32_t)(10 * I2C_SHORT_TIMEOUT))
23 #define I2C_DEFAULT_TIMEOUT I2C_LONG_TIMEOUT
25 #define I2C_TIMEOUT (10000)
27 #include "drivers/io_types.h"
28 #include "drivers/rcc_types.h"
30 typedef enum { // Weird mapping to keep config compatible with previos version
37 typedef enum I2CDevice
{
39 I2CDEV_EMULATED
= -1, // Hack until we have proper I2C abstraction
43 #ifdef USE_I2C_DEVICE_4
49 typedef struct i2cDevice_s
{
59 #if defined(STM32F7) || defined(STM32H7) || defined(AT32F43x)
66 void i2cSetSpeed(uint8_t speed
);
67 void i2cInit(I2CDevice device
);
68 bool i2cWriteBuffer(I2CDevice device
, uint8_t addr_
, uint8_t reg_
, uint8_t len_
, const uint8_t *data
, bool allowRawAccess
);
69 bool i2cWrite(I2CDevice device
, uint8_t addr_
, uint8_t reg
, uint8_t data
, bool allowRawAccess
);
70 bool i2cRead(I2CDevice device
, uint8_t addr_
, uint8_t reg
, uint8_t len
, uint8_t* buf
, bool allowRawAccess
);
71 bool i2cBusy(I2CDevice device
, bool *error
);
73 uint16_t i2cGetErrorCounter(void);