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,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