i2c: set high and low times to values that conform to the i2c specification (#314)

This commit is contained in:
Brian Cooke 2021-04-09 12:00:33 +02:00 committed by GitHub
parent 4fe995d0ec
commit f69f513a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,8 +67,8 @@ uint i2c_set_baudrate(i2c_inst_t *i2c, uint baudrate) {
// TODO there are some subtleties to I2C timing which we are completely ignoring here
uint period = (freq_in + baudrate / 2) / baudrate;
uint hcnt = period * 3 / 5; // oof this one hurts
uint lcnt = period - hcnt;
uint lcnt = period * 3 / 5; // oof this one hurts
uint hcnt = period - lcnt;
// Check for out-of-range divisors:
invalid_params_if(I2C, hcnt > I2C_IC_FS_SCL_HCNT_IC_FS_SCL_HCNT_BITS);
invalid_params_if(I2C, lcnt > I2C_IC_FS_SCL_LCNT_IC_FS_SCL_LCNT_BITS);