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,4 +1,5 @@
#include <api-hal-i2c.h>
#include <stm32wbxx_ll_i2c.h>
#include <furi.h>
osMutexId_t api_hal_i2c_mutex = NULL;
@@ -8,6 +9,35 @@ void api_hal_i2c_init() {
furi_check(api_hal_i2c_mutex);
}
void api_hal_i2c_tx(I2C_TypeDef* instance, uint8_t address, const uint8_t *data, uint8_t size) {
LL_I2C_HandleTransfer(instance, address, LL_I2C_ADDRSLAVE_7BIT, size, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_WRITE);
while (!LL_I2C_IsActiveFlag_STOP(instance)) {
if (LL_I2C_IsActiveFlag_TXIS(instance)) {
LL_I2C_TransmitData8(instance, (*data++));
}
}
LL_I2C_ClearFlag_STOP(instance);
}
void api_hal_i2c_rx(I2C_TypeDef* instance, uint8_t address, uint8_t *data, uint8_t size) {
LL_I2C_HandleTransfer(instance, address, LL_I2C_ADDRSLAVE_7BIT, size, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_READ);
while (!LL_I2C_IsActiveFlag_STOP(instance)) {
if (LL_I2C_IsActiveFlag_RXNE(instance)) {
*data++ = LL_I2C_ReceiveData8(instance);
}
}
LL_I2C_ClearFlag_STOP(instance);
}
void api_hal_i2c_trx(I2C_TypeDef* instance, uint8_t address, const uint8_t *tx_data, uint8_t tx_size, uint8_t *rx_data, uint8_t rx_size) {
api_hal_i2c_tx(instance, address, tx_data, tx_size);
api_hal_i2c_rx(instance, address, rx_data, rx_size);
}
void api_hal_i2c_lock() {
furi_check(osMutexAcquire(api_hal_i2c_mutex, osWaitForever) == osOK);
}