Skip to content

Commit

Permalink
PMICDRV-184: Change what data is sent to pFnPmicCommIo{Rx,Wr}
Browse files Browse the repository at this point in the history
The prior implementation of `Pmic_io{Tx,Rx\}Byte()` passed the entire
I2C buffer that is used to calculate the I2C CRC into the user provided
functions `pFnPmicCommIo{Rd,Wr}()`;

Generally I2C driver functions are either designed so that they expect
to receive register subaddress and then data as two separate parameters,
or designed so that they don't have knowledge of subaddresses and the
user embeds those in the single 'data' parameter.

I'm not aware of any I2C APIs which expect to receive the device address
as part of the data packet to be transmitted.

The updated implementation provides all necessary components as separate
arguments:

- I2C device address -> handle->slaveAddress
- Register subaddress -> uint16_t regAddr parameter
- Data packet -> uint8_t *{rx,tx}Data parameter

Signed-off-by: Michael Leonard <[email protected]>
  • Loading branch information
LeonardMH committed Jul 1, 2024
1 parent ab34bcb commit 9cb4862
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/pmic_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ static uint8_t IO_calcCRC8(uint8_t cmd, uint8_t rdwr, uint8_t dat) {
int32_t Pmic_ioRxByte(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t *pRxBuffer) {
int32_t status = PMIC_ST_SUCCESS;
uint8_t rxBuf[PMIC_IO_BUF_SIZE] = {0};
const uint8_t frameSize = handle->crcEnable ? 2U : 1U;

status = handle->pFnPmicCommIoRd(handle, (uint8_t)PMIC_MAIN_INST, regAddr, &rxBuf[0], 2U);
status = handle->pFnPmicCommIoRd(handle, (uint8_t)PMIC_MAIN_INST, regAddr, &rxBuf[0], frameSize);

if (status == PMIC_ST_SUCCESS) {
*pRxBuffer = rxBuf[0];
Expand All @@ -98,7 +99,7 @@ int32_t Pmic_ioRxByte_CS(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t *r
int32_t Pmic_ioTxByte(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t txData) {
/* Set write data to txBuf[2], with WDATA[7:0] */
uint8_t txBuf[PMIC_IO_BUF_SIZE] = {0U, 0U, txData, 0U};
const uint8_t frameSize = handle->crcEnable ? 4U : 3U;
const uint8_t frameSize = handle->crcEnable ? 2U : 1U;

/* Frame 3 Bytes with IO header+data as per PMIC I2C IO algorithm explained
* in PMIC TRM */
Expand All @@ -112,7 +113,7 @@ int32_t Pmic_ioTxByte(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t txDat
txBuf[3U] = IO_calcCRC8(txBuf[0], txBuf[1], txData);
}

return handle->pFnPmicCommIoWr(handle, (uint8_t)PMIC_MAIN_INST, regAddr, &txBuf[0], frameSize);
return handle->pFnPmicCommIoWr(handle, (uint8_t)PMIC_MAIN_INST, regAddr, &txBuf[2], frameSize);
}

int32_t Pmic_ioTxByte_CS(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t txData) {
Expand Down

0 comments on commit 9cb4862

Please sign in to comment.