# HG changeset patch # User Paul Boddie # Date 1563922290 -7200 # Node ID e60d54c4797f4d91ab148f625cc0e27a9c4ad82b # Parent e65cdd33bc715f65c9497963bd4187fc56e7dcc9 Simplified the read threshold computation. Added some more commentary. diff -r e65cdd33bc71 -r e60d54c4797f pkg/devices/lib/i2c/src/jz4780.cc --- a/pkg/devices/lib/i2c/src/jz4780.cc Mon Jul 22 00:17:30 2019 +0200 +++ b/pkg/devices/lib/i2c/src/jz4780.cc Wed Jul 24 00:51:30 2019 +0200 @@ -472,6 +472,8 @@ if (!can_queue) return; + // At most, only queue as many reads as are remaining. + if (remaining < can_queue) can_queue = remaining; @@ -487,6 +489,7 @@ // Issue the stop condition after the final read request. // In practice, an extra read request works better since it does not risk a // transmission abort condition and would permit following transactions. + // However, it does risk causing an address autoincrement with some devices. if (_total == _reqpos) _regs[Smb_data_command] = Smb_command_read; @@ -542,13 +545,7 @@ // Read all expected. - if (queued <= Smb_fifo_limit) - _regs[Rx_fifo_thold] = queued - 1; - - // Read to limit. - - else - _regs[Rx_fifo_thold] = Smb_fifo_limit - 1; + _regs[Rx_fifo_thold] = queued - 1; } // Read from the target device.