Skip to content

Commit

Permalink
Merge pull request #363 from majenkotech/master
Browse files Browse the repository at this point in the history
Added support for different core versions
  • Loading branch information
ricklon committed Jun 23, 2013
2 parents ae186a8 + 683d5ae commit 6dcd512
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 33 deletions.
33 changes: 25 additions & 8 deletions app/src/processing/app/debug/AvrdudeUploader.java
Expand Up @@ -37,6 +37,8 @@
import javax.swing.*;
import gnu.io.*;

import java.util.regex.*;

import org.apache.log4j.Logger;


Expand Down Expand Up @@ -109,8 +111,14 @@ public boolean uploadUsingPreferences(String buildPath, String className, boolea
logger.debug("Command: " + command);
logger.debug("");

String[] spl = command.split("\\s+");
String executable = spl[0];

ArrayList <String> spl = new ArrayList();
Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(command);
while (m.find())
spl.add(m.group(1));

String executable = spl.get(0);
executable = executable.replace("\"", "");
if (Base.isWindows()) {
executable = executable + ".exe";
}
Expand Down Expand Up @@ -152,7 +160,10 @@ public boolean uploadUsingPreferences(String buildPath, String className, boolea
(Base.isWindows() ? "\\\\.\\" : "") +
Preferences.get("serial.port")
);
command = command.replace("%B", boardPreferences.get("upload.speed"));
command = command.replace("%B",
boardPreferences.get("upload.speed") != null ?
boardPreferences.get("upload.speed"): ""
);
command = command.replace("%O",
boardPreferences.get("upload.protocol") != null ?
boardPreferences.get("upload.protocol") : ""
Expand All @@ -164,16 +175,22 @@ public boolean uploadUsingPreferences(String buildPath, String className, boolea
);
command = command.trim();

spl.clear();
// Split the command into words
spl = command.split("\\s+");
m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(command);
while (m.find())
spl.add(m.group(1));

// Parse each word, doing string replacement as needed, trimming it, and
// generally getting it ready for executing.

for (int i = 0; i < spl.length; i++) {
spl[i] = spl[i].trim();
if (spl[i].length() > 0) {
parts.add(spl[i]);
for (int i = 0; i < spl.size(); i++) {
String tmp = spl.get(i);
tmp = tmp.replace("\"", "");
tmp = tmp.trim();
spl.set(i, tmp);
if (spl.get(i).length() > 0) {
parts.add(spl.get(i));
}
}

Expand Down
57 changes: 34 additions & 23 deletions app/src/processing/app/debug/Compiler.java
Expand Up @@ -457,7 +457,9 @@ static private String getCommandCompilerS(String avrBasePath,
configPreferences.get("compiler.cpudef"), //3
configPreferences.get("build.mcu"), //4
configPreferences.get("build.f_cpu"), //5
configPreferences.get("software") + "=" + Base.REVISION,//6
configPreferences.get("software") + "=" +
( configPreferences.get("core.version") != null ?
configPreferences.get("core.version") : Base.REVISION),
configPreferences.get("board") , //7,
configPreferences.get("compiler.define") + " " + configPreferences.get("board.define") , //8
includes, //9
Expand Down Expand Up @@ -486,7 +488,9 @@ private String getCommandCompilerC(String avrBasePath,
configPreferences.get("compiler.cpudef"),
configPreferences.get("build.mcu"),
configPreferences.get("build.f_cpu"),
configPreferences.get("software") + "=" + Base.REVISION,
configPreferences.get("software") + "=" +
( configPreferences.get("core.version") != null ?
configPreferences.get("core.version") : Base.REVISION),
configPreferences.get("board"),
configPreferences.get("compiler.define") + " " + configPreferences.get("board.define"),
includes,
Expand All @@ -508,15 +512,16 @@ static private String getCommandCompilerCPP(String avrBasePath,
String includes = preparePaths(includePaths);
logger.debug("Source: " + sourceName);


Object[] Args = {
avrBasePath,
configPreferences.get("compiler.cpp.cmd"),
configPreferences.get("compiler.cpp.flags"),
configPreferences.get("compiler.cpudef"),
configPreferences.get("build.mcu"),
configPreferences.get("build.f_cpu"),
configPreferences.get("software") + "=" + Base.REVISION,
configPreferences.get("software") + "=" +
( configPreferences.get("core.version") != null ?
configPreferences.get("core.version") : Base.REVISION),
configPreferences.get("board"),
configPreferences.get("compiler.define") + " " + configPreferences.get("board.define"),
includes,
Expand Down Expand Up @@ -706,26 +711,32 @@ void compileLink(String avrBasePath, String buildPath, String corePath, ArrayLis
}

String ldscript = configPreferences.get("ldscript");

String foundPath = null;
File testFile = null;
if (ldscript != null) {
File testFile = null;

testFile = new File(variantPath, ldscript);
logger.debug("Searching for " + variantPath + "/" + ldscript + "...");
if (testFile.exists()) {
logger.debug("... found");
foundPath = variantPath;
} else {
logger.debug("Searching for " + corePath + "/" + ldscript + "...");
testFile = new File(corePath, ldscript);
if (testFile.exists()) {
logger.debug("... found");
foundPath = corePath;
}
}

testFile = new File(variantPath, ldscript);
logger.debug("Searching for " + variantPath + "/" + ldscript + "...");
if (testFile.exists()) {
logger.debug("... found");
foundPath = variantPath;
if (foundPath == null) {
System.out.println("Linker script not found: " + ldscript);
return;
}
} else {
logger.debug("Searching for " + corePath + "/" + ldscript + "...");
testFile = new File(corePath, ldscript);
if (testFile.exists()) {
logger.debug("... found");
foundPath = corePath;
}
}

if (foundPath == null) {
System.out.println("Linker script not found: " + ldscript);
return;
ldscript = "";
foundPath = "";
}

Object[] Args = {
Expand All @@ -740,9 +751,9 @@ void compileLink(String avrBasePath, String buildPath, String corePath, ArrayLis
buildPath + File.separator + "core.a",
buildPath,
foundPath,
configPreferences.get("ldscript"),
configPreferences.get("ldscript") != null ? configPreferences.get("ldscript") : "",
corePath,
configPreferences.get("ldcommon")
configPreferences.get("ldcommon") != null ? configPreferences.get("ldcommon") : "",
};
commandString = compileFormat.format( Args );
logger.debug("Link command: " + commandString);
Expand Down
15 changes: 14 additions & 1 deletion app/src/processing/app/preproc/PdePreprocessor.java
Expand Up @@ -207,11 +207,24 @@ public String write() throws java.lang.Exception {
// Write the pde program to the cpp file
protected void writeProgram(PrintStream out, String program, List<String> prototypes) {
int prototypeInsertionPoint = firstStatement(program);
String platform;
Map<String, String> platformPreferences;
Map<String, String> boardPreferences;

boardPreferences = new HashMap(Base.getBoardPreferences());

platform = boardPreferences.get("platform");
if (platform == null) {
platformPreferences = new HashMap(Base.getPlatformPreferences());
} else {
platformPreferences = new HashMap(Base.getPlatformPreferences(platform));
}

logger.debug("Prepro: writeProgram");
logger.debug("Program: " + program);
logger.debug("prototypes: " + prototypes);
out.print(program.substring(0, prototypeInsertionPoint));
out.print("#include \"WProgram.h\"\n");
out.print("#include \"" + platformPreferences.get("core.header") + "\"\n");

// print user defined prototypes
for (int i = 0; i < prototypes.size(); i++) {
Expand Down
3 changes: 2 additions & 1 deletion hardware/arduino/platforms.txt
Expand Up @@ -62,5 +62,6 @@ avr.library.core.path=./hardware/arduino/cores/arduino
avr.library.path=./libraries
avr.compiler.define=::
avr.board.define=::

avr.core.header=WProgram.h
avr.core.version=23

1 change: 1 addition & 0 deletions hardware/pic32/platforms.txt
Expand Up @@ -43,3 +43,4 @@ pic32.ldscript=chipKIT-BL-mega.ld
pic32.ldcommon=chipKIT-application-COMMON.ld
pic32.compiler.define=::-DMPIDEVER=0x01000306::-DMPIDE=23::
pic32.build.variant=Default_100
pic32.core.header=WProgram.h

0 comments on commit 6dcd512

Please sign in to comment.