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"
28 #define I2C_TIMEOUT_US 10000
29 #define I2C_TIMEOUT_SYS_TICKS (I2C_TIMEOUT_US / 1000)
31 #define I2C_PIN_SEL_MAX 4
33 typedef struct i2cPinDef_s
{
35 #if defined(STM32F4) || defined(STM32H7) || defined(STM32G4)
40 #if defined(STM32F4) || defined(STM32H7) || defined(STM32G4)
41 #define I2CPINDEF(pin, af) { DEFIO_TAG_E(pin), af }
43 #define I2CPINDEF(pin) { DEFIO_TAG_E(pin) }
46 typedef struct i2cHardware_s
{
49 i2cPinDef_t sclPins
[I2C_PIN_SEL_MAX
];
50 i2cPinDef_t sdaPins
[I2C_PIN_SEL_MAX
];
56 extern const i2cHardware_t i2cHardware
[];
59 typedef struct i2cState_s
{
62 volatile uint8_t addr
;
64 volatile uint8_t bytes
;
65 volatile uint8_t writing
;
66 volatile uint8_t reading
;
67 volatile uint8_t* write_p
;
68 volatile uint8_t* read_p
;
72 typedef struct i2cDevice_s
{
73 const i2cHardware_t
*hardware
;
77 #if defined(STM32F4) || defined(STM32H7) || defined(STM32G4)
84 // MCU/Driver dependent member follows
89 I2C_HandleTypeDef handle
;
93 extern i2cDevice_t i2cDevice
[];