API HAL: takeover i2c initialization and abstraction. Update I2C drivers to match new api. Back port API HAL to bootloader and enable light support for F5. (#356)
Co-authored-by: coreglitch <mail@s3f.ru>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include <bq25896.h>
|
||||
#include <bq25896_reg.h>
|
||||
#include "bq25896.h"
|
||||
#include "bq25896_reg.h"
|
||||
|
||||
#include <api-hal.h>
|
||||
#include <api-hal-i2c.h>
|
||||
#include <stddef.h>
|
||||
|
||||
uint8_t bit_reverse(uint8_t b) {
|
||||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
|
||||
@@ -13,12 +14,10 @@ uint8_t bit_reverse(uint8_t b) {
|
||||
bool bq25896_read(uint8_t address, uint8_t* data, size_t size) {
|
||||
bool ret;
|
||||
with_api_hal_i2c(bool, &ret, (){
|
||||
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ25896_ADDRESS, &address, 1, 2000) != HAL_OK) {
|
||||
return false;
|
||||
}
|
||||
if (HAL_I2C_Master_Receive(&POWER_I2C, BQ25896_ADDRESS, data, size, 2000) != HAL_OK) {
|
||||
return false;
|
||||
}
|
||||
api_hal_i2c_trx(
|
||||
POWER_I2C, BQ25896_ADDRESS,
|
||||
&address, 1, data, size
|
||||
);
|
||||
return true;
|
||||
});
|
||||
return ret;
|
||||
@@ -33,9 +32,7 @@ bool bq25896_write_reg(uint8_t address, uint8_t* data) {
|
||||
uint8_t buffer[2] = { address, *data };
|
||||
bool ret;
|
||||
with_api_hal_i2c(bool, &ret, (){
|
||||
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ25896_ADDRESS, buffer, 2, 2000) != HAL_OK) {
|
||||
return false;
|
||||
}
|
||||
api_hal_i2c_tx(POWER_I2C, BQ25896_ADDRESS, buffer, 2);
|
||||
return true;
|
||||
});
|
||||
return ret;
|
||||
|
@@ -1,21 +1,18 @@
|
||||
#include <bq27220.h>
|
||||
#include <bq27220_reg.h>
|
||||
#include "bq27220.h"
|
||||
#include "bq27220_reg.h"
|
||||
|
||||
#include <api-hal.h>
|
||||
#include <api-hal-i2c.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
uint16_t bq27220_read_word(uint8_t address) {
|
||||
uint8_t data[2] = { address };
|
||||
uint8_t buffer[2] = { address };
|
||||
uint16_t ret;
|
||||
with_api_hal_i2c(uint16_t, &ret, (){
|
||||
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ27220_ADDRESS, data, 1, 2000) != HAL_OK) {
|
||||
return BQ27220_ERROR;
|
||||
}
|
||||
|
||||
if (HAL_I2C_Master_Receive(&POWER_I2C, BQ27220_ADDRESS, data, 2, 2000) != HAL_OK) {
|
||||
return BQ27220_ERROR;
|
||||
}
|
||||
return *(uint16_t*)data;
|
||||
api_hal_i2c_trx(
|
||||
POWER_I2C, BQ27220_ADDRESS,
|
||||
buffer, 1, buffer, 2
|
||||
);
|
||||
return *(uint16_t*)buffer;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
@@ -23,13 +20,11 @@ uint16_t bq27220_read_word(uint8_t address) {
|
||||
bool bq27220_control(uint16_t control) {
|
||||
bool ret;
|
||||
with_api_hal_i2c(bool, &ret, (){
|
||||
uint8_t data[3];
|
||||
data[0] = CommandControl;
|
||||
data[1] = (control>>8) & 0xFF;
|
||||
data[2] = control & 0xFF;
|
||||
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ27220_ADDRESS, data, 3, 2000) != HAL_OK) {
|
||||
return false;
|
||||
}
|
||||
uint8_t buffer[3];
|
||||
buffer[0] = CommandControl;
|
||||
buffer[1] = (control>>8) & 0xFF;
|
||||
buffer[2] = control & 0xFF;
|
||||
api_hal_i2c_tx(POWER_I2C, BQ27220_ADDRESS, buffer, 3);
|
||||
return true;
|
||||
});
|
||||
return ret;
|
||||
|
@@ -1,34 +1,14 @@
|
||||
#include "lp5562.h"
|
||||
#include "lp5562_reg.h"
|
||||
|
||||
#include <api-hal.h>
|
||||
#include <api-hal-i2c.h>
|
||||
#include <stdio.h>
|
||||
|
||||
bool lp5562_read(uint8_t address, uint8_t* data, size_t size) {
|
||||
bool ret;
|
||||
with_api_hal_i2c(bool, &ret, (){
|
||||
if (HAL_I2C_Master_Transmit(&POWER_I2C, LP5562_ADDRESS, &address, 1, 2000) != HAL_OK) {
|
||||
return false;
|
||||
}
|
||||
if (HAL_I2C_Master_Receive(&POWER_I2C, LP5562_ADDRESS, data, size, 2000) != HAL_OK) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool lp5562_read_reg(uint8_t address, uint8_t* data) {
|
||||
return lp5562_read(address, data, 1);
|
||||
}
|
||||
|
||||
bool lp5562_write_reg(uint8_t address, uint8_t *data) {
|
||||
uint8_t buffer[2] = { address, *data };
|
||||
bool ret;
|
||||
with_api_hal_i2c(bool, &ret, (){
|
||||
if (HAL_I2C_Master_Transmit(&POWER_I2C, LP5562_ADDRESS, buffer, 2, 2000) != HAL_OK) {
|
||||
return false;
|
||||
}
|
||||
api_hal_i2c_tx(POWER_I2C, LP5562_ADDRESS, buffer, 2);
|
||||
return true;
|
||||
});
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user