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 typedef struct i2cDefaultConfig_s
{
44 ioTag_t ioTagScl
, ioTagSda
;
49 static const i2cDefaultConfig_t i2cDefaultConfig
[] = {
50 #ifdef USE_I2C_DEVICE_1
51 { I2CDEV_1
, IO_TAG(I2C1_SCL
), IO_TAG(I2C1_SDA
), I2C1_PULLUP
, I2C1_CLOCKSPEED
},
53 #ifdef USE_I2C_DEVICE_2
54 { I2CDEV_2
, IO_TAG(I2C2_SCL
), IO_TAG(I2C2_SDA
), I2C2_PULLUP
, I2C2_CLOCKSPEED
},
56 #ifdef USE_I2C_DEVICE_3
57 { I2CDEV_3
, IO_TAG(I2C3_SCL
), IO_TAG(I2C3_SDA
), I2C3_PULLUP
, I2C3_CLOCKSPEED
},
59 #ifdef USE_I2C_DEVICE_4
60 { I2CDEV_4
, IO_TAG(I2C4_SCL
), IO_TAG(I2C4_SDA
), I2C4_PULLUP
, I2C4_CLOCKSPEED
},
64 void pgResetFn_i2cConfig(i2cConfig_t
*i2cConfig
)
66 memset(i2cConfig
, 0, sizeof(*i2cConfig
));
68 for (size_t index
= 0 ; index
< ARRAYLEN(i2cDefaultConfig
) ; index
++) {
69 const i2cDefaultConfig_t
*defconf
= &i2cDefaultConfig
[index
];
70 int device
= defconf
->device
;
71 i2cConfig
[device
].ioTagScl
= defconf
->ioTagScl
;
72 i2cConfig
[device
].ioTagSda
= defconf
->ioTagSda
;
73 i2cConfig
[device
].pullUp
= defconf
->pullUp
;
74 i2cConfig
[device
].clockSpeed
= defconf
->clockSpeed
;
78 PG_REGISTER_ARRAY_WITH_RESET_FN(i2cConfig_t
, I2CDEV_COUNT
, i2cConfig
, PG_I2C_CONFIG
, 1);
80 #endif // defined(USE_I2C) && !defined(USE_SOFT_I2C)