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/>.
31 #if defined(USE_I2C) && !defined(SOFT_I2C)
33 #include "common/utils.h"
35 #include "drivers/io.h"
38 #include "pg/pg_ids.h"
40 #include "pg/bus_i2c.h"
42 #ifdef I2C_FULL_RECONFIGURABILITY
79 #else // I2C_FULL_RECONFIGURABILITY
81 // Backward compatibility for exisiting targets
109 #define I2C2_SDA PA10
121 #define I2C2_SCL PB10
124 #define I2C2_SDA PB11
142 #define I2C2_SCL PB10
145 #define I2C2_SDA PB11
154 #define I2C4_SCL PD12
157 #define I2C4_SDA PD13
161 #endif // I2C_FULL_RECONFIGURABILITY
163 // Default values for internal pullup
165 #if defined(USE_I2C_PULLUP)
166 #define I2C1_PULLUP true
167 #define I2C2_PULLUP true
168 #define I2C3_PULLUP true
169 #define I2C4_PULLUP true
171 #define I2C1_PULLUP false
172 #define I2C2_PULLUP false
173 #define I2C3_PULLUP false
174 #define I2C4_PULLUP false
177 typedef struct i2cDefaultConfig_s
{
179 ioTag_t ioTagScl
, ioTagSda
;
182 } i2cDefaultConfig_t
;
184 static const i2cDefaultConfig_t i2cDefaultConfig
[] = {
185 #ifdef USE_I2C_DEVICE_1
186 { I2CDEV_1
, IO_TAG(I2C1_SCL
), IO_TAG(I2C1_SDA
), I2C1_OVERCLOCK
, I2C1_PULLUP
},
188 #ifdef USE_I2C_DEVICE_2
189 { I2CDEV_2
, IO_TAG(I2C2_SCL
), IO_TAG(I2C2_SDA
), I2C2_OVERCLOCK
, I2C2_PULLUP
},
191 #ifdef USE_I2C_DEVICE_3
192 { I2CDEV_3
, IO_TAG(I2C3_SCL
), IO_TAG(I2C3_SDA
), I2C3_OVERCLOCK
, I2C3_PULLUP
},
194 #ifdef USE_I2C_DEVICE_4
195 { I2CDEV_4
, IO_TAG(I2C4_SCL
), IO_TAG(I2C4_SDA
), I2C4_OVERCLOCK
, I2C4_PULLUP
},
199 void pgResetFn_i2cConfig(i2cConfig_t
*i2cConfig
)
201 memset(i2cConfig
, 0, sizeof(*i2cConfig
));
203 for (size_t index
= 0 ; index
< ARRAYLEN(i2cDefaultConfig
) ; index
++) {
204 const i2cDefaultConfig_t
*defconf
= &i2cDefaultConfig
[index
];
205 i2cConfig
->ioTagScl
[defconf
->device
] = defconf
->ioTagScl
;
206 i2cConfig
->ioTagSda
[defconf
->device
] = defconf
->ioTagSda
;
207 i2cConfig
->overClock
[defconf
->device
] = defconf
->overClock
;
208 i2cConfig
->pullUp
[defconf
->device
] = defconf
->pullUp
;
212 PG_REGISTER_WITH_RESET_FN(i2cConfig_t
, i2cConfig
, PG_I2C_CONFIG
, 0);
214 #endif // defined(USE_I2C) && !defined(USE_SOFT_I2C)