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 }
42 #elif defined(STM32F1)
43 #define I2CPINDEF(pin, af) { DEFIO_TAG_E(pin) }
45 #define I2CPINDEF(pin) { DEFIO_TAG_E(pin) }
48 typedef struct i2cHardware_s
{
51 i2cPinDef_t sclPins
[I2C_PIN_SEL_MAX
];
52 i2cPinDef_t sdaPins
[I2C_PIN_SEL_MAX
];
54 #if !defined(STM32F303xC)
60 extern const i2cHardware_t i2cHardware
[];
62 #if defined(STM32F1) || defined(STM32F4)
63 typedef struct i2cState_s
{
66 volatile uint8_t addr
;
68 volatile uint8_t bytes
;
69 volatile uint8_t writing
;
70 volatile uint8_t reading
;
71 volatile uint8_t* write_p
;
72 volatile uint8_t* read_p
;
76 typedef struct i2cDevice_s
{
77 const i2cHardware_t
*hardware
;
81 #if defined(STM32F4) || defined(STM32H7) || defined(STM32G4)
88 // MCU/Driver dependent member follows
89 #if defined(STM32F1) || defined(STM32F4)
93 I2C_HandleTypeDef handle
;
97 extern i2cDevice_t i2cDevice
[];