From d58cbe70571b7f6172014fafed63bd48abdad9c6 Mon Sep 17 00:00:00 2001
From: Sean Mathews <coder@f34r.com>
Date: Wed, 24 Oct 2018 17:06:35 -0700
Subject: [PATCH 1/4] Sync issue when host sends multiple signon requests

If the host sends a signon but does not get a SYNC response it will send again. This will lead to being out of sync with data in the rx buffer that is not consumed. To avoid this we consume all extra host bytes before sending a INSYNC reply.
---
 examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
index 43a91d3..f1baae1 100644
--- a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
+++ b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
@@ -341,6 +341,9 @@ uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
 
 void empty_reply() {
   if (CRC_EOP == getch()) {
+    // clear RX buffer. No more host data expected until after SYNC.
+    while(SERIAL.available())
+        SERIAL.read();
     SERIAL.print((char)STK_INSYNC);
     SERIAL.print((char)STK_OK);
   } else {

From aed98a8701fda12742dd0a8630e52ed5c0042acd Mon Sep 17 00:00:00 2001
From: per1234 <accounts@perglass.com>
Date: Thu, 25 Oct 2018 20:02:29 -0700
Subject: [PATCH 2/4] Update
 build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino

Co-Authored-By: f34rdotcom <coder@f34r.com>
---
 examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
index f1baae1..4139a56 100644
--- a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
+++ b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
@@ -343,7 +343,7 @@ void empty_reply() {
   if (CRC_EOP == getch()) {
     // clear RX buffer. No more host data expected until after SYNC.
     while(SERIAL.available())
-        SERIAL.read();
+      SERIAL.read();
     SERIAL.print((char)STK_INSYNC);
     SERIAL.print((char)STK_OK);
   } else {

From 8a5d05161084de20c2b1aaab59aa356df67a7cd5 Mon Sep 17 00:00:00 2001
From: per1234 <accounts@perglass.com>
Date: Thu, 25 Oct 2018 20:02:35 -0700
Subject: [PATCH 3/4] Update
 build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino

Co-Authored-By: f34rdotcom <coder@f34r.com>
---
 examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
index 4139a56..add4e1c 100644
--- a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
+++ b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
@@ -342,7 +342,7 @@ uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
 void empty_reply() {
   if (CRC_EOP == getch()) {
     // clear RX buffer. No more host data expected until after SYNC.
-    while(SERIAL.available())
+    while (SERIAL.available())
       SERIAL.read();
     SERIAL.print((char)STK_INSYNC);
     SERIAL.print((char)STK_OK);

From ed2de12e009f12e07fb741f82d17f65988f0c0d3 Mon Sep 17 00:00:00 2001
From: per1234 <accounts@perglass.com>
Date: Fri, 25 Sep 2020 20:13:41 -0700
Subject: [PATCH 4/4] Make ArduinoISP code formatting compliant with
 examples_formatter.conf

---
 examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
index add4e1c..5e906af 100644
--- a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
+++ b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
@@ -342,8 +342,9 @@ uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
 void empty_reply() {
   if (CRC_EOP == getch()) {
     // clear RX buffer. No more host data expected until after SYNC.
-    while (SERIAL.available())
+    while (SERIAL.available()) {
       SERIAL.read();
+    }
     SERIAL.print((char)STK_INSYNC);
     SERIAL.print((char)STK_OK);
   } else {