diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 1d540c3741c..a2bf73e7779 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -24,9 +24,11 @@ package processing.app; import processing.app.debug.AvrdudeUploader; +import processing.app.debug.BasicUploader; import processing.app.debug.Compiler; import processing.app.debug.RunnerException; import processing.app.debug.Sizer; +import processing.app.debug.Target; import processing.app.debug.Uploader; import processing.app.preproc.*; import processing.core.*; @@ -1694,6 +1696,39 @@ protected void size(String buildPath, String suggestedClassName) _("Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.")); } + /** + * Get the appropriate Uploader class to use. + * + * Currently this defaults to AvrdudeUploader. + * If you are using a programmer which has "programmer.uploader=basic", use BasicUploader + */ + private Uploader getUploader(boolean usingProgrammer) { + + // if no protocol is specified for this board, assume it lacks a + // bootloader and upload using the selected programmer. + // + Map boardPreferences = Base.getBoardPreferences(); + if (usingProgrammer || boardPreferences.get("upload.protocol") == null) { + String programmer = Preferences.get("programmer"); + Target target = Base.getTarget(); + + if (programmer.indexOf(":") != -1) { + target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":"))); + programmer = programmer.substring(programmer.indexOf(":") + 1); + } + Map programmerPreferences = target.getProgrammers().get(programmer); + + // If the programmer has "programmer.uploader=basic" specified, use the BasicUploader + // + if ("basic".equals(programmerPreferences.get("uploader"))) { + return new BasicUploader(); + } + } + + // Use AvrdudeUploader by default. + // + return new AvrdudeUploader(); + } protected String upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws RunnerException, SerialException { @@ -1702,7 +1737,7 @@ protected String upload(String buildPath, String suggestedClassName, boolean usi // download the program // - uploader = new AvrdudeUploader(); + uploader = getUploader(usingProgrammer); boolean success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer); diff --git a/app/src/processing/app/debug/AvrdudeUploader.java b/app/src/processing/app/debug/AvrdudeUploader.java index 408a9a67e8d..98129e006e5 100755 --- a/app/src/processing/app/debug/AvrdudeUploader.java +++ b/app/src/processing/app/debug/AvrdudeUploader.java @@ -114,6 +114,8 @@ private Collection getProgrammerCommands(Target target, String programmer) { if (programmerPreferences.get("speed") != null) { params.add("-b" + Integer.parseInt(programmerPreferences.get("speed"))); } + } else if ("avrdoper".equals(programmerPreferences.get("communication"))) { + params.add("-Pavrdoper"); } // XXX: add support for specifying the port address for parallel // programmers, although avrdude has a default that works in most cases. diff --git a/app/src/processing/app/debug/BasicUploader.java b/app/src/processing/app/debug/BasicUploader.java new file mode 100755 index 00000000000..31b04f02585 --- /dev/null +++ b/app/src/processing/app/debug/BasicUploader.java @@ -0,0 +1,120 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + BasicUploader - basic uploader implementation + Part of the Arduino project - http://www.arduino.cc/ + + Copyright (c) 2012 + Andrew Dalgleish + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + $Id$ +*/ + +package processing.app.debug; + +import processing.app.Base; +import processing.app.Preferences; +import processing.app.Serial; +import processing.app.SerialException; + +import java.io.*; +import java.util.*; +import java.util.zip.*; +import javax.swing.*; +import gnu.io.*; + + +public class BasicUploader extends Uploader { + public BasicUploader() { + } + + public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer) + throws RunnerException, SerialException { + this.verbose = verbose; + + + // if no protocol is specified for this board, assume it lacks a + // bootloader and upload using the selected programmer. + Map boardPreferences = Base.getBoardPreferences(); + if (!usingProgrammer && boardPreferences.get("upload.protocol") != null) { + // We should never get here - BasicUploader is only for using a programmer + return false; + } + + String programmer = Preferences.get("programmer"); + Target target = Base.getTarget(); + + if (programmer.indexOf(":") != -1) { + target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":"))); + programmer = programmer.substring(programmer.indexOf(":") + 1); + } + Map programmerPreferences = target.getProgrammers().get(programmer); + + String command = programmerPreferences.get("uploader.basic.command"); + String parameters = programmerPreferences.get("uploader.basic.parameters"); + + List commandList = new ArrayList(); + + // Try our tools directories first, else assume the command includes the full path + // + if ((new File(Base.getHardwarePath() + "/tools/" + command)).exists()) { + commandList.add(Base.getHardwarePath() + "/tools/" + command); + } else if ((new File(Base.getHardwarePath() + "/tools/avr/bin/" + command)).exists()) { + commandList.add(Base.getHardwarePath() + "/tools/avr/bin/" + command); + } else { + commandList.add(command); + } + + // If we have any parameters, split them using the first character + // This lets us define any character for the separator, but you always need at least one. + // For example: + // |param1 + // /param1/param2 + // + if (parameters != null) { + + // Get the first character to use as a separator, and remove it + // + String separator = parameters.substring(0, 1); + parameters = parameters.substring(1); + + // While we have another separator, split the first part off and remember the rest + // + while (parameters.indexOf(separator) != -1) { + commandList.add(parameters.substring(0, parameters.indexOf(separator))); + parameters = parameters.substring(parameters.indexOf(separator)+1); + } + + // If we have any left, use it + // + if (parameters != null) { + commandList.add(parameters); + } + } + + // Add our hex file as the last parameter + commandList.add(buildPath + File.separator + className + ".hex"); + + return executeUploadCommand(commandList); + } + + public boolean burnBootloader() throws RunnerException { + // BasicUploader does not handle burning a bootloader + return false; + } + +} diff --git a/hardware/arduino/programmers.txt b/hardware/arduino/programmers.txt index c34b88cd213..8b492ee9310 100644 --- a/hardware/arduino/programmers.txt +++ b/hardware/arduino/programmers.txt @@ -24,3 +24,14 @@ arduinoisp.name=Arduino as ISP arduinoisp.communication=serial arduinoisp.protocol=stk500v1 arduinoisp.speed=19200 + +# AVR-Doper using HID +avrdoper.name=AVR-Doper +avrdoper.communication=avrdoper +avrdoper.protocol=stk500v2 + +# bootloadHID +bootloadhid.name=bootloadHID +bootloadhid.uploader=basic +bootloadhid.uploader.basic.command=bootloadHID.exe +bootloadhid.uploader.basic.parameters=|-r