[FL-873] Add F5 target, lp5562 driver and api-hal-light (#347)
* Add F5 target, lp5562 driver and api-hal-light. Update api-usage, switch to F5 by default. * API HAL: add i2c and hardware version api. Dolphin: show hardware version. * OTP version generator and flashing utility. * Assets script: fix code formatting * Backport F5 changes to F4 * F4: disable insomnia, prevent damage to BLE RX path * F5 HAL API Light: remove magic delay to fix magic BLE * Dolphin: HW target validation on start * invert RSSI indication in sub-1 * API HAL: rename board to body in version api * Gpio tester: detach and release viewport on exit Co-authored-by: aanper <mail@s3f.ru>
This commit is contained in:
@@ -1,30 +1,38 @@
|
||||
#include <bq27220.h>
|
||||
#include <bq27220_reg.h>
|
||||
#include <i2c.h>
|
||||
|
||||
#include <api-hal.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
uint16_t bq27220_read_word(uint8_t address) {
|
||||
uint8_t data[2] = { address };
|
||||
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ27220_ADDRESS, data, 1, 2000) != HAL_OK) {
|
||||
return BQ27220_ERROR;
|
||||
}
|
||||
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;
|
||||
if (HAL_I2C_Master_Receive(&POWER_I2C, BQ27220_ADDRESS, data, 2, 2000) != HAL_OK) {
|
||||
return BQ27220_ERROR;
|
||||
}
|
||||
return *(uint16_t*)data;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool bq27220_control(uint16_t control) {
|
||||
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;
|
||||
}
|
||||
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bq27220_init() {
|
||||
|
Reference in New Issue
Block a user