29 lines
831 B
C
29 lines
831 B
C
#include "stm32h7xx_hal.h"
|
|
#include "tpa6130a2.h"
|
|
|
|
#define AMP_TXN_TIMEOUT 1000
|
|
|
|
tpa6130_ret_t tpa_impl_read_reg(void *handle, uint8_t addr, uint8_t reg, uint8_t *value) {
|
|
I2C_HandleTypeDef *hi2c = handle;
|
|
|
|
if (HAL_I2C_Master_Transmit(hi2c, addr << 1U, ®, 0x01, AMP_TXN_TIMEOUT) != HAL_OK) {
|
|
return TPA6130_FAIL;
|
|
}
|
|
|
|
if (HAL_I2C_Master_Receive(hi2c, addr << 1U, value, 0x01, AMP_TXN_TIMEOUT) != HAL_OK) {
|
|
return TPA6130_FAIL;
|
|
}
|
|
|
|
return TPA6130_OK;
|
|
}
|
|
|
|
tpa6130_ret_t tpa_impl_write_reg(void *handle, uint8_t addr, uint8_t reg, uint8_t value) {
|
|
I2C_HandleTypeDef *hi2c = handle;
|
|
uint8_t tx_buf[2] = {reg, value};
|
|
|
|
if (HAL_I2C_Master_Transmit(hi2c, addr << 1U, tx_buf, 0x02, AMP_TXN_TIMEOUT) != HAL_OK) {
|
|
return TPA6130_FAIL;
|
|
}
|
|
|
|
return TPA6130_OK;
|
|
} |