From 02135349a91b229da5fb82a538a5017b3904975a Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 16 May 2014 18:53:17 +0200 Subject: [PATCH 1/4] Support TIMER1C Some devices, such as the atmega2560 or the atmega256rfr2 have a timer1c output. It seems this output is not connected to anything on the Arduino Mega, but this allows using it on third party hardware nonetheless. --- hardware/arduino/avr/cores/arduino/Arduino.h | 27 ++++++++++--------- .../arduino/avr/cores/arduino/wiring_analog.c | 8 ++++++ .../avr/cores/arduino/wiring_digital.c | 3 +++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/Arduino.h b/hardware/arduino/avr/cores/arduino/Arduino.h index ec1389e14..6b923a46f 100644 --- a/hardware/arduino/avr/cores/arduino/Arduino.h +++ b/hardware/arduino/avr/cores/arduino/Arduino.h @@ -194,20 +194,21 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; #define TIMER0B 2 #define TIMER1A 3 #define TIMER1B 4 -#define TIMER2 5 -#define TIMER2A 6 -#define TIMER2B 7 +#define TIMER1C 5 +#define TIMER2 6 +#define TIMER2A 7 +#define TIMER2B 8 -#define TIMER3A 8 -#define TIMER3B 9 -#define TIMER3C 10 -#define TIMER4A 11 -#define TIMER4B 12 -#define TIMER4C 13 -#define TIMER4D 14 -#define TIMER5A 15 -#define TIMER5B 16 -#define TIMER5C 17 +#define TIMER3A 9 +#define TIMER3B 10 +#define TIMER3C 11 +#define TIMER4A 12 +#define TIMER4B 13 +#define TIMER4C 14 +#define TIMER4D 15 +#define TIMER5A 16 +#define TIMER5B 17 +#define TIMER5C 18 #ifdef __cplusplus } // extern "C" diff --git a/hardware/arduino/avr/cores/arduino/wiring_analog.c b/hardware/arduino/avr/cores/arduino/wiring_analog.c index 8feead957..48a9ef52d 100644 --- a/hardware/arduino/avr/cores/arduino/wiring_analog.c +++ b/hardware/arduino/avr/cores/arduino/wiring_analog.c @@ -160,6 +160,14 @@ void analogWrite(uint8_t pin, int val) break; #endif + #if defined(TCCR1A) && defined(COM1C1) + case TIMER1C: + // connect pwm to pin on timer 1, channel B + sbi(TCCR1A, COM1C1); + OCR1C = val; // set pwm duty + break; + #endif + #if defined(TCCR2) && defined(COM21) case TIMER2: // connect pwm to pin on timer 2 diff --git a/hardware/arduino/avr/cores/arduino/wiring_digital.c b/hardware/arduino/avr/cores/arduino/wiring_digital.c index be323b1df..df94cc1c5 100644 --- a/hardware/arduino/avr/cores/arduino/wiring_digital.c +++ b/hardware/arduino/avr/cores/arduino/wiring_digital.c @@ -84,6 +84,9 @@ static void turnOffPWM(uint8_t timer) #if defined(TCCR1A) && defined(COM1B1) case TIMER1B: cbi(TCCR1A, COM1B1); break; #endif + #if defined(TCCR1A) && defined(COM1C1) + case TIMER1C: cbi(TCCR1A, COM1C1); break; + #endif #if defined(TCCR2) && defined(COM21) case TIMER2: cbi(TCCR2, COM21); break; From 7d71b84ae26e54f7367c0b167aa28ef0114d9fc0 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 25 Jun 2014 16:21:31 +0200 Subject: [PATCH 2/4] Unconfuse error message When a core directory without boards.txt file was encountered, the IDE would show: Could not find boards.txt in /path/to/core/boards.txt. Is it pre-1.5? Which appears confusing: Is it looking inside a directory called boards.txt? Now this is improved to: Could not find boards.txt in /path/to/core/. Is it pre-1.5? which makes a lot more sense. --- app/src/processing/app/debug/TargetPlatform.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/processing/app/debug/TargetPlatform.java b/app/src/processing/app/debug/TargetPlatform.java index 3dfb29f6e..2666347fa 100644 --- a/app/src/processing/app/debug/TargetPlatform.java +++ b/app/src/processing/app/debug/TargetPlatform.java @@ -71,7 +71,7 @@ public class TargetPlatform { if (!boardsFile.exists() || !boardsFile.canRead()) throw new TargetPlatformException( format(_("Could not find boards.txt in {0}. Is it pre-1.5?"), - boardsFile.getAbsolutePath())); + folder.getAbsolutePath())); // Load boards try { From 4eb686673f7133d0aa000e8828825d1b077ff952 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 25 Jun 2014 15:53:45 +0200 Subject: [PATCH 3/4] Don't include .o files from the variant in core.a If a variant supplied source files, these would be included in core.a before. However, object files from core.a would only actually be included in the build if they supplied a symbol for a strong reference that was still missing. In practice, this meant that a variant source file that only defines interrupt handlers, or only defines strong versions of functions that already had weak versions available, was not included. By moving the variant .o files out of core.a and including them in the build directly, this problem is solved. Furthermore, the compilation of variant files is moved to after the generation of core.a, to make it clearer in the code and verbose output what is now happening. --- app/src/processing/app/debug/Compiler.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 92f25a1c5..2a94cbd6e 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -690,6 +690,8 @@ public class Compiler implements MessageConsumer { // 3. compile the core, outputting .o files to and then // collecting them into the core.a library file. + // Also compiles the variant (if it supplies actual source files), + // which are included in the link directly (not through core.a) void compileCore() throws RunnerException { @@ -702,13 +704,9 @@ public class Compiler implements MessageConsumer { if (variantFolder != null) includeFolders.add(variantFolder); - List objectFiles = compileFiles(buildFolder, coreFolder, true, - includeFolders); - if (variantFolder != null) - objectFiles.addAll(compileFiles(buildFolder, variantFolder, true, - includeFolders)); - - for (File file : objectFiles) { + List coreObjectFiles = compileFiles(buildFolder, coreFolder, true, + includeFolders); + for (File file : coreObjectFiles) { PreferencesMap dict = new PreferencesMap(prefs); dict.put("ide_version", "" + Base.REVISION); @@ -724,6 +722,10 @@ public class Compiler implements MessageConsumer { } execAsynchronously(cmdArray); } + + if (variantFolder != null) + objectFiles.addAll(compileFiles(buildFolder, variantFolder, true, + includeFolders)); } // 4. link it all together into the .elf file From 4014dd6070f8d8cd1da29129aee897388f511d51 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 25 Jun 2014 15:58:38 +0200 Subject: [PATCH 4/4] Allow variants to define an initVariant() function that is called at startup. See #2080 and #2139. --- hardware/arduino/avr/cores/arduino/Arduino.h | 1 + hardware/arduino/avr/cores/arduino/main.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/hardware/arduino/avr/cores/arduino/Arduino.h b/hardware/arduino/avr/cores/arduino/Arduino.h index 6b923a46f..630f0d6d7 100644 --- a/hardware/arduino/avr/cores/arduino/Arduino.h +++ b/hardware/arduino/avr/cores/arduino/Arduino.h @@ -118,6 +118,7 @@ typedef uint8_t boolean; typedef uint8_t byte; void init(void); +void initVariant(void); void pinMode(uint8_t, uint8_t); void digitalWrite(uint8_t, uint8_t); diff --git a/hardware/arduino/avr/cores/arduino/main.cpp b/hardware/arduino/avr/cores/arduino/main.cpp index 0ad696215..091c365fc 100644 --- a/hardware/arduino/avr/cores/arduino/main.cpp +++ b/hardware/arduino/avr/cores/arduino/main.cpp @@ -19,10 +19,17 @@ #include +// Weak empty variant initialization function. +// May be redefined by variant files. +void initVariant() __attribute__((weak)); +void initVariant() { } + int main(void) { init(); + initVariant(); + #if defined(USBCON) USBDevice.attach(); #endif