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"
43 #define I2C1_SCL_PIN NONE
46 #define I2C1_SDA_PIN NONE
49 #define I2C2_SCL_PIN NONE
52 #define I2C2_SDA_PIN NONE
55 #define I2C3_SCL_PIN NONE
58 #define I2C3_SDA_PIN NONE
61 #define I2C4_SCL_PIN NONE
64 #define I2C4_SDA_PIN NONE
67 typedef struct i2cDefaultConfig_s
{
69 ioTag_t ioTagScl
, ioTagSda
;
74 static const i2cDefaultConfig_t i2cDefaultConfig
[] = {
75 #ifdef USE_I2C_DEVICE_1
76 { I2CDEV_1
, IO_TAG(I2C1_SCL_PIN
), IO_TAG(I2C1_SDA_PIN
), I2C1_PULLUP
, I2C1_CLOCKSPEED
},
78 #ifdef USE_I2C_DEVICE_2
79 { I2CDEV_2
, IO_TAG(I2C2_SCL_PIN
), IO_TAG(I2C2_SDA_PIN
), I2C2_PULLUP
, I2C2_CLOCKSPEED
},
81 #ifdef USE_I2C_DEVICE_3
82 { I2CDEV_3
, IO_TAG(I2C3_SCL_PIN
), IO_TAG(I2C3_SDA_PIN
), I2C3_PULLUP
, I2C3_CLOCKSPEED
},
84 #ifdef USE_I2C_DEVICE_4
85 { I2CDEV_4
, IO_TAG(I2C4_SCL_PIN
), IO_TAG(I2C4_SDA_PIN
), I2C4_PULLUP
, I2C4_CLOCKSPEED
},
89 void pgResetFn_i2cConfig(i2cConfig_t
*i2cConfig
)
91 memset(i2cConfig
, 0, sizeof(*i2cConfig
));
93 for (size_t index
= 0 ; index
< ARRAYLEN(i2cDefaultConfig
) ; index
++) {
94 const i2cDefaultConfig_t
*defconf
= &i2cDefaultConfig
[index
];
95 int device
= defconf
->device
;
96 i2cConfig
[device
].ioTagScl
= defconf
->ioTagScl
;
97 i2cConfig
[device
].ioTagSda
= defconf
->ioTagSda
;
98 i2cConfig
[device
].pullUp
= defconf
->pullUp
;
99 i2cConfig
[device
].clockSpeed
= defconf
->clockSpeed
;
103 PG_REGISTER_ARRAY_WITH_RESET_FN(i2cConfig_t
, I2CDEV_COUNT
, i2cConfig
, PG_I2C_CONFIG
, 1);
105 #endif // defined(USE_I2C) && !defined(USE_SOFT_I2C)