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:
あく
2021-03-02 14:45:47 +03:00
committed by GitHub
parent 056e6ffa9c
commit 38011e88f3
26 changed files with 388 additions and 444 deletions

View File

@@ -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;