esp-idf-hal icon indicating copy to clipboard operation
esp-idf-hal copied to clipboard

Fix for #412

Open empirephoenix opened this issue 3 months ago • 3 comments

Use the newer calculation for the i2c

empirephoenix avatar May 08 '24 19:05 empirephoenix

@ivmarkov I would need some advice, log2 is not available in std but would be required for the calculation, I could do this with ilog2, but then I have no idea how to ensure the ceiling() is done correctly. Any advice?

empirephoenix avatar May 09 '24 18:05 empirephoenix

@ivmarkov I would need some advice, log2 is not available in std but would be required for the calculation, I could do this with ilog2, but then I have no idea how to ensure the ceiling() is done correctly. Any advice?

... assuming you do the math with u64, the following might work: abc.ilog2() + (if abc.leading_zeroes() + abc.trailing_zeroes() + 1 < 64 { 1 } else { 0 })

NOTE 1: Ideally, you should avoid floating point math anyway, on MCUs and esps specifically. NOTE 2: I have not checked yet your computation and why you need to take the logarithm of something

ivmarkov avatar May 09 '24 18:05 ivmarkov

Ok this seems to work, 104ms returns 22 for the register while 105 rounds up to 23 and is properly failing

empirephoenix avatar May 10 '24 11:05 empirephoenix