2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
27 #define UNUSED(x) ((void)(x))
30 #include "drivers/bus.h"
31 #include "drivers/bus_i2c.h"
33 bool i2cBusWriteBuffer(const busDevice_t
* dev
, uint8_t reg
, const uint8_t * data
, uint8_t length
)
35 const bool allowRawAccess
= (dev
->flags
& DEVFLAGS_USE_RAW_REGISTERS
);
36 return i2cWriteBuffer(dev
->busdev
.i2c
.i2cBus
, dev
->busdev
.i2c
.address
, reg
, length
, data
, allowRawAccess
);
39 bool i2cBusWriteRegister(const busDevice_t
* dev
, uint8_t reg
, uint8_t data
)
41 const bool allowRawAccess
= (dev
->flags
& DEVFLAGS_USE_RAW_REGISTERS
);
42 return i2cWrite(dev
->busdev
.i2c
.i2cBus
, dev
->busdev
.i2c
.address
, reg
, data
, allowRawAccess
);
45 bool i2cBusReadBuffer(const busDevice_t
* dev
, uint8_t reg
, uint8_t * data
, uint8_t length
)
47 const bool allowRawAccess
= (dev
->flags
& DEVFLAGS_USE_RAW_REGISTERS
);
48 return i2cRead(dev
->busdev
.i2c
.i2cBus
, dev
->busdev
.i2c
.address
, reg
, length
, data
, allowRawAccess
);
51 bool i2cBusReadRegister(const busDevice_t
* dev
, uint8_t reg
, uint8_t * data
)
53 const bool allowRawAccess
= (dev
->flags
& DEVFLAGS_USE_RAW_REGISTERS
);
54 return i2cRead(dev
->busdev
.i2c
.i2cBus
, dev
->busdev
.i2c
.address
, reg
, 1, data
, allowRawAccess
);
56 bool i2cBusBusy(const busDevice_t
*dev
, bool *error
)
59 return i2cBusy(dev
->busdev
.i2c
.i2cBus
, error
);