update serTcpOpen declaration to fix compile errors (#14113)
[betaflight.git] / src / main / pg / bus_i2c.c
blob1e70c23ccd55b8e35b4a7d73293e6510489a8ccf
1 /*
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)
8 * any later version.
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/>.
22 * Created by jflyper
25 #include <stdbool.h>
26 #include <stddef.h>
27 #include <string.h>
29 #include "platform.h"
31 #if defined(USE_I2C) && !defined(SOFT_I2C)
33 #include "common/utils.h"
35 #include "drivers/io.h"
37 #include "pg/pg.h"
38 #include "pg/pg_ids.h"
40 #include "pg/bus_i2c.h"
42 #ifndef I2C1_SCL_PIN
43 #define I2C1_SCL_PIN NONE
44 #endif
45 #ifndef I2C1_SDA_PIN
46 #define I2C1_SDA_PIN NONE
47 #endif
48 #ifndef I2C2_SCL_PIN
49 #define I2C2_SCL_PIN NONE
50 #endif
51 #ifndef I2C2_SDA_PIN
52 #define I2C2_SDA_PIN NONE
53 #endif
54 #ifndef I2C3_SCL_PIN
55 #define I2C3_SCL_PIN NONE
56 #endif
57 #ifndef I2C3_SDA_PIN
58 #define I2C3_SDA_PIN NONE
59 #endif
60 #ifndef I2C4_SCL_PIN
61 #define I2C4_SCL_PIN NONE
62 #endif
63 #ifndef I2C4_SDA_PIN
64 #define I2C4_SDA_PIN NONE
65 #endif
67 typedef struct i2cDefaultConfig_s {
68 I2CDevice device;
69 ioTag_t ioTagScl, ioTagSda;
70 bool pullUp;
71 uint16_t clockSpeed;
72 } i2cDefaultConfig_t;
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 },
77 #endif
78 #ifdef USE_I2C_DEVICE_2
79 { I2CDEV_2, IO_TAG(I2C2_SCL_PIN), IO_TAG(I2C2_SDA_PIN), I2C2_PULLUP, I2C2_CLOCKSPEED },
80 #endif
81 #ifdef USE_I2C_DEVICE_3
82 { I2CDEV_3, IO_TAG(I2C3_SCL_PIN), IO_TAG(I2C3_SDA_PIN), I2C3_PULLUP, I2C3_CLOCKSPEED },
83 #endif
84 #ifdef USE_I2C_DEVICE_4
85 { I2CDEV_4, IO_TAG(I2C4_SCL_PIN), IO_TAG(I2C4_SDA_PIN), I2C4_PULLUP, I2C4_CLOCKSPEED },
86 #endif
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)