# HG changeset patch # User Paul Boddie # Date 1612046325 -3600 # Node ID eada6b587c0cbb58e25319417b576e65f1d1957d # Parent 152c4fc0a9679f2e37abd6faec6fd2ef571ed50e Avoid needless (but harmless) entry into the read loop when NACK is present. Added various comments to the I2C driver. diff -r 152c4fc0a967 -r eada6b587c0c pkg/devices/lib/i2c/src/jz4730.cc --- a/pkg/devices/lib/i2c/src/jz4730.cc Sat Jan 16 23:48:09 2021 +0100 +++ b/pkg/devices/lib/i2c/src/jz4730.cc Sat Jan 30 23:38:45 2021 +0100 @@ -1,7 +1,7 @@ /* * I2C support for the JZ4730. * - * Copyright (C) 2017, 2018, 2020 Paul Boddie + * Copyright (C) 2017, 2018, 2020, 2021 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -179,6 +179,8 @@ if (!set_address(address, true)) return 0; + // Wait for an opportunity to begin reading. + do { if (!wait_for_irq(1000000)) @@ -186,6 +188,16 @@ } while (transferring() || (!data_valid() && !nack())); + // Device apparently unavailable. + + if (nack()) + { + stop(); + return nread; + } + + // Attempt to read from the device. + while (nread < length) { do