Skip to content

Commit

Permalink
Fix I2C handling of 1 byte external memory address
Browse files Browse the repository at this point in the history
  • Loading branch information
ShuopengDeng authored and Kyle Kearney committed Aug 27, 2019
1 parent 5f9881f commit 141742e
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions targets/TARGET_Cypress/TARGET_PSOC6/psoc6csp/hal/src/cyhal_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,19 @@ cy_rslt_t cyhal_i2c_slave_config_read_buff(cyhal_i2c_t *obj, uint8_t *data, uint
cy_rslt_t cyhal_i2c_master_mem_write(cyhal_i2c_t *obj, uint16_t address, uint16_t mem_addr, uint16_t mem_addr_size, const uint8_t *data, uint16_t size, uint32_t timeout)
{
uint8_t mem_addr_buf[2];
mem_addr_buf[0] = (uint8_t)(mem_addr >> 8);
mem_addr_buf[1] = (uint8_t)mem_addr;
if (mem_addr_size == 1)
{
mem_addr_buf[0] = (uint8_t)mem_addr;
}
else if (mem_addr_size == 2)
{
mem_addr_buf[0] = (uint8_t)(mem_addr >> 8);
mem_addr_buf[1] = (uint8_t)mem_addr;
}
else
{
return CYHAL_I2C_RSLT_ERR_INVALID_ADDRESS_SIZE;
}

cy_rslt_t status = cyhal_i2c_master_write(obj, address, mem_addr_buf, mem_addr_size, timeout, false);

Expand All @@ -427,8 +438,19 @@ cy_rslt_t cyhal_i2c_master_mem_write(cyhal_i2c_t *obj, uint16_t address, uint16_
cy_rslt_t cyhal_i2c_master_mem_read(cyhal_i2c_t *obj, uint16_t address, uint16_t mem_addr, uint16_t mem_addr_size, uint8_t *data, uint16_t size, uint32_t timeout)
{
uint8_t mem_addr_buf[2];
mem_addr_buf[0] = (uint8_t)(mem_addr >> 8);
mem_addr_buf[1] = (uint8_t)mem_addr;
if (mem_addr_size == 1)
{
mem_addr_buf[0] = (uint8_t)mem_addr;
}
else if (mem_addr_size == 2)
{
mem_addr_buf[0] = (uint8_t)(mem_addr >> 8);
mem_addr_buf[1] = (uint8_t)mem_addr;
}
else
{
return CYHAL_I2C_RSLT_ERR_INVALID_ADDRESS_SIZE;
}

cy_rslt_t status = cyhal_i2c_master_write(obj, address, mem_addr_buf, mem_addr_size, timeout, false);
if (status == CY_RSLT_SUCCESS)
Expand Down

0 comments on commit 141742e

Please sign in to comment.