Enable I2C FIFO full hold in slave mode (stretch clock when RX full), fixes #456 (#494)

This commit is contained in:
Luke Wren 2021-06-29 17:55:01 +01:00 committed by GitHub
parent f16ccfa1ff
commit edcb65c916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,16 +115,18 @@ void i2c_set_slave_mode(i2c_inst_t *i2c, bool slave, uint8_t addr) {
invalid_params_if(I2C, addr >= 0x80); // 7-bit addresses invalid_params_if(I2C, addr >= 0x80); // 7-bit addresses
invalid_params_if(I2C, i2c_reserved_addr(addr)); invalid_params_if(I2C, i2c_reserved_addr(addr));
i2c->hw->enable = 0; i2c->hw->enable = 0;
uint32_t ctrl_set_if_master = I2C_IC_CON_MASTER_MODE_BITS | I2C_IC_CON_IC_SLAVE_DISABLE_BITS;
uint32_t ctrl_set_if_slave = I2C_IC_CON_RX_FIFO_FULL_HLD_CTRL_BITS;
if (slave) { if (slave) {
hw_clear_bits(&i2c->hw->con, hw_write_masked(&i2c->hw->con,
I2C_IC_CON_MASTER_MODE_BITS | ctrl_set_if_slave,
I2C_IC_CON_IC_SLAVE_DISABLE_BITS ctrl_set_if_master | ctrl_set_if_slave
); );
i2c->hw->sar = addr; i2c->hw->sar = addr;
} else { } else {
hw_set_bits(&i2c->hw->con, hw_write_masked(&i2c->hw->con,
I2C_IC_CON_MASTER_MODE_BITS | ctrl_set_if_master,
I2C_IC_CON_IC_SLAVE_DISABLE_BITS ctrl_set_if_master | ctrl_set_if_slave
); );
} }
i2c->hw->enable = 1; i2c->hw->enable = 1;