Skip to content

Commit 29f9dd9

Browse files
committed
Merge pull request #2139 from cmaglie/init-variant
Allow variants to define an initVariant() function that is called at startup
2 parents f732097 + bb095a2 commit 29f9dd9

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

app/src/processing/app/debug/Compiler.java

+22-13
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,28 @@ public boolean compile(Sketch sketch,
186186
includePaths.remove(includePaths.size() - 1);
187187
}
188188

189-
// 3. compile the core, outputting .o files to <buildPath> and then
190-
// collecting them into the core.a library file.
191-
192-
sketch.setCompilingProgress(50);
193-
includePaths.clear();
194-
includePaths.add(corePath); // include path for core only
195-
if (variantPath != null) includePaths.add(variantPath);
196-
List<File> coreObjectFiles =
197-
compileFiles(avrBasePath, buildPath, includePaths,
198-
findFilesInPath(corePath, "S", true),
199-
findFilesInPath(corePath, "c", true),
200-
findFilesInPath(corePath, "cpp", true),
201-
boardPreferences);
189+
// 3. compile the core, outputting .o files to <buildPath> and then
190+
// collecting them into the core.a library file.
191+
192+
sketch.setCompilingProgress(50);
193+
includePaths.clear();
194+
includePaths.add(corePath); // include path for core only
195+
if (variantPath != null)
196+
includePaths.add(variantPath);
197+
List<File> coreObjectFiles = compileFiles( //
198+
avrBasePath, buildPath, includePaths, //
199+
findFilesInPath(corePath, "S", true), //
200+
findFilesInPath(corePath, "c", true), //
201+
findFilesInPath(corePath, "cpp", true), //
202+
boardPreferences);
203+
204+
if (variantPath != null)
205+
objectFiles.addAll(compileFiles( //
206+
avrBasePath, buildPath, includePaths, //
207+
findFilesInPath(variantPath, "S", true), //
208+
findFilesInPath(variantPath, "c", true), //
209+
findFilesInPath(variantPath, "cpp", true), //
210+
boardPreferences));
202211

203212
String runtimeLibraryName = buildPath + File.separator + "core.a";
204213
List baseCommandAR = new ArrayList(Arrays.asList(new String[] {

hardware/arduino/cores/arduino/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ typedef uint8_t boolean;
113113
typedef uint8_t byte;
114114

115115
void init(void);
116+
void initVariant(void);
116117

117118
void pinMode(uint8_t, uint8_t);
118119
void digitalWrite(uint8_t, uint8_t);

hardware/arduino/cores/arduino/main.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@
1919

2020
#include <Arduino.h>
2121

22+
// Weak empty variant initialization function.
23+
// May be redefined by variant files.
24+
void initVariant() __attribute__((weak));
25+
void initVariant() { }
26+
2227
int main(void)
2328
{
2429
init();
2530

31+
initVariant();
32+
2633
#if defined(USBCON)
2734
USBDevice.attach();
2835
#endif

0 commit comments

Comments
 (0)