Merging third-party hardware branch: svn merge -r 795:802 https://arduino.googlecode.com/svn/branches/third-party-hardware .

This commit is contained in:
David A. Mellis 2009-12-18 16:05:52 +00:00
commit 42ddb48786
137 changed files with 298 additions and 386 deletions

View File

@ -30,6 +30,7 @@ import java.util.*;
import javax.swing.*;
import processing.app.debug.Compiler;
import processing.app.debug.Target;
import processing.core.*;
@ -84,6 +85,8 @@ public class Base {
// (both those in the p5/libs folder and those with lib subfolders
// found in the sketchbook)
static public String librariesClassPath;
static public HashMap<String, Target> targetsTable;
// Location for untitled items
static File untitledFolder;
@ -246,7 +249,7 @@ public class Base {
// Get paths for the libraries and examples in the Processing folder
//String workingDirectory = System.getProperty("user.dir");
examplesFolder = getContentFile("examples");
librariesFolder = new File(getContentFile("hardware"), "libraries");
librariesFolder = getContentFile("libraries");
toolsFolder = getContentFile("tools");
// Get the sketchbook path, and make sure it's set properly
@ -275,6 +278,10 @@ public class Base {
defaultFolder.mkdirs();
}
}
targetsTable = new HashMap<String, Target>();
loadHardware(getHardwareFolder());
loadHardware(getSketchbookHardwareFolder());
// Check if there were previously opened sketches to be restored
boolean opened = restoreSketches();
@ -985,6 +992,56 @@ public class Base {
e.printStackTrace();
}
}
public void rebuildBoardsMenu(JMenu menu) {
//System.out.println("rebuilding boards menu");
menu.removeAll();
ButtonGroup group = new ButtonGroup();
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);
}
}
}
public void rebuildBurnBootloaderMenu(JMenu menu) {
//System.out.println("rebuilding burn bootloader menu");
menu.removeAll();
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);
}
}
}
/**
@ -1138,7 +1195,8 @@ public class Base {
// String packages[] =
// Compiler.packageListFromClassPath(libraryClassPath);
libraries.add(subfolder);
String packages[] = Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
String packages[] =
Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
for (String pkg : packages) {
importToLibraryTable.put(pkg, subfolder);
}
@ -1162,6 +1220,31 @@ public class Base {
}
return ifound;
}
protected void loadHardware(File folder) {
if (!folder.isDirectory()) return;
String list[] = folder.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
// skip .DS_Store files, .svn folders, etc
if (name.charAt(0) == '.') return false;
if (name.equals("CVS")) return false;
return (new File(dir, name).isDirectory());
}
});
// if a bad folder or something like that, this might come back null
if (list == null) return;
// alphabetize list, since it's not always alpha order
// replaced hella slow bubble sort with this feller for 0093
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
for (String target : list) {
File subfolder = new File(folder, target);
targetsTable.put(target, new Target(target, subfolder));
}
}
// .................................................................
@ -1432,6 +1515,16 @@ public class Base {
}
}
static public Target getTarget() {
return Base.targetsTable.get(Preferences.get("target"));
}
static public Map<String, String> getBoardPreferences() {
return getTarget().getBoards().get(Preferences.get("board"));
}
static public File getSketchbookFolder() {
return new File(Preferences.get("sketchbook.path"));
@ -1446,6 +1539,11 @@ public class Base {
static public String getSketchbookLibrariesPath() {
return getSketchbookLibrariesFolder().getAbsolutePath();
}
static public File getSketchbookHardwareFolder() {
return new File(getSketchbookFolder(), "hardware");
}
protected File getDefaultSketchbookFolder() {

View File

@ -706,16 +706,7 @@ public class Editor extends JFrame implements RunnerListener {
if (boardsMenu == null) {
boardsMenu = new JMenu("Board");
ButtonGroup boardGroup = new ButtonGroup();
for (Iterator i = Preferences.getSubKeys("boards"); i.hasNext(); ) {
String board = (String) i.next();
Action action = new BoardMenuAction(board);
item = new JRadioButtonMenuItem(action);
if (board.equals(Preferences.get("board")))
item.setSelected(true);
boardGroup.add(item);
boardsMenu.add(item);
}
base.rebuildBoardsMenu(boardsMenu);
}
menu.add(boardsMenu);
@ -727,14 +718,9 @@ public class Editor extends JFrame implements RunnerListener {
menu.add(serialMenu);
menu.addSeparator();
JMenu bootloaderMenu = new JMenu("Burn Bootloader");
for (Iterator i = Preferences.getSubKeys("programmers"); i.hasNext(); ) {
String programmer = (String) i.next();
Action action = new BootloaderMenuAction(programmer);
item = new JMenuItem(action);
bootloaderMenu.add(item);
}
base.rebuildBurnBootloaderMenu(bootloaderMenu);
menu.add(bootloaderMenu);
menu.addMenuListener(new MenuListener() {
@ -964,30 +950,6 @@ public class Editor extends JFrame implements RunnerListener {
}
class BoardMenuAction extends AbstractAction {
private String board;
public BoardMenuAction(String board) {
super(Preferences.get("boards." + board + ".name"));
this.board = board;
}
public void actionPerformed(ActionEvent actionevent) {
//System.out.println("Switching to " + board);
Preferences.set("board", board);
}
}
class BootloaderMenuAction extends AbstractAction {
private String programmer;
public BootloaderMenuAction(String programmer) {
super("w/ " + Preferences.get("programmers." + programmer + ".name"));
this.programmer = programmer;
}
public void actionPerformed(ActionEvent actionevent) {
handleBurnBootloader(programmer);
}
}
protected void populateSerialMenu() {
// getting list of ports
@ -1842,10 +1804,7 @@ public class Editor extends JFrame implements RunnerListener {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
sketch.compile(new Target(
Base.getHardwarePath() + File.separator + "cores",
Preferences.get("boards." + Preferences.get("board") + ".build.core")),
verbose);
sketch.compile(verbose);
statusNotice("Done compiling.");
} catch (RunnerException e) {
//statusError("Error compiling...");
@ -2257,10 +2216,7 @@ public class Editor extends JFrame implements RunnerListener {
uploading = true;
boolean success = sketch.exportApplet(new Target(
Base.getHardwarePath() + File.separator + "cores",
Preferences.get("boards." + Preferences.get("board") + ".build.core")),
verbose);
boolean success = sketch.exportApplet(verbose);
if (success) {
statusNotice("Done uploading.");
} else {
@ -2323,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.");

View File

@ -131,7 +131,6 @@ public class Preferences {
static Hashtable defaults;
static Hashtable table = new Hashtable();;
static Hashtable prefixes = new Hashtable();
static File preferencesFile;
@ -198,25 +197,6 @@ public class Preferences {
" and restart Arduino.", ex);
}
}
}
try {
load(new FileInputStream(new File(Base.getHardwareFolder(), "boards.txt")),
"boards");
} catch (Exception ex) {
Base.showError("Error reading board definitions",
"Error reading the board definitions file (" +
new File(Base.getHardwareFolder(), "boards.txt").getAbsolutePath() + "). " +
"Please re-download or re-unzip Arduino.\n", ex);
}
try {
load(new FileInputStream(new File(Base.getHardwareFolder(), "programmers.txt")),
"programmers");
} catch (Exception ex) {
Base.showError("Error reading programmers definitions",
"Error reading the programmers definitions file. " +
"Please re-download or re-unzip Arduino.\n", ex);
}
}
@ -569,13 +549,7 @@ public class Preferences {
load(input, table);
}
static protected void load(InputStream input, String prefix) throws IOException {
LinkedHashMap table = new LinkedHashMap();
prefixes.put(prefix, table);
load(input, table);
}
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) ||
@ -628,20 +602,8 @@ public class Preferences {
//static public String get(String attribute) {
//return get(attribute, null);
//}
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) ?
@ -654,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 Iterator 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.iterator();
}
static public String getDefault(String attribute) {
return (String) defaults.get(attribute);
}

View File

@ -27,7 +27,6 @@ import processing.app.debug.AvrdudeUploader;
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.*;
@ -1142,7 +1141,7 @@ public class Sketch {
* X. afterwards, some of these steps need a cleanup function
* </PRE>
*/
protected String compile(Target target, boolean verbose)
protected String compile(boolean verbose)
throws RunnerException {
String name;
@ -1177,7 +1176,7 @@ public class Sketch {
cleanup();
// handle preprocessing the main file's code
name = build(tempBuildFolder.getAbsolutePath(), target, verbose);
name = build(tempBuildFolder.getAbsolutePath(), verbose);
size(tempBuildFolder.getAbsolutePath(), name);
return name;
@ -1199,11 +1198,11 @@ public class Sketch {
* @param buildPath Location to copy all the .java files
* @return null if compilation failed, main class name if not
*/
public String preprocess(String buildPath, Target target) throws RunnerException {
return preprocess(buildPath, new PdePreprocessor(), target);
public String preprocess(String buildPath) throws RunnerException {
return preprocess(buildPath, new PdePreprocessor());
}
public String preprocess(String buildPath, PdePreprocessor preprocessor, Target target) throws RunnerException {
public String preprocess(String buildPath, PdePreprocessor preprocessor) throws RunnerException {
// make sure the user didn't hide the sketch folder
ensureExistence();
@ -1279,8 +1278,7 @@ public class Sketch {
headerOffset = preprocessor.writePrefix(bigCode.toString(),
buildPath,
name,
codeFolderPackages,
target);
codeFolderPackages);
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
String msg = "Build folder disappeared or could not be written";
@ -1378,31 +1376,31 @@ public class Sketch {
*
* @return null if compilation failed, main class name if not
*/
public String build(String buildPath, Target target, boolean verbose)
public String build(String buildPath, boolean verbose)
throws RunnerException {
// run the preprocessor
String primaryClassName = preprocess(buildPath, target);
String primaryClassName = preprocess(buildPath);
// compile the program. errors will happen as a RunnerException
// that will bubble up to whomever called build().
Compiler compiler = new Compiler();
if (compiler.compile(this, buildPath, primaryClassName, target, verbose)) {
if (compiler.compile(this, buildPath, primaryClassName, verbose)) {
return primaryClassName;
}
return null;
}
protected boolean exportApplet(Target target, boolean verbose) throws Exception {
return exportApplet(new File(folder, "applet").getAbsolutePath(), target, verbose);
protected boolean exportApplet(boolean verbose) throws Exception {
return exportApplet(new File(folder, "applet").getAbsolutePath(), verbose);
}
/**
* Handle export to applet.
*/
public boolean exportApplet(String appletPath, Target target, boolean verbose)
public boolean exportApplet(String appletPath, boolean verbose)
throws RunnerException, IOException {
// Make sure the user didn't hide the sketch folder
@ -1426,7 +1424,7 @@ public class Sketch {
appletFolder.mkdirs();
// build the sketch
String foundName = build(appletFolder.getPath(), target, false);
String foundName = build(appletFolder.getPath(), false);
// (already reported) error during export, exit this function
if (foundName == null) return false;
@ -1449,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();

View File

@ -45,7 +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<String, String> boardPreferences = Base.getBoardPreferences();
String uploadUsing = boardPreferences.get("upload.using");
if (uploadUsing == null) {
// fall back on global preference
uploadUsing = Preferences.get("upload.using");
@ -53,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);
}
@ -61,65 +63,70 @@ public class AvrdudeUploader extends Uploader {
private boolean uploadViaBootloader(String buildPath, String className)
throws RunnerException {
Map<String, String> 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"))
protocol = "stk500v1";
commandDownloader.add("-c" + protocol);
commandDownloader.add("-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port"));
commandDownloader.add(
"-b" + Preferences.getInteger("boards." + Preferences.get("board") + ".upload.speed"));
"-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port"));
commandDownloader.add(
"-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." + Preferences.get("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<String, String> 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<String, String> boardPreferences = Base.getBoardPreferences();
List fuses = new ArrayList();
fuses.add("-e"); // erase the chip
fuses.add("-Ulock:w:" + Preferences.get("boards." + Preferences.get("board") + ".bootloader.unlock_bits") + ":m");
if (Preferences.get("boards." + Preferences.get("board") + ".bootloader.extended_fuses") != null)
fuses.add("-Uefuse:w:" + Preferences.get("boards." + Preferences.get("board") + ".bootloader.extended_fuses") + ":m");
fuses.add("-Uhfuse:w:" + Preferences.get("boards." + Preferences.get("board") + ".bootloader.high_fuses") + ":m");
fuses.add("-Ulfuse:w:" + Preferences.get("boards." + Preferences.get("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;
@ -127,12 +134,26 @@ public class AvrdudeUploader extends Uploader {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
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:" + Base.getHardwarePath() + File.separator + "bootloaders" + File.separator +
Preferences.get("boards." + Preferences.get("board") + ".bootloader.path") +
File.separator + Preferences.get("boards." + Preferences.get("board") + ".bootloader.file") + ":i");
bootloader.add("-Ulock:w:" + Preferences.get("boards." + Preferences.get("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);
}
@ -165,7 +186,7 @@ public class AvrdudeUploader extends Uploader {
commandDownloader.add("-q");
commandDownloader.add("-q");
}
commandDownloader.add("-p" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"));
commandDownloader.add("-p" + Base.getBoardPreferences().get("build.mcu"));
commandDownloader.addAll(params);
return executeUploadCommand(commandDownloader);

View File

@ -36,7 +36,7 @@ import java.util.zip.*;
public class Compiler implements MessageConsumer {
static final String BUGS_URL =
"https://developer.berlios.de/bugs/?group_id=3590";
"http://code.google.com/p/arduino/issues/list";
static final String SUPER_BADNESS =
"Compiler error, please submit this code to " + BUGS_URL;
@ -55,14 +55,12 @@ public class Compiler implements MessageConsumer {
* @param sketch Sketch object to be compiled.
* @param buildPath Where the temporary files live and will be built from.
* @param primaryClassName the name of the combined sketch file w/ extension
* @param target the target (core) to build against
* @return true if successful.
* @throws RunnerException Only if there's a problem. Only then.
*/
public boolean compile(Sketch sketch,
String buildPath,
String primaryClassName,
Target target,
boolean verbose) throws RunnerException {
this.sketch = sketch;
this.buildPath = buildPath;
@ -73,22 +71,37 @@ public class Compiler implements MessageConsumer {
MessageStream pms = new MessageStream(this);
String avrBasePath = Base.getAvrBasePath();
Map<String, String> 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<File> objectFiles = new ArrayList<File>();
List includePaths = new ArrayList();
includePaths.add(target.getPath());
includePaths.add(corePath);
String runtimeLibraryName = buildPath + File.separator + "core.a";
// 1. compile the target (core), outputting .o files to <buildPath> and
// then collecting them into the core.a library file.
// 1. compile the core, outputting .o files to <buildPath> and then
// collecting them into the core.a library file.
List<File> targetObjectFiles =
List<File> coreObjectFiles =
compileFiles(avrBasePath, buildPath, includePaths,
findFilesInPath(target.getPath(), "S", true),
findFilesInPath(target.getPath(), "c", true),
findFilesInPath(target.getPath(), "cpp", true));
findFilesInPath(corePath, "S", true),
findFilesInPath(corePath, "c", true),
findFilesInPath(corePath, "cpp", true),
boardPreferences);
List baseCommandAR = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-ar",
@ -96,7 +109,7 @@ public class Compiler implements MessageConsumer {
runtimeLibraryName
}));
for(File file : targetObjectFiles) {
for(File file : coreObjectFiles) {
List commandAR = new ArrayList(baseCommandAR);
commandAR.add(file.getAbsolutePath());
execAsynchronously(commandAR);
@ -111,21 +124,24 @@ public class Compiler implements MessageConsumer {
for (File libraryFolder : sketch.getImportedLibraries()) {
File outputFolder = new File(buildPath, libraryFolder.getName());
File utilityFolder = new File(libraryFolder, "utility");
createFolder(outputFolder);
// this library can use includes in its utility/ folder
includePaths.add(libraryFolder.getPath() + File.separator + "utility");
includePaths.add(utilityFolder.getAbsolutePath());
objectFiles.addAll(
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(new File(libraryFolder, "utility"), "S", false),
findFilesInFolder(new File(libraryFolder, "utility"), "c", false),
findFilesInFolder(new File(libraryFolder, "utility"), "cpp", false)));
findFilesInFolder(utilityFolder, "S", false),
findFilesInFolder(utilityFolder, "c", false),
findFilesInFolder(utilityFolder, "cpp", false),
boardPreferences));
// other libraries should not see this library's utility/ folder
includePaths.remove(includePaths.size() - 1);
}
@ -136,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
@ -144,7 +161,7 @@ public class Compiler implements MessageConsumer {
avrBasePath + "avr-gcc",
"-Os",
"-Wl,--gc-sections",
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
"-mmcu=" + boardPreferences.get("build.mcu"),
"-o",
buildPath + File.separator + primaryClassName + ".elf"
}));
@ -195,7 +212,8 @@ public class Compiler implements MessageConsumer {
private List<File> compileFiles(String avrBasePath,
String buildPath, List<File> includePaths,
List<File> sSources,
List<File> cSources, List<File> cppSources)
List<File> cSources, List<File> cppSources,
Map<String, String> boardPreferences)
throws RunnerException {
List<File> objectPaths = new ArrayList<File>();
@ -205,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) {
@ -213,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) {
@ -221,7 +241,8 @@ public class Compiler implements MessageConsumer {
objectPaths.add(new File(objectPath));
execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths,
file.getAbsolutePath(),
objectPath));
objectPath,
boardPreferences));
}
return objectPaths;
@ -320,7 +341,9 @@ public class Compiler implements MessageConsumer {
// attemping to compare
//
//String buildPathSubst = buildPath.replace(File.separatorChar, '/') + "/";
String buildPathSubst = buildPath.replace(File.separatorChar,File.separatorChar) + File.separatorChar;
String buildPathSubst =
buildPath.replace(File.separatorChar,File.separatorChar) +
File.separatorChar;
String partialTempPath = null;
int partialStartIndex = -1; //s.indexOf(partialTempPath);
@ -444,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<String, String> 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." + Preferences.get("board") + ".build.mcu"),
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
"-mmcu=" + boardPreferences.get("build.mcu"),
"-DF_CPU=" + boardPreferences.get("build.f_cpu"),
"-DARDUINO=" + Base.REVISION,
}));
@ -467,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<String, String> boardPreferences) {
List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-gcc",
@ -477,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." + Preferences.get("board") + ".build.mcu"),
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
"-mmcu=" + boardPreferences.get("build.mcu"),
"-DF_CPU=" + boardPreferences.get("build.f_cpu"),
"-DARDUINO=" + Base.REVISION,
}));
@ -494,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<String, String> boardPreferences) {
List baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-g++",
@ -505,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." + Preferences.get("board") + ".build.mcu"),
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
"-mmcu=" + boardPreferences.get("build.mcu"),
"-DF_CPU=" + boardPreferences.get("build.f_cpu"),
"-DARDUINO=" + Base.REVISION,
}));

View File

@ -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<String, Map<String, String>> 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<String, Map<String, String>> getProgrammers() {
return programmers;
}
}
}

View File

@ -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

View File

@ -30,7 +30,6 @@
package processing.app.preproc;
import processing.app.*;
import processing.app.debug.Target;
import processing.core.*;
import java.io.*;
@ -50,7 +49,6 @@ public class PdePreprocessor {
// we always write one header: WProgram.h
public int headerCount = 1;
Target target;
List prototypes;
@ -82,12 +80,10 @@ public class PdePreprocessor {
public PdePreprocessor() { }
public int writePrefix(String program, String buildPath,
String name, String codeFolderPackages[],
Target target)
String name, String codeFolderPackages[])
throws FileNotFoundException {
this.buildPath = buildPath;
this.name = name;
this.target = target;
int tabSize = Preferences.getInteger("editor.tabs.size");
char[] indentChars = new char[tabSize];
@ -196,7 +192,7 @@ public class PdePreprocessor {
// String extraImports[]) throws java.lang.Exception {
public String write() throws java.lang.Exception {
writeProgram(stream, program, prototypes);
writeFooter(stream, target);
writeFooter(stream);
stream.close();
return name;
@ -223,23 +219,7 @@ public class PdePreprocessor {
*
* @param out PrintStream to write it to.
*/
protected void writeFooter(PrintStream out, Target target) throws java.lang.Exception {
// Open the file main.cxx and copy its entire contents to the bottom of the
// generated sketch .cpp file...
String mainFileName = target.getPath() + File.separator + "main.cxx";
FileReader reader = null;
reader = new FileReader(mainFileName);
LineNumberReader mainfile = new LineNumberReader(reader);
String line;
while ((line = mainfile.readLine()) != null) {
out.print(line + "\n");
}
mainfile.close();
}
protected void writeFooter(PrintStream out) throws java.lang.Exception {}
public ArrayList<String> getExtraImports() {

View File

@ -36,7 +36,7 @@ else
chmod +x work/Arduino.app/Contents/MacOS/JavaApplicationStub
cp -rX ../shared/lib "$RESOURCES/"
cp -rX ../shared/libraries "$RESOURCES/"
cp -rX ../../libraries "$RESOURCES/"
cp -rX ../shared/tools "$RESOURCES/"
cp -rX ../../hardware "$RESOURCES/"
@ -126,4 +126,4 @@ cd ../..
echo
echo Done.
echo Done.

View File

@ -34,7 +34,7 @@
// 2-dimensional array of row pin numbers:
const int row[8] = {
2,7,19,5,18,12,16 };
2,7,19,5,13,18,12,16 };
// 2-dimensional array of column pin numbers:
const int col[8] = {

View File

@ -1,3 +1,5 @@
#include <WProgram.h>
int main(void)
{
init();

View File

@ -1,119 +0,0 @@
/*
pin_atmega8.c - pin definitions for the atmega8
Part of Arduino / Wiring Lite
Copyright (c) 2005 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id$
*/
#include <avr/io.h>
#include "wiring.h"
// We map the pin numbers passed to digitalRead() or
// analogRead() directly to the corresponding pin
// numbers on the Atmega8. No distinction is made
// between analog and digital pins.
// ATMEL ATMEGA8
//
// +-\/-+
// PC6 1| |28 PC5
// PD0 2| |27 PC4
// PD1 3| |26 PC3
// PD2 4| |25 PC2
// PD3 5| |24 PC1
// PD4 6| |23 PC0
// VCC 7| |22 GND
// GND 8| |21 AREF
// PB6 9| |20 AVCC
// PB7 10| |19 PB5
// PD5 11| |18 PB4
// PD6 12| |17 PB3
// PD7 13| |16 PB2
// PB0 14| |15 PB1
// +----+
#define NUM_PINS 28
#define NUM_PORTS 4
#define PB 2
#define PC 3
#define PD 4
int port_to_mode[NUM_PORTS + 1] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(DDRB),
_SFR_IO_ADDR(DDRC),
_SFR_IO_ADDR(DDRD),
};
int port_to_output[NUM_PORTS + 1] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(PORTB),
_SFR_IO_ADDR(PORTC),
_SFR_IO_ADDR(PORTD),
};
int port_to_input[NUM_PORTS + 1] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(PINB),
_SFR_IO_ADDR(PINC),
_SFR_IO_ADDR(PIND),
};
pin_t digital_pin_to_port_array[] = {
{ NOT_A_PIN, NOT_A_PIN },
{ PC, 6 },
{ PD, 0 },
{ PD, 1 },
{ PD, 2 },
{ PD, 3 },
{ PD, 4 },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ PB, 6 },
{ PB, 7 },
{ PD, 5 },
{ PD, 6 },
{ PD, 7 },
{ PB, 0 },
{ PB, 1 },
{ PB, 2 },
{ PB, 3 },
{ PB, 4 },
{ PB, 5 },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ PC, 0 },
{ PC, 1 },
{ PC, 2 },
{ PC, 3 },
{ PC, 4 },
{ PC, 5 },
};
pin_t *digital_pin_to_port = digital_pin_to_port_array;
pin_t *analog_in_pin_to_port = digital_pin_to_port_array;
pin_t *analog_out_pin_to_port = digital_pin_to_port_array;

Some files were not shown because too many files have changed in this diff Show More