mirror of https://github.com/noisymime/Arduino.git
Factoring out uisp from the uploader in preparation for also allowing avrdude.
This commit is contained in:
parent
ca84925df8
commit
1c0c0fe69b
|
@ -53,7 +53,7 @@ import com.ice.jni.registry.*;
|
||||||
*/
|
*/
|
||||||
public class Base {
|
public class Base {
|
||||||
static final int VERSION = 3;
|
static final int VERSION = 3;
|
||||||
static final String VERSION_NAME = "0008 Alpha";
|
static final String VERSION_NAME = "0009 Alpha";
|
||||||
|
|
||||||
// platform IDs for PApplet.platform
|
// platform IDs for PApplet.platform
|
||||||
|
|
||||||
|
|
|
@ -2013,7 +2013,7 @@ public class Editor extends JFrame
|
||||||
try {
|
try {
|
||||||
//boolean success = sketch.isLibrary() ?
|
//boolean success = sketch.isLibrary() ?
|
||||||
//sketch.exportLibrary() : sketch.exportApplet();
|
//sketch.exportLibrary() : sketch.exportApplet();
|
||||||
Uploader uploader = new Uploader();
|
Uploader uploader = new UispUploader();
|
||||||
boolean success = parallel ?
|
boolean success = parallel ?
|
||||||
uploader.burnBootloaderParallel() :
|
uploader.burnBootloaderParallel() :
|
||||||
uploader.burnBootloaderAVRISP();
|
uploader.burnBootloaderAVRISP();
|
||||||
|
|
|
@ -1675,7 +1675,7 @@ public class Sketch {
|
||||||
|
|
||||||
// download the program
|
// download the program
|
||||||
//
|
//
|
||||||
Uploader uploader = new Uploader();
|
Uploader uploader = new UispUploader();
|
||||||
// macos9 now officially broken.. see PdeCompilerJavac
|
// macos9 now officially broken.. see PdeCompilerJavac
|
||||||
//PdeCompiler compiler =
|
//PdeCompiler compiler =
|
||||||
// ((PdeBase.platform == PdeBase.MACOS9) ?
|
// ((PdeBase.platform == PdeBase.MACOS9) ?
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Uploader - default downloader class that connects to uisp
|
||||||
|
Part of the Arduino project - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2004-05
|
||||||
|
Hernando Barragan
|
||||||
|
|
||||||
|
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;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.zip.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
//#ifndef RXTX
|
||||||
|
//import javax.comm.*;
|
||||||
|
//#else
|
||||||
|
// rxtx uses package gnu.io, but all the class names
|
||||||
|
// are the same as those used by javax.comm
|
||||||
|
import gnu.io.*;
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
|
||||||
|
public class UispUploader extends Uploader {
|
||||||
|
//PdePreferences preferences;
|
||||||
|
|
||||||
|
//Serial serialPort;
|
||||||
|
static InputStream serialInput;
|
||||||
|
static OutputStream serialOutput;
|
||||||
|
//int serial; // last byte of data received
|
||||||
|
|
||||||
|
public UispUploader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean uploadUsingPreferences(String buildPath, String className)
|
||||||
|
throws RunnerException {
|
||||||
|
List commandDownloader = new ArrayList();
|
||||||
|
commandDownloader.add("-dprog=" + Preferences.get("upload.programmer"));
|
||||||
|
if (Preferences.get("upload.programmer").equals("dapa"))
|
||||||
|
commandDownloader.add("-dlpt=" + Preferences.get("parallel.port"));
|
||||||
|
else {
|
||||||
|
commandDownloader.add(
|
||||||
|
"-dserial=" + (Base.isWindows() ?
|
||||||
|
"/dev/" + Preferences.get("serial.port").toLowerCase() :
|
||||||
|
Preferences.get("serial.port")));
|
||||||
|
commandDownloader.add(
|
||||||
|
"-dspeed=" + Preferences.getInteger("serial.download_rate"));
|
||||||
|
}
|
||||||
|
if (Preferences.getBoolean("upload.erase"))
|
||||||
|
commandDownloader.add("--erase");
|
||||||
|
commandDownloader.add("--upload");
|
||||||
|
if (Preferences.getBoolean("upload.verify"))
|
||||||
|
commandDownloader.add("--verify");
|
||||||
|
commandDownloader.add("if=" + buildPath + File.separator + className + ".hex");
|
||||||
|
return uisp(commandDownloader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean burnBootloaderAVRISP() throws RunnerException {
|
||||||
|
List commandDownloader = new ArrayList();
|
||||||
|
commandDownloader.add("-dprog=" + Preferences.get("bootloader.programmer"));
|
||||||
|
commandDownloader.add(
|
||||||
|
"-dserial=" + (Base.isWindows() ?
|
||||||
|
"/dev/" + Preferences.get("serial.port").toLowerCase() :
|
||||||
|
Preferences.get("serial.port")));
|
||||||
|
commandDownloader.add("-dspeed=" + Preferences.get("serial.burn_rate"));
|
||||||
|
return burnBootloader(commandDownloader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean burnBootloaderParallel() throws RunnerException {
|
||||||
|
List commandDownloader = new ArrayList();
|
||||||
|
commandDownloader.add("-dprog=dapa");
|
||||||
|
commandDownloader.add("-dlpt=" + Preferences.get("parallel.port"));
|
||||||
|
return burnBootloader(commandDownloader);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean burnBootloader(Collection params) throws RunnerException {
|
||||||
|
// I know this is ugly; apologies - that's what happens when you try to
|
||||||
|
// write Lisp-style code in Java.
|
||||||
|
return
|
||||||
|
// unlock bootloader segment of flash memory
|
||||||
|
uisp(params, Arrays.asList(new String[] {
|
||||||
|
"--wr_lock=" + Preferences.get("bootloader.unlock_bits") })) &&
|
||||||
|
// write fuses:
|
||||||
|
// bootloader size of 512 words; from 0xE00-0xFFF
|
||||||
|
// clock speed of 16 MHz, external quartz
|
||||||
|
uisp(params, Arrays.asList(new String[] {
|
||||||
|
"--wr_fuse_l=" + Preferences.get("bootloader.low_fuses"),
|
||||||
|
"--wr_fuse_h=" + Preferences.get("bootloader.high_fuses") })) &&
|
||||||
|
// upload bootloader
|
||||||
|
uisp(params, Arrays.asList(new String[] {
|
||||||
|
"--erase", "--upload", "--verify",
|
||||||
|
"if=" + Preferences.get("bootloader.path") + File.separator +
|
||||||
|
Preferences.get("bootloader.file") })) &&
|
||||||
|
// lock bootloader segment
|
||||||
|
uisp(params, Arrays.asList(new String[] {
|
||||||
|
"--wr_lock=" + Preferences.get("bootloader.lock_bits") }));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean uisp(Collection p1, Collection p2) throws RunnerException {
|
||||||
|
ArrayList p = new ArrayList(p1);
|
||||||
|
p.addAll(p2);
|
||||||
|
return uisp(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean uisp(Collection params) throws RunnerException {
|
||||||
|
flushSerialBuffer();
|
||||||
|
|
||||||
|
List commandDownloader = new ArrayList();
|
||||||
|
commandDownloader.add("uisp");
|
||||||
|
if (Preferences.getBoolean("upload.verbose"))
|
||||||
|
commandDownloader.add("-v=4");
|
||||||
|
commandDownloader.add("-dpart=" + Preferences.get("build.mcu"));
|
||||||
|
commandDownloader.addAll(params);
|
||||||
|
|
||||||
|
return executeUploadCommand(commandDownloader);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Uploader - default downloader class that connects to uisp
|
Uploader - abstract uploading baseclass (common to both uisp and avrdude)
|
||||||
Part of the Arduino project - http://www.arduino.cc/
|
Part of the Arduino project - http://www.arduino.cc/
|
||||||
|
|
||||||
Copyright (c) 2004-05
|
Copyright (c) 2004-05
|
||||||
|
@ -38,7 +38,7 @@ import gnu.io.*;
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
|
|
||||||
public class Uploader implements MessageConsumer {
|
public abstract class Uploader implements MessageConsumer {
|
||||||
static final String BUGS_URL =
|
static final String BUGS_URL =
|
||||||
"https://developer.berlios.de/bugs/?group_id=3590";
|
"https://developer.berlios.de/bugs/?group_id=3590";
|
||||||
static final String SUPER_BADNESS =
|
static final String SUPER_BADNESS =
|
||||||
|
@ -55,85 +55,40 @@ public class Uploader implements MessageConsumer {
|
||||||
public Uploader() {
|
public Uploader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean uploadUsingPreferences(String buildPath, String className)
|
public abstract boolean uploadUsingPreferences(String buildPath, String className)
|
||||||
throws RunnerException {
|
throws RunnerException;
|
||||||
List commandDownloader = new ArrayList();
|
|
||||||
commandDownloader.add("-dprog=" + Preferences.get("upload.programmer"));
|
public abstract boolean burnBootloaderAVRISP() throws RunnerException;
|
||||||
if (Preferences.get("upload.programmer").equals("dapa"))
|
|
||||||
commandDownloader.add("-dlpt=" + Preferences.get("parallel.port"));
|
public abstract boolean burnBootloaderParallel() throws RunnerException;
|
||||||
else {
|
|
||||||
commandDownloader.add(
|
protected void flushSerialBuffer() {
|
||||||
"-dserial=" + (Base.isWindows() ?
|
// Cleanup the serial buffer
|
||||||
"/dev/" + Preferences.get("serial.port").toLowerCase() :
|
Serial serialPort = new Serial();
|
||||||
Preferences.get("serial.port")));
|
byte[] readBuffer;
|
||||||
commandDownloader.add(
|
while(serialPort.available() > 0) {
|
||||||
"-dspeed=" + Preferences.getInteger("serial.download_rate"));
|
readBuffer = serialPort.readBytes();
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
if (Preferences.getBoolean("upload.erase"))
|
serialPort.dispose();
|
||||||
commandDownloader.add("--erase");
|
|
||||||
commandDownloader.add("--upload");
|
|
||||||
if (Preferences.getBoolean("upload.verify"))
|
|
||||||
commandDownloader.add("--verify");
|
|
||||||
commandDownloader.add("if=" + buildPath + File.separator + className + ".hex");
|
|
||||||
return uisp(commandDownloader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean burnBootloaderAVRISP() throws RunnerException {
|
protected boolean executeUploadCommand(Collection commandDownloader)
|
||||||
List commandDownloader = new ArrayList();
|
throws RunnerException
|
||||||
commandDownloader.add("-dprog=" + Preferences.get("bootloader.programmer"));
|
{
|
||||||
commandDownloader.add(
|
|
||||||
"-dserial=" + (Base.isWindows() ?
|
|
||||||
"/dev/" + Preferences.get("serial.port").toLowerCase() :
|
|
||||||
Preferences.get("serial.port")));
|
|
||||||
commandDownloader.add("-dspeed=" + Preferences.get("serial.burn_rate"));
|
|
||||||
return burnBootloader(commandDownloader);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean burnBootloaderParallel() throws RunnerException {
|
|
||||||
List commandDownloader = new ArrayList();
|
|
||||||
commandDownloader.add("-dprog=dapa");
|
|
||||||
commandDownloader.add("-dlpt=" + Preferences.get("parallel.port"));
|
|
||||||
return burnBootloader(commandDownloader);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean burnBootloader(Collection params) throws RunnerException {
|
|
||||||
// I know this is ugly; apologies - that's what happens when you try to
|
|
||||||
// write Lisp-style code in Java.
|
|
||||||
return
|
|
||||||
// unlock bootloader segment of flash memory
|
|
||||||
uisp(params, Arrays.asList(new String[] {
|
|
||||||
"--wr_lock=" + Preferences.get("bootloader.unlock_bits") })) &&
|
|
||||||
// write fuses:
|
|
||||||
// bootloader size of 512 words; from 0xE00-0xFFF
|
|
||||||
// clock speed of 16 MHz, external quartz
|
|
||||||
uisp(params, Arrays.asList(new String[] {
|
|
||||||
"--wr_fuse_l=" + Preferences.get("bootloader.low_fuses"),
|
|
||||||
"--wr_fuse_h=" + Preferences.get("bootloader.high_fuses") })) &&
|
|
||||||
// upload bootloader
|
|
||||||
uisp(params, Arrays.asList(new String[] {
|
|
||||||
"--erase", "--upload", "--verify",
|
|
||||||
"if=" + Preferences.get("bootloader.path") + File.separator +
|
|
||||||
Preferences.get("bootloader.file") })) &&
|
|
||||||
// lock bootloader segment
|
|
||||||
uisp(params, Arrays.asList(new String[] {
|
|
||||||
"--wr_lock=" + Preferences.get("bootloader.lock_bits") }));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean uisp(Collection p1, Collection p2) throws RunnerException {
|
|
||||||
ArrayList p = new ArrayList(p1);
|
|
||||||
p.addAll(p2);
|
|
||||||
return uisp(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean uisp(Collection params) throws RunnerException {
|
|
||||||
String userdir = System.getProperty("user.dir") + File.separator;
|
|
||||||
|
|
||||||
firstErrorFound = false; // haven't found any errors yet
|
firstErrorFound = false; // haven't found any errors yet
|
||||||
secondErrorFound = false;
|
secondErrorFound = false;
|
||||||
notFoundError = false;
|
notFoundError = false;
|
||||||
int result=0; // pre-initialized to quiet a bogus warning from jikes
|
int result=0; // pre-initialized to quiet a bogus warning from jikes
|
||||||
|
|
||||||
|
String userdir = System.getProperty("user.dir") + File.separator;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List commandDownloader = new ArrayList();
|
String[] commandArray = new String[commandDownloader.size()];
|
||||||
|
commandDownloader.toArray(commandArray);
|
||||||
|
|
||||||
String avrBasePath;
|
String avrBasePath;
|
||||||
if(Base.isMacOS()) {
|
if(Base.isMacOS()) {
|
||||||
avrBasePath = new String("tools/avr/bin/");
|
avrBasePath = new String("tools/avr/bin/");
|
||||||
|
@ -144,25 +99,9 @@ public class Uploader implements MessageConsumer {
|
||||||
else {
|
else {
|
||||||
avrBasePath = new String(userdir + "tools/avr/bin/");
|
avrBasePath = new String(userdir + "tools/avr/bin/");
|
||||||
}
|
}
|
||||||
commandDownloader.add(avrBasePath + "uisp");
|
|
||||||
//commandDownloader.add((!Base.isMacOS() ? "" : userdir) + "tools/avr/bin/uisp");
|
commandArray[0] = avrBasePath + commandArray[0];
|
||||||
if (Preferences.getBoolean("upload.verbose"))
|
|
||||||
commandDownloader.add("-v=4");
|
|
||||||
commandDownloader.add("-dpart=" + Preferences.get("build.mcu"));
|
|
||||||
commandDownloader.addAll(params);
|
|
||||||
//commandDownloader.add("-v=4"); // extra verbosity for help debugging.
|
|
||||||
|
|
||||||
// Cleanup the serial buffer
|
|
||||||
Serial serialPort = new Serial();
|
|
||||||
byte[] readBuffer;
|
|
||||||
while(serialPort.available() > 0) {
|
|
||||||
readBuffer = serialPort.readBytes();
|
|
||||||
Thread.sleep(100);
|
|
||||||
}
|
|
||||||
serialPort.dispose();
|
|
||||||
|
|
||||||
String[] commandArray = new String[commandDownloader.size()];
|
|
||||||
commandDownloader.toArray(commandArray);
|
|
||||||
if (Preferences.getBoolean("upload.verbose")) {
|
if (Preferences.getBoolean("upload.verbose")) {
|
||||||
for(int i = 0; i < commandArray.length; i++) {
|
for(int i = 0; i < commandArray.length; i++) {
|
||||||
System.out.print(commandArray[i] + " ");
|
System.out.print(commandArray[i] + " ");
|
||||||
|
|
Loading…
Reference in New Issue