stevemarple / SoftWire

Software I2C implementation for Arduino and other Wiring-type environments
GNU Lesser General Public License v2.1
136 stars 31 forks source link

llStartWait() case nack needs to include break or return #25

Closed waynepiekarski closed 2 years ago

waynepiekarski commented 2 years ago

In the llStartWait() function, the stop() call for case nack should include either a break; or a return immediately after it. Currently my compiler is giving "warning: this statement may fall through". It looks like it currently will call stop() twice, then return timedOut, but not sure what the actual intent is here.

SoftWire::result_t SoftWire::llStartWait(uint8_t rawAddr) const
{
        AsyncDelay timeout(_timeout_ms, AsyncDelay::MILLIS);

        while (!timeout.isExpired()) {
                // Force SDA low                                                                                                                                                                                  
                _sdaLow(this);
                delayMicroseconds(_delay_us);

                switch (llWrite(rawAddr)) {
                case ack:
                        return ack;
                case nack:
                        stop();
                default:
                        // timeout, and anything else we don't know about                                                                                                                                         
                        stop();
                        return timedOut;
                }
        }
        return timedOut;
}
stevemarple commented 2 years ago

I believe this error has already been corrected: https://github.com/stevemarple/SoftWire/commit/0e111150fe7d3d9832f725089d8a822254945046

waynepiekarski commented 2 years ago

Ah, thanks, you are right, this was fixed in 2.0.5.

The version on Arduino's download manager is still 2.0.4 with the bug, and that is what I was looking at.

Can this update be pushed to Arduino? Thanks.

stevemarple commented 2 years ago

Updates are pushed automatically when I add a tag to a commit and push to Github. I can see v2.0.5 in the Arduino library manager (tested with 1.18.13). There were some issues with an incorrectly tagged v2.0.6. I have removed that tag and pushed v2.0.7.