[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / pg / bus_i2c.c
blob37c4eb0585a08623e7113e6399ef6453bc102836
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 typedef struct i2cDefaultConfig_s {
43 I2CDevice device;
44 ioTag_t ioTagScl, ioTagSda;
45 bool pullUp;
46 uint16_t clockSpeed;
47 } i2cDefaultConfig_t;
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 },
52 #endif
53 #ifdef USE_I2C_DEVICE_2
54 { I2CDEV_2, IO_TAG(I2C2_SCL), IO_TAG(I2C2_SDA), I2C2_PULLUP, I2C2_CLOCKSPEED },
55 #endif
56 #ifdef USE_I2C_DEVICE_3
57 { I2CDEV_3, IO_TAG(I2C3_SCL), IO_TAG(I2C3_SDA), I2C3_PULLUP, I2C3_CLOCKSPEED },
58 #endif
59 #ifdef USE_I2C_DEVICE_4
60 { I2CDEV_4, IO_TAG(I2C4_SCL), IO_TAG(I2C4_SDA), I2C4_PULLUP, I2C4_CLOCKSPEED },
61 #endif
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)