From a2a06f56cce4f378ffa9e21c442ca1b1a57f8b76 Mon Sep 17 00:00:00 2001 From: "Randall Bohn (Huckle)" Date: Tue, 31 Jan 2012 05:51:18 -0700 Subject: [PATCH 001/175] Be more specific about datatypes in the parameter struct. --- .../examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index d5bf7b81a..622d7cd35 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -91,12 +91,12 @@ typedef struct param { uint8_t selftimed; uint8_t lockbytes; uint8_t fusebytes; - int flashpoll; - int eeprompoll; - int pagesize; - int eepromsize; - int flashsize; -} + uint8_t flashpoll; + uint16_t eeprompoll; + uint16_t pagesize; + uint16_t eepromsize; + uint32_t flashsize; +} parameter; parameter param; From d968c7a8eee7f334ce7c3f9fcaba58c81f207630 Mon Sep 17 00:00:00 2001 From: "Randall Bohn (Huckle)" Date: Sat, 18 Feb 2012 07:18:29 -0700 Subject: [PATCH 002/175] Don't start_pmode if we're already in pmode. --- .../examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 622d7cd35..060ad77ac 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -66,7 +66,7 @@ void pulse(int pin, int times); void setup() { - Serial.begin(19200); + Serial.begin(9600); pinMode(LED_PMODE, OUTPUT); pulse(LED_PMODE, 2); pinMode(LED_ERR, OUTPUT); @@ -510,9 +510,13 @@ int avrisp() { fill(5); empty_reply(); break; - case 'P': - start_pmode(); + if (pmode) { + pulse(LED_ERR, 3); + } + else { + start_pmode(); + } empty_reply(); break; case 'U': // set address (word) From 8dfe833e499c05205caf369b22dfcda7f727f2de Mon Sep 17 00:00:00 2001 From: "Randall Bohn (Huckle)" Date: Sat, 18 Feb 2012 09:11:58 -0700 Subject: [PATCH 003/175] Set error if GET_SIGN_ON not followed by CRC_EOP --- .../shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 060ad77ac..6578aa4bf 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -497,6 +497,10 @@ int avrisp() { Serial.print("AVR ISP"); Serial.print((char) STK_OK); } + else { + error++; + Serial.print((char) STK_NOSYNC); + } break; case 'A': get_version(getch()); @@ -574,5 +578,3 @@ int avrisp() { } } - - From aeaed27e1342141da72959e8602b813ee2d5273d Mon Sep 17 00:00:00 2001 From: "Randall Bohn (Huckle)" Date: Sat, 18 Feb 2012 10:11:05 -0700 Subject: [PATCH 004/175] Use SPI library. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 52 ++++++------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 6578aa4bf..7b67f6e54 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -43,6 +43,7 @@ // - The SPI functions herein were developed for the AVR910_ARD programmer // - More information at http://code.google.com/p/mega-isp +#include "SPI.h" #include "pins_arduino.h" #define RESET SS @@ -67,12 +68,17 @@ void pulse(int pin, int times); void setup() { Serial.begin(9600); + SPI.setDataMode(0); + SPI.setBitOrder(MSBFIRST); + // Clock Div can be 2,4,8,16,32,64, or 128 + SPI.setClockDivider(SPI_CLOCK_DIV128); pinMode(LED_PMODE, OUTPUT); pulse(LED_PMODE, 2); pinMode(LED_ERR, OUTPUT); pulse(LED_ERR, 2); pinMode(LED_HB, OUTPUT); pulse(LED_HB, 2); + } int error = 0; @@ -96,7 +102,7 @@ typedef struct param { uint16_t pagesize; uint16_t eepromsize; uint32_t flashsize; -} +} parameter; parameter param; @@ -164,33 +170,13 @@ void prog_lamp(int state) { } } -void spi_init() { - uint8_t x; - SPCR = 0x53; - x = SPSR; - x = SPDR; -} - -void spi_wait() { - do { - } while (!(SPSR & (1 << SPIF))); -} - -uint8_t spi_send(uint8_t b) { - uint8_t reply; - SPDR = b; - spi_wait(); - reply = SPDR; - return reply; -} - uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { uint8_t n; - spi_send(a); - n = spi_send(b); + SPI.transfer(a); + n = SPI.transfer(b); //if (n != a) error = -1; - n = spi_send(c); - return spi_send(d); + n = SPI.transfer(c); + return SPI.transfer(d); } void empty_reply() { @@ -259,25 +245,19 @@ void set_parameters() { } void start_pmode() { - spi_init(); - // following delays may not work on all targets... - pinMode(RESET, OUTPUT); + SPI.begin(); digitalWrite(RESET, HIGH); - pinMode(SCK, OUTPUT); + pinMode(RESET, OUTPUT); digitalWrite(SCK, LOW); - delay(50); + delay(20); digitalWrite(RESET, LOW); - delay(50); - pinMode(MISO, INPUT); - pinMode(MOSI, OUTPUT); spi_transaction(0xAC, 0x53, 0x00, 0x00); pmode = 1; } void end_pmode() { - pinMode(MISO, INPUT); - pinMode(MOSI, INPUT); - pinMode(SCK, INPUT); + SPI.end(); + digitalWrite(RESET, HIGH); pinMode(RESET, INPUT); pmode = 0; } From ad2a32fd24edbe4e6052995594badacfa4cd2bab Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Fri, 13 Feb 2015 20:48:40 +0100 Subject: [PATCH 005/175] Avoid delay in heartbeat. That way we can also set the baudrate back to the value used in the IDE. In fact, with this fix, baud rates of up to 115200 work also. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 7b67f6e54..9ad5a1b33 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -67,7 +67,7 @@ void pulse(int pin, int times); void setup() { - Serial.begin(9600); + Serial.begin(19200); SPI.setDataMode(0); SPI.setBitOrder(MSBFIRST); // Clock Div can be 2,4,8,16,32,64, or 128 @@ -111,18 +111,17 @@ parameter param; uint8_t hbval = 128; int8_t hbdelta = 8; void heartbeat() { - if (hbval > 192) { - hbdelta = -hbdelta; - } - if (hbval < 32) { - hbdelta = -hbdelta; - } + static unsigned long last_time = 0; + unsigned long now = millis(); + if ((now - last_time) < 40) + return; + last_time = now; + if (hbval > 192) hbdelta = -hbdelta; + if (hbval < 32) hbdelta = -hbdelta; hbval += hbdelta; analogWrite(LED_HB, hbval); - delay(20); } - void loop(void) { // is pmode active? if (pmode) { From 93b31b6cfa721372260a810f1048b6fb75b15ee1 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Wed, 25 Feb 2015 21:17:22 +0100 Subject: [PATCH 006/175] Simply use pin 10 to reset the target. It works for all Arduino's and allows the same "ArduinoISP shield" to be used on all of them. Such a shield has an ISP connector that: - wires MISO,MOSI, SCK, GND and 5V to the ISP connector of the programming Arduino - wires RESET to pin 10 of the programming Arduino. --- .../shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 9ad5a1b33..bff56fd54 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -7,7 +7,7 @@ // using the following arduino pins: // // pin name: not-mega: mega(1280 and 2560) -// slave reset: 10: 53 +// slave reset: 10: 10 // MOSI: 11: 51 // MISO: 12: 50 // SCK: 13: 52 @@ -45,7 +45,8 @@ #include "SPI.h" #include "pins_arduino.h" -#define RESET SS +// Use pin 10 to reset the target +#define RESET 10 #define LED_HB 9 #define LED_ERR 8 From 56e09109dfd051c4af8bee8e21972a87ac05faa4 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Wed, 25 Feb 2015 21:30:34 +0100 Subject: [PATCH 007/175] The delay between reset and the enter progmode command got lost when introducing the SPI library. Put it back in. --- build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index bff56fd54..2f31d6269 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -251,6 +251,7 @@ void start_pmode() { digitalWrite(SCK, LOW); delay(20); digitalWrite(RESET, LOW); + delay(50); spi_transaction(0xAC, 0x53, 0x00, 0x00); pmode = 1; } From 15da182399658719fbf2906295cc413aedac706e Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Wed, 25 Feb 2015 21:52:30 +0100 Subject: [PATCH 008/175] Support at89sx mcu's by adding the possibility to specify the polarity of the target reset signal. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 2f31d6269..0569a3464 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -123,6 +123,13 @@ void heartbeat() { analogWrite(LED_HB, hbval); } +static bool rst_active_high; + +void reset_target(bool reset) +{ + digitalWrite(RESET, ((reset && rst_active_high) || (!reset && !rst_active_high)) ? HIGH : LOW); +} + void loop(void) { // is pmode active? if (pmode) { @@ -242,15 +249,24 @@ void set_parameters() { + buff[18] * 0x00000100 + buff[19]; + // avr devices have active low reset, at89sx are active high + rst_active_high = (param.devicecode >= 0xe0); } void start_pmode() { SPI.begin(); - digitalWrite(RESET, HIGH); + // SPI.begin() has configured SS as output, + // so SPI master mode is selected. + // We have defined RESET as pin 10, + // which for many arduino's is not the SS pin. + // So we have to configure RESET as output here, + // (reset_target() first sets the level correct) + reset_target(false); pinMode(RESET, OUTPUT); + digitalWrite(SCK, LOW); delay(20); - digitalWrite(RESET, LOW); + reset_target(true); delay(50); spi_transaction(0xAC, 0x53, 0x00, 0x00); pmode = 1; @@ -258,7 +274,7 @@ void start_pmode() { void end_pmode() { SPI.end(); - digitalWrite(RESET, HIGH); + reset_target(false); pinMode(RESET, INPUT); pmode = 0; } From a17a7577224d33cb36be590fde994d7327707ae5 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Wed, 25 Feb 2015 21:55:14 +0100 Subject: [PATCH 009/175] Configure SPI pins as input when target is not in reset. --- build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 0569a3464..8a63e8e8b 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -274,6 +274,10 @@ void start_pmode() { void end_pmode() { SPI.end(); + // We're about to take the target out of reset + // so configure SPI pins as input + pinMode(MOSI, INPUT); + pinMode(SCK, INPUT); reset_target(false); pinMode(RESET, INPUT); pmode = 0; From 64e52d8016662a3c741e64697377ab7dc37408d0 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Tue, 16 Jun 2015 22:10:25 +0200 Subject: [PATCH 010/175] Implement bitbang SPI for slow clock devices. (Sylvan Butler). --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 8a63e8e8b..09e33b66c 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -43,7 +43,6 @@ // - The SPI functions herein were developed for the AVR910_ARD programmer // - More information at http://code.google.com/p/mega-isp -#include "SPI.h" #include "pins_arduino.h" // Use pin 10 to reset the target #define RESET 10 @@ -53,6 +52,17 @@ #define LED_PMODE 7 #define PROG_FLICKER true +#if defined(ARDUINO_ARCH_SAM) or defined(ARDUINO_ARCH_SAMD) + +#define SPI_CLOCK_DIV_MAX 255 + +#else + +#define USE_HARDWARE_SPI +#define SPI_CLOCK_DIV_MAX SPI_CLOCK_DIV_128 + +#endif + #define HWVER 2 #define SWMAJ 1 #define SWMIN 18 @@ -67,12 +77,52 @@ void pulse(int pin, int times); +#ifdef USE_HARDWARE_SPI +#include "SPI.h" +#else + +class BitBangedSPI { + public: + void setDataMode(uint8_t dataMode) { + (void) dataMode; + } + void setBitOrder(uint8_t bitOrder) { + (void) bitOrder; + } + void setClockDivider(uint8_t clockDiv) { + (void) clockDiv; + } + + void begin() { + pinMode(MISO, INPUT); + pinMode(RESET, OUTPUT); + pinMode(SCK, OUTPUT); + pinMode(MOSI, OUTPUT); + } + + void end() {} + + uint8_t transfer (uint8_t b) { + for (unsigned int i = 0; i < 8; ++i) { + digitalWrite(MOSI, b & 0x80); + digitalWrite(SCK, HIGH); + b = (b << 1) | digitalRead(MISO); + digitalWrite(SCK, LOW); // slow pulse + } + return b; + } +}; + +static BitBangedSPI SPI; + +#endif + void setup() { Serial.begin(19200); SPI.setDataMode(0); SPI.setBitOrder(MSBFIRST); - // Clock Div can be 2,4,8,16,32,64, or 128 - SPI.setClockDivider(SPI_CLOCK_DIV128); + // Select the slowest possible clock + SPI.setClockDivider(SPI_CLOCK_DIV_MAX); pinMode(LED_PMODE, OUTPUT); pulse(LED_PMODE, 2); pinMode(LED_ERR, OUTPUT); From c8b5e99267d4eb0979b8f7586dbb2dbb54276251 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Tue, 7 Jul 2015 21:42:21 +0200 Subject: [PATCH 011/175] Configure the serial port to use. Prefer native USB port if the Arduino has one. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 112 ++++++++++-------- 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 09e33b66c..7e7a33c4f 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -43,7 +43,9 @@ // - The SPI functions herein were developed for the AVR910_ARD programmer // - More information at http://code.google.com/p/mega-isp -#include "pins_arduino.h" +#include "Arduino.h" +#undef SERIAL + // Use pin 10 to reset the target #define RESET 10 @@ -63,6 +65,26 @@ #endif + +// Configure the serial port to use. +// +// Prefer the USB virtual serial port (aka. native USB port), if the Arduino has one: +// - it does not autoreset (except for the magic baud rate of 1200). +// - it is more reliable because of USB handshaking. +// +// Leonardo and similar have an USB virtual serial port: 'Serial'. +// Due and Zero have an USB virtual serial port: 'SerialUSB'. +// +// On the Due and Zero, 'Serial' can be used too, provided you disable autoreset. +// To use 'Serial': #define SERIAL Serial + +#ifdef SERIAL_PORT_USBVIRTUAL +#define SERIAL SERIAL_PORT_USBVIRTUAL +#else +#define SERIAL Serial +#endif + + #define HWVER 2 #define SWMAJ 1 #define SWMIN 18 @@ -118,7 +140,7 @@ static BitBangedSPI SPI; #endif void setup() { - Serial.begin(19200); + SERIAL.begin(19200); SPI.setDataMode(0); SPI.setBitOrder(MSBFIRST); // Select the slowest possible clock @@ -196,14 +218,14 @@ void loop(void) { // light the heartbeat LED heartbeat(); - if (Serial.available()) { + if (SERIAL.available()) { avrisp(); } } uint8_t getch() { - while (!Serial.available()); - return Serial.read(); + while (!SERIAL.available()); + return SERIAL.read(); } void fill(int n) { for (int x = 0; x < n; x++) { @@ -238,22 +260,22 @@ uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { void empty_reply() { if (CRC_EOP == getch()) { - Serial.print((char)STK_INSYNC); - Serial.print((char)STK_OK); + SERIAL.print((char)STK_INSYNC); + SERIAL.print((char)STK_OK); } else { error++; - Serial.print((char)STK_NOSYNC); + SERIAL.print((char)STK_NOSYNC); } } void breply(uint8_t b) { if (CRC_EOP == getch()) { - Serial.print((char)STK_INSYNC); - Serial.print((char)b); - Serial.print((char)STK_OK); + SERIAL.print((char)STK_INSYNC); + SERIAL.print((char)b); + SERIAL.print((char)STK_OK); } else { error++; - Serial.print((char)STK_NOSYNC); + SERIAL.print((char)STK_NOSYNC); } } @@ -380,11 +402,11 @@ int current_page(int addr) { void write_flash(int length) { fill(length); if (CRC_EOP == getch()) { - Serial.print((char) STK_INSYNC); - Serial.print((char) write_flash_pages(length)); + SERIAL.print((char) STK_INSYNC); + SERIAL.print((char) write_flash_pages(length)); } else { error++; - Serial.print((char) STK_NOSYNC); + SERIAL.print((char) STK_NOSYNC); } } @@ -451,15 +473,15 @@ void program_page() { if (memtype == 'E') { result = (char)write_eeprom(length); if (CRC_EOP == getch()) { - Serial.print((char) STK_INSYNC); - Serial.print(result); + SERIAL.print((char) STK_INSYNC); + SERIAL.print(result); } else { error++; - Serial.print((char) STK_NOSYNC); + SERIAL.print((char) STK_NOSYNC); } return; } - Serial.print((char)STK_FAILED); + SERIAL.print((char)STK_FAILED); return; } @@ -473,9 +495,9 @@ uint8_t flash_read(uint8_t hilo, int addr) { char flash_read_page(int length) { for (int x = 0; x < length; x += 2) { uint8_t low = flash_read(LOW, here); - Serial.print((char) low); + SERIAL.print((char) low); uint8_t high = flash_read(HIGH, here); - Serial.print((char) high); + SERIAL.print((char) high); here++; } return STK_OK; @@ -487,7 +509,7 @@ char eeprom_read_page(int length) { for (int x = 0; x < length; x++) { int addr = start + x; uint8_t ee = spi_transaction(0xA0, (addr >> 8) & 0xFF, addr & 0xFF, 0xFF); - Serial.print((char) ee); + SERIAL.print((char) ee); } return STK_OK; } @@ -499,34 +521,29 @@ void read_page() { char memtype = getch(); if (CRC_EOP != getch()) { error++; - Serial.print((char) STK_NOSYNC); + SERIAL.print((char) STK_NOSYNC); return; } - Serial.print((char) STK_INSYNC); - if (memtype == 'F') { - result = flash_read_page(length); - } - if (memtype == 'E') { - result = eeprom_read_page(length); - } - Serial.print(result); - return; + SERIAL.print((char) STK_INSYNC); + if (memtype == 'F') result = flash_read_page(length); + if (memtype == 'E') result = eeprom_read_page(length); + SERIAL.print(result); } void read_signature() { if (CRC_EOP != getch()) { error++; - Serial.print((char) STK_NOSYNC); + SERIAL.print((char) STK_NOSYNC); return; } - Serial.print((char) STK_INSYNC); + SERIAL.print((char) STK_INSYNC); uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00); - Serial.print((char) high); + SERIAL.print((char) high); uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00); - Serial.print((char) middle); + SERIAL.print((char) middle); uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00); - Serial.print((char) low); - Serial.print((char) STK_OK); + SERIAL.print((char) low); + SERIAL.print((char) STK_OK); } ////////////////////////////////////////// ////////////////////////////////////////// @@ -544,13 +561,13 @@ int avrisp() { break; case '1': if (getch() == CRC_EOP) { - Serial.print((char) STK_INSYNC); - Serial.print("AVR ISP"); - Serial.print((char) STK_OK); + SERIAL.print((char) STK_INSYNC); + SERIAL.print("AVR ISP"); + SERIAL.print((char) STK_OK); } else { error++; - Serial.print((char) STK_NOSYNC); + SERIAL.print((char) STK_NOSYNC); } break; case 'A': @@ -615,17 +632,16 @@ int avrisp() { // this is how we can get back in sync case CRC_EOP: error++; - Serial.print((char) STK_NOSYNC); + SERIAL.print((char) STK_NOSYNC); break; // anything else we will return STK_UNKNOWN default: error++; - if (CRC_EOP == getch()) { - Serial.print((char)STK_UNKNOWN); - } else { - Serial.print((char)STK_NOSYNC); - } + if (CRC_EOP == getch()) + SERIAL.print((char)STK_UNKNOWN); + else + SERIAL.print((char)STK_NOSYNC); } } From eca360bf4204d95093a7c9e54e8babdf180df9ae Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Fri, 10 Jul 2015 14:02:47 +0200 Subject: [PATCH 012/175] Fix typo: SPI_CLOCK_DIV128 --- .../examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 7e7a33c4f..215a16bf7 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -54,14 +54,9 @@ #define LED_PMODE 7 #define PROG_FLICKER true -#if defined(ARDUINO_ARCH_SAM) or defined(ARDUINO_ARCH_SAMD) - -#define SPI_CLOCK_DIV_MAX 255 - -#else +#if !defined(ARDUINO_ARCH_SAM) and !defined(ARDUINO_ARCH_SAMD) #define USE_HARDWARE_SPI -#define SPI_CLOCK_DIV_MAX SPI_CLOCK_DIV_128 #endif @@ -101,8 +96,11 @@ void pulse(int pin, int times); #ifdef USE_HARDWARE_SPI #include "SPI.h" +#define SPI_CLOCK_DIV_MAX SPI_CLOCK_DIV128 #else +#define SPI_CLOCK_DIV_MAX 255 + class BitBangedSPI { public: void setDataMode(uint8_t dataMode) { From 5a04ab2a322ac18029232ff75c2ba4417f3f535a Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Mon, 13 Jul 2015 21:49:42 +0200 Subject: [PATCH 013/175] Don't pulse error led if avrdude enters programming mode twice --- .../shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 215a16bf7..eddeb11cb 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -581,12 +581,8 @@ int avrisp() { empty_reply(); break; case 'P': - if (pmode) { - pulse(LED_ERR, 3); - } - else { + if (!pmode) start_pmode(); - } empty_reply(); break; case 'U': // set address (word) From 50f9e539d8b424842f4dab9d1357b30c6db3e0d8 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Tue, 14 Jul 2015 21:20:39 +0200 Subject: [PATCH 014/175] Ensure minimum spi pulse width. --- .../examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index eddeb11cb..5c3144ba5 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -114,6 +114,10 @@ class BitBangedSPI { } void begin() { + // slow enough for an attiny85 @ 1MHz + // (pulseWidth should be > 2 cpu cycles, so take 3 cycles:) + pulseWidth = 3; + pinMode(MISO, INPUT); pinMode(RESET, OUTPUT); pinMode(SCK, OUTPUT); @@ -126,11 +130,16 @@ class BitBangedSPI { for (unsigned int i = 0; i < 8; ++i) { digitalWrite(MOSI, b & 0x80); digitalWrite(SCK, HIGH); + delayMicroseconds(pulseWidth); b = (b << 1) | digitalRead(MISO); digitalWrite(SCK, LOW); // slow pulse + delayMicroseconds(pulseWidth); } return b; } + + private: + unsigned long pulseWidth; // in microseconds }; static BitBangedSPI SPI; From 89184a36682abed7377ab508c7abb42389751f21 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Tue, 14 Jul 2015 23:06:54 +0200 Subject: [PATCH 015/175] Use new style SPI::beginTransaction() api, make SPI_CLOCK configurable, select hardware or software SPI based on SPI_CLOCK. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 62 +++++++++++++------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 5c3144ba5..57e78f4e3 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -54,12 +54,32 @@ #define LED_PMODE 7 #define PROG_FLICKER true -#if !defined(ARDUINO_ARCH_SAM) and !defined(ARDUINO_ARCH_SAMD) +// Configure SPI clock. +// E.g. for an attiny @128 kHz: +// (pulseWidth should be > 2 cpu cycles, so take 3 cycles:) +// #define SPI_CLOCK (128000/3) +// +// A clock slow enough for an attiny85 @ 1MHz, is a reasonable default: +#define SPI_CLOCK (1000000/3) + +// Select hardware or software SPI, depending on SPI clock. +// Currently only for AVR, for other archs (Due, Zero,...), +// hardware SPI is probably too fast anyway. + +#if defined(ARDUINO_ARCH_AVR) + +#if SPI_CLOCK > (F_CPU / 128) #define USE_HARDWARE_SPI +#endif #endif +#ifdef USE_HARDWARE_SPI +#warning hw spi !!! +#else +#warning NOT usung hw spi +#endif // Configure the serial port to use. // @@ -96,27 +116,34 @@ void pulse(int pin, int times); #ifdef USE_HARDWARE_SPI #include "SPI.h" -#define SPI_CLOCK_DIV_MAX SPI_CLOCK_DIV128 #else -#define SPI_CLOCK_DIV_MAX 255 +#define SPI_MODE0 0x00 + +class SPISettings { +public: + // clock is in Hz + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : clock(clock){ + (void) bitOrder; + (void) dataMode; + }; + +private: + uint32_t clock; + +friend class BitBangedSPI; +}; class BitBangedSPI { public: - void setDataMode(uint8_t dataMode) { - (void) dataMode; - } - void setBitOrder(uint8_t bitOrder) { - (void) bitOrder; - } - void setClockDivider(uint8_t clockDiv) { - (void) clockDiv; + + void beginTransaction(SPISettings settings) { + pulseWidth = 1000 / (settings.clock / 1000); + if (pulseWidth == 0) + pulseWidth = 1; } void begin() { - // slow enough for an attiny85 @ 1MHz - // (pulseWidth should be > 2 cpu cycles, so take 3 cycles:) - pulseWidth = 3; pinMode(MISO, INPUT); pinMode(RESET, OUTPUT); @@ -148,10 +175,9 @@ static BitBangedSPI SPI; void setup() { SERIAL.begin(19200); - SPI.setDataMode(0); - SPI.setBitOrder(MSBFIRST); - // Select the slowest possible clock - SPI.setClockDivider(SPI_CLOCK_DIV_MAX); + + SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0)); + pinMode(LED_PMODE, OUTPUT); pulse(LED_PMODE, 2); pinMode(LED_ERR, OUTPUT); From 8d95899450dcd2bbc6544b202d561f192d77b5b0 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Tue, 28 Jul 2015 22:26:58 +0200 Subject: [PATCH 016/175] Call SPI.beginTransaction() after SPI.begin() --- build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 57e78f4e3..6d1b74633 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -176,7 +176,6 @@ static BitBangedSPI SPI; void setup() { SERIAL.begin(19200); - SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0)); pinMode(LED_PMODE, OUTPUT); pulse(LED_PMODE, 2); @@ -360,6 +359,7 @@ void set_parameters() { void start_pmode() { SPI.begin(); + SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0)); // SPI.begin() has configured SS as output, // so SPI master mode is selected. // We have defined RESET as pin 10, From d271c1c8a2fe06fd86dcf826c1ce044a69e80741 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Tue, 28 Jul 2015 22:31:34 +0200 Subject: [PATCH 017/175] BitBangedSPI::begin(): initialize levels of SCK and MOSI. Correct indentation. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 6d1b74633..a4d3d4dfb 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -135,38 +135,37 @@ friend class BitBangedSPI; }; class BitBangedSPI { - public: +public: + void begin() { + digitalWrite(SCK, LOW); + digitalWrite(MOSI, LOW); + pinMode(SCK, OUTPUT); + pinMode(MOSI, OUTPUT); + pinMode(MISO, INPUT); + } - void beginTransaction(SPISettings settings) { - pulseWidth = 1000 / (settings.clock / 1000); - if (pulseWidth == 0) - pulseWidth = 1; + void beginTransaction(SPISettings settings) { + pulseWidth = 1000 / (settings.clock / 1000); + if (pulseWidth == 0) + pulseWidth = 1; + } + + void end() {} + + uint8_t transfer (uint8_t b) { + for (unsigned int i = 0; i < 8; ++i) { + digitalWrite(MOSI, b & 0x80); + digitalWrite(SCK, HIGH); + delayMicroseconds(pulseWidth); + b = (b << 1) | digitalRead(MISO); + digitalWrite(SCK, LOW); // slow pulse + delayMicroseconds(pulseWidth); } + return b; + } - void begin() { - - pinMode(MISO, INPUT); - pinMode(RESET, OUTPUT); - pinMode(SCK, OUTPUT); - pinMode(MOSI, OUTPUT); - } - - void end() {} - - uint8_t transfer (uint8_t b) { - for (unsigned int i = 0; i < 8; ++i) { - digitalWrite(MOSI, b & 0x80); - digitalWrite(SCK, HIGH); - delayMicroseconds(pulseWidth); - b = (b << 1) | digitalRead(MISO); - digitalWrite(SCK, LOW); // slow pulse - delayMicroseconds(pulseWidth); - } - return b; - } - - private: - unsigned long pulseWidth; // in microseconds +private: + unsigned long pulseWidth; // in microseconds }; static BitBangedSPI SPI; From 044a7b78c764ce8493cd6fa09082427a10b4b6fb Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Wed, 29 Jul 2015 21:37:04 +0200 Subject: [PATCH 018/175] Fix warnings. Use unsigned int to represent a (word) address: the compiler will use the most efficient type on each platform: 32 bit on arm, 16 bit on avr which is is big enough. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 56 ++++++++----------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index a4d3d4dfb..ed467e8f6 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -75,12 +75,6 @@ #endif -#ifdef USE_HARDWARE_SPI -#warning hw spi !!! -#else -#warning NOT usung hw spi -#endif - // Configure the serial port to use. // // Prefer the USB virtual serial port (aka. native USB port), if the Arduino has one: @@ -188,7 +182,7 @@ void setup() { int error = 0; int pmode = 0; // address for reading and writing, set by 'U' command -int here; +unsigned int here; uint8_t buff[256]; // global block storage #define beget16(addr) (*addr * 256 + *(addr+1) ) @@ -228,8 +222,7 @@ void heartbeat() { static bool rst_active_high; -void reset_target(bool reset) -{ +void reset_target(bool reset) { digitalWrite(RESET, ((reset && rst_active_high) || (!reset && !rst_active_high)) ? HIGH : LOW); } @@ -281,11 +274,9 @@ void prog_lamp(int state) { } uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { - uint8_t n; SPI.transfer(a); - n = SPI.transfer(b); - //if (n != a) error = -1; - n = SPI.transfer(c); + SPI.transfer(b); + SPI.transfer(c); return SPI.transfer(d); } @@ -388,7 +379,6 @@ void end_pmode() { } void universal() { - int w; uint8_t ch; fill(4); @@ -396,13 +386,13 @@ void universal() { breply(ch); } -void flash(uint8_t hilo, int addr, uint8_t data) { +void flash(uint8_t hilo, unsigned int addr, uint8_t data) { spi_transaction(0x40 + 8 * hilo, addr >> 8 & 0xFF, addr & 0xFF, data); } -void commit(int addr) { +void commit(unsigned int addr) { if (PROG_FLICKER) { prog_lamp(LOW); } @@ -413,8 +403,7 @@ void commit(int addr) { } } -//#define _current_page(x) (here & 0xFFFFE0) -int current_page(int addr) { +unsigned int current_page() { if (param.pagesize == 32) { return here & 0xFFFFFFF0; } @@ -444,11 +433,11 @@ void write_flash(int length) { uint8_t write_flash_pages(int length) { int x = 0; - int page = current_page(here); + unsigned int page = current_page(); while (x < length) { - if (page != current_page(here)) { + if (page != current_page()) { commit(page); - page = current_page(here); + page = current_page(); } flash(LOW, here, buff[x++]); flash(HIGH, here, buff[x++]); @@ -461,10 +450,10 @@ uint8_t write_flash_pages(int length) { } #define EECHUNK (32) -uint8_t write_eeprom(int length) { +uint8_t write_eeprom(unsigned int length) { // here is a word address, get the byte address - int start = here * 2; - int remaining = length; + unsigned int start = here * 2; + unsigned int remaining = length; if (length > param.eepromsize) { error++; return STK_FAILED; @@ -478,13 +467,13 @@ uint8_t write_eeprom(int length) { return STK_OK; } // write (length) bytes, (start) is a byte address -uint8_t write_eeprom_chunk(int start, int length) { +uint8_t write_eeprom_chunk(unsigned int start, unsigned int length) { // this writes byte-by-byte, // page writing may be faster (4 bytes at a time) fill(length); prog_lamp(LOW); - for (int x = 0; x < length; x++) { - int addr = start + x; + for (unsigned int x = 0; x < length; x++) { + unsigned int addr = start + x; spi_transaction(0xC0, (addr >> 8) & 0xFF, addr & 0xFF, buff[x]); delay(45); } @@ -494,7 +483,7 @@ uint8_t write_eeprom_chunk(int start, int length) { void program_page() { char result = (char) STK_FAILED; - int length = 256 * getch(); + unsigned int length = 256 * getch(); length += getch(); char memtype = getch(); // flash memory @here, (length) bytes @@ -517,7 +506,7 @@ void program_page() { return; } -uint8_t flash_read(uint8_t hilo, int addr) { +uint8_t flash_read(uint8_t hilo, unsigned int addr) { return spi_transaction(0x20 + hilo * 8, (addr >> 8) & 0xFF, addr & 0xFF, @@ -583,8 +572,7 @@ void read_signature() { //////////////////////////////////// //////////////////////////////////// -int avrisp() { - uint8_t data, low, high; +void avrisp() { uint8_t ch = getch(); switch (ch) { case '0': // signon @@ -626,12 +614,12 @@ int avrisp() { break; case 0x60: //STK_PROG_FLASH - low = getch(); - high = getch(); + getch(); // low addr + getch(); // high addr empty_reply(); break; case 0x61: //STK_PROG_DATA - data = getch(); + getch(); // data empty_reply(); break; From 13cc57ed7e01fb468a521c759343b05ae26a7700 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Wed, 26 Aug 2015 22:43:00 +0200 Subject: [PATCH 019/175] Reset target before driving SCK or MOSI, reset sequence as in AVR datasheets under "Serial Programming Algorithm" --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index ed467e8f6..7247b2644 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -169,7 +169,6 @@ static BitBangedSPI SPI; void setup() { SERIAL.begin(19200); - pinMode(LED_PMODE, OUTPUT); pulse(LED_PMODE, 2); pinMode(LED_ERR, OUTPUT); @@ -348,21 +347,33 @@ void set_parameters() { } void start_pmode() { - SPI.begin(); - SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0)); - // SPI.begin() has configured SS as output, + + // Reset target before driving SCK or MOSI + + // SPI.begin() will configure SS as output, // so SPI master mode is selected. // We have defined RESET as pin 10, // which for many arduino's is not the SS pin. // So we have to configure RESET as output here, - // (reset_target() first sets the level correct) - reset_target(false); - pinMode(RESET, OUTPUT); - - digitalWrite(SCK, LOW); - delay(20); + // (reset_target() first sets the correct level) reset_target(true); - delay(50); + pinMode(RESET, OUTPUT); + SPI.begin(); + SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0)); + + // See avr datasheets, chapter "SERIAL_PRG Programming Algorithm": + + // Pulse RESET after SCK is low: + digitalWrite(SCK, LOW); + delay(20); // discharge SCK, value arbitrally chosen + reset_target(false); + // Pulse must be minimum 2 target CPU clock cycles + // so 100 usec is ok for CPU speeds above 20KHz + delayMicroseconds(100); + reset_target(true); + + // Send the enable programming command: + delay(50); // datasheet: must be > 20 msec spi_transaction(0xAC, 0x53, 0x00, 0x00); pmode = 1; } From e3866e0ef5ead4420b30abbcb477f87437994880 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Sun, 30 Aug 2015 20:27:38 +0200 Subject: [PATCH 020/175] Elaborate configuration of which pins to use: support HOODLOADER2 and old Uno style wiring. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 7247b2644..73c2fcc7e 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -46,12 +46,7 @@ #include "Arduino.h" #undef SERIAL -// Use pin 10 to reset the target -#define RESET 10 -#define LED_HB 9 -#define LED_ERR 8 -#define LED_PMODE 7 #define PROG_FLICKER true // Configure SPI clock. @@ -75,6 +70,44 @@ #endif +// Configure which pins to use + +// The standard pin configuration. +#ifndef ARDUINO_HOODLOADER2 + +#define RESET 10 // Use pin 10 to reset the target rather than SS +#define LED_HB 9 +#define LED_ERR 8 +#define LED_PMODE 7 + +// Uncomment following line to use the old uno style wiring +// (using pin 11, 12 and 13 instead of the SPI header) on Leonardo, Due... + +// #define USE_OLD_STYLE_WIRING + +#ifdef USE_OLD_STYLE_WIRING +#undef USE_HARDWARE_SPI +#undef MOSI +#undef MISO +#undef SCK +#define MOSI 11 +#define MISO 12 +#define SCK 13 +#endif + +// HOODLOADER2 means running sketches on the atmega16u2 +// serial converter chips on Uno or Mega boards. +// We must use pins that are broken out: +#else + +#define RESET 4 +#define LED_HB 7 +#define LED_ERR 6 +#define LED_PMODE 5 + +#endif + + // Configure the serial port to use. // // Prefer the USB virtual serial port (aka. native USB port), if the Arduino has one: From 2c1728f086051c602a16f943aea99f55ae8fa3b8 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Sun, 30 Aug 2015 20:36:39 +0200 Subject: [PATCH 021/175] Use digitalWrite() only with values HIGH and LOW. --- build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 73c2fcc7e..a791f210b 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -181,7 +181,7 @@ public: uint8_t transfer (uint8_t b) { for (unsigned int i = 0; i < 8; ++i) { - digitalWrite(MOSI, b & 0x80); + digitalWrite(MOSI, (b & 0x80) ? HIGH : LOW); digitalWrite(SCK, HIGH); delayMicroseconds(pulseWidth); b = (b << 1) | digitalRead(MISO); From 82e5d4a88daf4697e9c562d6756b95519848b94a Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Mon, 31 Aug 2015 22:17:12 +0200 Subject: [PATCH 022/175] Remove change history to make room for documentation. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index a791f210b..d290695a6 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -1,4 +1,4 @@ -// ArduinoISP version 04m3 +// ArduinoISP // Copyright (c) 2008-2011 Randall Bohn // If you require a license, see // http://www.opensource.org/licenses/bsd-license.php @@ -6,42 +6,31 @@ // This sketch turns the Arduino into a AVRISP // using the following arduino pins: // -// pin name: not-mega: mega(1280 and 2560) -// slave reset: 10: 10 -// MOSI: 11: 51 -// MISO: 12: 50 -// SCK: 13: 52 +// Pin 10 is used to reset the target microcontroller. +// +// The MISO, MOSI and SCK pins are used to communicate with the target, +// on all Arduinos, these pins can be found on the ICSP header: +// +// MISO °. . 5V (!) Avoid this pin on Due, Zero... +// SCK . . MOSI +// . . GND +// +// On some Arduinos (Uno,...), pins MOSI, MISO and SCK are the same pins +// as digital pin 11, 12 and 13, respectively. That is why many tutorials +// instruct you to hook up the target to these pins. If you find this wiring +// more practical, have a define USE_OLD_STYLE_WIRING. This will work even +// even when not using an Uno. (On an Uno this is not needed). +// +// IMPORTANT: When using an Arduino that is not 5V tolerant (Due, Zero, ...) +// as the programmer, make sure to not expose any of the programmer's pins to 5V. +// A simple way to accomplish this is to power the complete system (programmer +// and target) at 3V3. // // Put an LED (with resistor) on the following pins: // 9: Heartbeat - shows the programmer is running // 8: Error - Lights up if something goes wrong (use red if that makes sense) // 7: Programming - In communication with the slave // -// 23 July 2011 Randall Bohn -// -Address Arduino issue 509 :: Portability of ArduinoISP -// http://code.google.com/p/arduino/issues/detail?id=509 -// -// October 2010 by Randall Bohn -// - Write to EEPROM > 256 bytes -// - Better use of LEDs: -// -- Flash LED_PMODE on each flash commit -// -- Flash LED_PMODE while writing EEPROM (both give visual feedback of writing progress) -// - Light LED_ERR whenever we hit a STK_NOSYNC. Turn it off when back in sync. -// - Use pins_arduino.h (should also work on Arduino Mega) -// -// October 2009 by David A. Mellis -// - Added support for the read signature command -// -// February 2009 by Randall Bohn -// - Added support for writing to EEPROM (what took so long?) -// Windows users should consider WinAVR's avrdude instead of the -// avrdude included with Arduino software. -// -// January 2008 by Randall Bohn -// - Thanks to Amplificar for helping me with the STK500 protocol -// - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader -// - The SPI functions herein were developed for the AVR910_ARD programmer -// - More information at http://code.google.com/p/mega-isp #include "Arduino.h" #undef SERIAL From bfffb17e40e1a4d849505785df1084d8f2702fdc Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Sat, 5 Sep 2015 20:41:03 +0200 Subject: [PATCH 023/175] Improve SPI clock configuration. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index d290695a6..6b75ce549 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -38,14 +38,16 @@ #define PROG_FLICKER true -// Configure SPI clock. -// E.g. for an attiny @128 kHz: -// (pulseWidth should be > 2 cpu cycles, so take 3 cycles:) -// #define SPI_CLOCK (128000/3) +// Configure SPI clock (in Hz). +// E.g. for an attiny @128 kHz: the datasheet states that both the high +// and low spi clock pulse must be > 2 cpu cycles, so take 3 cycles i.e. +// divide target f_cpu by 6: +// #define SPI_CLOCK (128000/6) // -// A clock slow enough for an attiny85 @ 1MHz, is a reasonable default: +// A clock slow enough for an attiny85 @ 1MHz, is a reasonable default: + +#define SPI_CLOCK (1000000/6) -#define SPI_CLOCK (1000000/3) // Select hardware or software SPI, depending on SPI clock. // Currently only for AVR, for other archs (Due, Zero,...), @@ -161,7 +163,7 @@ public: } void beginTransaction(SPISettings settings) { - pulseWidth = 1000 / (settings.clock / 1000); + pulseWidth = (500000 + settings.clock - 1) / settings.clock; if (pulseWidth == 0) pulseWidth = 1; } From d2a38f23a831c993877c2cb723a1034b0d60c52c Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Sat, 5 Sep 2015 20:43:44 +0200 Subject: [PATCH 024/175] Rework pin configuration. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 80 ++++++++++++------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 6b75ce549..24c795203 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -8,8 +8,9 @@ // // Pin 10 is used to reset the target microcontroller. // -// The MISO, MOSI and SCK pins are used to communicate with the target, -// on all Arduinos, these pins can be found on the ICSP header: +// By default, the hardware SPI pins MISO, MOSI and SCK pins are used +// to communicate with the target. On all Arduinos, these pins can be found +// on the ICSP/SPI header: // // MISO °. . 5V (!) Avoid this pin on Due, Zero... // SCK . . MOSI @@ -20,6 +21,9 @@ // instruct you to hook up the target to these pins. If you find this wiring // more practical, have a define USE_OLD_STYLE_WIRING. This will work even // even when not using an Uno. (On an Uno this is not needed). +// +// Alternatively you can use any other digital pin by configuring software ('BitBanged') +// SPI and having appropriate defines for PIN_MOSI, PIN_MISO and PIN_SCK. // // IMPORTANT: When using an Arduino that is not 5V tolerant (Due, Zero, ...) // as the programmer, make sure to not expose any of the programmer's pins to 5V. @@ -61,7 +65,7 @@ #endif -// Configure which pins to use +// Configure which pins to use: // The standard pin configuration. #ifndef ARDUINO_HOODLOADER2 @@ -71,19 +75,17 @@ #define LED_ERR 8 #define LED_PMODE 7 -// Uncomment following line to use the old uno style wiring +// Uncomment following line to use the old Uno style wiring // (using pin 11, 12 and 13 instead of the SPI header) on Leonardo, Due... // #define USE_OLD_STYLE_WIRING #ifdef USE_OLD_STYLE_WIRING -#undef USE_HARDWARE_SPI -#undef MOSI -#undef MISO -#undef SCK -#define MOSI 11 -#define MISO 12 -#define SCK 13 + +#define PIN_MOSI 11 +#define PIN_MISO 12 +#define PIN_SCK 13 + #endif // HOODLOADER2 means running sketches on the atmega16u2 @@ -91,13 +93,31 @@ // We must use pins that are broken out: #else -#define RESET 4 -#define LED_HB 7 -#define LED_ERR 6 -#define LED_PMODE 5 +#define RESET 4 +#define LED_HB 7 +#define LED_ERR 6 +#define LED_PMODE 5 #endif +// By default, use hardware SPI pins: +#ifndef PIN_MOSI +#define PIN_MOSI MOSI +#endif + +#ifndef PIN_MISO +#define PIN_MISO MISO +#endif + +#ifndef PIN_SCK +#define PIN_SCK SCK +#endif + +// Force bitbanged SPI if not using the hardware SPI pins: +#if (PIN_MISO != MISO) || (PIN_MOSI != MOSI) || (PIN_SCK != SCK) +#undef USE_HARDWARE_SPI +#endif + // Configure the serial port to use. // @@ -155,11 +175,11 @@ friend class BitBangedSPI; class BitBangedSPI { public: void begin() { - digitalWrite(SCK, LOW); - digitalWrite(MOSI, LOW); - pinMode(SCK, OUTPUT); - pinMode(MOSI, OUTPUT); - pinMode(MISO, INPUT); + digitalWrite(PIN_SCK, LOW); + digitalWrite(PIN_MOSI, LOW); + pinMode(PIN_SCK, OUTPUT); + pinMode(PIN_MOSI, OUTPUT); + pinMode(PIN_MISO, INPUT); } void beginTransaction(SPISettings settings) { @@ -172,11 +192,11 @@ public: uint8_t transfer (uint8_t b) { for (unsigned int i = 0; i < 8; ++i) { - digitalWrite(MOSI, (b & 0x80) ? HIGH : LOW); - digitalWrite(SCK, HIGH); + digitalWrite(PIN_MOSI, (b & 0x80) ? HIGH : LOW); + digitalWrite(PIN_SCK, HIGH); delayMicroseconds(pulseWidth); - b = (b << 1) | digitalRead(MISO); - digitalWrite(SCK, LOW); // slow pulse + b = (b << 1) | digitalRead(PIN_MISO); + digitalWrite(PIN_SCK, LOW); // slow pulse delayMicroseconds(pulseWidth); } return b; @@ -372,7 +392,7 @@ void set_parameters() { void start_pmode() { - // Reset target before driving SCK or MOSI + // Reset target before driving PIN_SCK or PIN_MOSI // SPI.begin() will configure SS as output, // so SPI master mode is selected. @@ -387,9 +407,9 @@ void start_pmode() { // See avr datasheets, chapter "SERIAL_PRG Programming Algorithm": - // Pulse RESET after SCK is low: - digitalWrite(SCK, LOW); - delay(20); // discharge SCK, value arbitrally chosen + // Pulse RESET after PIN_SCK is low: + digitalWrite(PIN_SCK, LOW); + delay(20); // discharge PIN_SCK, value arbitrally chosen reset_target(false); // Pulse must be minimum 2 target CPU clock cycles // so 100 usec is ok for CPU speeds above 20KHz @@ -406,8 +426,8 @@ void end_pmode() { SPI.end(); // We're about to take the target out of reset // so configure SPI pins as input - pinMode(MOSI, INPUT); - pinMode(SCK, INPUT); + pinMode(PIN_MOSI, INPUT); + pinMode(PIN_SCK, INPUT); reset_target(false); pinMode(RESET, INPUT); pmode = 0; From ff1158a1b97f46de159e097523266666a0ac0d26 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Sat, 5 Sep 2015 20:45:15 +0200 Subject: [PATCH 025/175] Add a define for baudrate configuration. --- .../examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 24c795203..d4fd37ea5 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -138,6 +138,13 @@ #endif +// Configure the baud rate: + +#define BAUDRATE 19200 +// #define BAUDRATE 115200 +// #define BAUDRATE 1000000 + + #define HWVER 2 #define SWMAJ 1 #define SWMIN 18 @@ -211,7 +218,7 @@ static BitBangedSPI SPI; #endif void setup() { - SERIAL.begin(19200); + SERIAL.begin(BAUDRATE); pinMode(LED_PMODE, OUTPUT); pulse(LED_PMODE, 2); From 3fe6272feba8bf57c21c853205299ac35972b8a6 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 29 Sep 2015 16:40:27 +0200 Subject: [PATCH 026/175] [PUSB] PUSBCallback struct has been merged into PUSBListNode This slightly simplifies PluggableUSB API. --- .../arduino/avr/cores/arduino/PluggableUSB.cpp | 16 ++++++++-------- .../arduino/avr/cores/arduino/PluggableUSB.h | 9 +++------ hardware/arduino/avr/libraries/HID/HID.cpp | 18 +++++++----------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 857a27fe9..9597adc94 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -40,7 +40,7 @@ int PUSB_GetInterface(u8* interfaceNum) int ret = 0; PUSBListNode* node = rootNode; for (u8 i=0; icb->getInterface(interfaceNum); + ret = node->getInterface(interfaceNum); node = node->next; } return ret; @@ -51,7 +51,7 @@ int PUSB_GetDescriptor(int8_t t) int ret = 0; PUSBListNode* node = rootNode; for (u8 i=0; icb->getDescriptor(t); + ret = node->getDescriptor(t); node = node->next; } return ret; @@ -62,7 +62,7 @@ bool PUSB_Setup(USBSetup& setup, u8 j) bool ret = false; PUSBListNode* node = rootNode; for (u8 i=0; icb->setup(setup, j); + ret = node->setup(setup, j); node = node->next; } return ret; @@ -85,16 +85,16 @@ int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface) } *interface = lastIf; - lastIf += node->cb->numInterfaces; - for ( u8 i = 0; i< node->cb->numEndpoints; i++) { - _initEndpoints[lastEp] = node->cb->endpointType[i]; + lastIf += node->numInterfaces; + for ( u8 i = 0; i< node->numEndpoints; i++) { + _initEndpoints[lastEp] = node->endpointType[i]; lastEp++; } modules_count++; - return lastEp - node->cb->numEndpoints; + return lastEp - node->numEndpoints; // restart USB layer??? } #endif -#endif /* if defined(USBCON) */ \ No newline at end of file +#endif /* if defined(USBCON) */ diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 33108db91..9210d7c6d 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -25,21 +25,18 @@ #if defined(USBCON) -typedef struct __attribute__((packed)) -{ +class PUSBListNode { +public: + PUSBListNode() { } bool (*setup)(USBSetup& setup, u8 i); int (*getInterface)(u8* interfaceNum); int (*getDescriptor)(int8_t t); int8_t numEndpoints; int8_t numInterfaces; uint8_t *endpointType; -} PUSBCallbacks; -class PUSBListNode { public: PUSBListNode *next = NULL; - PUSBCallbacks *cb; - PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;} }; int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface); diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 42e0ee5d2..24e6f5c60 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -133,19 +133,15 @@ bool HID_Setup(USBSetup& setup, uint8_t i) HID_::HID_(void) { static uint8_t endpointType[1]; - endpointType[0] = EP_TYPE_INTERRUPT_IN; - static PUSBCallbacks cb = { - .setup = &HID_Setup, - .getInterface = &HID_GetInterface, - .getDescriptor = &HID_GetDescriptor, - .numEndpoints = 1, - .numInterfaces = 1, - .endpointType = endpointType, - }; - - static PUSBListNode node(&cb); + static PUSBListNode node; + node.setup = &HID_Setup, + node.getInterface = &HID_GetInterface, + node.getDescriptor = &HID_GetDescriptor, + node.numEndpoints = 1, + node.numInterfaces = 1, + node.endpointType = endpointType, HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE); } From 5aeff8ec25ed5dfc16bcfcf52e3ddfac4cb9aa8c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 29 Sep 2015 16:46:11 +0200 Subject: [PATCH 027/175] [PUSB] Global functions PUSB_* are now methods of PluggableUSB class --- .../arduino/avr/cores/arduino/PluggableUSB.cpp | 8 ++++---- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 14 ++++++++------ hardware/arduino/avr/cores/arduino/USBCore.cpp | 6 +++--- hardware/arduino/avr/libraries/HID/HID.cpp | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 9597adc94..9dc334e81 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -35,7 +35,7 @@ static u8 modules_count = 0; static PUSBListNode* rootNode = NULL; -int PUSB_GetInterface(u8* interfaceNum) +int PluggableUSB_::getInterface(u8* interfaceNum) { int ret = 0; PUSBListNode* node = rootNode; @@ -46,7 +46,7 @@ int PUSB_GetInterface(u8* interfaceNum) return ret; } -int PUSB_GetDescriptor(int8_t t) +int PluggableUSB_::getDescriptor(int8_t t) { int ret = 0; PUSBListNode* node = rootNode; @@ -57,7 +57,7 @@ int PUSB_GetDescriptor(int8_t t) return ret; } -bool PUSB_Setup(USBSetup& setup, u8 j) +bool PluggableUSB_::setup(USBSetup& setup, u8 j) { bool ret = false; PUSBListNode* node = rootNode; @@ -68,7 +68,7 @@ bool PUSB_Setup(USBSetup& setup, u8 j) return ret; } -int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface) +int8_t PluggableUSB_::addFunction(PUSBListNode *node, u8* interface) { if (modules_count >= MAX_MODULES) { return 0; diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 9210d7c6d..dcd9e2599 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -39,13 +39,15 @@ public: PUSBListNode *next = NULL; }; -int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface); +class PluggableUSB_ { +public: + static int8_t addFunction(PUSBListNode *node, u8 *interface); + static int getInterface(u8* interfaceNum); + static int getDescriptor(int8_t t); + static bool setup(USBSetup& setup, u8 i); +}; -int PUSB_GetInterface(u8* interfaceNum); - -int PUSB_GetDescriptor(int8_t t); - -bool PUSB_Setup(USBSetup& setup, u8 i); +extern PluggableUSB_ PluggableUSB; #endif diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index 733a178c9..f96ff27ab 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -367,7 +367,7 @@ bool ClassInterfaceRequest(USBSetup& setup) return CDC_Setup(setup); #ifdef PLUGGABLE_USB_ENABLED - return PUSB_Setup(setup, i); + return PluggableUSB.setup(setup, i); #endif return false; } @@ -445,7 +445,7 @@ static u8 SendInterfaces() CDC_GetInterface(&interfaces); #ifdef PLUGGABLE_USB_ENABLED - PUSB_GetInterface(&interfaces); + PluggableUSB.getInterface(&interfaces); #endif return interfaces; @@ -481,7 +481,7 @@ bool SendDescriptor(USBSetup& setup) InitControl(setup.wLength); #ifdef PLUGGABLE_USB_ENABLED - ret = PUSB_GetDescriptor(t); + ret = PluggableUSB.getDescriptor(t); if (ret != 0) { return (ret > 0 ? true : false); } diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 24e6f5c60..ec2842426 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -143,7 +143,7 @@ HID_::HID_(void) node.numInterfaces = 1, node.endpointType = endpointType, - HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE); + HID_ENDPOINT_INT = PluggableUSB.addFunction(&node, &HID_INTERFACE); } int HID_::begin(void) From 5e14b1fe37ac74d892b326e57a06a43a3c0b8727 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 29 Sep 2015 17:10:48 +0200 Subject: [PATCH 028/175] [HID] Now HID extends directly PluggableUSBListNode This avoid duplicate instatiation of callback and save a considerable amount of flash. --- hardware/arduino/avr/libraries/HID/HID.cpp | 20 +++++++++----------- hardware/arduino/avr/libraries/HID/HID.h | 3 ++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index ec2842426..06587114a 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -36,6 +36,8 @@ HIDDescriptor _hidInterface; static HIDDescriptorListNode* rootNode = NULL; static uint16_t sizeof_hidReportDescriptor = 0; static uint8_t modules_count = 0; +static uint8_t epType[] = { EP_TYPE_INTERRUPT_IN }; + //================================================================================ //================================================================================ // Driver @@ -132,18 +134,14 @@ bool HID_Setup(USBSetup& setup, uint8_t i) HID_::HID_(void) { - static uint8_t endpointType[1]; - endpointType[0] = EP_TYPE_INTERRUPT_IN; + setup = &HID_Setup; + getInterface = &HID_GetInterface; + getDescriptor = &HID_GetDescriptor; + numEndpoints = 1; + numInterfaces = 1; + endpointType = epType; - static PUSBListNode node; - node.setup = &HID_Setup, - node.getInterface = &HID_GetInterface, - node.getDescriptor = &HID_GetDescriptor, - node.numEndpoints = 1, - node.numInterfaces = 1, - node.endpointType = endpointType, - - HID_ENDPOINT_INT = PluggableUSB.addFunction(&node, &HID_INTERFACE); + HID_ENDPOINT_INT = PluggableUSB.addFunction(this, &HID_INTERFACE); } int HID_::begin(void) diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index 47ac3b967..b7ad457c8 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -24,6 +24,7 @@ #include #include +#include "PluggableUSB.h" #if defined(USBCON) @@ -53,7 +54,7 @@ public: uint16_t length; }; -class HID_ +class HID_ : public PUSBListNode { public: HID_(void); From 8f259c8a80d528b5cd4375998904357127188c16 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 29 Sep 2015 17:59:54 +0200 Subject: [PATCH 029/175] [PUSB] Selected interface and endpoint are now part of PUSBListNode The method int8_t PluggableUSB::addFunction(PUSBListNode *, uint8_t *) has been changed to bool PluggableUSB::plug(PUSBListNode *node) since both EP and Interfaces are now saved directly into node --- .../arduino/avr/cores/arduino/PluggableUSB.cpp | 11 ++++++----- .../arduino/avr/cores/arduino/PluggableUSB.h | 11 ++++++++++- hardware/arduino/avr/libraries/HID/HID.cpp | 16 ++++++---------- hardware/arduino/avr/libraries/HID/HID.h | 2 -- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 9dc334e81..b27146b5f 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -68,10 +68,10 @@ bool PluggableUSB_::setup(USBSetup& setup, u8 j) return ret; } -int8_t PluggableUSB_::addFunction(PUSBListNode *node, u8* interface) +bool PluggableUSB_::plug(PUSBListNode *node) { if (modules_count >= MAX_MODULES) { - return 0; + return false; } if (modules_count == 0) { @@ -84,14 +84,15 @@ int8_t PluggableUSB_::addFunction(PUSBListNode *node, u8* interface) current->next = node; } - *interface = lastIf; + node->pluggedInterface = lastIf; + node->pluggedEndpoint = lastEp; lastIf += node->numInterfaces; - for ( u8 i = 0; i< node->numEndpoints; i++) { + for (uint8_t i=0; inumEndpoints; i++) { _initEndpoints[lastEp] = node->endpointType[i]; lastEp++; } modules_count++; - return lastEp - node->numEndpoints; + return true; // restart USB layer??? } diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index dcd9e2599..275a444a3 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -35,13 +35,22 @@ public: int8_t numInterfaces; uint8_t *endpointType; + inline uint8_t interface() const { return pluggedInterface; } + inline int8_t endpoint() const { return pluggedEndpoint; } + +protected: + uint8_t pluggedInterface; + int8_t pluggedEndpoint; + public: PUSBListNode *next = NULL; + + friend class PluggableUSB_; }; class PluggableUSB_ { public: - static int8_t addFunction(PUSBListNode *node, u8 *interface); + static bool plug(PUSBListNode *node); static int getInterface(u8* interfaceNum); static int getDescriptor(int8_t t); static bool setup(USBSetup& setup, u8 i); diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 06587114a..7e4d99162 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -23,14 +23,10 @@ HID_ HID; -static uint8_t HID_ENDPOINT_INT; - //================================================================================ //================================================================================ // HID Interface -static uint8_t HID_INTERFACE; - HIDDescriptor _hidInterface; static HIDDescriptorListNode* rootNode = NULL; @@ -50,9 +46,9 @@ int HID_GetInterface(uint8_t* interfaceNum) interfaceNum[0] += 1; // uses 1 _hidInterface = { - D_INTERFACE(HID_INTERFACE,1,3,0,0), + D_INTERFACE(HID.interface(), 1, 3, 0, 0), D_HIDREPORT(sizeof_hidReportDescriptor), - D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,USB_EP_SIZE,0x01) + D_ENDPOINT(USB_ENDPOINT_IN(HID.endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) }; return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface)); } @@ -89,13 +85,13 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node) void HID_::SendReport(u8 id, const void* data, int len) { - USB_Send(HID_TX, &id, 1); - USB_Send(HID_TX | TRANSFER_RELEASE,data,len); + USB_Send(HID.endpoint(), &id, 1); + USB_Send(HID.endpoint() | TRANSFER_RELEASE,data,len); } bool HID_Setup(USBSetup& setup, uint8_t i) { - if (HID_INTERFACE != i) { + if (HID.interface() != i) { return false; } else { uint8_t r = setup.bRequest; @@ -141,7 +137,7 @@ HID_::HID_(void) numInterfaces = 1; endpointType = epType; - HID_ENDPOINT_INT = PluggableUSB.addFunction(this, &HID_INTERFACE); + PluggableUSB.plug(this); } int HID_::begin(void) diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index b7ad457c8..d0fe265b5 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -83,8 +83,6 @@ typedef struct EndpointDescriptor in; } HIDDescriptor; -#define HID_TX HID_ENDPOINT_INT - #define D_HIDREPORT(_descriptorLength) \ { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength & 0xFF, _descriptorLength >> 8 } From 6ffd7e39ba7e0bddfa8a44c41ca477096eb3052a Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 14:51:11 +0200 Subject: [PATCH 030/175] [PUSB] replaced u8 with uint8_t --- .../arduino/avr/cores/arduino/PluggableUSB.cpp | 18 +++++++++--------- .../arduino/avr/cores/arduino/PluggableUSB.h | 8 ++++---- hardware/arduino/avr/libraries/HID/HID.cpp | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index b27146b5f..2c7221de2 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -25,21 +25,21 @@ #define MAX_MODULES 6 -static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; -static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; +static uint8_t lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; +static uint8_t lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; -extern u8 _initEndpoints[]; +extern uint8_t _initEndpoints[]; //PUSBCallbacks cbs[MAX_MODULES]; -static u8 modules_count = 0; +static uint8_t modules_count = 0; static PUSBListNode* rootNode = NULL; -int PluggableUSB_::getInterface(u8* interfaceNum) +int PluggableUSB_::getInterface(uint8_t* interfaceNum) { int ret = 0; PUSBListNode* node = rootNode; - for (u8 i=0; igetInterface(interfaceNum); node = node->next; } @@ -50,18 +50,18 @@ int PluggableUSB_::getDescriptor(int8_t t) { int ret = 0; PUSBListNode* node = rootNode; - for (u8 i=0; igetDescriptor(t); node = node->next; } return ret; } -bool PluggableUSB_::setup(USBSetup& setup, u8 j) +bool PluggableUSB_::setup(USBSetup& setup, uint8_t j) { bool ret = false; PUSBListNode* node = rootNode; - for (u8 i=0; isetup(setup, j); node = node->next; } diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 275a444a3..d4a109633 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -28,8 +28,8 @@ class PUSBListNode { public: PUSBListNode() { } - bool (*setup)(USBSetup& setup, u8 i); - int (*getInterface)(u8* interfaceNum); + bool (*setup)(USBSetup& setup, uint8_t i); + int (*getInterface)(uint8_t* interfaceNum); int (*getDescriptor)(int8_t t); int8_t numEndpoints; int8_t numInterfaces; @@ -51,9 +51,9 @@ public: class PluggableUSB_ { public: static bool plug(PUSBListNode *node); - static int getInterface(u8* interfaceNum); + static int getInterface(uint8_t* interfaceNum); static int getDescriptor(int8_t t); - static bool setup(USBSetup& setup, u8 i); + static bool setup(USBSetup& setup, uint8_t i); }; extern PluggableUSB_ PluggableUSB; diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 7e4d99162..e36601f3d 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -83,7 +83,7 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node) sizeof_hidReportDescriptor += (uint16_t)node->length; } -void HID_::SendReport(u8 id, const void* data, int len) +void HID_::SendReport(uint8_t id, const void* data, int len) { USB_Send(HID.endpoint(), &id, 1); USB_Send(HID.endpoint() | TRANSFER_RELEASE,data,len); From 2ac2a27173b43b9594af2a888da2fde8f9cde74e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 16:19:21 +0200 Subject: [PATCH 031/175] [PUSB] Moved static members inside HID_ class This commit prepares for the next refactoring --- hardware/arduino/avr/libraries/HID/HID.cpp | 38 +++++++-------- hardware/arduino/avr/libraries/HID/HID.h | 57 +++++++++++++--------- 2 files changed, 54 insertions(+), 41 deletions(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index e36601f3d..118d0c5f4 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -27,33 +27,33 @@ HID_ HID; //================================================================================ // HID Interface -HIDDescriptor _hidInterface; +HIDDescriptor HID_::hidInterface; -static HIDDescriptorListNode* rootNode = NULL; -static uint16_t sizeof_hidReportDescriptor = 0; -static uint8_t modules_count = 0; -static uint8_t epType[] = { EP_TYPE_INTERRUPT_IN }; +HIDDescriptorListNode* HID_::rootNode = NULL; +uint16_t HID_::sizeof_hidReportDescriptor = 0; +uint8_t HID_::modules_count = 0; +uint8_t HID_::epType[] = { EP_TYPE_INTERRUPT_IN }; //================================================================================ //================================================================================ // Driver -uint8_t _hid_protocol = 1; -uint8_t _hid_idle = 1; +uint8_t HID_::protocol = 1; +uint8_t HID_::idle = 1; -int HID_GetInterface(uint8_t* interfaceNum) +int HID_::GetInterface(uint8_t* interfaceNum) { interfaceNum[0] += 1; // uses 1 - _hidInterface = + hidInterface = { D_INTERFACE(HID.interface(), 1, 3, 0, 0), D_HIDREPORT(sizeof_hidReportDescriptor), D_ENDPOINT(USB_ENDPOINT_IN(HID.endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) }; - return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface)); + return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int HID_GetDescriptor(int8_t t) +int HID_::GetDescriptor(int8_t t) { if (HID_REPORT_DESCRIPTOR_TYPE == t) { HIDDescriptorListNode* current = rootNode; @@ -89,7 +89,7 @@ void HID_::SendReport(uint8_t id, const void* data, int len) USB_Send(HID.endpoint() | TRANSFER_RELEASE,data,len); } -bool HID_Setup(USBSetup& setup, uint8_t i) +bool HID_::Setup(USBSetup& setup, uint8_t i) { if (HID.interface() != i) { return false; @@ -100,12 +100,12 @@ bool HID_Setup(USBSetup& setup, uint8_t i) { if (HID_GET_REPORT == r) { - //HID_GetReport(); + //HID_GetReport(); return true; } if (HID_GET_PROTOCOL == r) { - //Send8(_hid_protocol); // TODO + //Send8(protocol); // TODO return true; } } @@ -114,13 +114,13 @@ bool HID_Setup(USBSetup& setup, uint8_t i) { if (HID_SET_PROTOCOL == r) { - _hid_protocol = setup.wValueL; + protocol = setup.wValueL; return true; } if (HID_SET_IDLE == r) { - _hid_idle = setup.wValueL; + idle = setup.wValueL; return true; } } @@ -130,9 +130,9 @@ bool HID_Setup(USBSetup& setup, uint8_t i) HID_::HID_(void) { - setup = &HID_Setup; - getInterface = &HID_GetInterface; - getDescriptor = &HID_GetDescriptor; + setup = HID_::Setup; + getInterface = HID_::GetInterface; + getDescriptor = HID_::GetDescriptor; numEndpoints = 1; numInterfaces = 1; endpointType = epType; diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index d0fe265b5..cb1125efd 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -30,10 +30,8 @@ #define _USING_HID -//================================================================================ -//================================================================================ -// HID 'Driver' - +// HID 'Driver' +// ------------ #define HID_GET_REPORT 0x01 #define HID_GET_IDLE 0x02 #define HID_GET_PROTOCOL 0x03 @@ -45,24 +43,6 @@ #define HID_REPORT_DESCRIPTOR_TYPE 0x22 #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 -class HIDDescriptorListNode { -public: - HIDDescriptorListNode *next = NULL; - HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { } - - const void* data; - uint16_t length; -}; - -class HID_ : public PUSBListNode -{ -public: - HID_(void); - int begin(void); - void SendReport(uint8_t id, const void* data, int len); - void AppendDescriptor(HIDDescriptorListNode* node); -}; - typedef struct { uint8_t len; // 9 @@ -83,6 +63,39 @@ typedef struct EndpointDescriptor in; } HIDDescriptor; +class HIDDescriptorListNode { +public: + HIDDescriptorListNode *next = NULL; + HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { } + + const void* data; + uint16_t length; +}; + +class HID_ : public PUSBListNode +{ +public: + HID_(void); + int begin(void); + void SendReport(uint8_t id, const void* data, int len); + void AppendDescriptor(HIDDescriptorListNode* node); + +private: + static int GetInterface(uint8_t* interfaceNum); + static int GetDescriptor(int8_t t); + static bool Setup(USBSetup& setup, uint8_t i); + + static HIDDescriptor hidInterface; + + static HIDDescriptorListNode* rootNode; + static uint16_t sizeof_hidReportDescriptor; + static uint8_t modules_count; + static uint8_t epType[]; + + static uint8_t protocol; + static uint8_t idle; +}; + #define D_HIDREPORT(_descriptorLength) \ { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength & 0xFF, _descriptorLength >> 8 } From 0dfa815ce4ea76b7e558e389fb229de0dfa1cfe5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 16:35:43 +0200 Subject: [PATCH 032/175] [PUSB] callbacks are now pure virtual methods This change allows the compiler to handle callbacks resolution. Callbacks now must be implemented on the class that extends PUSBListNode and this is forced by compiler by means of pure virtual methods. Also the calls to HID.interface() and HID.endpoint() can now be simplified to interface() and endpoint() respectively since the methods are no more static. --- .../arduino/avr/cores/arduino/PluggableUSB.h | 7 ++++--- hardware/arduino/avr/libraries/HID/HID.cpp | 19 ++++++++----------- hardware/arduino/avr/libraries/HID/HID.h | 10 ++++++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index d4a109633..c08bc9992 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -28,9 +28,6 @@ class PUSBListNode { public: PUSBListNode() { } - bool (*setup)(USBSetup& setup, uint8_t i); - int (*getInterface)(uint8_t* interfaceNum); - int (*getDescriptor)(int8_t t); int8_t numEndpoints; int8_t numInterfaces; uint8_t *endpointType; @@ -39,6 +36,10 @@ public: inline int8_t endpoint() const { return pluggedEndpoint; } protected: + virtual bool setup(USBSetup& setup, uint8_t i) = 0; + virtual int getInterface(uint8_t* interfaceNum) = 0; + virtual int getDescriptor(int8_t t) = 0; + uint8_t pluggedInterface; int8_t pluggedEndpoint; diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 118d0c5f4..568595726 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -41,19 +41,19 @@ uint8_t HID_::epType[] = { EP_TYPE_INTERRUPT_IN }; uint8_t HID_::protocol = 1; uint8_t HID_::idle = 1; -int HID_::GetInterface(uint8_t* interfaceNum) +int HID_::getInterface(uint8_t* interfaceNum) { interfaceNum[0] += 1; // uses 1 hidInterface = { - D_INTERFACE(HID.interface(), 1, 3, 0, 0), + D_INTERFACE(interface(), 1, 3, 0, 0), D_HIDREPORT(sizeof_hidReportDescriptor), - D_ENDPOINT(USB_ENDPOINT_IN(HID.endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) + D_ENDPOINT(USB_ENDPOINT_IN(endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) }; return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int HID_::GetDescriptor(int8_t t) +int HID_::getDescriptor(int8_t t) { if (HID_REPORT_DESCRIPTOR_TYPE == t) { HIDDescriptorListNode* current = rootNode; @@ -85,13 +85,13 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node) void HID_::SendReport(uint8_t id, const void* data, int len) { - USB_Send(HID.endpoint(), &id, 1); - USB_Send(HID.endpoint() | TRANSFER_RELEASE,data,len); + USB_Send(endpoint(), &id, 1); + USB_Send(endpoint() | TRANSFER_RELEASE,data,len); } -bool HID_::Setup(USBSetup& setup, uint8_t i) +bool HID_::setup(USBSetup& setup, uint8_t i) { - if (HID.interface() != i) { + if (interface() != i) { return false; } else { uint8_t r = setup.bRequest; @@ -130,9 +130,6 @@ bool HID_::Setup(USBSetup& setup, uint8_t i) HID_::HID_(void) { - setup = HID_::Setup; - getInterface = HID_::GetInterface; - getDescriptor = HID_::GetDescriptor; numEndpoints = 1; numInterfaces = 1; endpointType = epType; diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index cb1125efd..1c8e2fcfe 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -80,11 +80,13 @@ public: void SendReport(uint8_t id, const void* data, int len); void AppendDescriptor(HIDDescriptorListNode* node); -private: - static int GetInterface(uint8_t* interfaceNum); - static int GetDescriptor(int8_t t); - static bool Setup(USBSetup& setup, uint8_t i); +protected: + // Implementation of the PUSBListNode + int getInterface(uint8_t* interfaceNum); + int getDescriptor(int8_t t); + bool setup(USBSetup& setup, uint8_t i); +private: static HIDDescriptor hidInterface; static HIDDescriptorListNode* rootNode; From 0369b8ec333482b63b16ba47608f5cca75ac974f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 16:48:11 +0200 Subject: [PATCH 033/175] [PUSB] The latest fields are now set via constructor --- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 11 +++++++---- hardware/arduino/avr/libraries/HID/HID.cpp | 7 ++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index c08bc9992..0f776c080 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -27,10 +27,9 @@ class PUSBListNode { public: - PUSBListNode() { } - int8_t numEndpoints; - int8_t numInterfaces; - uint8_t *endpointType; + PUSBListNode(int8_t numEps, int8_t numIfs, uint8_t *epType) : + numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) + { } inline uint8_t interface() const { return pluggedInterface; } inline int8_t endpoint() const { return pluggedEndpoint; } @@ -43,6 +42,10 @@ protected: uint8_t pluggedInterface; int8_t pluggedEndpoint; + const int8_t numEndpoints; + const int8_t numInterfaces; + const uint8_t *endpointType; + public: PUSBListNode *next = NULL; diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 568595726..d358f4512 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -128,12 +128,9 @@ bool HID_::setup(USBSetup& setup, uint8_t i) } } -HID_::HID_(void) +HID_::HID_(void) : PUSBListNode(1, 1, epType) { - numEndpoints = 1; - numInterfaces = 1; - endpointType = epType; - + // XXX: Shall this be done in PUSBListNode(...) constructor? PluggableUSB.plug(this); } From 2d70691dbe714f2e1b10edaa5ec577bfff5efff5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 17:13:54 +0200 Subject: [PATCH 034/175] [HID] Removed static fields in HID class There is still the epType[] array to be handled in some way. --- hardware/arduino/avr/libraries/HID/HID.cpp | 26 ++++++---------------- hardware/arduino/avr/libraries/HID/HID.h | 13 +++++------ 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index d358f4512..10cd5a6a8 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -23,24 +23,6 @@ HID_ HID; -//================================================================================ -//================================================================================ -// HID Interface - -HIDDescriptor HID_::hidInterface; - -HIDDescriptorListNode* HID_::rootNode = NULL; -uint16_t HID_::sizeof_hidReportDescriptor = 0; -uint8_t HID_::modules_count = 0; -uint8_t HID_::epType[] = { EP_TYPE_INTERRUPT_IN }; - -//================================================================================ -//================================================================================ -// Driver - -uint8_t HID_::protocol = 1; -uint8_t HID_::idle = 1; - int HID_::getInterface(uint8_t* interfaceNum) { interfaceNum[0] += 1; // uses 1 @@ -128,7 +110,13 @@ bool HID_::setup(USBSetup& setup, uint8_t i) } } -HID_::HID_(void) : PUSBListNode(1, 1, epType) +// XXX: I've found no way to pass literal value directly in +// the PUSBListNode constructor +static uint8_t epTypeDef[] = { EP_TYPE_INTERRUPT_IN }; + +HID_::HID_(void) : PUSBListNode(1, 1, epTypeDef), + rootNode(NULL), sizeof_hidReportDescriptor(0), + modules_count(0), protocol(1), idle(1) { // XXX: Shall this be done in PUSBListNode(...) constructor? PluggableUSB.plug(this); diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index 1c8e2fcfe..bff51bb11 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -87,15 +87,14 @@ protected: bool setup(USBSetup& setup, uint8_t i); private: - static HIDDescriptor hidInterface; + HIDDescriptor hidInterface; - static HIDDescriptorListNode* rootNode; - static uint16_t sizeof_hidReportDescriptor; - static uint8_t modules_count; - static uint8_t epType[]; + HIDDescriptorListNode* rootNode; + uint16_t sizeof_hidReportDescriptor; + uint8_t modules_count; - static uint8_t protocol; - static uint8_t idle; + uint8_t protocol; + uint8_t idle; }; #define D_HIDREPORT(_descriptorLength) \ From 9acbbe63c0ab001de8d375a3573bf5ff3e43f507 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 18:45:09 +0200 Subject: [PATCH 035/175] [PUSB] epType array is now part of HID class --- hardware/arduino/avr/libraries/HID/HID.cpp | 8 ++------ hardware/arduino/avr/libraries/HID/HID.h | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 10cd5a6a8..a8714157d 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -110,15 +110,11 @@ bool HID_::setup(USBSetup& setup, uint8_t i) } } -// XXX: I've found no way to pass literal value directly in -// the PUSBListNode constructor -static uint8_t epTypeDef[] = { EP_TYPE_INTERRUPT_IN }; - -HID_::HID_(void) : PUSBListNode(1, 1, epTypeDef), +HID_::HID_(void) : PUSBListNode(1, 1, epType), rootNode(NULL), sizeof_hidReportDescriptor(0), modules_count(0), protocol(1), idle(1) { - // XXX: Shall this be done in PUSBListNode(...) constructor? + epType[0] = EP_TYPE_INTERRUPT_IN; PluggableUSB.plug(this); } diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index bff51bb11..9e6e67542 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -88,6 +88,7 @@ protected: private: HIDDescriptor hidInterface; + uint8_t epType[1]; HIDDescriptorListNode* rootNode; uint16_t sizeof_hidReportDescriptor; From 183ec1c83f87e80a788cda915597abfe713eb74d Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 19:04:01 +0200 Subject: [PATCH 036/175] [PUSB] No more static fields in PluggableUSB class --- .../avr/cores/arduino/PluggableUSB.cpp | 25 +++++++++++-------- .../arduino/avr/cores/arduino/PluggableUSB.h | 15 ++++++++--- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 2c7221de2..a8c69d4e2 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -25,21 +25,17 @@ #define MAX_MODULES 6 -static uint8_t lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; -static uint8_t lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; - extern uint8_t _initEndpoints[]; //PUSBCallbacks cbs[MAX_MODULES]; -static uint8_t modules_count = 0; -static PUSBListNode* rootNode = NULL; +PluggableUSB_ PluggableUSB; int PluggableUSB_::getInterface(uint8_t* interfaceNum) { int ret = 0; PUSBListNode* node = rootNode; - for (uint8_t i=0; igetInterface(interfaceNum); node = node->next; } @@ -50,7 +46,7 @@ int PluggableUSB_::getDescriptor(int8_t t) { int ret = 0; PUSBListNode* node = rootNode; - for (uint8_t i=0; igetDescriptor(t); node = node->next; } @@ -61,7 +57,7 @@ bool PluggableUSB_::setup(USBSetup& setup, uint8_t j) { bool ret = false; PUSBListNode* node = rootNode; - for (uint8_t i=0; isetup(setup, j); node = node->next; } @@ -70,11 +66,11 @@ bool PluggableUSB_::setup(USBSetup& setup, uint8_t j) bool PluggableUSB_::plug(PUSBListNode *node) { - if (modules_count >= MAX_MODULES) { + if (modulesCount >= MAX_MODULES) { return false; } - if (modules_count == 0) { + if (modulesCount == 0) { rootNode = node; } else { PUSBListNode *current = rootNode; @@ -91,11 +87,18 @@ bool PluggableUSB_::plug(PUSBListNode *node) _initEndpoints[lastEp] = node->endpointType[i]; lastEp++; } - modules_count++; + modulesCount++; return true; // restart USB layer??? } +PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT), + lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT), + modulesCount(0), rootNode(NULL) +{ + // Empty +} + #endif #endif /* if defined(USBCON) */ diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 0f776c080..93ee15ce5 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -54,10 +54,17 @@ public: class PluggableUSB_ { public: - static bool plug(PUSBListNode *node); - static int getInterface(uint8_t* interfaceNum); - static int getDescriptor(int8_t t); - static bool setup(USBSetup& setup, uint8_t i); + PluggableUSB_(); + bool plug(PUSBListNode *node); + int getInterface(uint8_t* interfaceNum); + int getDescriptor(int8_t t); + bool setup(USBSetup& setup, uint8_t i); + +private: + uint8_t lastIf; + uint8_t lastEp; + uint8_t modulesCount; + PUSBListNode* rootNode; }; extern PluggableUSB_ PluggableUSB; From e823ef0c16a0977f0fbe6c0e9ac0a4b59f303a4b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 19:30:23 +0200 Subject: [PATCH 037/175] [PUSB] Fixed check for available endpoints The check for available slot in PluggableUSB is done on the endpoint and not on the number of plugged modules. The modulesCount field is no longer useful and it has been removed. --- .../avr/cores/arduino/PluggableUSB.cpp | 45 +++++++++---------- .../arduino/avr/cores/arduino/PluggableUSB.h | 1 - 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index a8c69d4e2..5a53eb170 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -23,58 +23,56 @@ #if defined(USBCON) #ifdef PLUGGABLE_USB_ENABLED -#define MAX_MODULES 6 +// TODO: set correct value for different CPUs +#define MAX_EP 6 extern uint8_t _initEndpoints[]; -//PUSBCallbacks cbs[MAX_MODULES]; - PluggableUSB_ PluggableUSB; int PluggableUSB_::getInterface(uint8_t* interfaceNum) { int ret = 0; - PUSBListNode* node = rootNode; - for (uint8_t i=0; inext) { ret = node->getInterface(interfaceNum); - node = node->next; } return ret; } int PluggableUSB_::getDescriptor(int8_t t) { - int ret = 0; - PUSBListNode* node = rootNode; - for (uint8_t i=0; igetDescriptor(t); - node = node->next; + PUSBListNode* node; + for (node = rootNode; node; node = node->next) { + int ret = node->getDescriptor(t); + if (ret) + return ret; } - return ret; + return 0; } bool PluggableUSB_::setup(USBSetup& setup, uint8_t j) { - bool ret = false; - PUSBListNode* node = rootNode; - for (uint8_t i=0; isetup(setup, j); - node = node->next; + PUSBListNode* node; + for (node = rootNode; node; node = node->next) { + if (node->setup(setup, j)) { + return true; + } } - return ret; + return false; } bool PluggableUSB_::plug(PUSBListNode *node) { - if (modulesCount >= MAX_MODULES) { + if ((lastEp + node->numEndpoints) >= MAX_EP) { return false; } - if (modulesCount == 0) { + if (!rootNode) { rootNode = node; } else { PUSBListNode *current = rootNode; - while(current->next != NULL) { + while (current->next) { current = current->next; } current->next = node; @@ -83,18 +81,17 @@ bool PluggableUSB_::plug(PUSBListNode *node) node->pluggedInterface = lastIf; node->pluggedEndpoint = lastEp; lastIf += node->numInterfaces; - for (uint8_t i=0; inumEndpoints; i++) { + for (uint8_t i = 0; i < node->numEndpoints; i++) { _initEndpoints[lastEp] = node->endpointType[i]; lastEp++; } - modulesCount++; return true; // restart USB layer??? } PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT), lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT), - modulesCount(0), rootNode(NULL) + rootNode(NULL) { // Empty } diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 93ee15ce5..824440a9c 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -63,7 +63,6 @@ public: private: uint8_t lastIf; uint8_t lastEp; - uint8_t modulesCount; PUSBListNode* rootNode; }; From d1f0c6953af72f4d82e45bc38ebfbd5f2b48cb46 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 20:52:00 +0200 Subject: [PATCH 038/175] [PUSB] Fixed the correct number of endpoints --- .../arduino/avr/cores/arduino/PluggableUSB.cpp | 5 +---- hardware/arduino/avr/cores/arduino/USBCore.cpp | 17 ++++++----------- hardware/arduino/avr/cores/arduino/USBDesc.h | 5 +++++ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 5a53eb170..50fd79825 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -23,9 +23,6 @@ #if defined(USBCON) #ifdef PLUGGABLE_USB_ENABLED -// TODO: set correct value for different CPUs -#define MAX_EP 6 - extern uint8_t _initEndpoints[]; PluggableUSB_ PluggableUSB; @@ -64,7 +61,7 @@ bool PluggableUSB_::setup(USBSetup& setup, uint8_t j) bool PluggableUSB_::plug(PUSBListNode *node) { - if ((lastEp + node->numEndpoints) >= MAX_EP) { + if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) { return false; } diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index f96ff27ab..ebdce361f 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -308,20 +308,15 @@ int USB_Send(u8 ep, const void* d, int len) return r; } -u8 _initEndpoints[] = +u8 _initEndpoints[USB_ENDPOINTS] = { - 0, + 0, // Control Endpoint - EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM - EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT - EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN + EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM + EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT + EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN -#ifdef PLUGGABLE_USB_ENABLED - //allocate 3 endpoints and remove const so they can be changed by the user - 0, - 0, - 0, -#endif + // Following endpoints are automatically initialized to 0 }; #define EP_SINGLE_64 0x32 // EP0 diff --git a/hardware/arduino/avr/cores/arduino/USBDesc.h b/hardware/arduino/avr/cores/arduino/USBDesc.h index 1962727ca..528a7fd51 100644 --- a/hardware/arduino/avr/cores/arduino/USBDesc.h +++ b/hardware/arduino/avr/cores/arduino/USBDesc.h @@ -18,6 +18,11 @@ #define PLUGGABLE_USB_ENABLED +#if defined(EPRST6) +#define USB_ENDPOINTS 7 // AtMegaxxU4 +#else +#define USB_ENDPOINTS 5 // AtMegaxxU2 +#endif #define CDC_INTERFACE_COUNT 2 #define CDC_ENPOINT_COUNT 3 From 1851fcc23c75e148dc6e165194c7295373146388 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 20:53:05 +0200 Subject: [PATCH 039/175] [USB] Fixed some compiler warnings --- hardware/arduino/avr/cores/arduino/USBCore.h | 6 +++--- hardware/arduino/avr/libraries/HID/HID.h | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBCore.h b/hardware/arduino/avr/cores/arduino/USBCore.h index eaeecef82..806fa6028 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.h +++ b/hardware/arduino/avr/cores/arduino/USBCore.h @@ -99,8 +99,8 @@ // bEndpointAddress in Endpoint Descriptor #define USB_ENDPOINT_DIRECTION_MASK 0x80 -#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) -#define USB_ENDPOINT_IN(addr) ((addr) | 0x80) +#define USB_ENDPOINT_OUT(addr) (lowByte((addr) | 0x00)) +#define USB_ENDPOINT_IN(addr) (lowByte((addr) | 0x80)) #define USB_ENDPOINT_TYPE_MASK 0x03 #define USB_ENDPOINT_TYPE_CONTROL 0x00 @@ -277,4 +277,4 @@ typedef struct #define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 } -#endif \ No newline at end of file +#endif diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index 9e6e67542..f951229f8 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -98,8 +98,7 @@ private: uint8_t idle; }; -#define D_HIDREPORT(_descriptorLength) \ - { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength & 0xFF, _descriptorLength >> 8 } +#define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) } #define WEAK __attribute__ ((weak)) From 8a5ad75c501027c15e645f50bb533f3c64109354 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 1 Oct 2015 12:35:24 +0200 Subject: [PATCH 040/175] [PUSB] Fixed checks on return values --- .../avr/cores/arduino/PluggableUSB.cpp | 14 ++++++++----- hardware/arduino/avr/libraries/HID/HID.cpp | 20 +++++++++++-------- hardware/arduino/avr/libraries/HID/HID.h | 4 ++-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 50fd79825..acc627652 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -29,19 +29,23 @@ PluggableUSB_ PluggableUSB; int PluggableUSB_::getInterface(uint8_t* interfaceNum) { - int ret = 0; + int sent = 0; PUSBListNode* node; for (node = rootNode; node; node = node->next) { - ret = node->getInterface(interfaceNum); + int res = node->getInterface(interfaceNum); + if (res == -1) + return -1; + sent += res; } - return ret; + return sent; } -int PluggableUSB_::getDescriptor(int8_t t) +int PluggableUSB_::getDescriptor(int8_t type) { PUSBListNode* node; for (node = rootNode; node; node = node->next) { - int ret = node->getDescriptor(t); + int ret = node->getDescriptor(type); + // ret!=0 -> request has been processed if (ret) return ret; } diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index a8714157d..a10957429 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -35,19 +35,23 @@ int HID_::getInterface(uint8_t* interfaceNum) return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int HID_::getDescriptor(int8_t t) +int HID_::getDescriptor(int8_t type) { - if (HID_REPORT_DESCRIPTOR_TYPE == t) { + if (HID_REPORT_DESCRIPTOR_TYPE == type) { HIDDescriptorListNode* current = rootNode; int total = 0; - while(current != NULL) { - total += USB_SendControl(TRANSFER_PGM,current->data,current->length); + while (current != NULL) { + int res = USB_SendControl(TRANSFER_PGM, current->data, current->length); + if (res == -1) + return -1; + total += res; current = current->next; } return total; - } else { - return 0; } + + // Ignored + return 0; } void HID_::AppendDescriptor(HIDDescriptorListNode *node) @@ -71,9 +75,9 @@ void HID_::SendReport(uint8_t id, const void* data, int len) USB_Send(endpoint() | TRANSFER_RELEASE,data,len); } -bool HID_::setup(USBSetup& setup, uint8_t i) +bool HID_::setup(USBSetup& setup, uint8_t interfaceNum) { - if (interface() != i) { + if (interface() != interfaceNum) { return false; } else { uint8_t r = setup.bRequest; diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index f951229f8..ed08cf051 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -83,8 +83,8 @@ public: protected: // Implementation of the PUSBListNode int getInterface(uint8_t* interfaceNum); - int getDescriptor(int8_t t); - bool setup(USBSetup& setup, uint8_t i); + int getDescriptor(int8_t type); + bool setup(USBSetup& setup, uint8_t interfaceNum); private: HIDDescriptor hidInterface; From 81aa7df09353ff8f6152a6906516a3ed357d9793 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 1 Oct 2015 12:39:57 +0200 Subject: [PATCH 041/175] [HID] removed unused modules_count field --- hardware/arduino/avr/libraries/HID/HID.cpp | 5 ++--- hardware/arduino/avr/libraries/HID/HID.h | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index a10957429..3a439f073 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -56,7 +56,7 @@ int HID_::getDescriptor(int8_t type) void HID_::AppendDescriptor(HIDDescriptorListNode *node) { - if (modules_count == 0) { + if (!rootNode) { rootNode = node; } else { HIDDescriptorListNode *current = rootNode; @@ -65,7 +65,6 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node) } current->next = node; } - modules_count++; sizeof_hidReportDescriptor += (uint16_t)node->length; } @@ -116,7 +115,7 @@ bool HID_::setup(USBSetup& setup, uint8_t interfaceNum) HID_::HID_(void) : PUSBListNode(1, 1, epType), rootNode(NULL), sizeof_hidReportDescriptor(0), - modules_count(0), protocol(1), idle(1) + protocol(1), idle(1) { epType[0] = EP_TYPE_INTERRUPT_IN; PluggableUSB.plug(this); diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index ed08cf051..c6f9ab518 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -92,7 +92,6 @@ private: HIDDescriptorListNode* rootNode; uint16_t sizeof_hidReportDescriptor; - uint8_t modules_count; uint8_t protocol; uint8_t idle; From 214b260a82235c87649cce12cbf4f9b30c629e77 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 1 Oct 2015 12:50:18 +0200 Subject: [PATCH 042/175] [HID] Code cleanup (no semantic changes) --- hardware/arduino/avr/cores/arduino/USBDesc.h | 30 ++--- hardware/arduino/avr/libraries/HID/HID.cpp | 117 +++++++++---------- hardware/arduino/avr/libraries/HID/HID.h | 35 +++--- 3 files changed, 86 insertions(+), 96 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBDesc.h b/hardware/arduino/avr/cores/arduino/USBDesc.h index 528a7fd51..4b9cf6636 100644 --- a/hardware/arduino/avr/cores/arduino/USBDesc.h +++ b/hardware/arduino/avr/cores/arduino/USBDesc.h @@ -1,20 +1,20 @@ +/* + Copyright (c) 2011, Peter Barrett + Copyright (c) 2015, Arduino LLC + Permission to use, copy, modify, and/or distribute this software for + any purpose with or without fee is hereby granted, provided that the + above copyright notice and this permission notice appear in all copies. -/* Copyright (c) 2011, Peter Barrett -** -** Permission to use, copy, modify, and/or distribute this software for -** any purpose with or without fee is hereby granted, provided that the -** above copyright notice and this permission notice appear in all copies. -** -** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL -** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED -** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR -** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES -** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -** SOFTWARE. -*/ + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR + BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES + OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + SOFTWARE. + */ #define PLUGGABLE_USB_ENABLED diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 3a439f073..574af6ba3 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -1,20 +1,20 @@ -/* Copyright (c) 2015, Arduino LLC -** -** Original code (pre-library): Copyright (c) 2011, Peter Barrett -** -** Permission to use, copy, modify, and/or distribute this software for -** any purpose with or without fee is hereby granted, provided that the -** above copyright notice and this permission notice appear in all copies. -** -** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL -** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED -** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR -** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES -** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -** SOFTWARE. -*/ +/* + Copyright (c) 2015, Arduino LLC + Original code (pre-library): Copyright (c) 2011, Peter Barrett + + Permission to use, copy, modify, and/or distribute this software for + any purpose with or without fee is hereby granted, provided that the + above copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR + BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES + OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + SOFTWARE. + */ #include "PluggableUSB.h" #include "HID.h" @@ -25,11 +25,10 @@ HID_ HID; int HID_::getInterface(uint8_t* interfaceNum) { - interfaceNum[0] += 1; // uses 1 - hidInterface = - { + *interfaceNum += 1; // uses 1 + hidInterface = { D_INTERFACE(interface(), 1, 3, 0, 0), - D_HIDREPORT(sizeof_hidReportDescriptor), + D_HIDREPORT(descriptorSize), D_ENDPOINT(USB_ENDPOINT_IN(endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) }; return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); @@ -38,14 +37,13 @@ int HID_::getInterface(uint8_t* interfaceNum) int HID_::getDescriptor(int8_t type) { if (HID_REPORT_DESCRIPTOR_TYPE == type) { - HIDDescriptorListNode* current = rootNode; int total = 0; - while (current != NULL) { - int res = USB_SendControl(TRANSFER_PGM, current->data, current->length); + HIDDescriptorListNode* node; + for (node = rootNode; node; node = node->next) { + int res = USB_SendControl(TRANSFER_PGM, node->data, node->length); if (res == -1) return -1; total += res; - current = current->next; } return total; } @@ -60,61 +58,58 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node) rootNode = node; } else { HIDDescriptorListNode *current = rootNode; - while(current->next != NULL) { + while (current->next) { current = current->next; } current->next = node; } - sizeof_hidReportDescriptor += (uint16_t)node->length; + descriptorSize += node->length; } void HID_::SendReport(uint8_t id, const void* data, int len) { USB_Send(endpoint(), &id, 1); - USB_Send(endpoint() | TRANSFER_RELEASE,data,len); + USB_Send(endpoint() | TRANSFER_RELEASE, data, len); } bool HID_::setup(USBSetup& setup, uint8_t interfaceNum) { if (interface() != interfaceNum) { return false; - } else { - uint8_t r = setup.bRequest; - uint8_t requestType = setup.bmRequestType; - if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType) - { - if (HID_GET_REPORT == r) - { - //HID_GetReport(); - return true; - } - if (HID_GET_PROTOCOL == r) - { - //Send8(protocol); // TODO - return true; - } - } - - if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType) - { - if (HID_SET_PROTOCOL == r) - { - protocol = setup.wValueL; - return true; - } - - if (HID_SET_IDLE == r) - { - idle = setup.wValueL; - return true; - } - } - return false; } + + uint8_t request = setup.bRequest; + uint8_t requestType = setup.bmRequestType; + + if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) + { + if (request == HID_GET_REPORT) { + // TODO: HID_GetReport(); + return true; + } + if (request == HID_GET_PROTOCOL) { + // TODO: Send8(protocol); + return true; + } + } + + if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) + { + if (request == HID_SET_PROTOCOL) { + protocol = setup.wValueL; + return true; + } + if (request == HID_SET_IDLE) { + idle = setup.wValueL; + return true; + } + } + + return false; } HID_::HID_(void) : PUSBListNode(1, 1, epType), - rootNode(NULL), sizeof_hidReportDescriptor(0), + rootNode(NULL), descriptorSize(0), protocol(1), idle(1) { epType[0] = EP_TYPE_INTERRUPT_IN; diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index c6f9ab518..d31d9c5ac 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -1,23 +1,20 @@ /* - HID.h - Copyright (c) 2015, Arduino LLC Original code (pre-library): Copyright (c) 2011, Peter Barrett - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + Permission to use, copy, modify, and/or distribute this software for + any purpose with or without fee is hereby granted, provided that the + above copyright notice and this permission notice appear in all copies. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR + BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES + OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + SOFTWARE. + */ #ifndef HID_h #define HID_h @@ -91,7 +88,7 @@ private: uint8_t epType[1]; HIDDescriptorListNode* rootNode; - uint16_t sizeof_hidReportDescriptor; + uint16_t descriptorSize; uint8_t protocol; uint8_t idle; @@ -99,8 +96,6 @@ private: #define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) } -#define WEAK __attribute__ ((weak)) +#endif // USBCON -#endif - -#endif +#endif // HID_h From d13aadc7d54c352e36bac3bbc40a1bd95f3d66e4 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 1 Oct 2015 12:53:24 +0200 Subject: [PATCH 043/175] [HID] removed HIDDescriptor field The field is now built on-the-fly on the stack and sent over USB. This change increase Flash usage and decrease SRAM usage: before: 6114 / 241 after: 6152 / 216 (removed HIDDescriptor field) delta: +38 / -25 SRAM is a much more scarse resource and this change free up to about 10% of the "base" usage. --- hardware/arduino/avr/libraries/HID/HID.cpp | 2 +- hardware/arduino/avr/libraries/HID/HID.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 574af6ba3..b7aab6cee 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -26,7 +26,7 @@ HID_ HID; int HID_::getInterface(uint8_t* interfaceNum) { *interfaceNum += 1; // uses 1 - hidInterface = { + HIDDescriptor hidInterface = { D_INTERFACE(interface(), 1, 3, 0, 0), D_HIDREPORT(descriptorSize), D_ENDPOINT(USB_ENDPOINT_IN(endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index d31d9c5ac..2cd0f4a0e 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -84,7 +84,6 @@ protected: bool setup(USBSetup& setup, uint8_t interfaceNum); private: - HIDDescriptor hidInterface; uint8_t epType[1]; HIDDescriptorListNode* rootNode; From 65b8430fece7a708be740089864835a862678cff Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 1 Oct 2015 17:35:26 +0200 Subject: [PATCH 044/175] [PUSB] Fix static initialization order fiasco For details see: https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use --- hardware/arduino/avr/cores/arduino/PluggableUSB.cpp | 8 ++++++-- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 5 ++++- hardware/arduino/avr/cores/arduino/USBCore.cpp | 6 +++--- hardware/arduino/avr/libraries/HID/HID.cpp | 8 ++++++-- hardware/arduino/avr/libraries/HID/HID.h | 5 +++++ libraries/Keyboard/src/Keyboard.cpp | 4 ++-- libraries/Keyboard/src/Keyboard.h | 1 - libraries/Mouse/src/Mouse.cpp | 4 ++-- libraries/Mouse/src/Mouse.h | 1 - 9 files changed, 28 insertions(+), 14 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index acc627652..582379a84 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -25,8 +25,6 @@ extern uint8_t _initEndpoints[]; -PluggableUSB_ PluggableUSB; - int PluggableUSB_::getInterface(uint8_t* interfaceNum) { int sent = 0; @@ -90,6 +88,12 @@ bool PluggableUSB_::plug(PUSBListNode *node) // restart USB layer??? } +PluggableUSB_& PluggableUSB() +{ + static PluggableUSB_ obj; + return obj; +} + PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT), lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT), rootNode(NULL) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 824440a9c..b0668f40e 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -66,7 +66,10 @@ private: PUSBListNode* rootNode; }; -extern PluggableUSB_ PluggableUSB; +// Replacement for global singleton. +// This function prevents static-initialization-order-fiasco +// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use +PluggableUSB_& PluggableUSB(); #endif diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index ebdce361f..5db9f521a 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -362,7 +362,7 @@ bool ClassInterfaceRequest(USBSetup& setup) return CDC_Setup(setup); #ifdef PLUGGABLE_USB_ENABLED - return PluggableUSB.setup(setup, i); + return PluggableUSB().setup(setup, i); #endif return false; } @@ -440,7 +440,7 @@ static u8 SendInterfaces() CDC_GetInterface(&interfaces); #ifdef PLUGGABLE_USB_ENABLED - PluggableUSB.getInterface(&interfaces); + PluggableUSB().getInterface(&interfaces); #endif return interfaces; @@ -476,7 +476,7 @@ bool SendDescriptor(USBSetup& setup) InitControl(setup.wLength); #ifdef PLUGGABLE_USB_ENABLED - ret = PluggableUSB.getDescriptor(t); + ret = PluggableUSB().getDescriptor(t); if (ret != 0) { return (ret > 0 ? true : false); } diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index b7aab6cee..ff8e67b2d 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -21,7 +21,11 @@ #if defined(USBCON) -HID_ HID; +HID_& HID() +{ + static HID_ obj; + return obj; +} int HID_::getInterface(uint8_t* interfaceNum) { @@ -113,7 +117,7 @@ HID_::HID_(void) : PUSBListNode(1, 1, epType), protocol(1), idle(1) { epType[0] = EP_TYPE_INTERRUPT_IN; - PluggableUSB.plug(this); + PluggableUSB().plug(this); } int HID_::begin(void) diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index 2cd0f4a0e..a7f5c682f 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -93,6 +93,11 @@ private: uint8_t idle; }; +// Replacement for global singleton. +// This function prevents static-initialization-order-fiasco +// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use +HID_& HID(); + #define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) } #endif // USBCON diff --git a/libraries/Keyboard/src/Keyboard.cpp b/libraries/Keyboard/src/Keyboard.cpp index 2663e6e62..d899e92e4 100644 --- a/libraries/Keyboard/src/Keyboard.cpp +++ b/libraries/Keyboard/src/Keyboard.cpp @@ -63,7 +63,7 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = { Keyboard_::Keyboard_(void) { static HIDDescriptorListNode node(_hidReportDescriptor, sizeof(_hidReportDescriptor)); - HID.AppendDescriptor(&node); + HID().AppendDescriptor(&node); } void Keyboard_::begin(void) @@ -76,7 +76,7 @@ void Keyboard_::end(void) void Keyboard_::sendReport(KeyReport* keys) { - HID.SendReport(2,keys,sizeof(KeyReport)); + HID().SendReport(2,keys,sizeof(KeyReport)); } extern diff --git a/libraries/Keyboard/src/Keyboard.h b/libraries/Keyboard/src/Keyboard.h index 1c728ae9e..8f173f31c 100644 --- a/libraries/Keyboard/src/Keyboard.h +++ b/libraries/Keyboard/src/Keyboard.h @@ -94,7 +94,6 @@ public: void releaseAll(void); }; extern Keyboard_ Keyboard; -extern HID_ HID; #endif #endif diff --git a/libraries/Mouse/src/Mouse.cpp b/libraries/Mouse/src/Mouse.cpp index 0cb5b2908..64d02bc86 100644 --- a/libraries/Mouse/src/Mouse.cpp +++ b/libraries/Mouse/src/Mouse.cpp @@ -63,7 +63,7 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = { Mouse_::Mouse_(void) : _buttons(0) { static HIDDescriptorListNode node(_hidReportDescriptor, sizeof(_hidReportDescriptor)); - HID.AppendDescriptor(&node); + HID().AppendDescriptor(&node); } void Mouse_::begin(void) @@ -89,7 +89,7 @@ void Mouse_::move(signed char x, signed char y, signed char wheel) m[1] = x; m[2] = y; m[3] = wheel; - HID.SendReport(1,m,4); + HID().SendReport(1,m,4); } void Mouse_::buttons(uint8_t b) diff --git a/libraries/Mouse/src/Mouse.h b/libraries/Mouse/src/Mouse.h index 3ab57a5eb..2672b5c93 100644 --- a/libraries/Mouse/src/Mouse.h +++ b/libraries/Mouse/src/Mouse.h @@ -55,7 +55,6 @@ public: bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default }; extern Mouse_ Mouse; -extern HID_ HID; #endif #endif \ No newline at end of file From 7fdb0efc985c009f521595188d0d1649765b3cfd Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 3 Oct 2015 07:56:48 +0200 Subject: [PATCH 045/175] Removed not needed public statement for root node --- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 1 - 1 file changed, 1 deletion(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index b0668f40e..40a898ec0 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -46,7 +46,6 @@ protected: const int8_t numInterfaces; const uint8_t *endpointType; -public: PUSBListNode *next = NULL; friend class PluggableUSB_; From 7f4c29927db35a8cec7f7c7cb81774406ed2ec6f Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 4 Oct 2015 05:03:31 -0700 Subject: [PATCH 046/175] Clean up Ethernet example comments - Fix typos and formatting. - Remove analog inputs part of Circuit comment in ChatServer and AdvancedChatServer. The examples don't use these analog inputs. --- .../examples/AdvancedChatServer/AdvancedChatServer.ino | 7 +++---- .../BarometricPressureWebServer.ino | 2 +- libraries/Ethernet/examples/ChatServer/ChatServer.ino | 7 +++---- .../Ethernet/examples/DhcpChatServer/DhcpChatServer.ino | 4 ++-- libraries/Ethernet/examples/TelnetClient/TelnetClient.ino | 2 +- .../examples/UDPSendReceiveString/UDPSendReceiveString.ino | 6 +++--- libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino | 4 ++-- libraries/Ethernet/examples/WebClient/WebClient.ino | 3 +-- 8 files changed, 16 insertions(+), 19 deletions(-) diff --git a/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino b/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino index 3bcd3a1ec..592a00e48 100644 --- a/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino +++ b/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino @@ -3,13 +3,12 @@ A more advanced server that distributes any incoming messages to all connected clients but the client the message comes from. - To use telnet to your device's IP address and type. + To use, telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. Using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 - * Analog inputs attached to pins A0 through A5 (optional) created 18 Dec 2009 by David A. Mellis @@ -41,7 +40,7 @@ EthernetServer server(23); EthernetClient clients[4]; void setup() { - // initialize the ethernet device + // initialize the Ethernet device Ethernet.begin(mac, ip, myDns, gateway, subnet); // start listening for clients server.begin(); @@ -77,7 +76,7 @@ void loop() { for (byte i = 0; i < 4; i++) { if (!clients[i] && clients[i] != client) { clients[i] = client; - // clead out the input buffer: + // clear out the input buffer: client.flush(); Serial.println("We have a new client"); client.print("Hello, client number: "); diff --git a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino index c0a3298a9..794e22444 100644 --- a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino +++ b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino @@ -26,7 +26,7 @@ #include -// assign a MAC address for the ethernet controller. +// assign a MAC address for the Ethernet controller. // fill in your address here: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED diff --git a/libraries/Ethernet/examples/ChatServer/ChatServer.ino b/libraries/Ethernet/examples/ChatServer/ChatServer.ino index 63f7c6b2a..fe501d6ab 100644 --- a/libraries/Ethernet/examples/ChatServer/ChatServer.ino +++ b/libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -1,14 +1,13 @@ /* - Chat Server + Chat Server A simple server that distributes any incoming messages to all - connected clients. To use telnet to your device's IP address and type. + connected clients. To use, telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. Using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 - * Analog inputs attached to pins A0 through A5 (optional) created 18 Dec 2009 by David A. Mellis @@ -59,7 +58,7 @@ void loop() { // when the client sends the first byte, say hello: if (client) { if (!alreadyConnected) { - // clead out the input buffer: + // clear out the input buffer: client.flush(); Serial.println("We have a new client"); client.println("Hello, client!"); diff --git a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino index bc93cdc43..4cfb5945d 100644 --- a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino +++ b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino @@ -2,7 +2,7 @@ DHCP Chat Server A simple server that distributes any incoming messages to all - connected clients. To use telnet to your device's IP address and type. + connected clients. To use, telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. Using an Arduino Wiznet Ethernet shield. @@ -51,7 +51,7 @@ void setup() { Serial.println("Trying to get an IP address using DHCP"); if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); - // initialize the ethernet device not using DHCP: + // initialize the Ethernet device not using DHCP: Ethernet.begin(mac, ip, myDns, gateway, subnet); } // print your local IP address: diff --git a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino index 350ce2072..c9249b794 100644 --- a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino +++ b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -34,7 +34,7 @@ IPAddress server(1, 1, 1, 1); // Initialize the Ethernet client library // with the IP address and port of the server // that you want to connect to (port 23 is default for telnet; -// if you're using Processing's ChatServer, use port 10002): +// if you're using Processing's ChatServer, use port 10002): EthernetClient client; void setup() { diff --git a/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino b/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino index c38b05eb7..62d008ff5 100644 --- a/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino +++ b/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino @@ -1,5 +1,5 @@ /* - UDPSendReceive.pde: + UDPSendReceiveString: This sketch receives UDP message strings, prints them to the serial port and sends an "acknowledge" string back to the sender @@ -28,7 +28,7 @@ IPAddress ip(192, 168, 1, 177); unsigned int localPort = 8888; // local port to listen on // buffers for receiving and sending data -char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, +char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, char ReplyBuffer[] = "acknowledged"; // a string to send back // An EthernetUDP instance to let us send and receive packets over UDP @@ -64,7 +64,7 @@ void loop() { Serial.println("Contents:"); Serial.println(packetBuffer); - // send a reply, to the IP address and port that sent us the packet we received + // send a reply to the IP address and port that sent us the packet we received Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); Udp.write(ReplyBuffer); Udp.endPacket(); diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino index 3b4bb34bc..157136cf8 100644 --- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino +++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -66,8 +66,8 @@ void loop() { // We've received a packet, read the data from it Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer - //the timestamp starts at byte 40 of the received packet and is four bytes, - // or two words, long. First, esxtract the two words: + // the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); diff --git a/libraries/Ethernet/examples/WebClient/WebClient.ino b/libraries/Ethernet/examples/WebClient/WebClient.ino index 54927a0b9..5e265a77c 100644 --- a/libraries/Ethernet/examples/WebClient/WebClient.ino +++ b/libraries/Ethernet/examples/WebClient/WebClient.ino @@ -43,7 +43,6 @@ void setup() { // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); - // no point in carrying on, so do nothing forevermore: // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip); } @@ -60,7 +59,7 @@ void setup() { client.println("Connection: close"); client.println(); } else { - // kf you didn't get a connection to the server: + // if you didn't get a connection to the server: Serial.println("connection failed"); } } From 7fbedc24558010a9698a171bdde98cb66136ad9f Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 5 Oct 2015 13:33:05 +0200 Subject: [PATCH 047/175] Updating arduino-builder to 1.0.0-beta23 --- build/arduino-builder-linux32-1.0.0-beta22.tar.bz2.sha | 1 - build/arduino-builder-linux32-1.0.0-beta23.tar.bz2.sha | 1 + build/arduino-builder-linux64-1.0.0-beta22.tar.bz2.sha | 1 - build/arduino-builder-linux64-1.0.0-beta23.tar.bz2.sha | 1 + build/arduino-builder-macosx-1.0.0-beta22.tar.bz2.sha | 1 - build/arduino-builder-macosx-1.0.0-beta23.tar.bz2.sha | 1 + build/arduino-builder-windows-1.0.0-beta22.zip.sha | 1 - build/arduino-builder-windows-1.0.0-beta23.zip.sha | 1 + build/build.xml | 2 +- 9 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 build/arduino-builder-linux32-1.0.0-beta22.tar.bz2.sha create mode 100644 build/arduino-builder-linux32-1.0.0-beta23.tar.bz2.sha delete mode 100644 build/arduino-builder-linux64-1.0.0-beta22.tar.bz2.sha create mode 100644 build/arduino-builder-linux64-1.0.0-beta23.tar.bz2.sha delete mode 100644 build/arduino-builder-macosx-1.0.0-beta22.tar.bz2.sha create mode 100644 build/arduino-builder-macosx-1.0.0-beta23.tar.bz2.sha delete mode 100644 build/arduino-builder-windows-1.0.0-beta22.zip.sha create mode 100644 build/arduino-builder-windows-1.0.0-beta23.zip.sha diff --git a/build/arduino-builder-linux32-1.0.0-beta22.tar.bz2.sha b/build/arduino-builder-linux32-1.0.0-beta22.tar.bz2.sha deleted file mode 100644 index b43179c7d..000000000 --- a/build/arduino-builder-linux32-1.0.0-beta22.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -b7bb169b0948f64eba04677464c46fccce0f4634 diff --git a/build/arduino-builder-linux32-1.0.0-beta23.tar.bz2.sha b/build/arduino-builder-linux32-1.0.0-beta23.tar.bz2.sha new file mode 100644 index 000000000..14dc528e8 --- /dev/null +++ b/build/arduino-builder-linux32-1.0.0-beta23.tar.bz2.sha @@ -0,0 +1 @@ +23ba6fb0969cf81bafb1d3c37b9d491e332fae71 diff --git a/build/arduino-builder-linux64-1.0.0-beta22.tar.bz2.sha b/build/arduino-builder-linux64-1.0.0-beta22.tar.bz2.sha deleted file mode 100644 index 5aab5741d..000000000 --- a/build/arduino-builder-linux64-1.0.0-beta22.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -8c1e4c07900129b42828ab2be70c3b477cebfb50 diff --git a/build/arduino-builder-linux64-1.0.0-beta23.tar.bz2.sha b/build/arduino-builder-linux64-1.0.0-beta23.tar.bz2.sha new file mode 100644 index 000000000..0e99c9d89 --- /dev/null +++ b/build/arduino-builder-linux64-1.0.0-beta23.tar.bz2.sha @@ -0,0 +1 @@ +c2e8bf47d10112f1145976792032121041735414 diff --git a/build/arduino-builder-macosx-1.0.0-beta22.tar.bz2.sha b/build/arduino-builder-macosx-1.0.0-beta22.tar.bz2.sha deleted file mode 100644 index 3fe261fa7..000000000 --- a/build/arduino-builder-macosx-1.0.0-beta22.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -8aa7d8a1d3bf436aef6e603feecde8b07e75ab66 diff --git a/build/arduino-builder-macosx-1.0.0-beta23.tar.bz2.sha b/build/arduino-builder-macosx-1.0.0-beta23.tar.bz2.sha new file mode 100644 index 000000000..1bbe20b31 --- /dev/null +++ b/build/arduino-builder-macosx-1.0.0-beta23.tar.bz2.sha @@ -0,0 +1 @@ +725c998d08c73fb292fbd558106494acf7d1f9cf diff --git a/build/arduino-builder-windows-1.0.0-beta22.zip.sha b/build/arduino-builder-windows-1.0.0-beta22.zip.sha deleted file mode 100644 index 7f6efefae..000000000 --- a/build/arduino-builder-windows-1.0.0-beta22.zip.sha +++ /dev/null @@ -1 +0,0 @@ -ab362a5198352e7488719b8793f73313f2c1d17b diff --git a/build/arduino-builder-windows-1.0.0-beta23.zip.sha b/build/arduino-builder-windows-1.0.0-beta23.zip.sha new file mode 100644 index 000000000..36f4da551 --- /dev/null +++ b/build/arduino-builder-windows-1.0.0-beta23.zip.sha @@ -0,0 +1 @@ +f54e4dc2d71a2f1e0141afee7f28f9d896c11593 diff --git a/build/build.xml b/build/build.xml index 7883f3164..c00104cb4 100644 --- a/build/build.xml +++ b/build/build.xml @@ -71,7 +71,7 @@ - + From 10fafd755cb34568876561bc4f1bdeb8286f4622 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 5 Oct 2015 15:09:58 +0200 Subject: [PATCH 048/175] Windows: fixed ctags path --- build/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build.xml b/build/build.xml index c00104cb4..217f4fa6e 100644 --- a/build/build.xml +++ b/build/build.xml @@ -835,7 +835,7 @@ - + From aa654ba24203c6252ff9516ef1ddf78549a1406b Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 6 Oct 2015 10:16:41 +0200 Subject: [PATCH 049/175] Updating arduino-builder to 1.0.0-beta24 --- arduino-core/src/cc/arduino/Compiler.java | 32 ++++++++++++++++--- ...o-builder-linux32-1.0.0-beta23.tar.bz2.sha | 1 - ...o-builder-linux32-1.0.0-beta24.tar.bz2.sha | 1 + ...o-builder-linux64-1.0.0-beta23.tar.bz2.sha | 1 - ...o-builder-linux64-1.0.0-beta24.tar.bz2.sha | 1 + ...no-builder-macosx-1.0.0-beta23.tar.bz2.sha | 1 - ...no-builder-macosx-1.0.0-beta24.tar.bz2.sha | 1 + ...duino-builder-windows-1.0.0-beta23.zip.sha | 1 - ...duino-builder-windows-1.0.0-beta24.zip.sha | 1 + build/build.xml | 2 +- 10 files changed, 32 insertions(+), 10 deletions(-) delete mode 100644 build/arduino-builder-linux32-1.0.0-beta23.tar.bz2.sha create mode 100644 build/arduino-builder-linux32-1.0.0-beta24.tar.bz2.sha delete mode 100644 build/arduino-builder-linux64-1.0.0-beta23.tar.bz2.sha create mode 100644 build/arduino-builder-linux64-1.0.0-beta24.tar.bz2.sha delete mode 100644 build/arduino-builder-macosx-1.0.0-beta23.tar.bz2.sha create mode 100644 build/arduino-builder-macosx-1.0.0-beta24.tar.bz2.sha delete mode 100644 build/arduino-builder-windows-1.0.0-beta23.zip.sha create mode 100644 build/arduino-builder-windows-1.0.0-beta24.zip.sha diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java index 41dfc47dd..06c5be7d7 100644 --- a/arduino-core/src/cc/arduino/Compiler.java +++ b/arduino-core/src/cc/arduino/Compiler.java @@ -30,9 +30,11 @@ package cc.arduino; import cc.arduino.i18n.I18NAwareMessageConsumer; +import cc.arduino.packages.BoardPort; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.PumpStreamHandler; +import org.apache.commons.lang3.StringUtils; import processing.app.*; import processing.app.debug.*; import processing.app.helpers.PreferencesMap; @@ -128,13 +130,14 @@ public class Compiler implements MessageConsumer { TargetPlatform platform = board.getContainerPlatform(); TargetPackage aPackage = platform.getContainerPackage(); + String vidpid = VIDPID(); - PreferencesMap prefs = loadPreferences(board, platform, aPackage); + PreferencesMap prefs = loadPreferences(board, platform, aPackage, vidpid); MessageConsumerOutputStream out = new MessageConsumerOutputStream(new ProgressAwareMessageConsumer(new I18NAwareMessageConsumer(System.out), progListener), "\n"); MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(System.err, Compiler.this), "\n"); - callArduinoBuilder(board, platform, aPackage, BuilderAction.COMPILE, new PumpStreamHandler(out, err)); + callArduinoBuilder(board, platform, aPackage, vidpid, BuilderAction.COMPILE, new PumpStreamHandler(out, err)); out.flush(); err.flush(); @@ -152,12 +155,27 @@ public class Compiler implements MessageConsumer { return sketch.getName() + ".ino"; } - private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platform, TargetPackage aPackage) throws RunnerException, IOException { + private String VIDPID() { + BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port")); + if (boardPort == null) { + return ""; + } + + String vid = boardPort.getPrefs().get("vid"); + String pid = boardPort.getPrefs().get("pid"); + if (StringUtils.isEmpty(vid) || StringUtils.isEmpty(pid)) { + return ""; + } + + return vid.toUpperCase() + "_" + pid.toUpperCase(); + } + + private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid) throws RunnerException, IOException { ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(new PrintStream(stderr), Compiler.this), "\n"); try { - callArduinoBuilder(board, platform, aPackage, BuilderAction.DUMP_PREFS, new PumpStreamHandler(stdout, err)); + callArduinoBuilder(board, platform, aPackage, vidpid, BuilderAction.DUMP_PREFS, new PumpStreamHandler(stdout, err)); } catch (RunnerException e) { System.err.println(new String(stderr.toByteArray())); throw e; @@ -167,7 +185,7 @@ public class Compiler implements MessageConsumer { return prefs; } - private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, BuilderAction action, PumpStreamHandler streamHandler) throws RunnerException { + private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid, BuilderAction action, PumpStreamHandler streamHandler) throws RunnerException { File executable = BaseNoGui.getContentFile("arduino-builder"); CommandLine commandLine = new CommandLine(executable); commandLine.addArgument(action.value, false); @@ -197,6 +215,10 @@ public class Compiler implements MessageConsumer { String fqbn = Stream.of(aPackage.getId(), platform.getId(), board.getId(), boardOptions(board)).filter(s -> !s.isEmpty()).collect(Collectors.joining(":")); commandLine.addArgument("-fqbn=" + fqbn, false); + if (!"".equals(vidpid)) { + commandLine.addArgument("-vid-pid=" + vidpid, false); + } + commandLine.addArgument("-ide-version=" + BaseNoGui.REVISION, false); commandLine.addArgument("-build-path", false); commandLine.addArgument("\"" + buildPath + "\"", false); diff --git a/build/arduino-builder-linux32-1.0.0-beta23.tar.bz2.sha b/build/arduino-builder-linux32-1.0.0-beta23.tar.bz2.sha deleted file mode 100644 index 14dc528e8..000000000 --- a/build/arduino-builder-linux32-1.0.0-beta23.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -23ba6fb0969cf81bafb1d3c37b9d491e332fae71 diff --git a/build/arduino-builder-linux32-1.0.0-beta24.tar.bz2.sha b/build/arduino-builder-linux32-1.0.0-beta24.tar.bz2.sha new file mode 100644 index 000000000..5c09eaad1 --- /dev/null +++ b/build/arduino-builder-linux32-1.0.0-beta24.tar.bz2.sha @@ -0,0 +1 @@ +d8c3e22428fa0953038f2ac21cd7be6d614fee30 diff --git a/build/arduino-builder-linux64-1.0.0-beta23.tar.bz2.sha b/build/arduino-builder-linux64-1.0.0-beta23.tar.bz2.sha deleted file mode 100644 index 0e99c9d89..000000000 --- a/build/arduino-builder-linux64-1.0.0-beta23.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -c2e8bf47d10112f1145976792032121041735414 diff --git a/build/arduino-builder-linux64-1.0.0-beta24.tar.bz2.sha b/build/arduino-builder-linux64-1.0.0-beta24.tar.bz2.sha new file mode 100644 index 000000000..317154324 --- /dev/null +++ b/build/arduino-builder-linux64-1.0.0-beta24.tar.bz2.sha @@ -0,0 +1 @@ +329b5e616165fa5cf7414a75f5e544d598dc944f diff --git a/build/arduino-builder-macosx-1.0.0-beta23.tar.bz2.sha b/build/arduino-builder-macosx-1.0.0-beta23.tar.bz2.sha deleted file mode 100644 index 1bbe20b31..000000000 --- a/build/arduino-builder-macosx-1.0.0-beta23.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -725c998d08c73fb292fbd558106494acf7d1f9cf diff --git a/build/arduino-builder-macosx-1.0.0-beta24.tar.bz2.sha b/build/arduino-builder-macosx-1.0.0-beta24.tar.bz2.sha new file mode 100644 index 000000000..cddfb7a92 --- /dev/null +++ b/build/arduino-builder-macosx-1.0.0-beta24.tar.bz2.sha @@ -0,0 +1 @@ +d8f371c06abce0a177101a16ed90d8e3ee989d37 diff --git a/build/arduino-builder-windows-1.0.0-beta23.zip.sha b/build/arduino-builder-windows-1.0.0-beta23.zip.sha deleted file mode 100644 index 36f4da551..000000000 --- a/build/arduino-builder-windows-1.0.0-beta23.zip.sha +++ /dev/null @@ -1 +0,0 @@ -f54e4dc2d71a2f1e0141afee7f28f9d896c11593 diff --git a/build/arduino-builder-windows-1.0.0-beta24.zip.sha b/build/arduino-builder-windows-1.0.0-beta24.zip.sha new file mode 100644 index 000000000..3e063c9c2 --- /dev/null +++ b/build/arduino-builder-windows-1.0.0-beta24.zip.sha @@ -0,0 +1 @@ +5efc19b5245b994f71ceae41f9da4c4aab67bd16 diff --git a/build/build.xml b/build/build.xml index 217f4fa6e..78ba5029c 100644 --- a/build/build.xml +++ b/build/build.xml @@ -71,7 +71,7 @@ - + From 8bc21f7e36c740bb55b7d16cbeae46559b952854 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 3 Oct 2015 08:16:40 +0200 Subject: [PATCH 050/175] Small return value error check correction --- hardware/arduino/avr/cores/arduino/PluggableUSB.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 582379a84..7125775d8 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -31,7 +31,7 @@ int PluggableUSB_::getInterface(uint8_t* interfaceNum) PUSBListNode* node; for (node = rootNode; node; node = node->next) { int res = node->getInterface(interfaceNum); - if (res == -1) + if (res < 0) return -1; sent += res; } From 5b1b0330b212f772537582bd048109cde6e30777 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 7 Oct 2015 13:21:21 +0200 Subject: [PATCH 051/175] [PUSB] renamed some parameters --- hardware/arduino/avr/cores/arduino/PluggableUSB.cpp | 8 ++++---- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 10 +++++----- hardware/arduino/avr/libraries/HID/HID.cpp | 4 ++-- hardware/arduino/avr/libraries/HID/HID.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 7125775d8..95d40791c 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -25,12 +25,12 @@ extern uint8_t _initEndpoints[]; -int PluggableUSB_::getInterface(uint8_t* interfaceNum) +int PluggableUSB_::getInterface(uint8_t* interfaceCount) { int sent = 0; PUSBListNode* node; for (node = rootNode; node; node = node->next) { - int res = node->getInterface(interfaceNum); + int res = node->getInterface(interfaceCount); if (res < 0) return -1; sent += res; @@ -50,11 +50,11 @@ int PluggableUSB_::getDescriptor(int8_t type) return 0; } -bool PluggableUSB_::setup(USBSetup& setup, uint8_t j) +bool PluggableUSB_::setup(USBSetup& setup, uint8_t interfaceNum) { PUSBListNode* node; for (node = rootNode; node; node = node->next) { - if (node->setup(setup, j)) { + if (node->setup(setup, interfaceNum)) { return true; } } diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 40a898ec0..433e23efd 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -35,8 +35,8 @@ public: inline int8_t endpoint() const { return pluggedEndpoint; } protected: - virtual bool setup(USBSetup& setup, uint8_t i) = 0; - virtual int getInterface(uint8_t* interfaceNum) = 0; + virtual bool setup(USBSetup& setup, uint8_t interfaceNum) = 0; + virtual int getInterface(uint8_t* interfaceCount) = 0; virtual int getDescriptor(int8_t t) = 0; uint8_t pluggedInterface; @@ -55,9 +55,9 @@ class PluggableUSB_ { public: PluggableUSB_(); bool plug(PUSBListNode *node); - int getInterface(uint8_t* interfaceNum); - int getDescriptor(int8_t t); - bool setup(USBSetup& setup, uint8_t i); + int getInterface(uint8_t* interfaceCount); + int getDescriptor(int8_t type); + bool setup(USBSetup& setup, uint8_t interfaceNum); private: uint8_t lastIf; diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index ff8e67b2d..b6b9ceadc 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -27,9 +27,9 @@ HID_& HID() return obj; } -int HID_::getInterface(uint8_t* interfaceNum) +int HID_::getInterface(uint8_t* interfaceCount) { - *interfaceNum += 1; // uses 1 + *interfaceCount += 1; // uses 1 HIDDescriptor hidInterface = { D_INTERFACE(interface(), 1, 3, 0, 0), D_HIDREPORT(descriptorSize), diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index a7f5c682f..e54e45e19 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -79,7 +79,7 @@ public: protected: // Implementation of the PUSBListNode - int getInterface(uint8_t* interfaceNum); + int getInterface(uint8_t* interfaceCount); int getDescriptor(int8_t type); bool setup(USBSetup& setup, uint8_t interfaceNum); From 9af0eee33871228151e0369074c38d556a282f8c Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Wed, 7 Oct 2015 15:16:05 +0200 Subject: [PATCH 052/175] Fail to save sketch if user attempts to save it with the same name of one of its tabs, excluding the first. Fixes #3914 --- app/src/processing/app/Sketch.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 9c6a93c59..d317b4dfe 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -652,14 +652,13 @@ public class Sketch { // make sure there doesn't exist a .cpp file with that name already // but ignore this situation for the first tab, since it's probably being // resaved (with the same name) to another location/folder. - for (SketchCode code : data.getCodes()) { - if (newName.equalsIgnoreCase(code.getPrettyName()) && code.isExtension("cpp")) { + for (int i = 0; i < data.getCodeCount(); i++) { + SketchCode code = data.getCode(i); + if (newName.equalsIgnoreCase(code.getPrettyName())) { Base.showMessage(tr("Error"), - I18n.format( - tr("You can't save the sketch as \"{0}\"\n" + - "because the sketch already has a .cpp file with that name."), - newName - )); + I18n.format(tr("You can't save the sketch as \"{0}\"\n" + + "because the sketch already has a file with that name."), newName + )); return false; } } From 417857ee4558c528b123617d2ef148b3b82bca45 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Wed, 7 Oct 2015 15:16:53 +0200 Subject: [PATCH 053/175] Fixed a crashed when user attempted to delete a tab of a not yet compiled sketch. Fixes #3913 --- .../src/processing/app/SketchCode.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/arduino-core/src/processing/app/SketchCode.java b/arduino-core/src/processing/app/SketchCode.java index af4db284c..0e3f26560 100644 --- a/arduino-core/src/processing/app/SketchCode.java +++ b/arduino-core/src/processing/app/SketchCode.java @@ -26,8 +26,13 @@ import processing.app.helpers.FileUtils; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static processing.app.I18n.tr; @@ -91,35 +96,39 @@ public class SketchCode { } - protected boolean deleteFile(File tempBuildFolder) { + protected boolean deleteFile(File tempBuildFolder) throws IOException { if (!file.delete()) { return false; } - if (!deleteCompiledFilesFrom(tempBuildFolder)) { - return false; - } + List tempBuildFolders = Stream.of(tempBuildFolder.toPath(), Paths.get(tempBuildFolder.getAbsolutePath(), "sketch")) + .filter(path -> Files.exists(path)) + .collect(Collectors.toList()); - if (!deleteCompiledFilesFrom(new File(tempBuildFolder, "sketch"))) { - return false; + for (Path folder : tempBuildFolders) { + if (!deleteCompiledFilesFrom(folder)) { + return false; + } } return true; } - private boolean deleteCompiledFilesFrom(File tempBuildFolder) { - File[] compiledFiles = tempBuildFolder.listFiles(pathname -> { - return pathname.getName().startsWith(getFileName()); - }); - for (File compiledFile : compiledFiles) { - if (!compiledFile.delete()) { + private boolean deleteCompiledFilesFrom(Path tempBuildFolder) throws IOException { + List compiledFiles = Files.list(tempBuildFolder) + .filter(pathname -> pathname.getFileName().toString().startsWith(getFileName())) + .collect(Collectors.toList()); + + for (Path compiledFile : compiledFiles) { + try { + Files.delete(compiledFile); + } catch (IOException e) { return false; } } return true; } - protected boolean renameTo(File what) { boolean success = file.renameTo(what); if (success) { From 5c7b8e6587156697efdedc2b6b12c2a9c29d0b8f Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Wed, 7 Oct 2015 15:32:19 +0200 Subject: [PATCH 054/175] Don't stop downloading package*index.json files if ONE fails for whatever reason. Fixes #3906 --- .../contributions/packages/ContributionInstaller.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java index 24712c896..194029f49 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java @@ -282,7 +282,11 @@ public class ContributionInstaller { } for (String packageIndexURL : packageIndexURLs) { - downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, packageIndexURL, progressListener); + try { + downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, packageIndexURL, progressListener); + } catch (Exception e) { + System.err.println(e.getMessage()); + } } progress.stepDone(); From 688c406cb9b5653208576a866e7e7068f8d373c5 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Wed, 7 Oct 2015 15:40:34 +0200 Subject: [PATCH 055/175] Checking every candidate path when exporting, instead of assuming one is good if the other is not. Fixes #3905 --- arduino-core/src/cc/arduino/Compiler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java index 06c5be7d7..0280a8a2d 100644 --- a/arduino-core/src/cc/arduino/Compiler.java +++ b/arduino-core/src/cc/arduino/Compiler.java @@ -361,8 +361,10 @@ public class Compiler implements MessageConsumer { Path compiledSketchPathInBuildPath = Paths.get(prefs.get("build.path"), compiledSketch); if (Files.exists(compiledSketchPathInSubfolder)) { compiledSketchPath = compiledSketchPathInSubfolder; - } else { + } else if (Files.exists(compiledSketchPathInBuildPath)) { compiledSketchPath = compiledSketchPathInBuildPath; + } else { + return; } Path copyOfCompiledSketchFilePath = Paths.get(this.sketch.getFolder().getAbsolutePath(), copyOfCompiledSketch); From cc4874bb8de792f24ea35f600da1112c62895886 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 7 Oct 2015 15:51:27 +0200 Subject: [PATCH 056/175] update revisions.txt --- build/shared/revisions.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index e94b71d47..4411177a2 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -29,7 +29,8 @@ ARDUINO 1.6.6 * Bridge: YunClient.stop() now empties all buffers. Thanks @RobAtticus [core] -AVR: fixed wrong turnOffPWM() for TIMER0B. Thanks @gonzoveliki +* AVR: fixed wrong turnOffPWM() for TIMER0B. Thanks @gonzoveliki +* ArduinoISP is now compatible with every architecture (not only AVR) and is much more stable. Thanks @PeterVH ARDUINO 1.6.5-r5 - 2015.08.28 From ef15667ae844456aa8232306d59d67d3742f14ee Mon Sep 17 00:00:00 2001 From: chaveiro Date: Fri, 18 Sep 2015 00:50:17 +0100 Subject: [PATCH 057/175] Expose optional DHCP timout parameters to Ethernet:begin() A no brainer update. Expose optional timeout parameter values of dhcp for user to adjust on their code. Currently if dhcp server is not available, code will block inside DhcpClass::request_DHCP_lease() for 60s. Having this parameters exposed user can specify their timeout requirements without changing the lib code. Change is backward compatible as parameters are optional and defaults to existing values. --- libraries/Ethernet/src/Ethernet.cpp | 4 ++-- libraries/Ethernet/src/Ethernet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 3eea69a2a..54cf8d64c 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -8,7 +8,7 @@ uint8_t EthernetClass::_state[MAX_SOCK_NUM] = { uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 }; -int EthernetClass::begin(uint8_t *mac_address) +int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned long responseTimeout) { static DhcpClass s_dhcp; _dhcp = &s_dhcp; @@ -22,7 +22,7 @@ int EthernetClass::begin(uint8_t *mac_address) SPI.endTransaction(); // Now try to get our config info from a DHCP server - int ret = _dhcp->beginWithDHCP(mac_address); + int ret = _dhcp->beginWithDHCP(mac_address, timeout, responseTimeout); if(ret == 1) { // We've successfully found a DHCP server and got our configuration info, so set things diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index 2a07ff35f..083df4427 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -20,7 +20,7 @@ public: // Initialise the Ethernet shield to use the provided MAC address and gain the rest of the // configuration through DHCP. // Returns 0 if the DHCP configuration failed, and 1 if it succeeded - int begin(uint8_t *mac_address); + int begin(uint8_t *mac_address, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); void begin(uint8_t *mac_address, IPAddress local_ip); void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server); void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway); From 6151972b7438a30c015e91541cb8b9e4778b49c8 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Wed, 7 Oct 2015 18:45:10 +0200 Subject: [PATCH 058/175] [PUSB] Changed Interface + Endpoint to unsigned variables The iterations in the for loop also use unsigned and the setup struct etc as well. There was no change in HID required since we just init the inherited variables via constructor and the type is never mentioned. --- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 433e23efd..b7c52d610 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -27,12 +27,12 @@ class PUSBListNode { public: - PUSBListNode(int8_t numEps, int8_t numIfs, uint8_t *epType) : + PUSBListNode(uint8_t numEps, uint8_t numIfs, uint8_t *epType) : numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) { } inline uint8_t interface() const { return pluggedInterface; } - inline int8_t endpoint() const { return pluggedEndpoint; } + inline uint8_t endpoint() const { return pluggedEndpoint; } protected: virtual bool setup(USBSetup& setup, uint8_t interfaceNum) = 0; @@ -40,10 +40,10 @@ protected: virtual int getDescriptor(int8_t t) = 0; uint8_t pluggedInterface; - int8_t pluggedEndpoint; + uint8_t pluggedEndpoint; - const int8_t numEndpoints; - const int8_t numInterfaces; + const uint8_t numEndpoints; + const uint8_t numInterfaces; const uint8_t *endpointType; PUSBListNode *next = NULL; From 0f9f63f2a5c25124b4f5bf20762382f4b0482216 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Wed, 7 Oct 2015 19:02:40 +0200 Subject: [PATCH 059/175] [PUSB] Made getDescriptor() and setup() more flexible Alternatively we can only pass the wIndex to getDescriptor but I suggest to just pass the pointer aka reference of the whole setup. In guess (havent tested this) that this results in more or less the code size but its a) idential with the other functions and b) we late have more flexibility here. The Code got a quick SerialKeyboard.ino test --- .../avr/cores/arduino/PluggableUSB.cpp | 8 ++--- .../arduino/avr/cores/arduino/PluggableUSB.h | 8 ++--- .../arduino/avr/cores/arduino/USBCore.cpp | 4 +-- hardware/arduino/avr/libraries/HID/HID.cpp | 29 +++++++++---------- hardware/arduino/avr/libraries/HID/HID.h | 4 +-- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 95d40791c..21dc7a89d 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -38,11 +38,11 @@ int PluggableUSB_::getInterface(uint8_t* interfaceCount) return sent; } -int PluggableUSB_::getDescriptor(int8_t type) +int PluggableUSB_::getDescriptor(USBSetup& setup) { PUSBListNode* node; for (node = rootNode; node; node = node->next) { - int ret = node->getDescriptor(type); + int ret = node->getDescriptor(setup); // ret!=0 -> request has been processed if (ret) return ret; @@ -50,11 +50,11 @@ int PluggableUSB_::getDescriptor(int8_t type) return 0; } -bool PluggableUSB_::setup(USBSetup& setup, uint8_t interfaceNum) +bool PluggableUSB_::setup(USBSetup& setup) { PUSBListNode* node; for (node = rootNode; node; node = node->next) { - if (node->setup(setup, interfaceNum)) { + if (node->setup(setup)) { return true; } } diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index b7c52d610..d12c4c432 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -35,9 +35,9 @@ public: inline uint8_t endpoint() const { return pluggedEndpoint; } protected: - virtual bool setup(USBSetup& setup, uint8_t interfaceNum) = 0; + virtual bool setup(USBSetup& setup) = 0; virtual int getInterface(uint8_t* interfaceCount) = 0; - virtual int getDescriptor(int8_t t) = 0; + virtual int getDescriptor(USBSetup& setup) = 0; uint8_t pluggedInterface; uint8_t pluggedEndpoint; @@ -56,8 +56,8 @@ public: PluggableUSB_(); bool plug(PUSBListNode *node); int getInterface(uint8_t* interfaceCount); - int getDescriptor(int8_t type); - bool setup(USBSetup& setup, uint8_t interfaceNum); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); private: uint8_t lastIf; diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index 5db9f521a..f67bfeabc 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -362,7 +362,7 @@ bool ClassInterfaceRequest(USBSetup& setup) return CDC_Setup(setup); #ifdef PLUGGABLE_USB_ENABLED - return PluggableUSB().setup(setup, i); + return PluggableUSB().setup(setup); #endif return false; } @@ -476,7 +476,7 @@ bool SendDescriptor(USBSetup& setup) InitControl(setup.wLength); #ifdef PLUGGABLE_USB_ENABLED - ret = PluggableUSB().getDescriptor(t); + ret = PluggableUSB().getDescriptor(setup); if (ret != 0) { return (ret > 0 ? true : false); } diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index b6b9ceadc..500eec9da 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -38,22 +38,21 @@ int HID_::getInterface(uint8_t* interfaceCount) return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int HID_::getDescriptor(int8_t type) +int HID_::getDescriptor(USBSetup& setup) { - if (HID_REPORT_DESCRIPTOR_TYPE == type) { - int total = 0; - HIDDescriptorListNode* node; - for (node = rootNode; node; node = node->next) { - int res = USB_SendControl(TRANSFER_PGM, node->data, node->length); - if (res == -1) - return -1; - total += res; - } - return total; + if (interface() != setup.wIndex) { + return 0; } - // Ignored - return 0; + int total = 0; + HIDDescriptorListNode* node; + for (node = rootNode; node; node = node->next) { + int res = USB_SendControl(TRANSFER_PGM, node->data, node->length); + if (res == -1) + return -1; + total += res; + } + return total; } void HID_::AppendDescriptor(HIDDescriptorListNode *node) @@ -76,9 +75,9 @@ void HID_::SendReport(uint8_t id, const void* data, int len) USB_Send(endpoint() | TRANSFER_RELEASE, data, len); } -bool HID_::setup(USBSetup& setup, uint8_t interfaceNum) +bool HID_::setup(USBSetup& setup) { - if (interface() != interfaceNum) { + if (interface() != setup.wIndex) { return false; } diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index e54e45e19..b282c20d5 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -80,8 +80,8 @@ public: protected: // Implementation of the PUSBListNode int getInterface(uint8_t* interfaceCount); - int getDescriptor(int8_t type); - bool setup(USBSetup& setup, uint8_t interfaceNum); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); private: uint8_t epType[1]; From c8867462a8a8d1d0df921b21642c07483ec8118a Mon Sep 17 00:00:00 2001 From: NicoHood Date: Wed, 7 Oct 2015 19:11:23 +0200 Subject: [PATCH 060/175] [PHID] Added SetReport function This commit just shows other that this option is available and not implemented. You may use this to determine the Led Lights state of a keyboard or transmit data via RAWHID from the PC. Quick usage guide: int length = ((setup.wValueH << 8) | setup.wLength); USB_RecvControl((uint8_t* data, USB_EP_SIZE); // Needs to be splitted into USB_EP_SIZE packets, not shown here. See HID Project. --- hardware/arduino/avr/libraries/HID/HID.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 500eec9da..fe88ecd34 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -106,6 +106,9 @@ bool HID_::setup(USBSetup& setup) idle = setup.wValueL; return true; } + if (request == HID_SET_REPORT) + { + } } return false; From 05477fc85dec2a1a150d05d696bc8a8c5f5f0f1c Mon Sep 17 00:00:00 2001 From: NicoHood Date: Wed, 7 Oct 2015 20:39:50 +0200 Subject: [PATCH 061/175] [PUSB] Removed unnecessary endpoint and interface function --- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 3 --- hardware/arduino/avr/libraries/HID/HID.cpp | 12 ++++++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index d12c4c432..1f3057ad2 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -31,9 +31,6 @@ public: numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) { } - inline uint8_t interface() const { return pluggedInterface; } - inline uint8_t endpoint() const { return pluggedEndpoint; } - protected: virtual bool setup(USBSetup& setup) = 0; virtual int getInterface(uint8_t* interfaceCount) = 0; diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index fe88ecd34..762d17080 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -31,16 +31,16 @@ int HID_::getInterface(uint8_t* interfaceCount) { *interfaceCount += 1; // uses 1 HIDDescriptor hidInterface = { - D_INTERFACE(interface(), 1, 3, 0, 0), + D_INTERFACE(pluggedInterface, 1, 3, 0, 0), D_HIDREPORT(descriptorSize), - D_ENDPOINT(USB_ENDPOINT_IN(endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) }; return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } int HID_::getDescriptor(USBSetup& setup) { - if (interface() != setup.wIndex) { + if (pluggedInterface != setup.wIndex) { return 0; } @@ -71,13 +71,13 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node) void HID_::SendReport(uint8_t id, const void* data, int len) { - USB_Send(endpoint(), &id, 1); - USB_Send(endpoint() | TRANSFER_RELEASE, data, len); + USB_Send(pluggedEndpoint, &id, 1); + USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len); } bool HID_::setup(USBSetup& setup) { - if (interface() != setup.wIndex) { + if (pluggedInterface != setup.wIndex) { return false; } From c280955bb1f498555adcab2cc003d172f9108540 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Thu, 8 Oct 2015 10:56:36 +0200 Subject: [PATCH 062/175] Updating arduino-builder to 1.0.0-beta25 --- build/arduino-builder-linux32-1.0.0-beta24.tar.bz2.sha | 1 - build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha | 1 + build/arduino-builder-linux64-1.0.0-beta24.tar.bz2.sha | 1 - build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha | 1 + build/arduino-builder-macosx-1.0.0-beta24.tar.bz2.sha | 1 - build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha | 1 + build/arduino-builder-windows-1.0.0-beta24.zip.sha | 1 - build/arduino-builder-windows-1.0.0-beta25.zip.sha | 1 + build/build.xml | 2 +- 9 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 build/arduino-builder-linux32-1.0.0-beta24.tar.bz2.sha create mode 100644 build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha delete mode 100644 build/arduino-builder-linux64-1.0.0-beta24.tar.bz2.sha create mode 100644 build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha delete mode 100644 build/arduino-builder-macosx-1.0.0-beta24.tar.bz2.sha create mode 100644 build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha delete mode 100644 build/arduino-builder-windows-1.0.0-beta24.zip.sha create mode 100644 build/arduino-builder-windows-1.0.0-beta25.zip.sha diff --git a/build/arduino-builder-linux32-1.0.0-beta24.tar.bz2.sha b/build/arduino-builder-linux32-1.0.0-beta24.tar.bz2.sha deleted file mode 100644 index 5c09eaad1..000000000 --- a/build/arduino-builder-linux32-1.0.0-beta24.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -d8c3e22428fa0953038f2ac21cd7be6d614fee30 diff --git a/build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha b/build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha new file mode 100644 index 000000000..09287d17e --- /dev/null +++ b/build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha @@ -0,0 +1 @@ +b584915e9171eda78b35d1bcb71a1b07728834ff diff --git a/build/arduino-builder-linux64-1.0.0-beta24.tar.bz2.sha b/build/arduino-builder-linux64-1.0.0-beta24.tar.bz2.sha deleted file mode 100644 index 317154324..000000000 --- a/build/arduino-builder-linux64-1.0.0-beta24.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -329b5e616165fa5cf7414a75f5e544d598dc944f diff --git a/build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha b/build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha new file mode 100644 index 000000000..0f0100a9f --- /dev/null +++ b/build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha @@ -0,0 +1 @@ +62e87b8ce6a8004a9c983299f5cb027cfb055eab diff --git a/build/arduino-builder-macosx-1.0.0-beta24.tar.bz2.sha b/build/arduino-builder-macosx-1.0.0-beta24.tar.bz2.sha deleted file mode 100644 index cddfb7a92..000000000 --- a/build/arduino-builder-macosx-1.0.0-beta24.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -d8f371c06abce0a177101a16ed90d8e3ee989d37 diff --git a/build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha b/build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha new file mode 100644 index 000000000..b59edcd33 --- /dev/null +++ b/build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha @@ -0,0 +1 @@ +ee8ca09f79b94c2276fc12ed7f4e69ba185b5e81 diff --git a/build/arduino-builder-windows-1.0.0-beta24.zip.sha b/build/arduino-builder-windows-1.0.0-beta24.zip.sha deleted file mode 100644 index 3e063c9c2..000000000 --- a/build/arduino-builder-windows-1.0.0-beta24.zip.sha +++ /dev/null @@ -1 +0,0 @@ -5efc19b5245b994f71ceae41f9da4c4aab67bd16 diff --git a/build/arduino-builder-windows-1.0.0-beta25.zip.sha b/build/arduino-builder-windows-1.0.0-beta25.zip.sha new file mode 100644 index 000000000..77c562d5f --- /dev/null +++ b/build/arduino-builder-windows-1.0.0-beta25.zip.sha @@ -0,0 +1 @@ +93aaba59059adbc1636206b90f2ee64b90cc678a diff --git a/build/build.xml b/build/build.xml index 78ba5029c..0ffcfaeaf 100644 --- a/build/build.xml +++ b/build/build.xml @@ -71,7 +71,7 @@ - + From 7217f85b62a85574ad7b5f452aca74721f7508f4 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Thu, 8 Oct 2015 15:26:40 +0200 Subject: [PATCH 063/175] Updating arduino-builder to 1.0.0 --- build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha | 1 - build/arduino-builder-linux32-1.0.0.tar.bz2.sha | 1 + build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha | 1 - build/arduino-builder-linux64-1.0.0.tar.bz2.sha | 1 + build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha | 1 - build/arduino-builder-macosx-1.0.0.tar.bz2.sha | 1 + build/arduino-builder-windows-1.0.0-beta25.zip.sha | 1 - build/arduino-builder-windows-1.0.0.zip.sha | 1 + build/build.xml | 2 +- 9 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha create mode 100644 build/arduino-builder-linux32-1.0.0.tar.bz2.sha delete mode 100644 build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha create mode 100644 build/arduino-builder-linux64-1.0.0.tar.bz2.sha delete mode 100644 build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha create mode 100644 build/arduino-builder-macosx-1.0.0.tar.bz2.sha delete mode 100644 build/arduino-builder-windows-1.0.0-beta25.zip.sha create mode 100644 build/arduino-builder-windows-1.0.0.zip.sha diff --git a/build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha b/build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha deleted file mode 100644 index 09287d17e..000000000 --- a/build/arduino-builder-linux32-1.0.0-beta25.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -b584915e9171eda78b35d1bcb71a1b07728834ff diff --git a/build/arduino-builder-linux32-1.0.0.tar.bz2.sha b/build/arduino-builder-linux32-1.0.0.tar.bz2.sha new file mode 100644 index 000000000..dab74ab8b --- /dev/null +++ b/build/arduino-builder-linux32-1.0.0.tar.bz2.sha @@ -0,0 +1 @@ +09ad1e3b95f54e6769255a3d54bf5de653c15003 diff --git a/build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha b/build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha deleted file mode 100644 index 0f0100a9f..000000000 --- a/build/arduino-builder-linux64-1.0.0-beta25.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -62e87b8ce6a8004a9c983299f5cb027cfb055eab diff --git a/build/arduino-builder-linux64-1.0.0.tar.bz2.sha b/build/arduino-builder-linux64-1.0.0.tar.bz2.sha new file mode 100644 index 000000000..2a4625ca7 --- /dev/null +++ b/build/arduino-builder-linux64-1.0.0.tar.bz2.sha @@ -0,0 +1 @@ +9a83ae2a7a6583d5e325796b6a1ba52f60a1b092 diff --git a/build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha b/build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha deleted file mode 100644 index b59edcd33..000000000 --- a/build/arduino-builder-macosx-1.0.0-beta25.tar.bz2.sha +++ /dev/null @@ -1 +0,0 @@ -ee8ca09f79b94c2276fc12ed7f4e69ba185b5e81 diff --git a/build/arduino-builder-macosx-1.0.0.tar.bz2.sha b/build/arduino-builder-macosx-1.0.0.tar.bz2.sha new file mode 100644 index 000000000..1abd0fa8f --- /dev/null +++ b/build/arduino-builder-macosx-1.0.0.tar.bz2.sha @@ -0,0 +1 @@ +36cd700b0c7250613254939b0315463cdb1ceb36 diff --git a/build/arduino-builder-windows-1.0.0-beta25.zip.sha b/build/arduino-builder-windows-1.0.0-beta25.zip.sha deleted file mode 100644 index 77c562d5f..000000000 --- a/build/arduino-builder-windows-1.0.0-beta25.zip.sha +++ /dev/null @@ -1 +0,0 @@ -93aaba59059adbc1636206b90f2ee64b90cc678a diff --git a/build/arduino-builder-windows-1.0.0.zip.sha b/build/arduino-builder-windows-1.0.0.zip.sha new file mode 100644 index 000000000..6ad6e199f --- /dev/null +++ b/build/arduino-builder-windows-1.0.0.zip.sha @@ -0,0 +1 @@ +721aa1e2bbd79615904d40d95610f25cbe66c424 diff --git a/build/build.xml b/build/build.xml index 0ffcfaeaf..8359e30b4 100644 --- a/build/build.xml +++ b/build/build.xml @@ -71,7 +71,7 @@ - + From fb4f5066bfc74302fdd0aa58296f0bd923ce5d93 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 8 Oct 2015 16:38:57 +0200 Subject: [PATCH 064/175] [HID] Improved checks in getDescriptor() method --- hardware/arduino/avr/cores/arduino/USBCore.h | 5 +++-- hardware/arduino/avr/libraries/HID/HID.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBCore.h b/hardware/arduino/avr/cores/arduino/USBCore.h index 806fa6028..530abec72 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.h +++ b/hardware/arduino/avr/cores/arduino/USBCore.h @@ -49,8 +49,9 @@ #define REQUEST_OTHER 0x03 #define REQUEST_RECIPIENT 0x03 -#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE) -#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE) +#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_STANDARD + REQUEST_INTERFACE) // Class requests diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 762d17080..bff00e313 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -40,9 +40,12 @@ int HID_::getInterface(uint8_t* interfaceCount) int HID_::getDescriptor(USBSetup& setup) { - if (pluggedInterface != setup.wIndex) { - return 0; - } + // Check if this is a HID Class Descriptor request + if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; } + if (setup.wValueH != HID_REPORT_DESCRIPTOR_TYPE) { return 0; } + + // In a HID Class Descriptor wIndex cointains the interface number + if (setup.wIndex != pluggedInterface) { return 0; } int total = 0; HIDDescriptorListNode* node; From 79f5715c21a81743443269a855979a64188c93df Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 8 Oct 2015 17:24:09 +0200 Subject: [PATCH 065/175] Remove unnecessary include Its included by HID.h anyways. --- hardware/arduino/avr/libraries/HID/HID.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index bff00e313..972053d05 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -16,7 +16,6 @@ SOFTWARE. */ -#include "PluggableUSB.h" #include "HID.h" #if defined(USBCON) From 2cc3bb605b85401d6bb963ede181a9b586f10e68 Mon Sep 17 00:00:00 2001 From: Nico Date: Fri, 9 Oct 2015 22:10:45 +0200 Subject: [PATCH 066/175] [PUSB] Minor Style change --- hardware/arduino/avr/cores/arduino/USBCore.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBCore.h b/hardware/arduino/avr/cores/arduino/USBCore.h index 530abec72..4e08d711b 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.h +++ b/hardware/arduino/avr/cores/arduino/USBCore.h @@ -49,9 +49,9 @@ #define REQUEST_OTHER 0x03 #define REQUEST_RECIPIENT 0x03 -#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE) -#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE) -#define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_STANDARD + REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_CLASS | REQUEST_INTERFACE) +#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE | REQUEST_CLASS | REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_STANDARD | REQUEST_INTERFACE) // Class requests From 14ddc8b0bf24496788a845c66a0ef87b4a63c4f9 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 10 Oct 2015 12:49:45 +0200 Subject: [PATCH 067/175] Added official HID definitions Since the HID library adds some general HID definitions and structs, it is very useful to also include this in a custom library. If you dupe the information you have problems of redeclaration. Having those defintions inside the official HID library is essential for a good working additional HID API. --- hardware/arduino/avr/libraries/HID/HID.cpp | 2 +- hardware/arduino/avr/libraries/HID/HID.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 972053d05..841de4afc 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -30,7 +30,7 @@ int HID_::getInterface(uint8_t* interfaceCount) { *interfaceCount += 1; // uses 1 HIDDescriptor hidInterface = { - D_INTERFACE(pluggedInterface, 1, 3, 0, 0), + D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), D_HIDREPORT(descriptorSize), D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) }; diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index b282c20d5..77a9f24c5 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -40,6 +40,20 @@ #define HID_REPORT_DESCRIPTOR_TYPE 0x22 #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 +// HID subclass HID1.11 Page 8 4.2 Subclass +#define HID_SUBCLASS_NONE 0 +#define HID_SUBCLASS_BOOT_INTERFACE 1 + +// HID Keyboard/Mouse bios compatible protocols HID1.11 Page 9 4.3 Protocols +#define HID_PROTOCOL_NONE 0 +#define HID_PROTOCOL_KEYBOARD 1 +#define HID_PROTOCOL_MOUSE 2 + +// Normal or bios protocol (Keyboard/Mouse) HID1.11 Page 54 7.2.5 Get_Protocol Request +// "protocol" variable is used for this purpose. +#define HID_BOOT_PROTOCOL 0 +#define HID_REPORT_PROTOCOL 1 + typedef struct { uint8_t len; // 9 From 5e813b314bac1bdcaf583a90899bcc0351cfb4f7 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 10 Oct 2015 13:11:31 +0200 Subject: [PATCH 068/175] [PHID] Added some hints for further optional implementations --- hardware/arduino/avr/libraries/HID/HID.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 841de4afc..8da7d2c96 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -101,6 +101,8 @@ bool HID_::setup(USBSetup& setup) if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) { if (request == HID_SET_PROTOCOL) { + // The USB Host tells us if we are in boot or report mode. + // This only works with a real boot compatible device. protocol = setup.wValueL; return true; } @@ -110,6 +112,13 @@ bool HID_::setup(USBSetup& setup) } if (request == HID_SET_REPORT) { + //uint8_t reportID = setup.wValueL; + //uint16_t length = setup.wLength; + //uint8_t data[length]; + // Make sure to not read more data than USB_EP_SIZE. + // You can read multiple times through a loop. + // The first byte (may!) contain the reportID on a multreport. + //USB_RecvControl(data, length); } } From e69021550eb4f88c0027d5ec64a39a2512eadc37 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sun, 11 Oct 2015 14:39:36 +0200 Subject: [PATCH 069/175] [PHID] Added missing GET_IDLE Request --- hardware/arduino/avr/libraries/HID/HID.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 8da7d2c96..cce3834da 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -96,6 +96,9 @@ bool HID_::setup(USBSetup& setup) // TODO: Send8(protocol); return true; } + if (request == HID_GET_IDLE) { + // TODO: Send8(idle); + } } if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) From 80b79002fd8bb00973e67d97d37f1ea1e62eba0d Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 12 Oct 2015 11:59:08 +0200 Subject: [PATCH 070/175] [HID] made HIDDescriptorListNode.length constant --- hardware/arduino/avr/libraries/HID/HID.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index 77a9f24c5..c0c2b596f 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -80,7 +80,7 @@ public: HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { } const void* data; - uint16_t length; + const uint16_t length; }; class HID_ : public PUSBListNode From 11440d3fd7f33b21ac3372d52f9e621aafbb40f3 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 12 Oct 2015 12:14:07 +0200 Subject: [PATCH 071/175] [PUSB] Renamed PUSBListNode to PluggableUSBModule --- hardware/arduino/avr/cores/arduino/PluggableUSB.cpp | 10 +++++----- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 10 +++++----- hardware/arduino/avr/libraries/HID/HID.cpp | 2 +- hardware/arduino/avr/libraries/HID/HID.h | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 21dc7a89d..7a6351d8e 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -28,7 +28,7 @@ extern uint8_t _initEndpoints[]; int PluggableUSB_::getInterface(uint8_t* interfaceCount) { int sent = 0; - PUSBListNode* node; + PluggableUSBModule* node; for (node = rootNode; node; node = node->next) { int res = node->getInterface(interfaceCount); if (res < 0) @@ -40,7 +40,7 @@ int PluggableUSB_::getInterface(uint8_t* interfaceCount) int PluggableUSB_::getDescriptor(USBSetup& setup) { - PUSBListNode* node; + PluggableUSBModule* node; for (node = rootNode; node; node = node->next) { int ret = node->getDescriptor(setup); // ret!=0 -> request has been processed @@ -52,7 +52,7 @@ int PluggableUSB_::getDescriptor(USBSetup& setup) bool PluggableUSB_::setup(USBSetup& setup) { - PUSBListNode* node; + PluggableUSBModule* node; for (node = rootNode; node; node = node->next) { if (node->setup(setup)) { return true; @@ -61,7 +61,7 @@ bool PluggableUSB_::setup(USBSetup& setup) return false; } -bool PluggableUSB_::plug(PUSBListNode *node) +bool PluggableUSB_::plug(PluggableUSBModule *node) { if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) { return false; @@ -70,7 +70,7 @@ bool PluggableUSB_::plug(PUSBListNode *node) if (!rootNode) { rootNode = node; } else { - PUSBListNode *current = rootNode; + PluggableUSBModule *current = rootNode; while (current->next) { current = current->next; } diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 1f3057ad2..3df9bfff5 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -25,9 +25,9 @@ #if defined(USBCON) -class PUSBListNode { +class PluggableUSBModule { public: - PUSBListNode(uint8_t numEps, uint8_t numIfs, uint8_t *epType) : + PluggableUSBModule(uint8_t numEps, uint8_t numIfs, uint8_t *epType) : numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) { } @@ -43,7 +43,7 @@ protected: const uint8_t numInterfaces; const uint8_t *endpointType; - PUSBListNode *next = NULL; + PluggableUSBModule *next = NULL; friend class PluggableUSB_; }; @@ -51,7 +51,7 @@ protected: class PluggableUSB_ { public: PluggableUSB_(); - bool plug(PUSBListNode *node); + bool plug(PluggableUSBModule *node); int getInterface(uint8_t* interfaceCount); int getDescriptor(USBSetup& setup); bool setup(USBSetup& setup); @@ -59,7 +59,7 @@ public: private: uint8_t lastIf; uint8_t lastEp; - PUSBListNode* rootNode; + PluggableUSBModule* rootNode; }; // Replacement for global singleton. diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index cce3834da..7b17a6600 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -128,7 +128,7 @@ bool HID_::setup(USBSetup& setup) return false; } -HID_::HID_(void) : PUSBListNode(1, 1, epType), +HID_::HID_(void) : PluggableUSBModule(1, 1, epType), rootNode(NULL), descriptorSize(0), protocol(1), idle(1) { diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index c0c2b596f..638fb0396 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -83,7 +83,7 @@ public: const uint16_t length; }; -class HID_ : public PUSBListNode +class HID_ : public PluggableUSBModule { public: HID_(void); @@ -92,7 +92,7 @@ public: void AppendDescriptor(HIDDescriptorListNode* node); protected: - // Implementation of the PUSBListNode + // Implementation of the PluggableUSBModule int getInterface(uint8_t* interfaceCount); int getDescriptor(USBSetup& setup); bool setup(USBSetup& setup); From a151349a015dac3faa3ccea592297ac294ff2b04 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 12 Oct 2015 12:17:42 +0200 Subject: [PATCH 072/175] [HID] renamed HIDDescriptorListNode to HIDSubDescriptor --- hardware/arduino/avr/libraries/HID/HID.cpp | 6 +++--- hardware/arduino/avr/libraries/HID/HID.h | 10 +++++----- libraries/Keyboard/src/Keyboard.cpp | 2 +- libraries/Mouse/src/Mouse.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 7b17a6600..411529ecf 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -47,7 +47,7 @@ int HID_::getDescriptor(USBSetup& setup) if (setup.wIndex != pluggedInterface) { return 0; } int total = 0; - HIDDescriptorListNode* node; + HIDSubDescriptor* node; for (node = rootNode; node; node = node->next) { int res = USB_SendControl(TRANSFER_PGM, node->data, node->length); if (res == -1) @@ -57,12 +57,12 @@ int HID_::getDescriptor(USBSetup& setup) return total; } -void HID_::AppendDescriptor(HIDDescriptorListNode *node) +void HID_::AppendDescriptor(HIDSubDescriptor *node) { if (!rootNode) { rootNode = node; } else { - HIDDescriptorListNode *current = rootNode; + HIDSubDescriptor *current = rootNode; while (current->next) { current = current->next; } diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index 638fb0396..ba08da7be 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -74,10 +74,10 @@ typedef struct EndpointDescriptor in; } HIDDescriptor; -class HIDDescriptorListNode { +class HIDSubDescriptor { public: - HIDDescriptorListNode *next = NULL; - HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { } + HIDSubDescriptor *next = NULL; + HIDSubDescriptor(const void *d, const uint16_t l) : data(d), length(l) { } const void* data; const uint16_t length; @@ -89,7 +89,7 @@ public: HID_(void); int begin(void); void SendReport(uint8_t id, const void* data, int len); - void AppendDescriptor(HIDDescriptorListNode* node); + void AppendDescriptor(HIDSubDescriptor* node); protected: // Implementation of the PluggableUSBModule @@ -100,7 +100,7 @@ protected: private: uint8_t epType[1]; - HIDDescriptorListNode* rootNode; + HIDSubDescriptor* rootNode; uint16_t descriptorSize; uint8_t protocol; diff --git a/libraries/Keyboard/src/Keyboard.cpp b/libraries/Keyboard/src/Keyboard.cpp index d899e92e4..48f085219 100644 --- a/libraries/Keyboard/src/Keyboard.cpp +++ b/libraries/Keyboard/src/Keyboard.cpp @@ -62,7 +62,7 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = { Keyboard_::Keyboard_(void) { - static HIDDescriptorListNode node(_hidReportDescriptor, sizeof(_hidReportDescriptor)); + static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor)); HID().AppendDescriptor(&node); } diff --git a/libraries/Mouse/src/Mouse.cpp b/libraries/Mouse/src/Mouse.cpp index 64d02bc86..b2a2cd7b8 100644 --- a/libraries/Mouse/src/Mouse.cpp +++ b/libraries/Mouse/src/Mouse.cpp @@ -62,7 +62,7 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = { Mouse_::Mouse_(void) : _buttons(0) { - static HIDDescriptorListNode node(_hidReportDescriptor, sizeof(_hidReportDescriptor)); + static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor)); HID().AppendDescriptor(&node); } From b4541209cb447bb89feb62018e2043285a5633d0 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 12 Oct 2015 14:41:05 +0200 Subject: [PATCH 073/175] adapt SAM core to PluggableUSB stable API --- .../sam/cores/arduino/USB/PluggableUSB.cpp | 95 ++++++++++--------- .../sam/cores/arduino/USB/PluggableUSB.h | 55 +++++++---- .../arduino/sam/cores/arduino/USB/USBCore.cpp | 8 +- .../arduino/sam/cores/arduino/USB/USBCore.h | 7 +- 4 files changed, 97 insertions(+), 68 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp index 84d781d81..0f2d08c0d 100644 --- a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp @@ -19,80 +19,89 @@ #include "USBAPI.h" #include "USBDesc.h" +#include "USBCore.h" #include "PluggableUSB.h" +#if defined(USBCON) #ifdef PLUGGABLE_USB_ENABLED -#define MAX_MODULES 6 - -static uint8_t lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; -static uint8_t lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; - extern uint32_t EndPoints[]; -//PUSBCallbacks cbs[MAX_MODULES]; -static uint8_t modules_count = 0; - -static PUSBListNode* rootNode = NULL; - -int PUSB_GetInterface(uint8_t* interfaceNum) +int PluggableUSB_::getInterface(uint8_t* interfaceCount) { - int ret = 0; - PUSBListNode* node = rootNode; - for (uint8_t i=0; icb->getInterface(interfaceNum); - node = node->next; + int sent = 0; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + int res = node->getInterface(interfaceCount); + if (res < 0) + return -1; + sent += res; } - return ret; + return sent; } -int PUSB_GetDescriptor(int8_t t) +int PluggableUSB_::getDescriptor(USBSetup& setup) { - int ret = 0; - PUSBListNode* node = rootNode; - for (uint8_t i=0; icb->getDescriptor(t); - node = node->next; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + int ret = node->getDescriptor(setup); + // ret!=0 -> request has been processed + if (ret) + return ret; } - return ret; + return 0; } -bool PUSB_Setup(USBSetup& setup, uint8_t j) +bool PluggableUSB_::setup(USBSetup& setup) { - bool ret = false; - PUSBListNode* node = rootNode; - for (uint8_t i=0; icb->setup(setup, j); - node = node->next; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + if (node->setup(setup)) { + return true; + } } - return ret; + return false; } -int8_t PUSB_AddFunction(PUSBListNode *node, uint8_t* interface) +bool PluggableUSB_::plug(PluggableUSBModule *node) { - if (modules_count >= MAX_MODULES) { - return 0; + if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) { + return false; } - if (modules_count == 0) { + if (!rootNode) { rootNode = node; } else { - PUSBListNode *current = rootNode; - while(current->next != NULL) { + PluggableUSBModule *current = rootNode; + while (current->next) { current = current->next; } current->next = node; } - *interface = lastIf; - lastIf += node->cb->numInterfaces; - for ( uint8_t i = 0; i< node->cb->numEndpoints; i++) { - EndPoints[lastEp] = node->cb->endpointType[i]; + node->pluggedInterface = lastIf; + node->pluggedEndpoint = lastEp; + lastIf += node->numInterfaces; + for (uint8_t i = 0; i < node->numEndpoints; i++) { + EndPoints[lastEp] = node->endpointType[i]; lastEp++; } - modules_count++; - return lastEp - node->cb->numEndpoints; + return true; // restart USB layer??? } +PluggableUSB_& PluggableUSB() +{ + static PluggableUSB_ obj; + return obj; +} + +PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT), + lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT), + rootNode(NULL) +{ + // Empty +} + +#endif #endif \ No newline at end of file diff --git a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h index c53aae66f..eb18ca253 100644 --- a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h +++ b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h @@ -25,30 +25,47 @@ #if defined(USBCON) -typedef struct __attribute__((packed)) -{ - bool (*setup)(USBSetup& setup, uint8_t i); - int (*getInterface)(uint8_t* interfaceNum); - int (*getDescriptor)(int8_t t); - int8_t numEndpoints; - int8_t numInterfaces; - uint32_t *endpointType; -} PUSBCallbacks; - -class PUSBListNode { +class PluggableUSBModule { public: - PUSBListNode *next = NULL; - PUSBCallbacks *cb; - PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;} + PluggableUSBModule(uint8_t numEps, uint8_t numIfs, uint32_t *epType) : + numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) + { } + +protected: + virtual bool setup(USBSetup& setup) = 0; + virtual int getInterface(uint8_t* interfaceCount) = 0; + virtual int getDescriptor(USBSetup& setup) = 0; + + uint8_t pluggedInterface; + uint8_t pluggedEndpoint; + + const uint8_t numEndpoints; + const uint8_t numInterfaces; + const uint32_t *endpointType; + + PluggableUSBModule *next = NULL; + + friend class PluggableUSB_; }; -int8_t PUSB_AddFunction(PUSBListNode *node, uint8_t *interface); +class PluggableUSB_ { +public: + PluggableUSB_(); + bool plug(PluggableUSBModule *node); + int getInterface(uint8_t* interfaceCount); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); -int PUSB_GetInterface(uint8_t* interfaceNum); +private: + uint8_t lastIf; + uint8_t lastEp; + PluggableUSBModule* rootNode; +}; -int PUSB_GetDescriptor(int8_t t); - -bool PUSB_Setup(USBSetup& setup, uint8_t i); +// Replacement for global singleton. +// This function prevents static-initialization-order-fiasco +// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use +PluggableUSB_& PluggableUSB(); #endif diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 3fc6e43d6..421b48f7e 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -296,7 +296,7 @@ bool USBD_ClassInterfaceRequest(USBSetup& setup) #endif #ifdef PLUGGABLE_USB_ENABLED - return PUSB_Setup(setup, i); + return PluggableUSB().setup(setup); #endif return false; @@ -311,7 +311,7 @@ int USBD_SendInterfaces(void) #endif #ifdef PLUGGABLE_USB_ENABLED - PUSB_GetInterface(&interfaces); + PluggableUSB().getInterface(&interfaces); #endif TRACE_CORE(printf("=> USBD_SendInterfaces, interfaces=%d\r\n", interfaces);) @@ -327,7 +327,7 @@ int USBD_SendOtherInterfaces(void) #endif #ifdef PLUGGABLE_USB_ENABLED - PUSB_GetInterface(&interfaces); + PluggableUSB().getInterface(&interfaces); #endif TRACE_CORE(printf("=> USBD_SendInterfaces, interfaces=%d\r\n", interfaces);) @@ -399,7 +399,7 @@ static bool USBD_SendDescriptor(USBSetup& setup) USBD_InitControl(setup.wLength); #ifdef PLUGGABLE_USB_ENABLED - ret = PUSB_GetDescriptor(t); + ret = PluggableUSB().getDescriptor(setup); if (ret != 0) { return (ret > 0 ? true : false); } diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.h b/hardware/arduino/sam/cores/arduino/USB/USBCore.h index c522d4482..10df90ba7 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.h @@ -46,8 +46,9 @@ #define REQUEST_OTHER 0x03 #define REQUEST_RECIPIENT 0x1F -#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE) -#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_CLASS | REQUEST_INTERFACE) +#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE | REQUEST_CLASS | REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_STANDARD | REQUEST_INTERFACE) // Class requests @@ -91,6 +92,8 @@ #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) #define USB_ENDPOINT_IN(addr) ((addr) | 0x80) +#define USB_ENDPOINTS 7 + #define USB_ENDPOINT_TYPE_MASK 0x03 #define USB_ENDPOINT_TYPE_CONTROL 0x00 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 From ddae105dc316ca5e463404c28cf0c96949e6861d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 12 Oct 2015 14:41:23 +0200 Subject: [PATCH 074/175] [HID] port to stable PluggableUSB API --- hardware/arduino/sam/libraries/HID/HID.cpp | 204 +++++++++------------ hardware/arduino/sam/libraries/HID/HID.h | 127 ++++++++----- 2 files changed, 169 insertions(+), 162 deletions(-) diff --git a/hardware/arduino/sam/libraries/HID/HID.cpp b/hardware/arduino/sam/libraries/HID/HID.cpp index b2a79423e..8d3a5a52e 100644 --- a/hardware/arduino/sam/libraries/HID/HID.cpp +++ b/hardware/arduino/sam/libraries/HID/HID.cpp @@ -13,156 +13,134 @@ ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -** SOFTWARE. +** SOFTWARE. */ -#include "USB/PluggableUSB.h" #include "HID.h" -HID_ HID; +#if defined(USBCON) -static uint8_t HID_ENDPOINT_INT; - -//================================================================================ -//================================================================================ - -// HID report descriptor - -#define LSB(_x) ((_x) & 0xFF) -#define MSB(_x) ((_x) >> 8) - -#define RAWHID_USAGE_PAGE 0xFFC0 -#define RAWHID_USAGE 0x0C00 -#define RAWHID_TX_SIZE 64 -#define RAWHID_RX_SIZE 64 - -static uint8_t HID_INTERFACE; - -HIDDescriptor _hidInterface; - -static HIDDescriptorListNode* rootNode = NULL; -static uint8_t sizeof_hidReportDescriptor = 0; -static uint8_t modules_count = 0; -//================================================================================ -//================================================================================ -// Driver - -uint8_t _hid_protocol = 1; -uint8_t _hid_idle = 1; - -int HID_GetInterface(uint8_t* interfaceNum) +HID_& HID() { - interfaceNum[0] += 1; // uses 1 - _hidInterface = - { - D_INTERFACE(HID_INTERFACE,1,3,0,0), - D_HIDREPORT(sizeof_hidReportDescriptor), - D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) + static HID_ obj; + return obj; +} + +int HID_::getInterface(uint8_t* interfaceCount) +{ + *interfaceCount += 1; // uses 1 + HIDDescriptor hidInterface = { + D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), + D_HIDREPORT(descriptorSize), + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, 0x40, 0x01) }; - return USBD_SendControl(0,&_hidInterface,sizeof(_hidInterface)); + return USBD_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int HID_GetDescriptor(int8_t t) +int HID_::getDescriptor(USBSetup& setup) { - if (HID_REPORT_DESCRIPTOR_TYPE == t) { - HIDDescriptorListNode* current = rootNode; - int total = 0; - while(current != NULL) { - total += USBD_SendControl(0,current->data,current->length); - current = current->next; - } - return total; - } else { - return 0; + // Check if this is a HID Class Descriptor request + if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; } + if (setup.wValueH != HID_REPORT_DESCRIPTOR_TYPE) { return 0; } + + // In a HID Class Descriptor wIndex cointains the interface number + if (setup.wIndex != pluggedInterface) { return 0; } + + int total = 0; + HIDSubDescriptor* node; + for (node = rootNode; node; node = node->next) { + int res = USBD_SendControl(0, node->data, node->length); + if (res == -1) + return -1; + total += res; } + return total; } -void HID_::AppendDescriptor(HIDDescriptorListNode *node) +void HID_::AppendDescriptor(HIDSubDescriptor *node) { - if (modules_count == 0) { + if (!rootNode) { rootNode = node; } else { - HIDDescriptorListNode *current = rootNode; - while(current->next != NULL) { + HIDSubDescriptor *current = rootNode; + while (current->next) { current = current->next; } current->next = node; } - modules_count++; - sizeof_hidReportDescriptor += node->length; + descriptorSize += node->length; } void HID_::SendReport(uint8_t id, const void* data, int len) { uint8_t p[64]; - const uint8_t *d = reinterpret_cast(data); - p[0] = id; - for (uint32_t i=0; i #include +#include "USB/PluggableUSB.h" + +#if defined(USBCON) #define _USING_HID -//================================================================================ -//================================================================================ -// HID 'Driver' - +// HID 'Driver' +// ------------ #define HID_GET_REPORT 0x01 #define HID_GET_IDLE 0x02 #define HID_GET_PROTOCOL 0x03 @@ -42,49 +40,80 @@ #define HID_REPORT_DESCRIPTOR_TYPE 0x22 #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 -class HIDDescriptorListNode { +// HID subclass HID1.11 Page 8 4.2 Subclass +#define HID_SUBCLASS_NONE 0 +#define HID_SUBCLASS_BOOT_INTERFACE 1 + +// HID Keyboard/Mouse bios compatible protocols HID1.11 Page 9 4.3 Protocols +#define HID_PROTOCOL_NONE 0 +#define HID_PROTOCOL_KEYBOARD 1 +#define HID_PROTOCOL_MOUSE 2 + +// Normal or bios protocol (Keyboard/Mouse) HID1.11 Page 54 7.2.5 Get_Protocol Request +// "protocol" variable is used for this purpose. +#define HID_BOOT_PROTOCOL 0 +#define HID_REPORT_PROTOCOL 1 + +typedef struct +{ + uint8_t len; // 9 + uint8_t dtype; // 0x21 + uint8_t addr; + uint8_t versionL; // 0x101 + uint8_t versionH; // 0x101 + uint8_t country; + uint8_t desctype; // 0x22 report + uint8_t descLenL; + uint8_t descLenH; +} HIDDescDescriptor; + +typedef struct +{ + InterfaceDescriptor hid; + HIDDescDescriptor desc; + EndpointDescriptor in; +} HIDDescriptor; + +class HIDSubDescriptor { public: - HIDDescriptorListNode *next = NULL; - HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { } + HIDSubDescriptor *next = NULL; + HIDSubDescriptor(const void *d, const uint16_t l) : data(d), length(l) { } const void* data; const uint16_t length; }; -class HID_ +class HID_ : public PluggableUSBModule { public: HID_(void); int begin(void); void SendReport(uint8_t id, const void* data, int len); - void AppendDescriptor(HIDDescriptorListNode* node); + void AppendDescriptor(HIDSubDescriptor* node); + +protected: + // Implementation of the PluggableUSBModule + int getInterface(uint8_t* interfaceCount); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); + +private: + uint32_t epType[1]; + + HIDSubDescriptor* rootNode; + uint16_t descriptorSize; + + uint8_t protocol; + uint8_t idle; }; -typedef struct -{ - uint8_t len; // 9 - uint8_t dtype; // 0x21 - uint8_t addr; - uint8_t versionL; // 0x101 - uint8_t versionH; // 0x101 - uint8_t country; - uint8_t desctype; // 0x22 report - uint8_t descLenL; - uint8_t descLenH; -} HIDDescDescriptor; +// Replacement for global singleton. +// This function prevents static-initialization-order-fiasco +// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use +HID_& HID(); -typedef struct -{ - InterfaceDescriptor hid; - HIDDescDescriptor desc; - EndpointDescriptor in; -} HIDDescriptor; +#define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) } -#define HID_TX HID_ENDPOINT_INT +#endif // USBCON -#define D_HIDREPORT(_descriptorLength) \ - { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 } - -#define WEAK __attribute__ ((weak)) - -#endif +#endif // HID_h From bf609ecc4cf1478b5b81cd2a2a6b2185673babcd Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 12 Oct 2015 14:42:13 +0200 Subject: [PATCH 075/175] [USB] remove all warnings from SAM USB core --- .../arduino/sam/cores/arduino/USB/USBAPI.h | 2 +- .../arduino/sam/cores/arduino/USB/USBCore.cpp | 18 +++++++++--------- .../arduino/sam/cores/arduino/USB/USBCore.h | 18 +++++++++++++++--- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h index 97e8ad6fe..ee9739cb5 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h @@ -131,7 +131,7 @@ bool CDC_Setup(USBSetup& setup); void USBD_InitControl(int end); int USBD_SendControl(uint8_t flags, const void* d, uint32_t len); int USBD_RecvControl(void* d, uint32_t len); -int USBD_SendInterfaces(void); +uint8_t USBD_SendInterfaces(void); bool USBD_ClassInterfaceRequest(USBSetup& setup); diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 421b48f7e..6631ec006 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -101,7 +101,7 @@ const DeviceDescriptor USB_DeviceDescriptor = const DeviceDescriptor USB_DeviceDescriptorA = D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); -const DeviceDescriptor USB_DeviceQualifier = +const QualifierDescriptor USB_DeviceQualifier = D_QUALIFIER(0x00,0x00,0x00,64,1); //! 7.1.20 Test Mode Support @@ -130,7 +130,7 @@ class LockEP { irqflags_t flags; public: - LockEP(uint32_t ep) : flags(cpu_irq_save()) + LockEP(uint32_t ep __attribute__ ((unused))) : flags(cpu_irq_save()) { } ~LockEP() @@ -219,8 +219,8 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len) return r; } -int _cmark; -int _cend; +uint16_t _cmark; +uint16_t _cend; void USBD_InitControl(int end) { @@ -229,7 +229,7 @@ void USBD_InitControl(int end) } // Clipped by _cmark/_cend -int USBD_SendControl(uint8_t flags, const void* d, uint32_t len) +int USBD_SendControl(uint8_t flags __attribute__ ((unused)), const void* d, uint32_t len) { const uint8_t* data = (const uint8_t*)d; uint32_t length = len; @@ -302,7 +302,7 @@ bool USBD_ClassInterfaceRequest(USBSetup& setup) return false; } -int USBD_SendInterfaces(void) +uint8_t USBD_SendInterfaces(void) { uint8_t interfaces = 0; @@ -318,7 +318,7 @@ int USBD_SendInterfaces(void) return interfaces; } -int USBD_SendOtherInterfaces(void) +uint8_t USBD_SendOtherInterfaces(void) { uint8_t interfaces = 0; @@ -342,7 +342,7 @@ static bool USBD_SendConfiguration(int maxlen) // Count and measure interfaces USBD_InitControl(0); //TRACE_CORE(printf("=> USBD_SendConfiguration _cmark1=%d\r\n", _cmark);) - int interfaces = USBD_SendInterfaces(); + uint8_t interfaces = USBD_SendInterfaces(); //TRACE_CORE(printf("=> USBD_SendConfiguration _cmark2=%d\r\n", _cmark);) //TRACE_CORE(printf("=> USBD_SendConfiguration sizeof=%d\r\n", sizeof(ConfigDescriptor));) @@ -365,7 +365,7 @@ static bool USBD_SendOtherConfiguration(int maxlen) // Count and measure interfaces USBD_InitControl(0); //TRACE_CORE(printf("=> USBD_SendConfiguration _cmark1=%d\r\n", _cmark);) - int interfaces = USBD_SendOtherInterfaces(); + uint8_t interfaces = USBD_SendOtherInterfaces(); //TRACE_CORE(printf("=> USBD_SendConfiguration _cmark2=%d\r\n", _cmark);) //TRACE_CORE(printf("=> USBD_SendConfiguration sizeof=%d\r\n", sizeof(ConfigDescriptor));) diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.h b/hardware/arduino/sam/cores/arduino/USB/USBCore.h index 10df90ba7..893d84fcb 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.h @@ -149,6 +149,18 @@ typedef struct { uint8_t maxPower; } ConfigDescriptor; +// Device Qualifier (only needed for USB2.0 devices) +typedef struct { + uint8_t bLength; + uint8_t dtype; + uint16_t bDescriptorType; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint8_t bNumConfigurations; +} QualifierDescriptor; + // String // Interface @@ -257,16 +269,16 @@ _Pragma("pack()") { 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs } #define D_CONFIG(_totalLength,_interfaces) \ - { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_SELF_POWERED, USB_CONFIG_POWER_MA(500) } + { 9, 2, (uint16_t)(_totalLength),_interfaces, 1, 0, USB_CONFIG_SELF_POWERED, USB_CONFIG_POWER_MA(500) } #define D_OTHERCONFIG(_totalLength,_interfaces) \ - { 9, 7, _totalLength,_interfaces, 1, 0, USB_CONFIG_SELF_POWERED, USB_CONFIG_POWER_MA(500) } + { 9, 7, (uint16_t)(_totalLength),_interfaces, 1, 0, USB_CONFIG_SELF_POWERED, USB_CONFIG_POWER_MA(500) } #define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \ { 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 } #define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \ - { 7, 5, _addr,_attr,_packetSize, _interval } + { 7, 5, (uint8_t)(_addr),_attr,_packetSize, _interval } #define D_QUALIFIER(_class,_subClass,_proto,_packetSize0,_configs) \ { 10, 6, 0x200, _class,_subClass,_proto,_packetSize0,_configs } From 9fe2023c28c9e44999a463c9584cfa6113f323b8 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Mon, 12 Oct 2015 17:31:35 +0200 Subject: [PATCH 076/175] [PHID] Fixes protocol on reenumeration --- hardware/arduino/avr/libraries/HID/HID.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 411529ecf..be95ec22c 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -54,6 +54,11 @@ int HID_::getDescriptor(USBSetup& setup) return -1; total += res; } + + // Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol + // due to the USB specs, but Windows and Linux just assumes its in report mode. + protocol = HID_REPORT_PROTOCOL; + return total; } @@ -130,7 +135,7 @@ bool HID_::setup(USBSetup& setup) HID_::HID_(void) : PluggableUSBModule(1, 1, epType), rootNode(NULL), descriptorSize(0), - protocol(1), idle(1) + protocol(HID_REPORT_PROTOCOL), idle(1) { epType[0] = EP_TYPE_INTERRUPT_IN; PluggableUSB().plug(this); From 739c656b1dd73532e0bbb5964b8b11701a8cf342 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Sun, 11 Oct 2015 19:29:29 +0200 Subject: [PATCH 077/175] Port Scheduler library to Arduino Zero. --- libraries/Scheduler/library.properties | 8 ++-- libraries/Scheduler/src/Scheduler.cpp | 57 +++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/libraries/Scheduler/library.properties b/libraries/Scheduler/library.properties index c7d34533b..c9ee1d5c4 100644 --- a/libraries/Scheduler/library.properties +++ b/libraries/Scheduler/library.properties @@ -1,9 +1,9 @@ name=Scheduler -version=0.4.3 +version=0.4.4 author=Arduino maintainer=Arduino -sentence=Allows multiple tasks to run at the same time, without interrupting each other. For Arduino DUE only. -paragraph=The Scheduler library enables the Arduino Due to run multiple functions at the same time. This allows tasks to happen without interrupting each other.
This is a cooperative scheduler in that the CPU switches from one task to another. The library includes methods for passing control between tasks. +sentence=Allows multiple tasks to run at the same time, without interrupting each other. For Arduino sam and samd architectures only (Due, Zero...). +paragraph=The Scheduler library enables the Arduino to run multiple functions at the same time. This allows tasks to happen without interrupting each other.
This is a cooperative scheduler in that the CPU switches from one task to another. The library includes methods for passing control between tasks. category=Other url=http://www.arduino.cc/en/Reference/Scheduler -architectures=sam +architectures=sam,samd diff --git a/libraries/Scheduler/src/Scheduler.cpp b/libraries/Scheduler/src/Scheduler.cpp index 2be2d8206..6d7d676c2 100644 --- a/libraries/Scheduler/src/Scheduler.cpp +++ b/libraries/Scheduler/src/Scheduler.cpp @@ -53,10 +53,30 @@ static void __attribute__((naked)) __attribute__((noinline)) coopTaskStart(void) asm ( "mov r0, r5;" "blx r4;" - "mov r0, #1;" + /* schedule. */ + "mov r0, #1;" /* returned from task func: task done */ "bl coopSchedule;" + /* r0 holds address of next task context */ +#if defined(ARDUINO_ARCH_SAMD) + /* for cortex m0, ldm and stm are restricted to low registers */ + /* load high registers */ + "add r0, #16;" /* they are 4 words higher in memory */ + "ldmia r0, {r1-r6};" /* load them in low registers first... */ + "mov r8, r1;" /* ...and move them into high registers... */ + "mov r9, r2;" + "mov r10, r3;" + "mov r11, r4;" + "mov r12, r5;" + "mov lr, r6;" + /* load low registers */ + "sub r0, r0, #40;" /* back to begin of context */ + "ldmia r0, {r4-r7};" +#else "ldmia r0, {r4-r12, lr};" +#endif + /* restore task stack */ "mov sp, r12;" + /* resume task */ "bx lr;" ); } @@ -64,11 +84,44 @@ static void __attribute__((naked)) __attribute__((noinline)) coopTaskStart(void) static void __attribute__((naked)) __attribute__((noinline)) coopDoYield(CoopTask* curTask) { asm ( "mov r12, sp;" +#if defined(ARDUINO_ARCH_SAMD) + /* store low registers */ + "stmia r0, {r4-r7};" + /* store high registers */ + "mov r1, r8;" /* move them to low registers first. */ + "mov r2, r9;" + "mov r3, r10;" + "mov r4, r11;" + "mov r5, r12;" + "mov r6, lr;" + "stmia r0, {r1-r6};" +#else "stmia r0, {r4-r12, lr};" - "mov r0, #0;" +#endif + /* schedule. */ + "mov r0, #0;" /* previous task did not complete */ "bl coopSchedule;" + /* r0 holds address of next task context */ +#if defined(ARDUINO_ARCH_SAMD) + /* for cortex m0, ldm and stm are restricted to low registers */ + /* load high registers */ + "add r0, #16;" /* they are 4 words higher in memory */ + "ldmia r0, {r1-r6};" /* load them in low registers first... */ + "mov r8, r1;" /* ...and move them into high registers... */ + "mov r9, r2;" + "mov r10, r3;" + "mov r11, r4;" + "mov r12, r5;" + "mov lr, r6;" + /* load low registers */ + "sub r0, r0, #40;" /* back to begin of context */ + "ldmia r0, {r4-r7};" +#else "ldmia r0, {r4-r12, lr};" +#endif + /* restore task stack */ "mov sp, r12;" + /* resume task */ "bx lr;" ); } From c1ce649554dd84b75c8c6c0aa419d78d09415dac Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 12 Oct 2015 14:34:52 -0700 Subject: [PATCH 078/175] Fix typos in ArchiveExtractor.java error messages --- arduino-core/src/cc/arduino/utils/ArchiveExtractor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arduino-core/src/cc/arduino/utils/ArchiveExtractor.java b/arduino-core/src/cc/arduino/utils/ArchiveExtractor.java index d892e9ec2..1fc007997 100644 --- a/arduino-core/src/cc/arduino/utils/ArchiveExtractor.java +++ b/arduino-core/src/cc/arduino/utils/ArchiveExtractor.java @@ -164,7 +164,7 @@ public class ArchiveExtractor { while (stripPath > 0) { slash = name.indexOf("/", slash); if (slash == -1) { - throw new IOException("Invalid archive: it must contains a single root folder"); + throw new IOException("Invalid archive: it must contain a single root folder"); } slash++; stripPath--; @@ -174,7 +174,7 @@ public class ArchiveExtractor { // Strip the common path prefix when requested if (!name.startsWith(pathPrefix)) { - throw new IOException("Invalid archive: it must contains a single root folder while file " + name + " is outside " + pathPrefix); + throw new IOException("Invalid archive: it must contain a single root folder while file " + name + " is outside " + pathPrefix); } name = name.substring(pathPrefix.length()); if (name.isEmpty()) { @@ -185,7 +185,7 @@ public class ArchiveExtractor { File outputLinkedFile = null; if (isLink) { if (!linkName.startsWith(pathPrefix)) { - throw new IOException("Invalid archive: it must contains a single root folder while file " + linkName + " is outside " + pathPrefix); + throw new IOException("Invalid archive: it must contain a single root folder while file " + linkName + " is outside " + pathPrefix); } linkName = linkName.substring(pathPrefix.length()); outputLinkedFile = new File(destFolder, linkName); From bef7bb5b7693c7ba850700bad283be9f39c0f193 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 13 Oct 2015 14:10:43 +0200 Subject: [PATCH 079/175] Allow spaces in IDE install path on Linux The startup bash script lacked quotes in some places, causing it to interpret part of the path to the splash image as the main class and fail to start: arduino: line 29: [: /home/a/Arduino: binary operator expected Error: Could not find or load main class IDE.lib.splash.png For the -splash option, simply adding quotes was not sufficient. If no splash screen was to be used (so when $SPLASH was empty), using "$SPLASH" would result in an empty argument being passed to java, which was then interpreted by java as the name of the base class. To allow spaces to occur in the -splash option, but also allow it to be omitted entirely, options to java are now passed through the $JAVA_OPTIONS array. By using the special "${JAVA_OPTIONS[@]}" syntax, each element in the array is expanded into a single argument, even when spaces are present inside (this is identical to what happens with "$@"). This fixes #3950 --- build/linux/dist/arduino | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/build/linux/dist/arduino b/build/linux/dist/arduino index 178766745..505da121c 100755 --- a/build/linux/dist/arduino +++ b/build/linux/dist/arduino @@ -3,9 +3,9 @@ APPDIR="$(dirname -- "$(readlink -f -- "${0}")" )" for LIB in \ - $APPDIR/java/lib/rt.jar \ - $APPDIR/java/lib/tools.jar \ - $APPDIR/lib/*.jar \ + "$APPDIR"/java/lib/rt.jar \ + "$APPDIR"/java/lib/tools.jar \ + "$APPDIR"/lib/*.jar \ ; do CLASSPATH="${CLASSPATH}:${LIB}" @@ -17,18 +17,19 @@ export LD_LIBRARY_PATH export PATH="${APPDIR}/java/bin:${PATH}" -if [[ "$@" == *"--upload"* || "$@" == *"--verify"* || "$@" == *"--get-pref"* || "$@" == *"--install-board"* || "$@" == *"--install-library"* ]] ; then - SPLASH="" -else - SPLASH="-splash:$APPDIR/lib/splash.png" -fi - export JAVA_TOOL_OPTIONS=`echo $JAVA_TOOL_OPTIONS | sed 's|-javaagent:/usr/share/java/jayatanaag.jar||g'` JAVA=java -if [ -x $APPDIR/java/bin/java ]; then +if [ -x "$APPDIR/java/bin/java" ]; then JAVA=$APPDIR/java/bin/java fi -$JAVA -DAPP_DIR="$APPDIR" -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel $SPLASH processing.app.Base "$@" +# Collect options to java in an array, to properly handle whitespace in options +JAVA_OPTIONS=("-DAPP_DIR=$APPDIR" "-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel") + +if [[ "$@" != *"--upload"* && "$@" != *"--verify"* && "$@" != *"--get-pref"* && "$@" != *"--install-board"* && "$@" != *"--install-library"* ]] ; then + JAVA_OPTIONS+=("-splash:$APPDIR/lib/splash.png") +fi + +$JAVA "${JAVA_OPTIONS[@]}" processing.app.Base "$@" From a6602cac096c9d589f3d9b8ab917d9b38fcb8332 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 14 Oct 2015 21:42:20 +0200 Subject: [PATCH 080/175] Another small fix for 'spaces in IDE install path on Linux' See #3973 --- build/linux/dist/arduino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/linux/dist/arduino b/build/linux/dist/arduino index 505da121c..d4e7f1965 100755 --- a/build/linux/dist/arduino +++ b/build/linux/dist/arduino @@ -31,5 +31,5 @@ if [[ "$@" != *"--upload"* && "$@" != *"--verify"* && "$@" != *"--get-pref"* && JAVA_OPTIONS+=("-splash:$APPDIR/lib/splash.png") fi -$JAVA "${JAVA_OPTIONS[@]}" processing.app.Base "$@" +"$JAVA" "${JAVA_OPTIONS[@]}" processing.app.Base "$@" From e3fae38c4167aff5237a6b5ec0820bedd542ddd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20P=C3=A9rez?= Date: Mon, 19 Oct 2015 15:55:08 +0200 Subject: [PATCH 081/175] Declare paths parameters as constant This way we will avoid some warnings when using paths as constants in #define's `warning: deprecated conversion from string constant to 'char*'` --- libraries/SD/src/SD.cpp | 22 +++++++++++----------- libraries/SD/src/SD.h | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index 0b3194b27..2afb9d9af 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -58,7 +58,7 @@ namespace SDLib { #define MAX_COMPONENT_LEN 12 // What is max length? #define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1 -bool getNextPathComponent(char *path, unsigned int *p_offset, +bool getNextPathComponent(const char *path, unsigned int *p_offset, char *buffer) { /* @@ -117,9 +117,9 @@ bool getNextPathComponent(char *path, unsigned int *p_offset, -boolean walkPath(char *filepath, SdFile& parentDir, +boolean walkPath(const char *filepath, SdFile& parentDir, boolean (*callback)(SdFile& parentDir, - char *filePathComponent, + const char *filePathComponent, boolean isLastComponent, void *object), void *object = NULL) { @@ -232,7 +232,7 @@ boolean walkPath(char *filepath, SdFile& parentDir, */ -boolean callback_pathExists(SdFile& parentDir, char *filePathComponent, +boolean callback_pathExists(SdFile& parentDir, const char *filePathComponent, boolean isLastComponent, void *object) { /* @@ -255,7 +255,7 @@ boolean callback_pathExists(SdFile& parentDir, char *filePathComponent, -boolean callback_makeDirPath(SdFile& parentDir, char *filePathComponent, +boolean callback_makeDirPath(SdFile& parentDir, const char *filePathComponent, boolean isLastComponent, void *object) { /* @@ -310,7 +310,7 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent, -boolean callback_remove(SdFile& parentDir, char *filePathComponent, +boolean callback_remove(SdFile& parentDir, const char *filePathComponent, boolean isLastComponent, void *object) { if (isLastComponent) { return SdFile::remove(parentDir, filePathComponent); @@ -318,7 +318,7 @@ boolean callback_remove(SdFile& parentDir, char *filePathComponent, return true; } -boolean callback_rmdir(SdFile& parentDir, char *filePathComponent, +boolean callback_rmdir(SdFile& parentDir, const char *filePathComponent, boolean isLastComponent, void *object) { if (isLastComponent) { SdFile f; @@ -517,7 +517,7 @@ File SDClass::open(char *filepath, uint8_t mode) { //} -boolean SDClass::exists(char *filepath) { +boolean SDClass::exists(const char *filepath) { /* Returns true if the supplied file path exists. @@ -538,7 +538,7 @@ boolean SDClass::exists(char *filepath) { //} -boolean SDClass::mkdir(char *filepath) { +boolean SDClass::mkdir(const char *filepath) { /* Makes a single directory or a heirarchy of directories. @@ -549,7 +549,7 @@ boolean SDClass::mkdir(char *filepath) { return walkPath(filepath, root, callback_makeDirPath); } -boolean SDClass::rmdir(char *filepath) { +boolean SDClass::rmdir(const char *filepath) { /* Remove a single directory or a heirarchy of directories. @@ -560,7 +560,7 @@ boolean SDClass::rmdir(char *filepath) { return walkPath(filepath, root, callback_rmdir); } -boolean SDClass::remove(char *filepath) { +boolean SDClass::remove(const char *filepath) { return walkPath(filepath, root, callback_remove); } diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index 999dac175..0435c38ba 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -76,19 +76,19 @@ public: File open(const String &filename, uint8_t mode = FILE_READ) { return open( filename.c_str(), mode ); } // Methods to determine if the requested file path exists. - boolean exists(char *filepath); + boolean exists(const char *filepath); boolean exists(const String &filepath) { return exists(filepath.c_str()); } // Create the requested directory heirarchy--if intermediate directories // do not exist they will be created. - boolean mkdir(char *filepath); + boolean mkdir(const char *filepath); boolean mkdir(const String &filepath) { return mkdir(filepath.c_str()); } // Delete the file. - boolean remove(char *filepath); + boolean remove(const char *filepath); boolean remove(const String &filepath) { return remove(filepath.c_str()); } - boolean rmdir(char *filepath); + boolean rmdir(const char *filepath); boolean rmdir(const String &filepath) { return rmdir(filepath.c_str()); } private: @@ -101,7 +101,7 @@ private: int fileOpenMode; friend class File; - friend boolean callback_openPath(SdFile&, char *, boolean, void *); + friend boolean callback_openPath(SdFile&, const char *, boolean, void *); }; extern SDClass SD; From 2eaa6ff937c752a3abc0677ef38fe7b3ebcc0590 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Oct 2015 18:29:40 +0200 Subject: [PATCH 082/175] Removed unused imports --- app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java | 2 -- app/src/processing/app/EditorLineStatus.java | 3 --- app/src/processing/app/Preferences.java | 4 ---- .../processing/app/AutoformatProducesOneUndoActionTest.java | 1 - app/test/processing/app/syntax/PdeKeywordsTest.java | 2 -- 5 files changed, 12 deletions(-) diff --git a/app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java b/app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java index 800756c19..3dcda9272 100644 --- a/app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java +++ b/app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java @@ -33,14 +33,12 @@ import cc.arduino.contributions.filters.BuiltInPredicate; import cc.arduino.contributions.filters.InstalledPredicate; import cc.arduino.contributions.packages.ContributedPackage; import cc.arduino.contributions.packages.ContributedPlatform; -import cc.arduino.view.Event; import processing.app.Base; import processing.app.BaseNoGui; import processing.app.I18n; import processing.app.PreferencesData; import javax.swing.*; -import java.awt.event.ActionEvent; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; diff --git a/app/src/processing/app/EditorLineStatus.java b/app/src/processing/app/EditorLineStatus.java index 253f3919d..b1ad221df 100644 --- a/app/src/processing/app/EditorLineStatus.java +++ b/app/src/processing/app/EditorLineStatus.java @@ -24,13 +24,10 @@ package processing.app; import java.awt.*; import java.awt.geom.Rectangle2D; -import java.util.Map; - import javax.swing.JComponent; import processing.app.helpers.OSUtils; import processing.app.helpers.PreferencesMap; -import processing.app.syntax.SketchTextArea; /** diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 8dc00c137..d53f5b0d8 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -21,12 +21,8 @@ package processing.app; -import processing.app.helpers.PreferencesHelper; import processing.app.helpers.PreferencesMap; -import java.awt.*; -import java.io.File; - /** * Storage class for user preferences and environment settings. diff --git a/app/test/processing/app/AutoformatProducesOneUndoActionTest.java b/app/test/processing/app/AutoformatProducesOneUndoActionTest.java index 8c5243a66..33314b4a1 100644 --- a/app/test/processing/app/AutoformatProducesOneUndoActionTest.java +++ b/app/test/processing/app/AutoformatProducesOneUndoActionTest.java @@ -34,7 +34,6 @@ import org.junit.Test; import processing.app.helpers.SketchTextAreaFixture; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; public class AutoformatProducesOneUndoActionTest extends AbstractGUITest { diff --git a/app/test/processing/app/syntax/PdeKeywordsTest.java b/app/test/processing/app/syntax/PdeKeywordsTest.java index 29c6b4675..f59deac21 100644 --- a/app/test/processing/app/syntax/PdeKeywordsTest.java +++ b/app/test/processing/app/syntax/PdeKeywordsTest.java @@ -32,8 +32,6 @@ package processing.app.syntax; import org.fife.ui.rsyntaxtextarea.TokenTypes; import org.junit.Test; import processing.app.AbstractWithPreferencesTest; -import processing.app.BaseNoGui; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; From 635de0197521d35d740f21287731a4dd9b7e424b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Oct 2015 18:30:27 +0200 Subject: [PATCH 083/175] Suppress java 'serial' warning in SignatureVerificationFailedException class --- .../contributions/SignatureVerificationFailedException.java | 1 + 1 file changed, 1 insertion(+) diff --git a/arduino-core/src/cc/arduino/contributions/SignatureVerificationFailedException.java b/arduino-core/src/cc/arduino/contributions/SignatureVerificationFailedException.java index 32f7d4d1d..77136cb46 100644 --- a/arduino-core/src/cc/arduino/contributions/SignatureVerificationFailedException.java +++ b/arduino-core/src/cc/arduino/contributions/SignatureVerificationFailedException.java @@ -33,6 +33,7 @@ import processing.app.I18n; import static processing.app.I18n.tr; +@SuppressWarnings("serial") public class SignatureVerificationFailedException extends Exception { public SignatureVerificationFailedException(String filename) { From 38701678b24bfde6c97fb0d5390e4269a6fa70db Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Oct 2015 18:31:58 +0200 Subject: [PATCH 084/175] Specialized some Iterators with correct inferred type --- .../contributions/GPGDetachedSignatureVerifier.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arduino-core/src/cc/arduino/contributions/GPGDetachedSignatureVerifier.java b/arduino-core/src/cc/arduino/contributions/GPGDetachedSignatureVerifier.java index a09bd12fd..216c6dbcb 100644 --- a/arduino-core/src/cc/arduino/contributions/GPGDetachedSignatureVerifier.java +++ b/arduino-core/src/cc/arduino/contributions/GPGDetachedSignatureVerifier.java @@ -97,13 +97,13 @@ public class GPGDetachedSignatureVerifier extends SignatureVerifier { private PGPPublicKey readPublicKey(InputStream input, String keyId) throws IOException, PGPException { PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(input), new BcKeyFingerprintCalculator()); - Iterator keyRingIter = pgpPub.getKeyRings(); + Iterator keyRingIter = pgpPub.getKeyRings(); while (keyRingIter.hasNext()) { - PGPPublicKeyRing keyRing = (PGPPublicKeyRing) keyRingIter.next(); + PGPPublicKeyRing keyRing = keyRingIter.next(); - Iterator keyIter = keyRing.getPublicKeys(); + Iterator keyIter = keyRing.getPublicKeys(); while (keyIter.hasNext()) { - PGPPublicKey key = (PGPPublicKey) keyIter.next(); + PGPPublicKey key = keyIter.next(); if (Long.toHexString(key.getKeyID()).toUpperCase().endsWith(keyId)) { return key; From 869137469c5ed84e5dab761a7645425a45d75a45 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Oct 2015 18:37:59 +0200 Subject: [PATCH 085/175] Silence unused warning in I18N class --- app/src/cc/arduino/view/preferences/Preferences.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/cc/arduino/view/preferences/Preferences.java b/app/src/cc/arduino/view/preferences/Preferences.java index eb4078982..ffeaf53dc 100644 --- a/app/src/cc/arduino/view/preferences/Preferences.java +++ b/app/src/cc/arduino/view/preferences/Preferences.java @@ -48,7 +48,13 @@ import static processing.app.I18n.tr; public class Preferences extends javax.swing.JDialog { private final Language[] languages; + + // Languages that are not translated at least to 65% are + // kept in the "missingLanguages" array until they have enough + // translated strings. + @SuppressWarnings("unused") private final Language[] missingLanguages; + private final WarningItem[] warningItems; private final Base base; From 9f5efe210aebeb81ee275348b1db01e830ba96f6 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Oct 2015 18:38:34 +0200 Subject: [PATCH 086/175] Removed a bunch of unused variables --- app/src/processing/app/AbstractMonitor.java | 3 --- app/src/processing/app/Base.java | 2 +- arduino-core/src/processing/app/SketchCode.java | 15 --------------- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/app/src/processing/app/AbstractMonitor.java b/app/src/processing/app/AbstractMonitor.java index 976041eaf..e8cc0df75 100644 --- a/app/src/processing/app/AbstractMonitor.java +++ b/app/src/processing/app/AbstractMonitor.java @@ -13,7 +13,6 @@ import java.awt.event.WindowEvent; @SuppressWarnings("serial") public abstract class AbstractMonitor extends JFrame implements ActionListener { - private boolean monitorEnabled; private boolean closed; private StringBuffer updateBuffer; @@ -78,7 +77,6 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener { updateTimer = new Timer(33, this); // redraw serial monitor at 30 Hz updateTimer.start(); - monitorEnabled = true; closed = false; } @@ -86,7 +84,6 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener { public void enableWindow(boolean enable) { onEnableWindow(enable); - monitorEnabled = enable; } protected abstract void onEnableWindow(boolean enable); diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 2ef29d54e..3990aa07e 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -748,7 +748,7 @@ public class Base { try { File file = createNewUntitled(); if (file != null) { - Editor editor = handleOpen(file, true); + handleOpen(file, true); } } catch (IOException e) { diff --git a/arduino-core/src/processing/app/SketchCode.java b/arduino-core/src/processing/app/SketchCode.java index 0e3f26560..54d070775 100644 --- a/arduino-core/src/processing/app/SketchCode.java +++ b/arduino-core/src/processing/app/SketchCode.java @@ -53,11 +53,6 @@ public class SketchCode { private boolean modified; - /** - * where this code starts relative to the concat'd code - */ - private int preprocOffset; - private Object metadata; public SketchCode(File file) { @@ -190,16 +185,6 @@ public class SketchCode { } - public void setPreprocOffset(int preprocOffset) { - this.preprocOffset = preprocOffset; - } - - - public void addPreprocOffset(int extra) { - preprocOffset += extra; - } - - /** * Load this piece of code from a file. */ From 28ad89d694e57e30b50df46959fdd37afe45af49 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Oct 2015 19:21:13 +0200 Subject: [PATCH 087/175] Make SystemProfilerParser.extractVIDAndPID() static There is no need to instantiate a SystemProfilerParser object each time extractVIDAndPID is invoked. Added also `synchronized` keword to avoid reentrance problems if the method is being used in multiple threads. --- .../app/macosx/SystemProfilerParserTest.java | 65 ++++++++++--------- .../src/processing/app/macosx/Platform.java | 2 +- .../app/macosx/SystemProfilerParser.java | 17 ++--- 3 files changed, 39 insertions(+), 45 deletions(-) diff --git a/app/test/processing/app/macosx/SystemProfilerParserTest.java b/app/test/processing/app/macosx/SystemProfilerParserTest.java index 1476822c4..a958282a2 100644 --- a/app/test/processing/app/macosx/SystemProfilerParserTest.java +++ b/app/test/processing/app/macosx/SystemProfilerParserTest.java @@ -33,50 +33,51 @@ import org.junit.Test; import processing.app.TestHelper; import static org.junit.Assert.assertEquals; +import static processing.app.macosx.SystemProfilerParser.extractVIDAndPID; + +import java.io.IOException; +import java.io.InputStream; public class SystemProfilerParserTest { @Test public void shouldCorrectlyParse() throws Exception { - String output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output.txt")); + String output = getFileContent("system_profiler_output.txt"); + assertEquals("0X2341_0X0044", extractVIDAndPID(output, "/dev/cu.usbmodemfa121")); + assertEquals("0X2341_0X0044", extractVIDAndPID(output, "/dev/tty.usbmodemfa121")); - assertEquals("0X2341_0X0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfa121")); - assertEquals("0X2341_0X0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfa121")); + output = getFileContent("system_profiler_output2.txt"); + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/cu.usbmodemfd131")); + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodemfd131")); - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output2.txt")); + output = getFileContent("system_profiler_output3.txt"); + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodemfd121")); + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodemfd121")); - assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfd131")); - assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd131")); + output = getFileContent("system_profiler_output4.txt"); + assertEquals("0X2341_0X0041", extractVIDAndPID(output, "/dev/cu.usbmodem411")); + assertEquals("0X2341_0X0041", extractVIDAndPID(output, "/dev/tty.usbmodem411")); - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output3.txt")); + output = getFileContent("system_profiler_output5.txt"); + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodem621")); + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodem621")); - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfd121")); - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd121")); + output = getFileContent("system_profiler_output6.txt"); + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodem1421")); + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodem1421")); - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output4.txt")); + output = getFileContent("system_profiler_output7.txt"); + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/cu.usbmodem24131")); + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodem24131")); + assertEquals("0X0403_0X6015", extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV")); + assertEquals("0X0403_0X6015", extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV")); - assertEquals("0X2341_0X0041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem411")); - assertEquals("0X2341_0X0041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem411")); + output = getFileContent("system_profiler_output8.txt"); + assertEquals("0X03EB_0X2157", extractVIDAndPID(output, "/dev/tty.usbmodemfd132")); + } - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output5.txt")); - - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem621")); - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem621")); - - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output6.txt")); - - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem1421")); - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem1421")); - - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output7.txt")); - - assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem24131")); - assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem24131")); - assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV")); - assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV")); - - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output8.txt")); - - assertEquals("0X03EB_0X2157", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd132")); + private String getFileContent(String filename) throws IOException { + InputStream resource = SystemProfilerParserTest.class.getResourceAsStream(filename); + return TestHelper.inputStreamToString(resource); } } diff --git a/arduino-core/src/processing/app/macosx/Platform.java b/arduino-core/src/processing/app/macosx/Platform.java index a7a6a75bb..31118c47f 100644 --- a/arduino-core/src/processing/app/macosx/Platform.java +++ b/arduino-core/src/processing/app/macosx/Platform.java @@ -172,7 +172,7 @@ public class Platform extends processing.app.Platform { } try { - String vidPid = new SystemProfilerParser().extractVIDAndPID(devicesListOutput, serial); + String vidPid = SystemProfilerParser.extractVIDAndPID(devicesListOutput, serial); if (vidPid == null) { return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); diff --git a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java index 2e1d77462..2ab97f116 100644 --- a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java +++ b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java @@ -19,19 +19,12 @@ public class SystemProfilerParser { private static final String DEV_TTY_USBMODEM = "/dev/tty.usbmodem"; private static final String DEV_CU_USBMODEM = "/dev/cu.usbmodem"; - private final Pattern vidRegex; - private final Pattern serialNumberRegex; - private final Pattern locationRegex; - private final Pattern pidRegex; + private static final Pattern serialNumberRegex = Pattern.compile("^Serial Number: (.+)$"); + private static final Pattern locationRegex = Pattern.compile("^Location ID: (.+)$"); + private static final Pattern pidRegex = Pattern.compile("^Product ID: (.+)$"); + private static final Pattern vidRegex = Pattern.compile("^Vendor ID: (.+)$"); - public SystemProfilerParser() { - this.serialNumberRegex = Pattern.compile("^Serial Number: (.+)$"); - this.locationRegex = Pattern.compile("^Location ID: (.+)$"); - this.pidRegex = Pattern.compile("^Product ID: (.+)$"); - this.vidRegex = Pattern.compile("^Vendor ID: (.+)$"); - } - - public String extractVIDAndPID(String output, String serial) throws IOException { + public synchronized static String extractVIDAndPID(String output, String serial) throws IOException { BufferedReader reader = new BufferedReader(new StringReader(output)); String devicePrefix; From 2ae36940c656175157962937108224ed939ece30 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Oct 2015 23:17:18 +0200 Subject: [PATCH 088/175] Fixed parsing for SystemProfiler on Macosx El Capitan Should alleviate #3928 --- .../app/macosx/SystemProfilerParserTest.java | 4 + .../app/macosx/system_profiler_output9.txt | 117 ++++++++++++++++++ .../app/macosx/SystemProfilerParser.java | 2 +- 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 app/test/processing/app/macosx/system_profiler_output9.txt diff --git a/app/test/processing/app/macosx/SystemProfilerParserTest.java b/app/test/processing/app/macosx/SystemProfilerParserTest.java index a958282a2..2fce4d00f 100644 --- a/app/test/processing/app/macosx/SystemProfilerParserTest.java +++ b/app/test/processing/app/macosx/SystemProfilerParserTest.java @@ -74,6 +74,10 @@ public class SystemProfilerParserTest { output = getFileContent("system_profiler_output8.txt"); assertEquals("0X03EB_0X2157", extractVIDAndPID(output, "/dev/tty.usbmodemfd132")); + + // OSX El Capitan + output = getFileContent("system_profiler_output9.txt"); + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodemFA121")); } private String getFileContent(String filename) throws IOException { diff --git a/app/test/processing/app/macosx/system_profiler_output9.txt b/app/test/processing/app/macosx/system_profiler_output9.txt new file mode 100644 index 000000000..ca82cedd4 --- /dev/null +++ b/app/test/processing/app/macosx/system_profiler_output9.txt @@ -0,0 +1,117 @@ +USB: + + USB 2.0 Bus: + + Host Controller Driver: AppleUSBEHCIPCI + PCI Device ID: 0x1c2d + PCI Revision ID: 0x0005 + PCI Vendor ID: 0x8086 + + Hub: + + Product ID: 0x2513 + Vendor ID: 0x0424 (SMSC) + Version: b.b3 + Speed: Up to 480 Mb/sec + Location ID: 0xfa100000 / 1 + Current Available (mA): 1000 + Current Required (mA): 2 + Extra Operating Current (mA): 0 + Built-In: Yes + + Arduino Leonardo: + + Product ID: 0x8036 + Vendor ID: 0x2341 + Version: 1.00 + Speed: Up to 12 Mb/sec + Manufacturer: Arduino LLC + Location ID: 0xfa120000 / 3 + Current Available (mA): 1000 + Current Required (mA): 500 + Extra Operating Current (mA): 0 + + BRCM20702 Hub: + + Product ID: 0x4500 + Vendor ID: 0x0a5c (Broadcom Corp.) + Version: 1.00 + Speed: Up to 12 Mb/sec + Manufacturer: Apple Inc. + Location ID: 0xfa110000 / 4 + Current Available (mA): 1000 + Current Required (mA): 94 + Extra Operating Current (mA): 0 + Built-In: Yes + + Bluetooth USB Host Controller: + + Product ID: 0x8281 + Vendor ID: 0x05ac (Apple Inc.) + Version: 1.51 + Speed: Up to 12 Mb/sec + Manufacturer: Apple Inc. + Location ID: 0xfa113000 / 2 + Current Available (mA): 1000 + Current Required (mA): 0 + Extra Operating Current (mA): 0 + Built-In: Yes + + USB 2.0 Bus: + + Host Controller Driver: AppleUSBEHCIPCI + PCI Device ID: 0x1c26 + PCI Revision ID: 0x0005 + PCI Vendor ID: 0x8086 + + Hub: + + Product ID: 0x2513 + Vendor ID: 0x0424 (SMSC) + Version: b.b3 + Speed: Up to 480 Mb/sec + Location ID: 0xfd100000 / 1 + Current Available (mA): 1000 + Current Required (mA): 2 + Extra Operating Current (mA): 0 + Built-In: Yes + + USB Keyboard: + + Product ID: 0x2000 + Vendor ID: 0x040b (Weltrend Semiconductor) + Version: 2.05 + Speed: Up to 1.5 Mb/sec + Manufacturer: Generic + Location ID: 0xfd130000 / 4 + Current Available (mA): 1000 + Current Required (mA): 100 + Extra Operating Current (mA): 0 + + USB OPTICAL MOUSE: + + Product ID: 0x2510 + Vendor ID: 0x093a (Pixart Imaging, Inc.) + Version: 1.00 + Speed: Up to 1.5 Mb/sec + Manufacturer: PIXART + Location ID: 0xfd120000 / 3 + Current Available (mA): 1000 + Current Required (mA): 100 + Extra Operating Current (mA): 0 + + IR Receiver: + + Product ID: 0x8242 + Vendor ID: 0x05ac (Apple Inc.) + Version: 0.16 + Speed: Up to 1.5 Mb/sec + Manufacturer: Apple Computer, Inc. + Location ID: 0xfd110000 / 2 + Current Available (mA): 1000 + Current Required (mA): 100 + Extra Operating Current (mA): 0 + Built-In: Yes + + + diff --git a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java index 2ab97f116..73f692bf3 100644 --- a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java +++ b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java @@ -73,7 +73,7 @@ public class SystemProfilerParser { String computedDevicePath = device.get(DEVICE_PATH); String computedDevicePathMinusChar = computedDevicePath.substring(0, computedDevicePath.length() - 1); String serialMinusChar = serial.substring(0, serial.length() - 1); - if (computedDevicePath.equals(serial) || computedDevicePathMinusChar.equals(serialMinusChar)) { + if (computedDevicePath.equalsIgnoreCase(serial) || computedDevicePathMinusChar.equalsIgnoreCase(serialMinusChar)) { return (device.get(VID) + "_" + device.get(PID)).toUpperCase(); } } From b945df9220e09461520bb19decf0a540fbd9c9fb Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 13 Oct 2015 15:13:31 +0200 Subject: [PATCH 089/175] [USB] use plugged modules name to create iSerial field --- .../avr/cores/arduino/PluggableUSB.cpp | 9 ++++++++ .../arduino/avr/cores/arduino/PluggableUSB.h | 2 ++ .../arduino/avr/cores/arduino/USBCore.cpp | 21 +++++++++++++------ hardware/arduino/avr/cores/arduino/USBDesc.h | 8 ++++--- hardware/arduino/avr/libraries/HID/HID.cpp | 10 +++++++++ hardware/arduino/avr/libraries/HID/HID.h | 1 + 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 7a6351d8e..c489d9f1a 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -50,6 +50,15 @@ int PluggableUSB_::getDescriptor(USBSetup& setup) return 0; } +void PluggableUSB_::getShortName(char *iSerialNum) +{ + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + iSerialNum += node->getShortName(iSerialNum); + } + *iSerialNum = 0; +} + bool PluggableUSB_::setup(USBSetup& setup) { PluggableUSBModule* node; diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 3df9bfff5..507f0df9b 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -35,6 +35,7 @@ protected: virtual bool setup(USBSetup& setup) = 0; virtual int getInterface(uint8_t* interfaceCount) = 0; virtual int getDescriptor(USBSetup& setup) = 0; + virtual uint8_t getShortName(char *name) { name[0] = 'A'+pluggedInterface; return 1; } uint8_t pluggedInterface; uint8_t pluggedEndpoint; @@ -55,6 +56,7 @@ public: int getInterface(uint8_t* interfaceCount); int getDescriptor(USBSetup& setup); bool setup(USBSetup& setup); + void getShortName(char *iSerialNum); private: uint8_t lastIf; diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index f67bfeabc..3c6610cd6 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -18,6 +18,7 @@ #include "USBAPI.h" #include "PluggableUSB.h" +#include #if defined(USBCON) @@ -69,10 +70,10 @@ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER; // DEVICE DESCRIPTOR const DeviceDescriptor USB_DeviceDescriptor = - D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); + D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1); const DeviceDescriptor USB_DeviceDescriptorB = - D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); + D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1); //================================================================== //================================================================== @@ -409,11 +410,12 @@ int USB_SendControl(u8 flags, const void* d, int len) // Send a USB descriptor string. The string is stored in PROGMEM as a // plain ASCII string but is sent out as UTF-16 with the correct 2-byte // prefix -static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len) { +static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len, uint8_t flags) { SendControl(2 + string_len * 2); SendControl(3); + bool pgm = flags & TRANSFER_PGM; for(u8 i = 0; i < string_len; i++) { - bool r = SendControl(pgm_read_byte(&string_P[i])); + bool r = SendControl(pgm ? pgm_read_byte(&string_P[i]) : string_P[i]); r &= SendControl(0); // high byte if(!r) { return false; @@ -495,10 +497,17 @@ bool SendDescriptor(USBSetup& setup) desc_addr = (const u8*)&STRING_LANGUAGE; } else if (setup.wValueL == IPRODUCT) { - return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT)); + return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT), TRANSFER_PGM); } else if (setup.wValueL == IMANUFACTURER) { - return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER)); + return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER), TRANSFER_PGM); + } + else if (setup.wValueL == ISERIAL) { +#ifdef PLUGGABLE_USB_ENABLED + char name[ISERIAL_MAX_LEN]; + PluggableUSB().getShortName(name); + return USB_SendStringDescriptor((uint8_t*)name, strlen(name), 0); +#endif } else return false; diff --git a/hardware/arduino/avr/cores/arduino/USBDesc.h b/hardware/arduino/avr/cores/arduino/USBDesc.h index 4b9cf6636..c0dce079e 100644 --- a/hardware/arduino/avr/cores/arduino/USBDesc.h +++ b/hardware/arduino/avr/cores/arduino/USBDesc.h @@ -24,6 +24,8 @@ #define USB_ENDPOINTS 5 // AtMegaxxU2 #endif +#define ISERIAL_MAX_LEN 20 + #define CDC_INTERFACE_COUNT 2 #define CDC_ENPOINT_COUNT 3 @@ -39,6 +41,6 @@ #define CDC_RX CDC_ENDPOINT_OUT #define CDC_TX CDC_ENDPOINT_IN -#define IMANUFACTURER 1 -#define IPRODUCT 2 - +#define IMANUFACTURER 1 +#define IPRODUCT 2 +#define ISERIAL 3 \ No newline at end of file diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 411529ecf..1a432fffd 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -57,6 +57,16 @@ int HID_::getDescriptor(USBSetup& setup) return total; } +uint8_t HID_::getShortName(char *name) +{ + name[0] = 'H'; + name[1] = 'I'; + name[2] = 'D'; + name[3] = 'A' + (descriptorSize & 0x0F); + name[4] = 'A' + ((descriptorSize >> 4) & 0x0F); + return 5; +} + void HID_::AppendDescriptor(HIDSubDescriptor *node) { if (!rootNode) { diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index ba08da7be..b6638c889 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -96,6 +96,7 @@ protected: int getInterface(uint8_t* interfaceCount); int getDescriptor(USBSetup& setup); bool setup(USBSetup& setup); + uint8_t getShortName(char* name); private: uint8_t epType[1]; From 775c82bbedac002f11ba654b7e25702ba73dcddd Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 21 Oct 2015 16:16:52 +0200 Subject: [PATCH 090/175] SAM: add iSerial USB field --- .../arduino/sam/cores/arduino/USB/PluggableUSB.cpp | 9 +++++++++ hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h | 2 ++ hardware/arduino/sam/cores/arduino/USB/USBCore.cpp | 11 +++++++++-- hardware/arduino/sam/cores/arduino/USB/USBDesc.h | 3 +++ hardware/arduino/sam/libraries/HID/HID.cpp | 10 ++++++++++ hardware/arduino/sam/libraries/HID/HID.h | 1 + 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp index 0f2d08c0d..e196da847 100644 --- a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp @@ -52,6 +52,15 @@ int PluggableUSB_::getDescriptor(USBSetup& setup) return 0; } +void PluggableUSB_::getShortName(char *iSerialNum) +{ + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + iSerialNum += node->getShortName(iSerialNum); + } + *iSerialNum = 0; +} + bool PluggableUSB_::setup(USBSetup& setup) { PluggableUSBModule* node; diff --git a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h index eb18ca253..4e08e5dfc 100644 --- a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h +++ b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h @@ -35,6 +35,7 @@ protected: virtual bool setup(USBSetup& setup) = 0; virtual int getInterface(uint8_t* interfaceCount) = 0; virtual int getDescriptor(USBSetup& setup) = 0; + virtual uint8_t getShortName(char *name) { name[0] = 'A'+pluggedInterface; return 1; } uint8_t pluggedInterface; uint8_t pluggedEndpoint; @@ -55,6 +56,7 @@ public: int getInterface(uint8_t* interfaceCount); int getDescriptor(USBSetup& setup); bool setup(USBSetup& setup); + void getShortName(char *iSerialNum); private: uint8_t lastIf; diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 6631ec006..56c4577b8 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -96,10 +96,10 @@ const uint8_t STRING_MANUFACTURER[12] = USB_MANUFACTURER; // DEVICE DESCRIPTOR const DeviceDescriptor USB_DeviceDescriptor = - D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); + D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1); const DeviceDescriptor USB_DeviceDescriptorA = - D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); + D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1); const QualifierDescriptor USB_DeviceQualifier = D_QUALIFIER(0x00,0x00,0x00,64,1); @@ -429,6 +429,13 @@ static bool USBD_SendDescriptor(USBSetup& setup) else if (setup.wValueL == IMANUFACTURER) { return USB_SendStringDescriptor(STRING_MANUFACTURER, setup.wLength); } + else if (setup.wValueL == ISERIAL) { +#ifdef PLUGGABLE_USB_ENABLED + char name[ISERIAL_MAX_LEN]; + PluggableUSB().getShortName(name); + return USB_SendStringDescriptor((uint8_t*)name, setup.wLength); +#endif + } else { return false; } diff --git a/hardware/arduino/sam/cores/arduino/USB/USBDesc.h b/hardware/arduino/sam/cores/arduino/USB/USBDesc.h index 389967cf9..f8f53ce17 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBDesc.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBDesc.h @@ -42,7 +42,10 @@ #define CDC_TX CDC_ENDPOINT_IN #endif +#define ISERIAL_MAX_LEN 20 + #define IMANUFACTURER 1 #define IPRODUCT 2 +#define ISERIAL 3 #endif /* __USBDESC_H__ */ diff --git a/hardware/arduino/sam/libraries/HID/HID.cpp b/hardware/arduino/sam/libraries/HID/HID.cpp index 8d3a5a52e..f27f8349a 100644 --- a/hardware/arduino/sam/libraries/HID/HID.cpp +++ b/hardware/arduino/sam/libraries/HID/HID.cpp @@ -57,6 +57,16 @@ int HID_::getDescriptor(USBSetup& setup) return total; } +uint8_t HID_::getShortName(char *name) +{ + name[0] = 'H'; + name[1] = 'I'; + name[2] = 'D'; + name[3] = 'A' + (descriptorSize & 0x0F); + name[4] = 'A' + ((descriptorSize >> 4) & 0x0F); + return 5; +} + void HID_::AppendDescriptor(HIDSubDescriptor *node) { if (!rootNode) { diff --git a/hardware/arduino/sam/libraries/HID/HID.h b/hardware/arduino/sam/libraries/HID/HID.h index 48ed91530..d7754860a 100644 --- a/hardware/arduino/sam/libraries/HID/HID.h +++ b/hardware/arduino/sam/libraries/HID/HID.h @@ -96,6 +96,7 @@ protected: int getInterface(uint8_t* interfaceCount); int getDescriptor(USBSetup& setup); bool setup(USBSetup& setup); + uint8_t getShortName(char* name); private: uint32_t epType[1]; From d56e3848b4227d94dca5c5b511b832c7cb798291 Mon Sep 17 00:00:00 2001 From: Arturo Guadalupi Date: Thu, 22 Oct 2015 12:38:01 +0200 Subject: [PATCH 091/175] Modified project14 for compatibility to Processing 3 --- .../p14_TweakTheArduinoLogo.ino | 102 +++++++++--------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino b/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino index a1e94ebc4..28cf7963e 100644 --- a/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino +++ b/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino @@ -34,71 +34,69 @@ void loop() { } /* Processing code for this example - // Tweak the Arduno Logo - // by Scott Fitzgerald - // This example code is in the public domain +// Tweak the Arduno Logo +// by Scott Fitzgerald +// This example code is in the public domain - // import the serial library - import processing.serial.*; +// import the serial library +import processing.serial.*; - // create an instance of the serial library - Serial myPort; +// create an instance of the serial library +Serial myPort; - // create an instance of PImage - PImage logo; +// create an instance of PImage +PImage logo; - // a variable to hold the background color - int bgcolor = 0; +// a variable to hold the background color +int bgcolor = 0; - void setup() { - // set the color mode to Hue/Saturation/Brightness - colorMode(HSB, 255); +void setup() { + size(1, 1); + surface.setResizable(true); + // set the color mode to Hue/Saturation/Brightness + colorMode(HSB, 255); - // load the Arduino logo into the PImage instance - logo = loadImage("http://www.arduino.cc/en/pub/skins/arduinoWide/img/logo.png"); + // load the Arduino logo into the PImage instance + logo = loadImage("http://www.arduino.cc/arduino_logo.png"); - // make the window the same size as the image - size(logo.width, logo.height); + // make the window the same size as the image + surface.setSize(logo.width, logo.height); - // print a list of available serial ports to the - // Processing staus window - println("Available serial ports:"); - println(Serial.list()); + // print a list of available serial ports to the + // Processing staus window + println("Available serial ports:"); + println(Serial.list()); - // Tell the serial object the information it needs to communicate - // with the Arduno. Change Serial.list()[0] to the correct - // port corresponding to your Arduino board. The last - // parameter (e.g. 9600) is the speed of the communication. It - // has to correspond to the value passed to Serial.begin() in your - // Arduino sketch. - myPort = new Serial(this, Serial.list()[0], 9600); + // Tell the serial object the information it needs to communicate + // with the Arduno. Change Serial.list()[0] to the correct + // port corresponding to your Arduino board. The last + // parameter (e.g. 9600) is the speed of the communication. It + // has to correspond to the value passed to Serial.begin() in your + // Arduino sketch. + myPort = new Serial(this, Serial.list()[0], 9600); - // If you know the name of the port used by the Arduino board, you - // can specify it directly like this. - // port = new Serial(this, "COM1", 9600); + // If you know the name of the port used by the Arduino board, you + // can specify it directly like this. + // port = new Serial(this, "COM1", 9600); +} - } +void draw() { - void draw() { + // if there is information in the serial port + if ( myPort.available() > 0) { + // read the value and store it in a variable + bgcolor = myPort.read(); - // if there is information in the serial port - if ( myPort.available() > 0) { - // read the value and store it in a variable - bgcolor = myPort.read(); + // print the value to the status window + println(bgcolor); + } - // print the value to the status window - println(bgcolor); - } - - // Draw the background. the variable bgcolor - // contains the Hue, determined by the value - // from the serial port - background(bgcolor, 255, 255); - - // draw the Arduino logo - image(logo, 0, 0); - } + // Draw the background. the variable bgcolor + // contains the Hue, determined by the value + // from the serial port + background(bgcolor, 255, 255); + // draw the Arduino logo + image(logo, 0, 0); +} */ - - From 589b411be710cf9e192f04b65a1adc9d758f9d9c Mon Sep 17 00:00:00 2001 From: Arturo Guadalupi Date: Thu, 22 Oct 2015 12:42:05 +0200 Subject: [PATCH 092/175] Changed commit to indicate Processing 3 The example is now tested and works with Processing 3. Comment was missing. --- .../p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino b/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino index 28cf7963e..2173f6eec 100644 --- a/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino +++ b/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino @@ -9,8 +9,8 @@ 10 kilohm potentiometer Software required : - Processing http://processing.org - Active internet connection + Processing (3.0 or newer) http://processing.org + Active internet connection Created 18 September 2012 by Scott Fitzgerald From 48ff3a10ad465afc08a76874cf0e9ef25a6da86a Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Thu, 27 Aug 2015 10:57:20 -0400 Subject: [PATCH 093/175] release TWI bus right after stop or repeated start is condition this resolves timing issues seen in #1477 --- hardware/arduino/avr/libraries/Wire/utility/twi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/avr/libraries/Wire/utility/twi.c b/hardware/arduino/avr/libraries/Wire/utility/twi.c index b436e6907..9fb87f133 100644 --- a/hardware/arduino/avr/libraries/Wire/utility/twi.c +++ b/hardware/arduino/avr/libraries/Wire/utility/twi.c @@ -476,6 +476,8 @@ ISR(TWI_vect) } break; case TW_SR_STOP: // stop or repeated start condition received + // ack future responses and leave slave receiver state + twi_releaseBus(); // put a null char after data if there's room if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){ twi_rxBuffer[twi_rxBufferIndex] = '\0'; @@ -484,8 +486,6 @@ ISR(TWI_vect) twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex); // since we submit rx buffer to "wire" library, we can reset it twi_rxBufferIndex = 0; - // ack future responses and leave slave receiver state - twi_releaseBus(); break; case TW_SR_DATA_NACK: // data received, returned nack case TW_SR_GCALL_DATA_NACK: // data received generally, returned nack From c71f5e9f883bac00f4013e4c94579bbd81002c58 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 28 Aug 2015 10:25:56 -0400 Subject: [PATCH 094/175] check TWWC (Write Collision Flag) bit after setting TWDR as suggested by @earlyprogrammer in #2173, to ensure TWDR value is set if there is a write collision --- hardware/arduino/avr/libraries/Wire/utility/twi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/avr/libraries/Wire/utility/twi.c b/hardware/arduino/avr/libraries/Wire/utility/twi.c index 9fb87f133..2af0597dd 100644 --- a/hardware/arduino/avr/libraries/Wire/utility/twi.c +++ b/hardware/arduino/avr/libraries/Wire/utility/twi.c @@ -167,7 +167,9 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen // up. Also, don't enable the START interrupt. There may be one pending from the // repeated start that we sent outselves, and that would really confuse things. twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR - TWDR = twi_slarw; + do { + TWDR = twi_slarw; + } while(TWCR & _BV(TWWC)); TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START } else @@ -247,7 +249,9 @@ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait // up. Also, don't enable the START interrupt. There may be one pending from the // repeated start that we sent outselves, and that would really confuse things. twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR - TWDR = twi_slarw; + do { + TWDR = twi_slarw; + } while(TWCR & _BV(TWWC)); TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START } else From 5b64cebdc581972c8d9e2ff8269ab46a0d2703c6 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Thu, 22 Oct 2015 15:27:12 -0700 Subject: [PATCH 095/175] Simplify and clarify new HID error messages. The libraries in question are supported on a number of official Arduino boards. The new error message tries to be a bit more helpful. --- arduino-core/src/cc/arduino/Compiler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java index 0280a8a2d..d5940ad70 100644 --- a/arduino-core/src/cc/arduino/Compiler.java +++ b/arduino-core/src/cc/arduino/Compiler.java @@ -549,12 +549,12 @@ public class Compiler implements MessageConsumer { } if (error.trim().equals("'Mouse' was not declared in this scope")) { - error = tr("'Mouse' only supported on the Arduino Leonardo"); + error = tr("'Mouse' not found. Does your sketch include the line '#include '?"); //msg = _("\nThe 'Mouse' class is only supported on the Arduino Leonardo.\n\n"); } if (error.trim().equals("'Keyboard' was not declared in this scope")) { - error = tr("'Keyboard' only supported on the Arduino Leonardo"); + error = tr("'Keyboard' not found. Does your sketch include the line '#include '?"); //msg = _("\nThe 'Keyboard' class is only supported on the Arduino Leonardo.\n\n"); } From e3351f6fb1717ce167a9c16781cf2c726f3d239e Mon Sep 17 00:00:00 2001 From: Arturo Guadalupi Date: Fri, 23 Oct 2015 10:16:43 +0200 Subject: [PATCH 096/175] Ethernet digitalPinToInterrupt support Added support for Arduino Ethernet as required in #3929 --- hardware/arduino/avr/variants/ethernet/pins_arduino.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hardware/arduino/avr/variants/ethernet/pins_arduino.h b/hardware/arduino/avr/variants/ethernet/pins_arduino.h index f6773a044..a11ecfc61 100644 --- a/hardware/arduino/avr/variants/ethernet/pins_arduino.h +++ b/hardware/arduino/avr/variants/ethernet/pins_arduino.h @@ -58,6 +58,8 @@ static const uint8_t A7 = 21; #define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0)))) #define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14))) +#define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT)) + #ifdef ARDUINO_MAIN // On the Arduino board, digital pins are also used From d52b5a87ba640fb6cdb933c68342aa3880892085 Mon Sep 17 00:00:00 2001 From: Arturo Guadalupi Date: Fri, 23 Oct 2015 10:44:02 +0200 Subject: [PATCH 097/175] Gemma digitalPinToInterrupt support Added support for Arduino Gemma as required in #3929 --- hardware/arduino/avr/variants/gemma/pins_arduino.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hardware/arduino/avr/variants/gemma/pins_arduino.h b/hardware/arduino/avr/variants/gemma/pins_arduino.h index 3150b6a6f..0af67c61c 100644 --- a/hardware/arduino/avr/variants/gemma/pins_arduino.h +++ b/hardware/arduino/avr/variants/gemma/pins_arduino.h @@ -54,6 +54,8 @@ static const uint8_t A3 = 9; #define digitalPinToPCMSK(p) ( ((p) <= 4) ? (&PCMSK) : ((uint8_t *)0) ) #define digitalPinToPCMSKbit(p) ( (p) ) +#define digitalPinToInterrupt(p) ((p) == 2 ? 0 : NOT_AN_INTERRUPT) + #define analogPinToChannel(p) ( (p) < 6 ? (p) : (p) - 6 ) #define TCCR1A GTCCR From b01eda179a559a12919ef03df89cd84102f7d3c0 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 26 Oct 2015 12:00:47 +0100 Subject: [PATCH 098/175] Print not aborting on write failure See #3614 --- build/shared/revisions.txt | 1 + hardware/arduino/sam/cores/arduino/Print.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 4411177a2..3389df5de 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -31,6 +31,7 @@ ARDUINO 1.6.6 [core] * AVR: fixed wrong turnOffPWM() for TIMER0B. Thanks @gonzoveliki * ArduinoISP is now compatible with every architecture (not only AVR) and is much more stable. Thanks @PeterVH +* Print not aborting on write() failure. Thanks @stickbreaker ARDUINO 1.6.5-r5 - 2015.08.28 diff --git a/hardware/arduino/sam/cores/arduino/Print.cpp b/hardware/arduino/sam/cores/arduino/Print.cpp index 379631955..6ae81609e 100644 --- a/hardware/arduino/sam/cores/arduino/Print.cpp +++ b/hardware/arduino/sam/cores/arduino/Print.cpp @@ -17,6 +17,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Modified 23 November 2006 by David A. Mellis + Modified 03 August 2015 by Chuck Todd */ #include @@ -34,7 +35,8 @@ size_t Print::write(const uint8_t *buffer, size_t size) { size_t n = 0; while (size--) { - n += write(*buffer++); + if (write(*buffer++)) n++; + else break; } return n; } From e20f818ea30b8d52755d2b92efde8a0f3fe39a61 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 26 Oct 2015 12:48:37 +0100 Subject: [PATCH 099/175] Updated revision log --- build/shared/revisions.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 3389df5de..a3248e146 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -23,15 +23,36 @@ ARDUINO 1.6.6 * "Go to line": CTRL+L or Edit > Go to line... will open a dialog where you can type the line number where you want the editor to jump to * Added boards.local.txt support: like platform.local.txt, allows to enrich a boards.txt definition without modifying the original file. Thanks @Wackerbarth * Library to library dependencies: when your sketch imports a library, and that library uses another, the IDE will find out without you having to add a useless #include to your sketch +* Allow per-platform keywords.txt. Thanks @PaulStoffregen +* Allow spaces in IDE install path on Linux. Thanks @matthijskooijman +* Fixed a lot of documentation. Thanks to @per1234 @q2dg +* Fixed parsing for SystemProfiler when scanning for available serial ports on Macosx El Capitan [libraries] * Bridge: YunClient.connected() returns true if there are bytes available for read. Thanks @RobAtticus * Bridge: YunClient.stop() now empties all buffers. Thanks @RobAtticus +* Ethernet: Added missing keywords. Thanks @per1234 +* Ethernet: Fixed DNSClient.inet_aton() function. Thanks @jhorck +* Ethernet: Expose optional DHCP timout parameters to Ethernet:begin(). Thanks @chaveiro +* Wire: Implemented Wire.end() for AVR. +* Wire: Fixed bug with repeated START for AVR. Thanks Nate Williams +* Wire: Resolved timing issues on AVR. See #2173 #1477. +* SD: Change "char *" to "const char *" on methods accepting a string as a parameter. Thanks @Ivan-Perez [core] +* Added new PluggableUSB and HID support. This change introduces a more powerful API for + libraries that wants use advanced features of USB-Device. + Thanks to @obra @NicoHood @matthijskooijman @nospam2000 @weizenspreu * AVR: fixed wrong turnOffPWM() for TIMER0B. Thanks @gonzoveliki +* AVR: added support for AtmegaXXu2. Thanks @NicoHood +* AVR: a bunch of USB Core bug fix. Thanks @NicoHood +* AVR: Expose serial setting from USB-CDC serial port. Thanks @matthijskooijman * ArduinoISP is now compatible with every architecture (not only AVR) and is much more stable. Thanks @PeterVH * Print not aborting on write() failure. Thanks @stickbreaker +* AVR: Faster interrupts patch. Thanks @xxxajk +* AVR: Fixed pulseInLong wrong measurements. +* AVR: Removed a bunch of compiler warnings. Thanks @NicoHood +* Improved variants files for Boards Gemma and Ethernet ARDUINO 1.6.5-r5 - 2015.08.28 From 6aa8b75a84051b0e54ebc55c45b6cfe3474ded55 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 26 Oct 2015 13:21:06 +0100 Subject: [PATCH 100/175] Updated driver for win --- build/windows/dist/drivers/genuino.cat | Bin 8193 -> 8369 bytes build/windows/dist/drivers/genuino.inf | 10 +++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/build/windows/dist/drivers/genuino.cat b/build/windows/dist/drivers/genuino.cat index 2c250449bc04116b25311af11965409a1a85c267..344a96f30374453cb433e3c5a1112423b3b3b2c3 100755 GIT binary patch delta 919 zcmZp4*yvbq(4?@IjZ>@5qwPB{BRkWACWU!Gp;=6fjE39>oNTPxe9TNztPBQCEO*&B zwb>Y17@N$w7#B3LoC6A-GT>q3f(r65GO`G$?~U-?`n%d|rqG(8tKaV(6z4TGH8e0X zGc+=^G&GAc;6qZ*1TuAEJ%_&&gBybjg8_pxgDHbKgE5fp#$XAgLC_2+;sz9V0b(~G zbOow20gF2W*=7tDK(-T*HehfBii7mIOuSYmvj4)-;`@`0)4yK*|G+utS@Sk7|GASB z7$379F=%2sFxi9YCZpM86&3@f6b1$cgBXOXm>60741DCc7(5ul89YJOPA*~A<2PYQ zVNhepWyoZR2U=yYnUR@WQlwi^_|rl8_~!wNE+VQIT=jnic>SBKAY)zcUhgehQLM1S zM(T{_-uk7J*rkO&Kif9@vR)yFg3yA837?DSzDwJ4sq&u{+bNq@4u<=JJLZ2!+PBjeVF|cwG15mTNXw&Fxn;ePB58h)FN* z)HkND+g#4L%x$kbrJ%xg+(Bjzr(ykan?_HCiVe&aJM5iOKFMy&&-nZ{uyKLehorNM zp80WIzPF~q%&R}wqNHMDq4rV^G*dsRkle_+j9I&6>mXf6OTx<^4|q73S{zv=A0-w@rgZ{ zNzr<8wCrI6NW>c%7+OXdD8thjCySvNi^weT+f^s>=6p6@J$22&{7Dmgrj*^8>?gOm zz91{f?D)rDmSq_W`AuJj?0&2^_qToI@=q;|ldX;im$py2yS&5c+w(PA83(-$^)Z9eI$1p?s*% zPWbqJgFoli#BymnW*ynsDO1tb@y|*>p<s?u*`i$AqL*%Ohv{PcRikIenk zt)8gGZ%&CWX(=$?oRc++HQoGB%a44?xVtAi=day8OJu*UPUo7{E8d;okYg>i#`Gaa z>MDb2LWSAdE)B`i8$ZrtzPpzF_C}63jlC_4_v%!rzRBE|bs=MF+phz!c_dsO$TFrK RVv;JWWYgR!#Lo0h2>{$#V>@5qwPB{BRkWACi!oNTPxe9TNztPBQCEV^u* z+H8z0j7{cTj0>7rMiznXJI{PM#M|Mzrm#CP;Nyovab81H0}CTF z0}E3FW8)|TJ|yK#AX6vSbNIV37&90#xG|V8I5HS8m;<2;kY~VP34}%r&Onv{Pz0pL z83M&f^Ia@pTZmXen%7w`Z zjE`AG44Rk(CVMd5+oapZGt!niSS<&7JW2_rB7m-V+RY)BbQu zUwBoRZd|y9yY~^}>5so-ihr_i-&=Uyy(0OVuDO%j#IuhX8#k705SV#7KEv?oPp{*< zd6%%ZzYls87!#9q^7Xs7ET<=ZSg6EOKiBJ0S$*TTyEm348NB{==Hrd3=sZi+l7L&h zQQJ(bFC-QCKKc;3tFZf|!K(^Qo<+WkYPpibPpuD`e@btz7HjijsdmmYZgVHRo|nV3 zGtuVGIl1zmQRm;zK4o;-dd=;}S5)nyw;o*mhLg*1AxBJJ;N%zCeyp1>tP46{ek*-) z)gpf;-Ga&7a)%9|ac5!*j5}p`GT~$~6k`!Nn61>KT)1G~=ap-{9RjBtH8m70oBU61 zbA8?YDQotp+nkl>aApzlx$p6Ht#7!C`1+lno{BEDcYR;AM~(HK>fv9$+m!VGqq6Nvblmb<)51oB)$dRd?-SZ~8G~D}jJdKG(LGhfE}WR=psi~~2W8Saf) Tc86ukmyVB98`p1QvN`|&U*%%| diff --git a/build/windows/dist/drivers/genuino.inf b/build/windows/dist/drivers/genuino.inf index 25197a722..0786a49d6 100755 --- a/build/windows/dist/drivers/genuino.inf +++ b/build/windows/dist/drivers/genuino.inf @@ -35,6 +35,8 @@ unoR3.name="Genuino Uno" mega2560rev3.name="Genuino Mega 2560" micro.bootloader.name="Genuino Micro bootloader" micro.sketch.name="Genuino Micro" +zero.sketch.name="Genuino Zero" +zero.bootloader.name="Genuino Zero bootloader" [DefaultInstall] CopyINF=genuino.inf @@ -46,7 +48,7 @@ Signature="$Windows NT$" Provider=%ManufacturerName% DriverPackageDisplayName=%DriverPackageDisplayName% CatalogFile=genuino.cat -DriverVer=08/25/2015,1.0.1.0 +DriverVer=10/25/2015,1.0.2.0 [Manufacturer] %ManufacturerName%=DeviceList, NTamd64, NTia64 @@ -60,18 +62,24 @@ DefaultDestDir=12 %micro.bootloader.name%=DriverInstall, USB\VID_2341&PID_0237 %micro.sketch.name%=DriverInstall, USB\VID_2341&PID_8237&MI_00 %unoR3.name%=DriverInstall, USB\VID_2341&PID_0243 +%zero.sketch.name%=DriverInstall, USB\VID_2341&PID_824D&MI_00 +%zero.bootloader.name%=DriverInstall, USB\VID_2341&PID_024D [DeviceList.NTamd64] %mega2560rev3.name%=DriverInstall, USB\VID_2341&PID_0242 %micro.bootloader.name%=DriverInstall, USB\VID_2341&PID_0237 %micro.sketch.name%=DriverInstall, USB\VID_2341&PID_8237&MI_00 %unoR3.name%=DriverInstall, USB\VID_2341&PID_0243 +%zero.sketch.name%=DriverInstall, USB\VID_2341&PID_824D&MI_00 +%zero.bootloader.name%=DriverInstall, USB\VID_2341&PID_024D [DeviceList.NTia64] %mega2560rev3.name%=DriverInstall, USB\VID_2341&PID_0242 %micro.bootloader.name%=DriverInstall, USB\VID_2341&PID_0237 %micro.sketch.name%=DriverInstall, USB\VID_2341&PID_8237&MI_00 %unoR3.name%=DriverInstall, USB\VID_2341&PID_0243 +%zero.sketch.name%=DriverInstall, USB\VID_2341&PID_824D&MI_00 +%zero.bootloader.name%=DriverInstall, USB\VID_2341&PID_024D [DriverInstall] include=mdmcpq.inf,usb.inf From 54ec785fd211c5c1142dc35995e832edd11095e3 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 26 Oct 2015 15:36:36 +0100 Subject: [PATCH 101/175] Updating bundled reference --- build/build.xml | 4 ++-- build/shared/reference-1.6.6-2.zip.sha | 1 - build/shared/reference-1.6.6-3.zip.sha | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 build/shared/reference-1.6.6-2.zip.sha create mode 100644 build/shared/reference-1.6.6-3.zip.sha diff --git a/build/build.xml b/build/build.xml index 8359e30b4..565c1618f 100644 --- a/build/build.xml +++ b/build/build.xml @@ -155,8 +155,8 @@ - - + + diff --git a/build/shared/reference-1.6.6-2.zip.sha b/build/shared/reference-1.6.6-2.zip.sha deleted file mode 100644 index 794998c7e..000000000 --- a/build/shared/reference-1.6.6-2.zip.sha +++ /dev/null @@ -1 +0,0 @@ -ca51b6e4e299b3c6b544768783780218dd8e12e5 diff --git a/build/shared/reference-1.6.6-3.zip.sha b/build/shared/reference-1.6.6-3.zip.sha new file mode 100644 index 000000000..eff35eeff --- /dev/null +++ b/build/shared/reference-1.6.6-3.zip.sha @@ -0,0 +1 @@ +cc4f36c9783772f07c9a1bb4a60d7be3b504c69e From 0102a58122ae7b5a73e9f711769c9fcdc7eee59d Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 26 Oct 2015 15:49:31 +0100 Subject: [PATCH 102/175] "static" makes sense for constants and few other things. Avoid it if you don't have a specific reason for using it. --- .../app/macosx/SystemProfilerParserTest.java | 49 +++++++++++-------- .../src/processing/app/macosx/Platform.java | 2 +- .../app/macosx/SystemProfilerParser.java | 21 +++++--- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/app/test/processing/app/macosx/SystemProfilerParserTest.java b/app/test/processing/app/macosx/SystemProfilerParserTest.java index 2fce4d00f..7c6e70d52 100644 --- a/app/test/processing/app/macosx/SystemProfilerParserTest.java +++ b/app/test/processing/app/macosx/SystemProfilerParserTest.java @@ -29,55 +29,62 @@ package processing.app.macosx; +import org.junit.Before; import org.junit.Test; import processing.app.TestHelper; -import static org.junit.Assert.assertEquals; -import static processing.app.macosx.SystemProfilerParser.extractVIDAndPID; - import java.io.IOException; import java.io.InputStream; +import static org.junit.Assert.assertEquals; + public class SystemProfilerParserTest { + private SystemProfilerParser parser; + + @Before + public void setUp() throws Exception { + parser = new SystemProfilerParser(); + } + @Test public void shouldCorrectlyParse() throws Exception { String output = getFileContent("system_profiler_output.txt"); - assertEquals("0X2341_0X0044", extractVIDAndPID(output, "/dev/cu.usbmodemfa121")); - assertEquals("0X2341_0X0044", extractVIDAndPID(output, "/dev/tty.usbmodemfa121")); + assertEquals("0X2341_0X0044", parser.extractVIDAndPID(output, "/dev/cu.usbmodemfa121")); + assertEquals("0X2341_0X0044", parser.extractVIDAndPID(output, "/dev/tty.usbmodemfa121")); output = getFileContent("system_profiler_output2.txt"); - assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/cu.usbmodemfd131")); - assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodemfd131")); + assertEquals("0X2341_0X8036", parser.extractVIDAndPID(output, "/dev/cu.usbmodemfd131")); + assertEquals("0X2341_0X8036", parser.extractVIDAndPID(output, "/dev/tty.usbmodemfd131")); output = getFileContent("system_profiler_output3.txt"); - assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodemfd121")); - assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodemfd121")); + assertEquals("0X2341_0X8041", parser.extractVIDAndPID(output, "/dev/cu.usbmodemfd121")); + assertEquals("0X2341_0X8041", parser.extractVIDAndPID(output, "/dev/tty.usbmodemfd121")); output = getFileContent("system_profiler_output4.txt"); - assertEquals("0X2341_0X0041", extractVIDAndPID(output, "/dev/cu.usbmodem411")); - assertEquals("0X2341_0X0041", extractVIDAndPID(output, "/dev/tty.usbmodem411")); + assertEquals("0X2341_0X0041", parser.extractVIDAndPID(output, "/dev/cu.usbmodem411")); + assertEquals("0X2341_0X0041", parser.extractVIDAndPID(output, "/dev/tty.usbmodem411")); output = getFileContent("system_profiler_output5.txt"); - assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodem621")); - assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodem621")); + assertEquals("0X2341_0X8041", parser.extractVIDAndPID(output, "/dev/cu.usbmodem621")); + assertEquals("0X2341_0X8041", parser.extractVIDAndPID(output, "/dev/tty.usbmodem621")); output = getFileContent("system_profiler_output6.txt"); - assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodem1421")); - assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodem1421")); + assertEquals("0X2341_0X8041", parser.extractVIDAndPID(output, "/dev/cu.usbmodem1421")); + assertEquals("0X2341_0X8041", parser.extractVIDAndPID(output, "/dev/tty.usbmodem1421")); output = getFileContent("system_profiler_output7.txt"); - assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/cu.usbmodem24131")); - assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodem24131")); - assertEquals("0X0403_0X6015", extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV")); - assertEquals("0X0403_0X6015", extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV")); + assertEquals("0X2341_0X8036", parser.extractVIDAndPID(output, "/dev/cu.usbmodem24131")); + assertEquals("0X2341_0X8036", parser.extractVIDAndPID(output, "/dev/tty.usbmodem24131")); + assertEquals("0X0403_0X6015", parser.extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV")); + assertEquals("0X0403_0X6015", parser.extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV")); output = getFileContent("system_profiler_output8.txt"); - assertEquals("0X03EB_0X2157", extractVIDAndPID(output, "/dev/tty.usbmodemfd132")); + assertEquals("0X03EB_0X2157", parser.extractVIDAndPID(output, "/dev/tty.usbmodemfd132")); // OSX El Capitan output = getFileContent("system_profiler_output9.txt"); - assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodemFA121")); + assertEquals("0X2341_0X8036", parser.extractVIDAndPID(output, "/dev/tty.usbmodemFA121")); } private String getFileContent(String filename) throws IOException { diff --git a/arduino-core/src/processing/app/macosx/Platform.java b/arduino-core/src/processing/app/macosx/Platform.java index 31118c47f..a7a6a75bb 100644 --- a/arduino-core/src/processing/app/macosx/Platform.java +++ b/arduino-core/src/processing/app/macosx/Platform.java @@ -172,7 +172,7 @@ public class Platform extends processing.app.Platform { } try { - String vidPid = SystemProfilerParser.extractVIDAndPID(devicesListOutput, serial); + String vidPid = new SystemProfilerParser().extractVIDAndPID(devicesListOutput, serial); if (vidPid == null) { return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); diff --git a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java index 73f692bf3..d9a08b294 100644 --- a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java +++ b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java @@ -19,12 +19,19 @@ public class SystemProfilerParser { private static final String DEV_TTY_USBMODEM = "/dev/tty.usbmodem"; private static final String DEV_CU_USBMODEM = "/dev/cu.usbmodem"; - private static final Pattern serialNumberRegex = Pattern.compile("^Serial Number: (.+)$"); - private static final Pattern locationRegex = Pattern.compile("^Location ID: (.+)$"); - private static final Pattern pidRegex = Pattern.compile("^Product ID: (.+)$"); - private static final Pattern vidRegex = Pattern.compile("^Vendor ID: (.+)$"); + private final Pattern vidRegex; + private final Pattern serialNumberRegex; + private final Pattern locationRegex; + private final Pattern pidRegex; - public synchronized static String extractVIDAndPID(String output, String serial) throws IOException { + public SystemProfilerParser() { + this.serialNumberRegex = Pattern.compile("^Serial Number: (.+)$"); + this.locationRegex = Pattern.compile("^Location ID: (.+)$"); + this.pidRegex = Pattern.compile("^Product ID: (.+)$"); + this.vidRegex = Pattern.compile("^Vendor ID: (.+)$"); + } + + public String extractVIDAndPID(String output, String serial) throws IOException { BufferedReader reader = new BufferedReader(new StringReader(output)); String devicePrefix; @@ -38,7 +45,7 @@ public class SystemProfilerParser { devicePrefix = DEV_CU_USBMODEM; } - Map device = new HashMap(); + Map device = new HashMap<>(); String line; Matcher matcher; @@ -77,7 +84,7 @@ public class SystemProfilerParser { return (device.get(VID) + "_" + device.get(PID)).toUpperCase(); } } - device = new HashMap(); + device = new HashMap<>(); } } From d8d70ee0bd23338fbb9ab0ccde25168c4c354f57 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 26 Oct 2015 18:14:05 +0100 Subject: [PATCH 103/175] Windows: ":" is an illegal char for a file name. Fixes #4026 --- arduino-core/src/cc/arduino/Compiler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java index d5940ad70..30fd876e7 100644 --- a/arduino-core/src/cc/arduino/Compiler.java +++ b/arduino-core/src/cc/arduino/Compiler.java @@ -355,6 +355,7 @@ public class Compiler implements MessageConsumer { try { compiledSketch = StringReplacer.replaceFromMapping(compiledSketch, prefs); copyOfCompiledSketch = StringReplacer.replaceFromMapping(copyOfCompiledSketch, prefs); + copyOfCompiledSketch = copyOfCompiledSketch.replaceAll(":", "_"); Path compiledSketchPath; Path compiledSketchPathInSubfolder = Paths.get(prefs.get("build.path"), "sketch", compiledSketch); From cc1ed440e5d5a4263e38954c9ed052e152d122e7 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 26 Oct 2015 18:30:23 +0100 Subject: [PATCH 104/175] Editor: disabled brace highlight animation. Can be re-enabled by manually editing theme/syntax/default.xml. Fixes #3991 --- build/shared/lib/theme/syntax/dark.xml | 2 +- build/shared/lib/theme/syntax/default.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/shared/lib/theme/syntax/dark.xml b/build/shared/lib/theme/syntax/dark.xml index c9283f38d..f04d68ea6 100644 --- a/build/shared/lib/theme/syntax/dark.xml +++ b/build/shared/lib/theme/syntax/dark.xml @@ -18,7 +18,7 @@ - + diff --git a/build/shared/lib/theme/syntax/default.xml b/build/shared/lib/theme/syntax/default.xml index f3553a4da..650a8ac8d 100644 --- a/build/shared/lib/theme/syntax/default.xml +++ b/build/shared/lib/theme/syntax/default.xml @@ -18,7 +18,7 @@ - + From 421508268c8c2a401cf0821eb924842258698cda Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 26 Oct 2015 19:41:09 +0100 Subject: [PATCH 105/175] Removing highlight when autoformatting. Fixes #3988. Current highlighting logic is a bit buggy: see https://github.com/bobbylight/RSyntaxTextArea/issues/150. --- .../cc/arduino/packages/formatter/AStyle.java | 5 +++-- app/src/processing/app/Editor.java | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/cc/arduino/packages/formatter/AStyle.java b/app/src/cc/arduino/packages/formatter/AStyle.java index 702f34ec8..7f7c244d6 100644 --- a/app/src/cc/arduino/packages/formatter/AStyle.java +++ b/app/src/cc/arduino/packages/formatter/AStyle.java @@ -91,10 +91,11 @@ public class AStyle implements Tool { int line = getLineOfOffset(textArea); int lineOffset = getLineOffset(textArea, line); - editor.getTextArea().getUndoManager().beginInternalAtomicEdit(); + textArea.getUndoManager().beginInternalAtomicEdit(); + editor.removeAllLineHighlights(); editor.setText(formattedText); editor.getSketch().setModified(true); - editor.getTextArea().getUndoManager().endInternalAtomicEdit(); + textArea.getUndoManager().endInternalAtomicEdit(); if (line != -1 && lineOffset != -1) { try { diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index f1491f153..a8855d835 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -41,8 +41,8 @@ import processing.app.forms.PasswordAuthorizationDialog; import processing.app.helpers.OSUtils; import processing.app.helpers.PreferencesMapException; import processing.app.legacy.PApplet; -import processing.app.syntax.PdeKeywords; import processing.app.syntax.ArduinoTokenMakerFactory; +import processing.app.syntax.PdeKeywords; import processing.app.syntax.SketchTextArea; import processing.app.tools.DiscourseFormat; import processing.app.tools.MenuScroller; @@ -2006,7 +2006,7 @@ public class Editor extends JFrame implements RunnerListener { @Override public void run() { try { - textarea.removeAllLineHighlights(); + removeAllLineHighlights(); sketch.prepare(); sketch.build(verbose, saveHex); statusNotice(tr("Done compiling.")); @@ -2024,6 +2024,15 @@ public class Editor extends JFrame implements RunnerListener { } } + public void removeAllLineHighlights() { + textarea.removeAllLineHighlights(); + } + + public void addLineHighlight(int line) throws BadLocationException { + textarea.addLineHighlight(line, new Color(1, 0, 0, 0.2f)); + textarea.setCaretPosition(textarea.getLineStartOffset(line)); + } + private class DefaultStopHandler implements Runnable { public void run() { // TODO @@ -2276,7 +2285,7 @@ public class Editor extends JFrame implements RunnerListener { public boolean handleSave(boolean immediately) { //stopRunner(); handleStop(); // 0136 - textarea.removeAllLineHighlights(); + removeAllLineHighlights(); if (untitled) { return handleSaveAs(); @@ -2430,7 +2439,7 @@ public class Editor extends JFrame implements RunnerListener { public void run() { try { - textarea.removeAllLineHighlights(); + removeAllLineHighlights(); if (serialMonitor != null) { serialMonitor.suspend(); } @@ -2876,8 +2885,7 @@ public class Editor extends JFrame implements RunnerListener { System.err.println(I18n.format(tr("Bad error line: {0}"), line)); } else { try { - textarea.addLineHighlight(line, new Color(1, 0, 0, 0.2f)); - textarea.setCaretPosition(textarea.getLineStartOffset(line)); + addLineHighlight(line); } catch (BadLocationException e1) { e1.printStackTrace(); } From 577a1cea6ddfe8537f7cb0fbc845402a297192b4 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 27 Oct 2015 09:45:22 +0100 Subject: [PATCH 106/175] Added NULL as keyword. Fixes #4033 --- build/shared/lib/keywords.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/build/shared/lib/keywords.txt b/build/shared/lib/keywords.txt index cc700403f..e75c087e1 100644 --- a/build/shared/lib/keywords.txt +++ b/build/shared/lib/keywords.txt @@ -59,6 +59,7 @@ false LITERAL2 Constants LITERAL_BOOLEAN float LITERAL2 Float RESERVED_WORD_2 double LITERAL2 RESERVED_WORD_2 null LITERAL2 RESERVED_WORD_2 +NULL LITERAL2 RESERVED_WORD_2 int LITERAL2 Int RESERVED_WORD_2 long LITERAL2 Long RESERVED_WORD_2 new LITERAL2 RESERVED_WORD_2 From 8c57dd8adb403a01cf5cbbe25b5199f50289b9aa Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 27 Oct 2015 10:35:07 +0100 Subject: [PATCH 107/175] MacOSX: setting java.ext.dirs to both jre and jdk paths --- build/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build.xml b/build/build.xml index 565c1618f..f916196a8 100644 --- a/build/build.xml +++ b/build/build.xml @@ -329,7 +329,7 @@