diff --git a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 8186a0f..43a91d3 100644 --- a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -164,19 +164,23 @@ void pulse(int pin, int times); #define SPI_MODE0 0x00 +#if !defined(ARDUINO_API_VERSION) // A SPISettings class is declared by ArduinoCore-API class SPISettings { public: // clock is in Hz - SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : clock(clock) { + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : clockFreq(clock) { (void) bitOrder; (void) dataMode; }; - private: - uint32_t clock; + uint32_t getClockFreq() const { + return clockFreq; + } - friend class BitBangedSPI; + private: + uint32_t clockFreq; }; +#endif // !defined(ARDUINO_API_VERSION) class BitBangedSPI { public: @@ -189,7 +193,7 @@ class BitBangedSPI { } void beginTransaction(SPISettings settings) { - pulseWidth = (500000 + settings.clock - 1) / settings.clock; + pulseWidth = (500000 + settings.getClockFreq() - 1) / settings.getClockFreq(); if (pulseWidth == 0) { pulseWidth = 1; } @@ -229,7 +233,7 @@ void setup() { } -int error = 0; +int ISPError = 0; int pmode = 0; // address for reading and writing, set by 'U' command unsigned int here; @@ -289,7 +293,7 @@ void loop(void) { digitalWrite(LED_PMODE, LOW); } // is there an error? - if (error) { + if (ISPError) { digitalWrite(LED_ERR, HIGH); } else { digitalWrite(LED_ERR, LOW); @@ -340,7 +344,7 @@ void empty_reply() { SERIAL.print((char)STK_INSYNC); SERIAL.print((char)STK_OK); } else { - error++; + ISPError++; SERIAL.print((char)STK_NOSYNC); } } @@ -351,7 +355,7 @@ void breply(uint8_t b) { SERIAL.print((char)b); SERIAL.print((char)STK_OK); } else { - error++; + ISPError++; SERIAL.print((char)STK_NOSYNC); } } @@ -490,7 +494,7 @@ void write_flash(int length) { SERIAL.print((char) STK_INSYNC); SERIAL.print((char) write_flash_pages(length)); } else { - error++; + ISPError++; SERIAL.print((char) STK_NOSYNC); } } @@ -519,7 +523,7 @@ uint8_t write_eeprom(unsigned int length) { unsigned int start = here * 2; unsigned int remaining = length; if (length > param.eepromsize) { - error++; + ISPError++; return STK_FAILED; } while (remaining > EECHUNK) { @@ -560,7 +564,7 @@ void program_page() { SERIAL.print((char) STK_INSYNC); SERIAL.print(result); } else { - error++; + ISPError++; SERIAL.print((char) STK_NOSYNC); } return; @@ -604,7 +608,7 @@ void read_page() { length += getch(); char memtype = getch(); if (CRC_EOP != getch()) { - error++; + ISPError++; SERIAL.print((char) STK_NOSYNC); return; } @@ -620,7 +624,7 @@ void read_page() { void read_signature() { if (CRC_EOP != getch()) { - error++; + ISPError++; SERIAL.print((char) STK_NOSYNC); return; } @@ -643,7 +647,7 @@ void avrisp() { uint8_t ch = getch(); switch (ch) { case '0': // signon - error = 0; + ISPError = 0; empty_reply(); break; case '1': @@ -652,7 +656,7 @@ void avrisp() { SERIAL.print("AVR ISP"); SERIAL.print((char) STK_OK); } else { - error++; + ISPError++; SERIAL.print((char) STK_NOSYNC); } break; @@ -702,7 +706,7 @@ void avrisp() { universal(); break; case 'Q': //0x51 - error = 0; + ISPError = 0; end_pmode(); empty_reply(); break; @@ -714,13 +718,13 @@ void avrisp() { // expecting a command, not CRC_EOP // this is how we can get back in sync case CRC_EOP: - error++; + ISPError++; SERIAL.print((char) STK_NOSYNC); break; // anything else we will return STK_UNKNOWN default: - error++; + ISPError++; if (CRC_EOP == getch()) { SERIAL.print((char)STK_UNKNOWN); } else {