Ditching default target for `make` in favour of `make all` (#14099)
[betaflight.git] / src / main / drivers / bus_i2c.h
blob74dcfadb3d27ed2cef05b45a0c5fa5b98c01e3ae
1 /*
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)
8 * any later version.
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/>.
21 #pragma once
23 #include "platform.h"
25 #include "drivers/io_types.h"
26 #include "drivers/rcc_types.h"
28 #ifndef I2C_DEVICE
29 #define I2C_DEVICE I2CINVALID
30 #endif
32 typedef enum I2CDevice {
33 I2CINVALID = -1,
34 I2CDEV_1 = 0,
35 I2CDEV_2,
36 I2CDEV_3,
37 I2CDEV_4,
38 } I2CDevice;
40 #if defined(STM32F4) || defined(APM32F4)
41 #define I2CDEV_COUNT 3
42 #elif defined(STM32F7)
43 #define I2CDEV_COUNT 4
44 #else
45 #define I2CDEV_COUNT 4
46 #endif
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
56 struct i2cConfig_s;
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);