From d2a38e4b5a4260a70b79276667d7e64ce6547010 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 21 Nov 2009 23:23:43 +0000 Subject: [PATCH] Improving third-party hardware support: - moving back to multple cores per platform - using target instead of platform - moving per-board and per-programmer preferences out of Preferences.java and into a new Target class - adding a new "target" preference - support for platform:value values in board preferences for bootloader path and core - XXX: need to support platform:value syntax for board upload.using preferences. --- app/src/processing/app/Base.java | 101 ++++++++--------- app/src/processing/app/Editor.java | 4 +- app/src/processing/app/Preferences.java | 47 +------- app/src/processing/app/Sketch.java | 2 +- .../processing/app/debug/AvrdudeUploader.java | 84 ++++++++------ app/src/processing/app/debug/Compiler.java | 62 ++++++---- app/src/processing/app/debug/Target.java | 106 ++++++++++-------- app/src/processing/app/debug/Uploader.java | 2 +- .../arduino}/HardwareSerial.cpp | 0 .../{core => cores/arduino}/HardwareSerial.h | 0 .../arduino/{core => cores/arduino}/Makefile | 0 .../arduino/{core => cores/arduino}/Print.cpp | 0 .../arduino/{core => cores/arduino}/Print.h | 0 .../{core => cores/arduino}/WConstants.h | 0 .../{core => cores/arduino}/WInterrupts.c | 0 .../arduino/{core => cores/arduino}/WMath.cpp | 0 .../{core => cores/arduino}/WProgram.h | 0 .../arduino/{core => cores/arduino}/binary.h | 0 .../arduino/{core => cores/arduino}/main.cpp | 0 .../{core => cores/arduino}/pins_arduino.c | 0 .../{core => cores/arduino}/pins_arduino.h | 0 .../arduino/{core => cores/arduino}/wiring.c | 0 .../arduino/{core => cores/arduino}/wiring.h | 0 .../{core => cores/arduino}/wiring_analog.c | 0 .../{core => cores/arduino}/wiring_digital.c | 0 .../{core => cores/arduino}/wiring_private.h | 0 .../{core => cores/arduino}/wiring_pulse.c | 0 .../{core => cores/arduino}/wiring_shift.c | 0 28 files changed, 205 insertions(+), 203 deletions(-) rename hardware/arduino/{core => cores/arduino}/HardwareSerial.cpp (100%) rename hardware/arduino/{core => cores/arduino}/HardwareSerial.h (100%) rename hardware/arduino/{core => cores/arduino}/Makefile (100%) rename hardware/arduino/{core => cores/arduino}/Print.cpp (100%) rename hardware/arduino/{core => cores/arduino}/Print.h (100%) rename hardware/arduino/{core => cores/arduino}/WConstants.h (100%) rename hardware/arduino/{core => cores/arduino}/WInterrupts.c (100%) rename hardware/arduino/{core => cores/arduino}/WMath.cpp (100%) rename hardware/arduino/{core => cores/arduino}/WProgram.h (100%) rename hardware/arduino/{core => cores/arduino}/binary.h (100%) rename hardware/arduino/{core => cores/arduino}/main.cpp (100%) rename hardware/arduino/{core => cores/arduino}/pins_arduino.c (100%) rename hardware/arduino/{core => cores/arduino}/pins_arduino.h (100%) rename hardware/arduino/{core => cores/arduino}/wiring.c (100%) rename hardware/arduino/{core => cores/arduino}/wiring.h (100%) rename hardware/arduino/{core => cores/arduino}/wiring_analog.c (100%) rename hardware/arduino/{core => cores/arduino}/wiring_digital.c (100%) rename hardware/arduino/{core => cores/arduino}/wiring_private.h (100%) rename hardware/arduino/{core => cores/arduino}/wiring_pulse.c (100%) rename hardware/arduino/{core => cores/arduino}/wiring_shift.c (100%) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 58bee2355..3a73e4a41 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -30,6 +30,7 @@ import java.util.*; import javax.swing.*; import processing.app.debug.Compiler; +import processing.app.debug.Target; import processing.core.*; @@ -85,7 +86,7 @@ public class Base { // found in the sketchbook) static public String librariesClassPath; - static public HashMap platformsTable; + static public HashMap targetsTable; // Location for untitled items static File untitledFolder; @@ -278,7 +279,7 @@ public class Base { } } - platformsTable = new HashMap(); + targetsTable = new HashMap(); loadHardware(getHardwareFolder()); loadHardware(getSketchbookHardwareFolder()); @@ -997,19 +998,26 @@ public class Base { //System.out.println("rebuilding boards menu"); menu.removeAll(); ButtonGroup group = new ButtonGroup(); - for (String board : Preferences.getSubKeys("boards")) { - AbstractAction action = - new AbstractAction(Preferences.get("boards." + board + ".name")) { - public void actionPerformed(ActionEvent actionevent) { - //System.out.println("Switching to " + board); - Preferences.set("board", (String) getValue("board")); - } - }; - action.putValue("board", board); - JMenuItem item = new JRadioButtonMenuItem(action); - if (board.equals(Preferences.get("board"))) item.setSelected(true); - group.add(item); - menu.add(item); + for (Target target : targetsTable.values()) { + for (String board : target.getBoards().keySet()) { + AbstractAction action = + new AbstractAction(target.getBoards().get(board).get("name")) { + public void actionPerformed(ActionEvent actionevent) { + //System.out.println("Switching to " + target + ":" + board); + Preferences.set("target", (String) getValue("target")); + Preferences.set("board", (String) getValue("board")); + } + }; + action.putValue("target", target.getName()); + action.putValue("board", board); + JMenuItem item = new JRadioButtonMenuItem(action); + if (target.getName().equals(Preferences.get("target")) && + board.equals(Preferences.get("board"))) { + item.setSelected(true); + } + group.add(item); + menu.add(item); + } } } @@ -1017,17 +1025,21 @@ public class Base { public void rebuildBurnBootloaderMenu(JMenu menu) { //System.out.println("rebuilding burn bootloader menu"); menu.removeAll(); - for (String programmer : Preferences.getSubKeys("programmers")) { - AbstractAction action = - new AbstractAction( - "w/ " + Preferences.get("programmers." + programmer + ".name")) { - public void actionPerformed(ActionEvent actionevent) { - activeEditor.handleBurnBootloader((String) getValue("programmer")); - } - }; - action.putValue("programmer", programmer); - JMenuItem item = new JMenuItem(action); - menu.add(item); + for (Target target : targetsTable.values()) { + for (String programmer : target.getProgrammers().keySet()) { + AbstractAction action = + new AbstractAction( + "w/ " + target.getProgrammers().get(programmer).get("name")) { + public void actionPerformed(ActionEvent actionevent) { + activeEditor.handleBurnBootloader((String) getValue("target"), + (String) getValue("programmer")); + } + }; + action.putValue("target", target.getName()); + action.putValue("programmer", programmer); + JMenuItem item = new JMenuItem(action); + menu.add(item); + } } } @@ -1228,30 +1240,9 @@ public class Base { // replaced hella slow bubble sort with this feller for 0093 Arrays.sort(list, String.CASE_INSENSITIVE_ORDER); - for (String platform : list) { - File subfolder = new File(folder, platform); - - File boardsFile = new File(subfolder, "boards.txt"); - try { - if (boardsFile.exists()) { - Preferences.load(new FileInputStream(boardsFile), "boards"); - } - } catch (Exception e) { - System.err.println("Error loading boards from " + - boardsFile + ": " + e); - } - - File programmersFile = new File(subfolder, "programmers.txt"); - try { - if (programmersFile.exists()) { - Preferences.load(new FileInputStream(programmersFile), "programmers"); - } - } catch (Exception e) { - System.err.println("Error loading programmers from " + - programmersFile + ": " + e); - } - - platformsTable.put(platform, subfolder); + for (String target : list) { + File subfolder = new File(folder, target); + targetsTable.put(target, new Target(target, subfolder)); } } @@ -1524,6 +1515,16 @@ public class Base { } } + + static public Target getTarget() { + return Base.targetsTable.get(Preferences.get("target")); + } + + + static public Map getBoardPreferences() { + return getTarget().getBoards().get(Preferences.get("board")); + } + static public File getSketchbookFolder() { return new File(Preferences.get("sketchbook.path")); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 355dca9d4..30ceb6b2b 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2279,14 +2279,14 @@ public class Editor extends JFrame implements RunnerListener { } - protected void handleBurnBootloader(final String programmer) { + protected void handleBurnBootloader(final String target, final String programmer) { console.clear(); statusNotice("Burning bootloader to I/O Board (this may take a minute)..."); SwingUtilities.invokeLater(new Runnable() { public void run() { try { Uploader uploader = new AvrdudeUploader(); - if (uploader.burnBootloader(programmer)) { + if (uploader.burnBootloader(target, programmer)) { statusNotice("Done burning bootloader."); } else { statusError("Error while burning bootloader."); diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 003804f0a..a2b790bba 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -131,7 +131,6 @@ public class Preferences { static Hashtable defaults; static Hashtable table = new Hashtable();; - static Hashtable prefixes = new Hashtable(); static File preferencesFile; @@ -550,12 +549,7 @@ public class Preferences { load(input, table); } - static protected void load(InputStream input, String prefix) throws IOException { - if (!prefixes.containsKey(prefix)) prefixes.put(prefix, new LinkedHashMap()); - load(input, (Map) prefixes.get(prefix)); - } - - static protected void load(InputStream input, Map table) throws IOException { + static public void load(InputStream input, Map table) throws IOException { String[] lines = PApplet.loadStrings(input); // Reads as UTF-8 for (String line : lines) { if ((line.length() == 0) || @@ -609,24 +603,7 @@ public class Preferences { //return get(attribute, null); //} - static public String get(String prefix, String selector, String suffix) { - if (get(selector) == null) return null; - return get(prefix + "." + get(selector) + "." + suffix); - } - static public String get(String attribute /*, String defaultValue */) { - // if the attribute starts with a prefix used by one of our subsidiary - // preference files, look up the attribute in that file's Hashtable - // (don't override with or fallback to the main file). otherwise, - // look up the attribute in the main file's Hashtable. - Map table = Preferences.table; - if (attribute.indexOf('.') != -1) { - String prefix = attribute.substring(0, attribute.indexOf('.')); - if (prefixes.containsKey(prefix)) { - table = (Map) prefixes.get(prefix); - attribute = attribute.substring(attribute.indexOf('.') + 1); - } - } return (String) table.get(attribute); /* //String value = (properties != null) ? @@ -639,28 +616,6 @@ public class Preferences { } - /** - * Get the top-level key prefixes defined in the subsidiary file loaded with - * the given prefix. For example, if the file contains: - * foo.count=1 - * bar.count=2 - * baz.count=3 - * this will return { "foo", "bar", "baz" }. - */ - static public Set getSubKeys(String prefix) { - if (!prefixes.containsKey(prefix)) - return null; - Set subkeys = new LinkedHashSet(); - for (Iterator i = ((Map) prefixes.get(prefix)).keySet().iterator(); i.hasNext(); ) { - String subkey = (String) i.next(); - if (subkey.indexOf('.') != -1) - subkey = subkey.substring(0, subkey.indexOf('.')); - subkeys.add(subkey); - } - return subkeys; - } - - static public String getDefault(String attribute) { return (String) defaults.get(attribute); } diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index a27ba72ed..b70abc019 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1447,7 +1447,7 @@ public class Sketch { protected void size(String buildPath, String suggestedClassName) throws RunnerException { long size = 0; - long maxsize = Preferences.getInteger("boards." + Preferences.get("board") + ".upload.maximum_size"); + long maxsize = Integer.parseInt(Base.getBoardPreferences().get("upload.maximum_size")); Sizer sizer = new Sizer(buildPath, suggestedClassName); try { size = sizer.computeSize(); diff --git a/app/src/processing/app/debug/AvrdudeUploader.java b/app/src/processing/app/debug/AvrdudeUploader.java index 27b5fecd1..02fdc7837 100755 --- a/app/src/processing/app/debug/AvrdudeUploader.java +++ b/app/src/processing/app/debug/AvrdudeUploader.java @@ -45,8 +45,8 @@ public class AvrdudeUploader extends Uploader { public boolean uploadUsingPreferences(String buildPath, String className, boolean verbose) throws RunnerException { this.verbose = verbose; - String uploadUsing = - Preferences.get("boards." + Preferences.get("board") + ".upload.using"); + Map boardPreferences = Base.getBoardPreferences(); + String uploadUsing = boardPreferences.get("upload.using"); if (uploadUsing == null) { // fall back on global preference uploadUsing = Preferences.get("upload.using"); @@ -54,7 +54,8 @@ public class AvrdudeUploader extends Uploader { if (uploadUsing.equals("bootloader")) { return uploadViaBootloader(buildPath, className); } else { - Collection params = getProgrammerCommands(uploadUsing); + // XXX: this needs to handle programmers in other targets. + Collection params = getProgrammerCommands(Base.getTarget().getName(), uploadUsing); params.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i"); return avrdude(params); } @@ -62,9 +63,9 @@ public class AvrdudeUploader extends Uploader { private boolean uploadViaBootloader(String buildPath, String className) throws RunnerException { + Map boardPreferences = Base.getBoardPreferences(); List commandDownloader = new ArrayList(); - String protocol = - Preferences.get("boards." + Preferences.get("board") + ".upload.protocol"); + String protocol = boardPreferences.get("upload.protocol"); // avrdude wants "stk500v1" to distinguish it from stk500v2 if (protocol.equals("stk500")) @@ -73,56 +74,59 @@ public class AvrdudeUploader extends Uploader { commandDownloader.add( "-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port")); commandDownloader.add( - "-b" + Preferences.getInteger("boards." + Preferences.get("board") + ".upload.speed")); + "-b" + Integer.parseInt(boardPreferences.get("upload.speed"))); commandDownloader.add("-D"); // don't erase commandDownloader.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i"); - if (Preferences.get("boards", "board", "upload.disable_flushing") == null || - Preferences.getBoolean("boards." + Preferences.get("board") + ".upload.disable_flushing") == false) { + if (boardPreferences.get("upload.disable_flushing") == null || + boardPreferences.get("upload.disable_flushing").toLowerCase().equals("false")) { flushSerialBuffer(); } return avrdude(commandDownloader); } - public boolean burnBootloader(String programmer) throws RunnerException { - return burnBootloader(getProgrammerCommands(programmer)); + public boolean burnBootloader(String target, String programmer) throws RunnerException { + return burnBootloader(getProgrammerCommands(target, programmer)); } - private Collection getProgrammerCommands(String programmer) { + private Collection getProgrammerCommands(String targetName, String programmer) { + Target target = Base.targetsTable.get(targetName); + Map programmerPreferences = target.getProgrammers().get(programmer); List params = new ArrayList(); - params.add("-c" + Preferences.get("programmers." + programmer + ".protocol")); + params.add("-c" + programmerPreferences.get("protocol")); - if ("usb".equals(Preferences.get("programmers." + programmer + ".communication"))) { + if ("usb".equals(programmerPreferences.get("communication"))) { params.add("-Pusb"); - } else if ("serial".equals(Preferences.get("programmers." + programmer + ".communication"))) { + } else if ("serial".equals(programmerPreferences.get("communication"))) { params.add("-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port")); - if (Preferences.get("programmers." + programmer + ".speed") != null) { - params.add("-b" + Preferences.getInteger("programmers." + programmer + ".speed")); + if (programmerPreferences.get("speed") != null) { + params.add("-b" + Integer.parseInt(programmerPreferences.get("speed"))); } } // XXX: add support for specifying the port address for parallel // programmers, although avrdude has a default that works in most cases. - if (Preferences.get("programmers." + programmer + ".force") != null && - Preferences.getBoolean("programmers." + programmer + ".force")) + if (programmerPreferences.get("force") != null && + programmerPreferences.get("force").toLowerCase().equals("true")) params.add("-F"); - if (Preferences.get("programmers." + programmer + ".delay") != null) - params.add("-i" + Preferences.get("programmers." + programmer + ".delay")); + if (programmerPreferences.get("delay") != null) + params.add("-i" + programmerPreferences.get("delay")); return params; } protected boolean burnBootloader(Collection params) throws RunnerException { + Map boardPreferences = Base.getBoardPreferences(); List fuses = new ArrayList(); fuses.add("-e"); // erase the chip - fuses.add("-Ulock:w:" + Preferences.get("boards", "board", "bootloader.unlock_bits") + ":m"); - if (Preferences.get("boards", "board", "bootloader.extended_fuses") != null) - fuses.add("-Uefuse:w:" + Preferences.get("boards", "board", "bootloader.extended_fuses") + ":m"); - fuses.add("-Uhfuse:w:" + Preferences.get("boards", "board", "bootloader.high_fuses") + ":m"); - fuses.add("-Ulfuse:w:" + Preferences.get("boards", "board", "bootloader.low_fuses") + ":m"); + fuses.add("-Ulock:w:" + boardPreferences.get("bootloader.unlock_bits") + ":m"); + if (boardPreferences.get("bootloader.extended_fuses") != null) + fuses.add("-Uefuse:w:" + boardPreferences.get("bootloader.extended_fuses") + ":m"); + fuses.add("-Uhfuse:w:" + boardPreferences.get("bootloader.high_fuses") + ":m"); + fuses.add("-Ulfuse:w:" + boardPreferences.get("bootloader.low_fuses") + ":m"); if (!avrdude(params, fuses)) return false; @@ -130,16 +134,26 @@ public class AvrdudeUploader extends Uploader { try { Thread.sleep(1000); } catch (InterruptedException e) {} - - String platform = Preferences.get("boards", "board", "build.core"); - File platformFile = Base.platformsTable.get(platform); - String bootloadersPath = new File(platformFile, "bootloaders").getAbsolutePath(); - + + Target t; + String bootloaderPath = boardPreferences.get("bootloader.path"); + + if (bootloaderPath.indexOf(':') == -1) { + t = Base.getTarget(); // the current target (associated with the board) + } else { + String targetName = bootloaderPath.substring(0, bootloaderPath.indexOf(':')); + t = Base.targetsTable.get(targetName); + bootloaderPath = bootloaderPath.substring(bootloaderPath.indexOf(':') + 1); + } + + File bootloadersFile = new File(t.getFolder(), "bootloaders"); + File bootloaderFile = new File(bootloadersFile, bootloaderPath); + bootloaderPath = bootloaderFile.getAbsolutePath(); + List bootloader = new ArrayList(); - bootloader.add("-Uflash:w:" + bootloadersPath + File.separator + - Preferences.get("boards", "board", "bootloader.path") + File.separator + - Preferences.get("boards", "board", "bootloader.file") + ":i"); - bootloader.add("-Ulock:w:" + Preferences.get("boards", "board", "bootloader.lock_bits") + ":m"); + bootloader.add("-Uflash:w:" + bootloaderPath + File.separator + + boardPreferences.get("bootloader.file") + ":i"); + bootloader.add("-Ulock:w:" + boardPreferences.get("bootloader.lock_bits") + ":m"); return avrdude(params, bootloader); } @@ -172,7 +186,7 @@ public class AvrdudeUploader extends Uploader { commandDownloader.add("-q"); commandDownloader.add("-q"); } - commandDownloader.add("-p" + Preferences.get("boards", "board", "build.mcu")); + commandDownloader.add("-p" + Base.getBoardPreferences().get("build.mcu")); commandDownloader.addAll(params); return executeUploadCommand(commandDownloader); diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index f1ba22123..850d10a64 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -71,9 +71,20 @@ public class Compiler implements MessageConsumer { MessageStream pms = new MessageStream(this); String avrBasePath = Base.getAvrBasePath(); - String platform = Preferences.get("boards", "board", "build.core"); - File platformFile = Base.platformsTable.get(platform); - String corePath = new File(platformFile, "core").getAbsolutePath(); + Map boardPreferences = Base.getBoardPreferences(); + String core = boardPreferences.get("build.core"); + String corePath; + + if (core.indexOf(':') == -1) { + Target t = Base.getTarget(); + File coreFolder = new File(new File(t.getFolder(), "cores"), core); + corePath = coreFolder.getAbsolutePath(); + } else { + Target t = Base.targetsTable.get(core.substring(0, core.indexOf(':'))); + File coresFolder = new File(t.getFolder(), "cores"); + File coreFolder = new File(coresFolder, core.substring(core.indexOf(':') + 1)); + corePath = coreFolder.getAbsolutePath(); + } List objectFiles = new ArrayList(); @@ -89,7 +100,8 @@ public class Compiler implements MessageConsumer { compileFiles(avrBasePath, buildPath, includePaths, findFilesInPath(corePath, "S", true), findFilesInPath(corePath, "c", true), - findFilesInPath(corePath, "cpp", true)); + findFilesInPath(corePath, "cpp", true), + boardPreferences); List baseCommandAR = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-ar", @@ -120,14 +132,16 @@ public class Compiler implements MessageConsumer { compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, findFilesInFolder(libraryFolder, "S", false), findFilesInFolder(libraryFolder, "c", false), - findFilesInFolder(libraryFolder, "cpp", false))); + findFilesInFolder(libraryFolder, "cpp", false), + boardPreferences)); outputFolder = new File(outputFolder, "utility"); createFolder(outputFolder); objectFiles.addAll( compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, findFilesInFolder(utilityFolder, "S", false), findFilesInFolder(utilityFolder, "c", false), - findFilesInFolder(utilityFolder, "cpp", false))); + findFilesInFolder(utilityFolder, "cpp", false), + boardPreferences)); // other libraries should not see this library's utility/ folder includePaths.remove(includePaths.size() - 1); } @@ -138,7 +152,8 @@ public class Compiler implements MessageConsumer { compileFiles(avrBasePath, buildPath, includePaths, findFilesInPath(buildPath, "S", false), findFilesInPath(buildPath, "c", false), - findFilesInPath(buildPath, "cpp", false))); + findFilesInPath(buildPath, "cpp", false), + boardPreferences)); // 4. link it all together into the .elf file @@ -146,7 +161,7 @@ public class Compiler implements MessageConsumer { avrBasePath + "avr-gcc", "-Os", "-Wl,--gc-sections", - "-mmcu=" + Preferences.get("boards", "board", "build.mcu"), + "-mmcu=" + boardPreferences.get("build.mcu"), "-o", buildPath + File.separator + primaryClassName + ".elf" })); @@ -197,7 +212,8 @@ public class Compiler implements MessageConsumer { private List compileFiles(String avrBasePath, String buildPath, List includePaths, List sSources, - List cSources, List cppSources) + List cSources, List cppSources, + Map boardPreferences) throws RunnerException { List objectPaths = new ArrayList(); @@ -207,7 +223,8 @@ public class Compiler implements MessageConsumer { objectPaths.add(new File(objectPath)); execAsynchronously(getCommandCompilerS(avrBasePath, includePaths, file.getAbsolutePath(), - objectPath)); + objectPath, + boardPreferences)); } for (File file : cSources) { @@ -215,7 +232,8 @@ public class Compiler implements MessageConsumer { objectPaths.add(new File(objectPath)); execAsynchronously(getCommandCompilerC(avrBasePath, includePaths, file.getAbsolutePath(), - objectPath)); + objectPath, + boardPreferences)); } for (File file : cppSources) { @@ -223,7 +241,8 @@ public class Compiler implements MessageConsumer { objectPaths.add(new File(objectPath)); execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths, file.getAbsolutePath(), - objectPath)); + objectPath, + boardPreferences)); } return objectPaths; @@ -448,14 +467,14 @@ public class Compiler implements MessageConsumer { ///////////////////////////////////////////////////////////////////////////// static private List getCommandCompilerS(String avrBasePath, List includePaths, - String sourceName, String objectName) { + String sourceName, String objectName, Map boardPreferences) { List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-c", // compile, don't link "-g", // include debugging info (so errors include line numbers) "-assembler-with-cpp", - "-mmcu=" + Preferences.get("boards", "board", "build.mcu"), - "-DF_CPU=" + Preferences.get("boards", "board", "build.f_cpu"), + "-mmcu=" + boardPreferences.get("build.mcu"), + "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, })); @@ -471,7 +490,7 @@ public class Compiler implements MessageConsumer { static private List getCommandCompilerC(String avrBasePath, List includePaths, - String sourceName, String objectName) { + String sourceName, String objectName, Map boardPreferences) { List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", @@ -481,8 +500,8 @@ public class Compiler implements MessageConsumer { "-w", // surpress all warnings "-ffunction-sections", // place each function in its own section "-fdata-sections", - "-mmcu=" + Preferences.get("boards", "board", "build.mcu"), - "-DF_CPU=" + Preferences.get("boards", "board", "build.f_cpu"), + "-mmcu=" + boardPreferences.get("build.mcu"), + "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, })); @@ -498,7 +517,8 @@ public class Compiler implements MessageConsumer { static private List getCommandCompilerCPP(String avrBasePath, - List includePaths, String sourceName, String objectName) { + List includePaths, String sourceName, String objectName, + Map boardPreferences) { List baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-g++", @@ -509,8 +529,8 @@ public class Compiler implements MessageConsumer { "-fno-exceptions", "-ffunction-sections", // place each function in its own section "-fdata-sections", - "-mmcu=" + Preferences.get("boards", "board", "build.mcu"), - "-DF_CPU=" + Preferences.get("boards", "board", "build.f_cpu"), + "-mmcu=" + boardPreferences.get("build.mcu"), + "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, })); diff --git a/app/src/processing/app/debug/Target.java b/app/src/processing/app/debug/Target.java index 6788cb319..1aa2f81be 100644 --- a/app/src/processing/app/debug/Target.java +++ b/app/src/processing/app/debug/Target.java @@ -1,11 +1,10 @@ /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* - Target - represents a target platform - Part of the Arduino project - http://arduino.berlios.de/ + Target - represents a hardware platform + Part of the Arduino project - http://www.arduino.cc/ - Copyright (c) 2005 - David A. Mellis + Copyright (c) 2009 David A. Mellis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,59 +20,72 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - $Id: Target.java 85 2006-01-12 23:24:12Z mellis $ + $Id$ */ package processing.app.debug; + import java.io.*; import java.util.*; -/** - * Represents a target platform (e.g. Wiring board, Arduino board). - */ -public class Target { - String path; - List sources = new ArrayList(); - List objects = new ArrayList(); +import processing.app.Preferences; - /** - * Create a Target. - * @param path the directory containing config, source, and object files for - * the target platform. - */ - public Target(String base, String target) throws IOException { - path = base + File.separator + target; - String[] files = (new File(path)).list(); +public class Target { + private String name; + private File folder; + private Map boards; + private Map programmers; + + public Target(String name, File folder) { + this.name = name; + this.folder = folder; + this.boards = new LinkedHashMap(); + this.programmers = new LinkedHashMap(); - if (files == null) - throw new IOException("Target platform: \"" + target + "\" not found.\n" + - "Make sure that \"build.target\" in the \n" + - "preferences file points to a subdirectory of \n" + - base); - - for (int i = 0; i < files.length; i++) { - if (files[i].endsWith(".S") || files[i].endsWith(".c") || files[i].endsWith(".cpp")) - sources.add(files[i]); - if (files[i].endsWith(".o")) - objects.add(files[i]); + File boardsFile = new File(folder, "boards.txt"); + try { + if (boardsFile.exists()) { + Map boardPreferences = new LinkedHashMap(); + Preferences.load(new FileInputStream(boardsFile), boardPreferences); + for (Object k : boardPreferences.keySet()) { + String key = (String) k; + String board = key.substring(0, key.indexOf('.')); + if (!boards.containsKey(board)) boards.put(board, new HashMap()); + ((Map) boards.get(board)).put( + key.substring(key.indexOf('.') + 1), + boardPreferences.get(key)); + } + } + } catch (Exception e) { + System.err.println("Error loading boards from " + boardsFile + ": " + e); } + + File programmersFile = new File(folder, "programmers.txt"); + try { + if (programmersFile.exists()) { + Map programmerPreferences = new LinkedHashMap(); + Preferences.load(new FileInputStream(programmersFile), programmerPreferences); + for (Object k : programmerPreferences.keySet()) { + String key = (String) k; + String programmer = key.substring(0, key.indexOf('.')); + if (!programmers.containsKey(programmer)) programmers.put(programmer, new HashMap()); + ((Map) programmers.get(programmer)).put( + key.substring(key.indexOf('.') + 1), + programmerPreferences.get(key)); + } + } + } catch (Exception e) { + System.err.println("Error loading programmers from " + + programmersFile + ": " + e); + } } - public String getPath() { return path; } - - /** - * The source files in the library for the target platform. - * @return A read-only collection of strings containing the name of each source file. - */ - public Collection getSourceFilenames() { - return Collections.unmodifiableList(sources); + public String getName() { return name; } + public File getFolder() { return folder; } + public Map> getBoards() { + return boards; } - - /** - * The object files in the library for the target platform. - * @return A read-only collection of strings containing the name of each object file. - */ - public Collection getObjectFilenames() { - return Collections.unmodifiableList(objects); + public Map> getProgrammers() { + return programmers; } -} +} \ No newline at end of file diff --git a/app/src/processing/app/debug/Uploader.java b/app/src/processing/app/debug/Uploader.java index e91dc2c71..8318727e5 100755 --- a/app/src/processing/app/debug/Uploader.java +++ b/app/src/processing/app/debug/Uploader.java @@ -65,7 +65,7 @@ public abstract class Uploader implements MessageConsumer { public abstract boolean uploadUsingPreferences(String buildPath, String className, boolean verbose) throws RunnerException; - public abstract boolean burnBootloader(String programmer) throws RunnerException; + public abstract boolean burnBootloader(String target, String programmer) throws RunnerException; protected void flushSerialBuffer() throws RunnerException { // Cleanup the serial buffer diff --git a/hardware/arduino/core/HardwareSerial.cpp b/hardware/arduino/cores/arduino/HardwareSerial.cpp similarity index 100% rename from hardware/arduino/core/HardwareSerial.cpp rename to hardware/arduino/cores/arduino/HardwareSerial.cpp diff --git a/hardware/arduino/core/HardwareSerial.h b/hardware/arduino/cores/arduino/HardwareSerial.h similarity index 100% rename from hardware/arduino/core/HardwareSerial.h rename to hardware/arduino/cores/arduino/HardwareSerial.h diff --git a/hardware/arduino/core/Makefile b/hardware/arduino/cores/arduino/Makefile similarity index 100% rename from hardware/arduino/core/Makefile rename to hardware/arduino/cores/arduino/Makefile diff --git a/hardware/arduino/core/Print.cpp b/hardware/arduino/cores/arduino/Print.cpp similarity index 100% rename from hardware/arduino/core/Print.cpp rename to hardware/arduino/cores/arduino/Print.cpp diff --git a/hardware/arduino/core/Print.h b/hardware/arduino/cores/arduino/Print.h similarity index 100% rename from hardware/arduino/core/Print.h rename to hardware/arduino/cores/arduino/Print.h diff --git a/hardware/arduino/core/WConstants.h b/hardware/arduino/cores/arduino/WConstants.h similarity index 100% rename from hardware/arduino/core/WConstants.h rename to hardware/arduino/cores/arduino/WConstants.h diff --git a/hardware/arduino/core/WInterrupts.c b/hardware/arduino/cores/arduino/WInterrupts.c similarity index 100% rename from hardware/arduino/core/WInterrupts.c rename to hardware/arduino/cores/arduino/WInterrupts.c diff --git a/hardware/arduino/core/WMath.cpp b/hardware/arduino/cores/arduino/WMath.cpp similarity index 100% rename from hardware/arduino/core/WMath.cpp rename to hardware/arduino/cores/arduino/WMath.cpp diff --git a/hardware/arduino/core/WProgram.h b/hardware/arduino/cores/arduino/WProgram.h similarity index 100% rename from hardware/arduino/core/WProgram.h rename to hardware/arduino/cores/arduino/WProgram.h diff --git a/hardware/arduino/core/binary.h b/hardware/arduino/cores/arduino/binary.h similarity index 100% rename from hardware/arduino/core/binary.h rename to hardware/arduino/cores/arduino/binary.h diff --git a/hardware/arduino/core/main.cpp b/hardware/arduino/cores/arduino/main.cpp similarity index 100% rename from hardware/arduino/core/main.cpp rename to hardware/arduino/cores/arduino/main.cpp diff --git a/hardware/arduino/core/pins_arduino.c b/hardware/arduino/cores/arduino/pins_arduino.c similarity index 100% rename from hardware/arduino/core/pins_arduino.c rename to hardware/arduino/cores/arduino/pins_arduino.c diff --git a/hardware/arduino/core/pins_arduino.h b/hardware/arduino/cores/arduino/pins_arduino.h similarity index 100% rename from hardware/arduino/core/pins_arduino.h rename to hardware/arduino/cores/arduino/pins_arduino.h diff --git a/hardware/arduino/core/wiring.c b/hardware/arduino/cores/arduino/wiring.c similarity index 100% rename from hardware/arduino/core/wiring.c rename to hardware/arduino/cores/arduino/wiring.c diff --git a/hardware/arduino/core/wiring.h b/hardware/arduino/cores/arduino/wiring.h similarity index 100% rename from hardware/arduino/core/wiring.h rename to hardware/arduino/cores/arduino/wiring.h diff --git a/hardware/arduino/core/wiring_analog.c b/hardware/arduino/cores/arduino/wiring_analog.c similarity index 100% rename from hardware/arduino/core/wiring_analog.c rename to hardware/arduino/cores/arduino/wiring_analog.c diff --git a/hardware/arduino/core/wiring_digital.c b/hardware/arduino/cores/arduino/wiring_digital.c similarity index 100% rename from hardware/arduino/core/wiring_digital.c rename to hardware/arduino/cores/arduino/wiring_digital.c diff --git a/hardware/arduino/core/wiring_private.h b/hardware/arduino/cores/arduino/wiring_private.h similarity index 100% rename from hardware/arduino/core/wiring_private.h rename to hardware/arduino/cores/arduino/wiring_private.h diff --git a/hardware/arduino/core/wiring_pulse.c b/hardware/arduino/cores/arduino/wiring_pulse.c similarity index 100% rename from hardware/arduino/core/wiring_pulse.c rename to hardware/arduino/cores/arduino/wiring_pulse.c diff --git a/hardware/arduino/core/wiring_shift.c b/hardware/arduino/cores/arduino/wiring_shift.c similarity index 100% rename from hardware/arduino/core/wiring_shift.c rename to hardware/arduino/cores/arduino/wiring_shift.c