miguelbalboa / rfid

Arduino RFID Library for MFRC522
The Unlicense
2.74k stars 1.43k forks source link

fix: timeout on Non-AVR boards; feat: Use yield() in busy wait loops #569

Closed greezybacon closed 3 years ago

greezybacon commented 3 years ago

Also, be more scientific about the timeouts rather than using a set number of loops, the time of which depends on the value of the MRFC522_SPICLOCK as well as F_CPU. Instead, use a set number of milliseconds as a deadline.

In my project, I'm using the EventResponder to perform activities during busy wait loops like some of the loops in the library. Using yield() allows the timing on the activities to be more consistent. Plus, I'm also putting the MCU into a lower power mode in as part of the EventResponder/idle loop which allows for better power and heat management in delay and wait loops.

On the Teensy platform, a call to millis() is free as it's a register lookup. It's also a register lookup on the Arduino platform with a very small amount of overhead. All in all, for folks not using yield() I would think this edit wouldn't provide a negative impact.

edit by @Rotzbua : The previous timeout code was designed for AVR based Arduinos. Now it should work properly on Non-AVR boards. So I think it is also a bug fix.

Q A
Bug fix? yes
New feature? yes
Doc update? no
BC breaks? no
Deprecations? no
Fixed tickets not sure
greezybacon commented 3 years ago

@Rotzbua I made the changes you requested. Let me know what you think of them and if you'd like other changes.

greezybacon commented 3 years ago

@Rotzbua done.