diff --git a/.gitignore b/.gitignore index fea0aa5fadf..a1322b9c839 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ build/macosx/work/ core/bin/ core/core.jar build/macosx/arduino.xcworkspace/contents.xcworkspacedata - build/macosx/arduino.xcworkspace/xcuserdata/mellis.xcuserdatad/UserInterfaceState.xcuserstate diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index a9cc13ded16..46c24c362fc 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -44,7 +44,7 @@ public class Base { public static final int REVISION = 101; /** This might be replaced by main() if there's a lib/version.txt file. */ - static String VERSION_NAME = "0101"; + static String VERSION_NAME = "0101E0006"; /** Set true if this a proper release rather than a numbered revision. */ static public boolean RELEASE = false; @@ -61,6 +61,12 @@ public class Base { platformIndices.put("macosx", PConstants.MACOSX); platformIndices.put("linux", PConstants.LINUX); } + + static Map archMap = new HashMap(); + static { + archMap.put("arduino", "avr"); + archMap.put("msp430", "msp430"); + } static Platform platform; static private boolean commandLine; @@ -240,7 +246,10 @@ public Base(String[] args) { // Get paths for the libraries and examples in the Processing folder //String workingDirectory = System.getProperty("user.dir"); examplesFolder = getContentFile("examples"); - librariesFolder = getContentFile("libraries"); + String targetLibDir = new String(""); + if(Preferences.get("target").equals("msp430")) + targetLibDir = "hardware/msp430/"; + librariesFolder = getContentFile(targetLibDir + "libraries"); toolsFolder = getContentFile("tools"); // Get the sketchbook path, and make sure it's set properly @@ -772,7 +781,7 @@ public boolean handleClose(Editor editor) { "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+ " " + "Are you sure you want to Quit?" + - "

Closing the last open sketch will quit Arduino."); + "

Closing the last open sketch will quit Energia."); int result = JOptionPane.showOptionDialog(editor, prompt, @@ -995,6 +1004,12 @@ public void onBoardOrPortChange() { editor.onBoardOrPortChange(); } } + + public void onArchChanged() { + for (Editor editor : editors) { + editor.onArchChanged(); + } + } public void rebuildBoardsMenu(JMenu menu) { @@ -1007,6 +1022,15 @@ public void rebuildBoardsMenu(JMenu menu) { new AbstractAction(target.getBoards().get(board).get("name")) { public void actionPerformed(ActionEvent actionevent) { //System.out.println("Switching to " + target + ":" + board); + String n = (String)getValue("target"); + String o = Preferences.get("target"); + if(!n.equals(o)) { + String targetLibDir = new String(""); + if(n.equals("msp430")) + targetLibDir = "hardware/msp430/"; + librariesFolder = getContentFile(targetLibDir + "libraries"); + onArchChanged(); + } Preferences.set("target", (String) getValue("target")); Preferences.set("board", (String) getValue("board")); onBoardOrPortChange(); @@ -1541,6 +1565,48 @@ static public String getAvrBasePath() { } return path; } + + static public String getMSP430BasePath() { + String path = getHardwarePath() + File.separator + "tools" + + File.separator + "msp430" + File.separator + "bin" + File.separator; + if (Base.isLinux() && !(new File(path)).exists()) { + return ""; // use distribution provided avr tools if bundled tools missing + } + return path; + } + + + static public String getArch() { + return archMap.get(Preferences.get("target")); + } + + static public String toShortPath(String longpath) { + String shortpath = ""; + longpath = longpath.replaceAll("\\s", ""); + longpath = longpath.toUpperCase(); + StringTokenizer tokenizer = new StringTokenizer(longpath, "\\"); + while(tokenizer.hasMoreTokens() == true) { + String temp = tokenizer.nextToken(); + if(temp.length() > 8) + temp = temp.substring(0, 6) + "~1"; + shortpath += temp + "\\"; + } + return shortpath; + } + + static public String getBasePath() { + if(Base.isLinux()) { + return ""; // avr tools are installed system-wide and in the path + } else if (Base.isWindows()){ + String ret = toShortPath(getHardwarePath() + File.separator + "tools" + + File.separator + getArch() + File.separator + "bin" + File.separator); + return ret; + } else { + return getHardwarePath() + File.separator + "tools" + + File.separator + getArch() + File.separator + "bin" + File.separator; + } + } + static public Target getTarget() { diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 30d05c73f71..60cb748355a 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -150,7 +150,7 @@ public class Editor extends JFrame implements RunnerListener { public Editor(Base ibase, String path, int[] location) { - super("Arduino"); + super("Energia"); this.base = ibase; Base.setIcon(this); @@ -543,15 +543,18 @@ public void actionPerformed(ActionEvent e) { }); fileMenu.add(item); - item = newJMenuItemShift(_("Upload Using Programmer"), 'U'); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - handleExport(true); - } - }); - fileMenu.add(item); + if(!Preferences.get("target").equals("msp430")) { + item = newJMenuItemShift(_("Upload Using Programmer"), 'U'); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + handleExport(true); + } + }); + + fileMenu.add(item); - fileMenu.addSeparator(); + fileMenu.addSeparator(); + } item = newJMenuItemShift(_("Page Setup"), 'P'); item.addActionListener(new ActionListener() { @@ -696,14 +699,16 @@ public void actionPerformed(ActionEvent e) { base.rebuildProgrammerMenu(programmerMenu); menu.add(programmerMenu); - item = new JMenuItem(_("Burn Bootloader")); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - handleBurnBootloader(); - } - }); - menu.add(item); - + if(!Preferences.get("target").equals("msp430")) { + item = new JMenuItem(_("Burn Bootloader")); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + handleBurnBootloader(); + } + }); + menu.add(item); + } + menu.addMenuListener(new MenuListener() { public void menuCanceled(MenuEvent e) {} public void menuDeselected(MenuEvent e) {} @@ -1099,7 +1104,7 @@ public void actionPerformed(ActionEvent e) { // macosx already has its own about menu if (!Base.isMacOS()) { menu.addSeparator(); - item = new JMenuItem(_("About Arduino")); + item = new JMenuItem(_("About Energia")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { base.handleAbout(); @@ -2163,7 +2168,7 @@ protected boolean handleOpenInternal(String path) { // Set the title of the window to "sketch_070752a - Processing 0126" setTitle( I18n.format( - _("{0} | Arduino {1}"), + _("{0} | Energia {1}"), sketch.getName(), Base.VERSION_NAME ) @@ -2612,7 +2617,10 @@ public void statusEmpty() { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - + protected void onArchChanged() { + base.rebuildImportMenu(importMenu); + } + protected void onBoardOrPortChange() { Map boardPreferences = Base.getBoardPreferences(); lineStatus.setBoardName(boardPreferences.get("name")); diff --git a/app/src/processing/app/Platform.java b/app/src/processing/app/Platform.java index 1fcdb899edd..d2354c93a7c 100644 --- a/app/src/processing/app/Platform.java +++ b/app/src/processing/app/Platform.java @@ -75,7 +75,7 @@ public void init(Base base) { public File getSettingsFolder() throws Exception { // otherwise make a .processing directory int the user's home dir File home = new File(System.getProperty("user.home")); - File dataFolder = new File(home, ".arduino"); + File dataFolder = new File(home, ".energia"); return dataFolder; /* diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 94ab1837647..84766697266 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -146,7 +146,7 @@ static protected void init(String commandLinePrefs) { load(Base.getLibStream("preferences.txt")); } catch (Exception e) { Base.showError(null, _("Could not read default settings.\n" + - "You'll need to reinstall Arduino."), e); + "You'll need to reinstall Energia."), e); } // check for platform-specific properties in the defaults @@ -200,7 +200,7 @@ static protected void init(String commandLinePrefs) { I18n.format( _("Error reading the preferences file. " + "Please delete (or move)\n" + - "{0} and restart Arduino."), + "{0} and restart Energia."), preferencesFile.getAbsolutePath() ), ex); } @@ -277,7 +277,7 @@ public void actionPerformed(ActionEvent e) { box.add(label); fontSizeField = new JTextField(4); box.add(fontSizeField); - label = new JLabel(_(" (requires restart of Arduino)")); + label = new JLabel(_(" (requires restart of Energia)")); box.add(label); pain.add(box); d = box.getPreferredSize(); @@ -342,7 +342,7 @@ public void actionPerformed(ActionEvent e) { if (Base.isWindows()) { autoAssociateBox = - new JCheckBox(_("Automatically associate .ino files with Arduino")); + new JCheckBox(_("Automatically associate .ino files with Energia")); pain.add(autoAssociateBox); d = autoAssociateBox.getPreferredSize(); autoAssociateBox.setBounds(left, top, d.width + 10, d.height); @@ -382,7 +382,7 @@ public void mouseExited(MouseEvent e) { right = Math.max(right, left + d.width); top += d.height; - label = new JLabel(_("(edit only when Arduino is not running)")); + label = new JLabel(_("(edit only when Energia is not running)")); pain.add(label); d = label.getPreferredSize(); label.setForeground(Color.gray); diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 1d540c3741c..642c5d2d2c3 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -24,6 +24,7 @@ package processing.app; import processing.app.debug.AvrdudeUploader; +import processing.app.debug.MSP430Uploader; import processing.app.debug.Compiler; import processing.app.debug.RunnerException; import processing.app.debug.Sizer; @@ -1702,10 +1703,15 @@ protected String upload(String buildPath, String suggestedClassName, boolean usi // download the program // - uploader = new AvrdudeUploader(); + if(Base.getArch() == "msp430"){ + uploader = new MSP430Uploader(); + } else { + uploader = new AvrdudeUploader(); + } + boolean success = uploader.uploadUsingPreferences(buildPath, - suggestedClassName, - usingProgrammer); + suggestedClassName, + usingProgrammer); return success ? suggestedClassName : null; } diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 29953666dd5..0e7383ed591 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -72,7 +72,8 @@ public boolean compile(Sketch sketch, // the pms object isn't used for anything but storage MessageStream pms = new MessageStream(this); - String avrBasePath = Base.getAvrBasePath(); + + String basePath = Base.getBasePath(); Map boardPreferences = Base.getBoardPreferences(); String core = boardPreferences.get("build.core"); if (core == null) { @@ -125,7 +126,7 @@ public boolean compile(Sketch sketch, sketch.setCompilingProgress(30); objectFiles.addAll( - compileFiles(avrBasePath, buildPath, includePaths, + compileFiles(basePath, buildPath, includePaths, findFilesInPath(buildPath, "S", false), findFilesInPath(buildPath, "c", false), findFilesInPath(buildPath, "cpp", false), @@ -141,7 +142,7 @@ public boolean compile(Sketch sketch, // this library can use includes in its utility/ folder includePaths.add(utilityFolder.getAbsolutePath()); objectFiles.addAll( - compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, + compileFiles(basePath, outputFolder.getAbsolutePath(), includePaths, findFilesInFolder(libraryFolder, "S", false), findFilesInFolder(libraryFolder, "c", false), findFilesInFolder(libraryFolder, "cpp", false), @@ -149,7 +150,7 @@ public boolean compile(Sketch sketch, outputFolder = new File(outputFolder, "utility"); createFolder(outputFolder); objectFiles.addAll( - compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, + compileFiles(basePath, outputFolder.getAbsolutePath(), includePaths, findFilesInFolder(utilityFolder, "S", false), findFilesInFolder(utilityFolder, "c", false), findFilesInFolder(utilityFolder, "cpp", false), @@ -166,19 +167,30 @@ public boolean compile(Sketch sketch, includePaths.add(corePath); // include path for core only if (variantPath != null) includePaths.add(variantPath); List coreObjectFiles = - compileFiles(avrBasePath, buildPath, includePaths, + compileFiles(basePath, buildPath, includePaths, findFilesInPath(corePath, "S", true), findFilesInPath(corePath, "c", true), findFilesInPath(corePath, "cpp", true), boardPreferences); - String runtimeLibraryName = buildPath + File.separator + "core.a"; - List baseCommandAR = new ArrayList(Arrays.asList(new String[] { - avrBasePath + "avr-ar", - "rcs", - runtimeLibraryName - })); - for(File file : coreObjectFiles) { + String arch = Base.getArch(); + String runtimeLibraryName = buildPath + File.separator + "core.a"; + List baseCommandAR; + if(arch == "msp430") { + baseCommandAR = new ArrayList(Arrays.asList(new String[] { + basePath + "msp430-ar", + "rcs", + runtimeLibraryName + })); + } else { + baseCommandAR = new ArrayList(Arrays.asList(new String[] { + basePath + "avr-ar", + "rcs", + runtimeLibraryName + })); + } + + for(File file : coreObjectFiles) { List commandAR = new ArrayList(baseCommandAR); commandAR.add(file.getAbsolutePath()); execAsynchronously(commandAR); @@ -192,15 +204,30 @@ public boolean compile(Sketch sketch, if ( atmega2560.equals(boardPreferences.get("build.mcu")) ) { optRelax = new String(",--relax"); } - sketch.setCompilingProgress(60); - List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { - avrBasePath + "avr-gcc", - "-Os", + sketch.setCompilingProgress(60); + List baseCommandLinker; + if (arch == "msp430") { + List objects = new ArrayList(baseCommandAR); + baseCommandLinker = new ArrayList(Arrays.asList(new String[] { + basePath + "msp430-gcc", + "-Os", + // msp430 linker has an issue with main residing in an archive, cora.a in this case. + // -u,main works around this by forcing the linker to find a definition for main. + "-Wl,-gc-sections,-u,main", + "-mmcu=" + boardPreferences.get("build.mcu"), + "-o", + buildPath + File.separator + primaryClassName + ".elf" + })); + } else { + baseCommandLinker = new ArrayList(Arrays.asList(new String[] { + basePath + "avr-gcc", + "-Os", "-Wl,--gc-sections"+optRelax, - "-mmcu=" + boardPreferences.get("build.mcu"), - "-o", - buildPath + File.separator + primaryClassName + ".elf" - })); + "-mmcu=" + boardPreferences.get("build.mcu"), + "-o", + buildPath + File.separator + primaryClassName + ".elf" + })); + } for (File file : objectFiles) { baseCommandLinker.add(file.getAbsolutePath()); @@ -212,27 +239,39 @@ public boolean compile(Sketch sketch, execAsynchronously(baseCommandLinker); - List baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] { - avrBasePath + "avr-objcopy", + List baseCommandObjcopy; + if (arch == "msp430") { + baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] { + basePath + "msp430-objcopy", "-O", "-R", })); - - List commandObjcopy; + } else { + baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] { + basePath + "avr-objcopy", + "-O", + "-R", + })); - // 5. extract EEPROM data (from EEMEM directive) to .eep file. - sketch.setCompilingProgress(70); - commandObjcopy = new ArrayList(baseCommandObjcopy); - commandObjcopy.add(2, "ihex"); - commandObjcopy.set(3, "-j"); - commandObjcopy.add(".eeprom"); - commandObjcopy.add("--set-section-flags=.eeprom=alloc,load"); - commandObjcopy.add("--no-change-warnings"); - commandObjcopy.add("--change-section-lma"); - commandObjcopy.add(".eeprom=0"); - commandObjcopy.add(buildPath + File.separator + primaryClassName + ".elf"); - commandObjcopy.add(buildPath + File.separator + primaryClassName + ".eep"); - execAsynchronously(commandObjcopy); + } + List commandObjcopy; + if (arch == "msp430") { + //nothing + } else { + // 5. extract EEPROM data (from EEMEM directive) to .eep file. + sketch.setCompilingProgress(70); + commandObjcopy = new ArrayList(baseCommandObjcopy); + commandObjcopy.add(2, "ihex"); + commandObjcopy.set(3, "-j"); + commandObjcopy.add(".eeprom"); + commandObjcopy.add("--set-section-flags=.eeprom=alloc,load"); + commandObjcopy.add("--no-change-warnings"); + commandObjcopy.add("--change-section-lma"); + commandObjcopy.add(".eeprom=0"); + commandObjcopy.add(buildPath + File.separator + primaryClassName + ".elf"); + commandObjcopy.add(buildPath + File.separator + primaryClassName + ".eep"); + execAsynchronously(commandObjcopy); + } // 6. build the .hex file sketch.setCompilingProgress(80); @@ -249,7 +288,7 @@ public boolean compile(Sketch sketch, } - private List compileFiles(String avrBasePath, + private List compileFiles(String basePath, String buildPath, List includePaths, List sSources, List cSources, List cppSources, @@ -261,7 +300,7 @@ private List compileFiles(String avrBasePath, for (File file : sSources) { String objectPath = buildPath + File.separator + file.getName() + ".o"; objectPaths.add(new File(objectPath)); - execAsynchronously(getCommandCompilerS(avrBasePath, includePaths, + execAsynchronously(getCommandCompilerS(basePath, includePaths, file.getAbsolutePath(), objectPath, boardPreferences)); @@ -274,7 +313,7 @@ private List compileFiles(String avrBasePath, File dependFile = new File(dependPath); objectPaths.add(objectFile); if (is_already_compiled(file, objectFile, dependFile, boardPreferences)) continue; - execAsynchronously(getCommandCompilerC(avrBasePath, includePaths, + execAsynchronously(getCommandCompilerC(basePath, includePaths, file.getAbsolutePath(), objectPath, boardPreferences)); @@ -287,7 +326,7 @@ private List compileFiles(String avrBasePath, File dependFile = new File(dependPath); objectPaths.add(objectFile); if (is_already_compiled(file, objectFile, dependFile, boardPreferences)) continue; - execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths, + execAsynchronously(getCommandCompilerCPP(basePath, includePaths, file.getAbsolutePath(), objectPath, boardPreferences)); @@ -524,18 +563,35 @@ public void message(String s) { ///////////////////////////////////////////////////////////////////////////// - static private List getCommandCompilerS(String avrBasePath, List includePaths, + static private List getCommandCompilerS(String basePath, List includePaths, 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=" + boardPreferences.get("build.mcu"), - "-DF_CPU=" + boardPreferences.get("build.f_cpu"), - "-DARDUINO=" + Base.REVISION, - })); - + String arch = Base.getArch(); + + List baseCommandCompiler; + + if (arch == "msp430") { + //as per + //http://mspgcc.sourceforge.net/manual/x1522.html + baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { + basePath + "msp430-gcc", + "-c", // compile, don't link + "-g", // include debugging info (so errors include line numbers) + "-mmcu=" + boardPreferences.get("build.mcu"), + "-DF_CPU=" + boardPreferences.get("build.f_cpu"), + "-DARDUINO=" + Base.REVISION, + })); + } else { + baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { + basePath + "avr-gcc", + "-c", // compile, don't link + "-g", // include debugging info (so errors include line numbers) + "-assembler-with-cpp", + "-mmcu=" + boardPreferences.get("build.mcu"), + "-DF_CPU=" + boardPreferences.get("build.f_cpu"), + "-DARDUINO=" + Base.REVISION, + })); + } + for (int i = 0; i < includePaths.size(); i++) { baseCommandCompiler.add("-I" + (String) includePaths.get(i)); } @@ -547,22 +603,39 @@ static private List getCommandCompilerS(String avrBasePath, List includePaths, } - static private List getCommandCompilerC(String avrBasePath, List includePaths, + static private List getCommandCompilerC(String basePath, List includePaths, 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) - "-Os", // optimize for size - Preferences.getBoolean("build.verbose") ? "-Wall" : "-w", // show warnings if verbose - "-ffunction-sections", // place each function in its own section - "-fdata-sections", - "-mmcu=" + boardPreferences.get("build.mcu"), - "-DF_CPU=" + boardPreferences.get("build.f_cpu"), + String arch = Base.getArch(); + List baseCommandCompiler; + + if (arch == "msp430") { + baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { + basePath + "msp430-gcc", + "-c", // compile, don't link + "-g", // include debugging info (so errors include line numbers) + "-Os", // optimize for size + Preferences.getBoolean("build.verbose") ? "-Wall" : "-w", // show warnings if verbose + "-ffunction-sections", // place each function in its own section + "-fdata-sections", + "-mmcu=" + boardPreferences.get("build.mcu"), + "-DF_CPU=" + boardPreferences.get("build.f_cpu"), + "-DARDUINO=" + Base.REVISION, + })); + } else { // default to avr + baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { + basePath + "avr-gcc", + "-c", // compile, don't link + "-g", // include debugging info (so errors include line numbers) + "-Os", // optimize for size + Preferences.getBoolean("build.verbose") ? "-Wall" : "-w", // show warnings if verbose + "-ffunction-sections", // place each function in its own section + "-fdata-sections", + "-mmcu=" + boardPreferences.get("build.mcu"), + "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-MMD", // output dependancy info - "-DARDUINO=" + Base.REVISION, - })); + "-DARDUINO=" + Base.REVISION, + })); + } for (int i = 0; i < includePaths.size(); i++) { baseCommandCompiler.add("-I" + (String) includePaths.get(i)); @@ -576,24 +649,41 @@ static private List getCommandCompilerC(String avrBasePath, List includePaths, } - static private List getCommandCompilerCPP(String avrBasePath, + static private List getCommandCompilerCPP(String basePath, List includePaths, String sourceName, String objectName, Map boardPreferences) { - List baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] { - avrBasePath + "avr-g++", - "-c", // compile, don't link - "-g", // include debugging info (so errors include line numbers) - "-Os", // optimize for size - Preferences.getBoolean("build.verbose") ? "-Wall" : "-w", // show warnings if verbose - "-fno-exceptions", - "-ffunction-sections", // place each function in its own section - "-fdata-sections", - "-mmcu=" + boardPreferences.get("build.mcu"), - "-DF_CPU=" + boardPreferences.get("build.f_cpu"), + String arch = Base.getArch(); + List baseCommandCompilerCPP; + if (arch == "msp430") { + baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] { + basePath + "msp430-g++", + "-c", // compile, don't link + "-g", // include debugging info (so errors include line numbers) + "-Os", // optimize for size + Preferences.getBoolean("build.verbose") ? "-Wall" : "-w", // show warnings if verbose + "-ffunction-sections", // place each function in its own section + "-fdata-sections", + "-mmcu=" + boardPreferences.get("build.mcu"), + "-DF_CPU=" + boardPreferences.get("build.f_cpu"), + "-DARDUINO=" + Base.REVISION, + })); + } else { // default to avr + baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] { + basePath + "avr-g++", + "-c", // compile, don't link + "-g", // include debugging info (so errors include line numbers) + "-Os", // optimize for size + Preferences.getBoolean("build.verbose") ? "-Wall" : "-w", // show warnings if verbose + "-fno-exceptions", + "-ffunction-sections", // place each function in its own section + "-fdata-sections", + "-mmcu=" + boardPreferences.get("build.mcu"), + "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-MMD", // output dependancy info - "-DARDUINO=" + Base.REVISION, - })); + "-DARDUINO=" + Base.REVISION, + })); + } for (int i = 0; i < includePaths.size(); i++) { baseCommandCompilerCPP.add("-I" + (String) includePaths.get(i)); diff --git a/app/src/processing/app/debug/MSP430Uploader.java b/app/src/processing/app/debug/MSP430Uploader.java new file mode 100644 index 00000000000..54ae39d571e --- /dev/null +++ b/app/src/processing/app/debug/MSP430Uploader.java @@ -0,0 +1,112 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + ************************************************************************ + * MSP430Uploader.java + * + * abstract uploading baseclass for msp430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + Uploader - abstract uploading baseclass (common to both uisp and avrdude) + 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.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 MSP430Uploader extends Uploader{ + public MSP430Uploader() { + } + public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer) + throws RunnerException, SerialException { + this.verbose = verbose; + Map boardPreferences = Base.getBoardPreferences(); + //No serial programming support (yet). Upload using programmer (MSP430Flasher for windows and mspdebug for Mac OS X and Linux). + + Target target = Base.getTarget(); + Collection params = new ArrayList(); + + if (Base.isMacOS() || Base.isLinux()) { + params.add(boardPreferences.get("upload.protocol")); + if(!Preferences.getBoolean("upload.verbose")) + params.add("-q"); + params.add("--force-reset"); + if ( Base.isLinux()) { + params.add("prog " + buildPath + File.separator + className + ".hex"); + } + else { + params.add("\"prog " + buildPath + File.separator + className + ".hex\""); + } + return mspdebug(params); + } else { + + params.add("-n " + boardPreferences.get("build.mcu")); + params.add("-w"); + params.add(buildPath + File.separator + className + ".hex"); + params.add("-g"); + if(!Preferences.getBoolean("upload.verbose")) + params.add("-q"); + + params.add("-z[VCC]"); + return MSP430Flasher(params); + } + } + + public boolean burnBootloader() throws RunnerException { + //nothing do do for MSP430 + return false; + } + + public boolean mspdebug(Collection params) throws RunnerException { + List commandDownloader = new ArrayList(); + + if ( Base.isLinux()) { + commandDownloader.add("mspdebug"); // use the one in the PATH + } else { + commandDownloader.add(Base.getHardwarePath() + "/tools/msp430/mspdebug/mspdebug"); + } + commandDownloader.addAll(params); + + return executeUploadCommand(commandDownloader); + } + + public boolean MSP430Flasher(Collection params) throws RunnerException { + List commandDownloader = new ArrayList(); + + commandDownloader.add(Base.toShortPath(Base.getHardwarePath()) + "\\tools\\msp430\\MSP430Flasher\\" + "MSP430Flasher.exe"); + commandDownloader.addAll(params); + + return executeUploadCommand(commandDownloader); + } +} diff --git a/app/src/processing/app/debug/Sizer.java b/app/src/processing/app/debug/Sizer.java index d67728a3c85..13c400e0df9 100644 --- a/app/src/processing/app/debug/Sizer.java +++ b/app/src/processing/app/debug/Sizer.java @@ -42,12 +42,23 @@ public Sizer(String buildPath, String sketchName) { } public long computeSize() throws RunnerException { - String avrBasePath = Base.getAvrBasePath(); - String commandSize[] = new String[] { - avrBasePath + "avr-size", - " " - }; + String commandSize[]; + String arch = Base.getArch(); + + if(arch == "msp430") { + String basePath = Base.getMSP430BasePath(); + commandSize = new String[] { + basePath + "msp430-size", + " " + }; + } else { + String basePath = Base.getAvrBasePath(); + commandSize = new String[] { + basePath + "avr-size", + " " + }; + } commandSize[1] = buildPath + File.separator + sketchName + ".hex"; int r = 0; @@ -105,4 +116,4 @@ public void message(String s) { } } } -} \ No newline at end of file +} diff --git a/app/src/processing/app/macosx/Platform.java b/app/src/processing/app/macosx/Platform.java index 06a8f521473..85d3e656cb1 100644 --- a/app/src/processing/app/macosx/Platform.java +++ b/app/src/processing/app/macosx/Platform.java @@ -84,12 +84,12 @@ public void init(Base base) { public File getSettingsFolder() throws Exception { - return new File(getLibraryFolder(), "Arduino"); + return new File(getLibraryFolder(), "Energia"); } public File getDefaultSketchbookFolder() throws Exception { - return new File(getDocumentsFolder(), "Arduino"); + return new File(getDocumentsFolder(), "Energia"); /* // looking for /Users/blah/Documents/Processing try { diff --git a/app/src/processing/app/preproc/PdePreprocessor.java b/app/src/processing/app/preproc/PdePreprocessor.java index 2b4f03e85a6..9e20baf8fff 100644 --- a/app/src/processing/app/preproc/PdePreprocessor.java +++ b/app/src/processing/app/preproc/PdePreprocessor.java @@ -196,17 +196,17 @@ public String write() throws java.lang.Exception { // Write the pde program to the cpp file protected void writeProgram(PrintStream out, String program, List prototypes) { - int prototypeInsertionPoint = firstStatement(program); - - out.print(program.substring(0, prototypeInsertionPoint)); - out.print("#include \"Arduino.h\"\n"); + + String arch = Base.getArch(); + if(arch == "msp430") out.print("#include \"Energia.h\"\n"); + else out.print("#include \"Arduino.h\"\n"); // print user defined prototypes for (int i = 0; i < prototypes.size(); i++) { out.print(prototypes.get(i) + "\n"); } - - out.print(program.substring(prototypeInsertionPoint)); + out.print("#line 1\n"); + out.print(program.substring(0)); } diff --git a/app/src/processing/app/windows/Platform.java b/app/src/processing/app/windows/Platform.java index 5afe4db1329..78947900612 100644 --- a/app/src/processing/app/windows/Platform.java +++ b/app/src/processing/app/windows/Platform.java @@ -187,7 +187,7 @@ public File getSettingsFolder() throws Exception { String appDataPath = Registry.getStringValue(REGISTRY_ROOT_KEY.CURRENT_USER, keyPath, "AppData"); - File dataFolder = new File(appDataPath, "Arduino"); + File dataFolder = new File(appDataPath, "Energia"); return dataFolder; } @@ -216,7 +216,7 @@ public File getDefaultSketchbookFolder() throws Exception { String personalPath = Registry.getStringValue(REGISTRY_ROOT_KEY.CURRENT_USER, keyPath, "Personal"); - return new File(personalPath, "Arduino"); + return new File(personalPath, "Energia"); } diff --git a/build/Terminal b/build/Terminal new file mode 100644 index 00000000000..805628920f0 Binary files /dev/null and b/build/Terminal differ diff --git a/build/build.xml b/build/build.xml index 245a9a37a57..bc354adc4fb 100644 --- a/build/build.xml +++ b/build/build.xml @@ -1,5 +1,5 @@ - + @@ -20,7 +20,7 @@ - + @@ -31,16 +31,16 @@ - + - + + description="Build Energia for distribution."> @@ -116,7 +116,7 @@ - + @@ -129,7 +129,7 @@ - + @@ -156,13 +156,13 @@ - + ======================================================= - Arduino for Mac OS X can only be built on Mac OS X. + Energia for Mac OS X can only be built on Mac OS X. Bye. ======================================================= @@ -174,76 +174,86 @@ - + + tofile="macosx/work/Energia.app" />--> - + - + - + - + - + - + + + + + + + + + + + - + - + - + - - - - - - + + + + + + - - - + ======================================================= - Arduino for Mac OS X was built. Grab the image from + Energia for Mac OS X was built. Grab the image from - macosx/arduino-${version}-macosx.zip + macosx/energia-${version}-macosx.zip ======================================================= @@ -263,14 +273,14 @@ - + - - - - - - + + + + + + @@ -295,9 +305,9 @@ ======================================================= - Arduino for Mac OS X was built. Grab the image from + Energia for Mac OS X was built. Grab the image from - macosx/arduino-${version}.dmg + macosx/energia-${version}.dmg ======================================================= @@ -313,7 +323,7 @@ ======================================================= - Arduino for Linux can only be built on on unix systems. + Energia for Linux can only be built on on unix systems. Bye. ======================================================= @@ -342,8 +352,8 @@ - - + + @@ -375,12 +385,12 @@ - + - + + destfile="linux/energia-${version}.tgz" /> - + - + + prefix="energia-${version}/hardware/tools" /> --> - + - - + + - + ======================================================= - Arduino for Linux was built. Grab the archive from + Energia for Linux was built. Grab the archive from - build/linux/arduino-${version}-linux.tgz + build/linux/energia-${version}-linux.tgz ======================================================= @@ -449,7 +459,7 @@ ======================================================= - Arduino for Windows can only be built on windows. + Energia for Windows can only be built on windows. Bye. ======================================================= @@ -484,6 +494,7 @@ + @@ -514,7 +525,7 @@ - @@ -529,31 +540,31 @@ - + + prefix="energia-${version}" /> - + ======================================================= - Arduino for Windows was built. Grab the archive from + Energia for Windows was built. Grab the archive from - windows/arduino-${version}-windows.zip - windows/arduino-${version}-windows-expert.zip + windows/energia-${version}-windows.zip + windows/energia-${version}-windows-expert.zip ======================================================= @@ -569,9 +580,9 @@ addproperty="version" defaultvalue="${revision}" /> - + - - - - CFBundleName - Arduino - - - CFBundleGetInfoString - VERSION - CFBundleVersion - REVISION - CFBundleShortVersionString - VERSION - - - CFBundleAllowMixedLocalizations - true - CFBundleExecutable - JavaApplicationStub - CFBundleDevelopmentRegion - English - CFBundlePackageType - APPL - CFBundleSignature - Pde1 - CFBundleInfoDictionaryVersion - 6.0 - CFBundleIconFile - processing.icns - CFBundleIdentifier - cc.arduino.Arduino - CFBundleDocumentTypes - - - CFBundleTypeExtensions - - ino - c - cpp - h - - CFBundleTypeIconFile - pde.icns - CFBundleTypeName - Arduino Source File - CFBundleTypeMIMETypes - - text/plain - - CFBundleTypeOSTypes - - TEXT - - CFBundleTypeRole - Editor - - - Java - - VMOptions - - -Xms128M - -Xmx256M - - - MainClass - processing.app.Base - - JVMVersion - 1.5* - - ClassPath - - $JAVAROOT/pde.jar:$JAVAROOT/core.jar:$JAVAROOT/antlr.jar:$JAVAROOT/ecj.jar:$JAVAROOT/registry.jar:$JAVAROOT/quaqua.jar:$JAVAROOT/RXTXcomm.jar - - JVMArchs - - - i386 - ppc - - - - Properties - - - javaroot - $JAVAROOT - - - apple.laf.useScreenMenuBar - true - - apple.awt.showGrowBox - false - com.apple.smallTabs + + + + CFBundleName + Energia + CFBundleGetInfoString + VERSION + CFBundleVersion + REVISION + CFBundleShortVersionString + VERSION + CFBundleAllowMixedLocalizations true - apple.awt.Antialiasing - false - apple.awt.TextAntialiasing - true - com.apple.hwaccel - true - apple.awt.use-file-dialog-packages - false - apple.awt.graphics.UseQuartz - true - - - + CFBundleExecutable + JavaApplicationStub + CFBundleDevelopmentRegion + English + CFBundlePackageType + APPL + CFBundleSignature + Pde1 + CFBundleInfoDictionaryVersion + 6.0 + CFBundleIconFile + energia.icns + CFBundleIdentifier + nu.energia.Energia + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + ino + c + cpp + h + + CFBundleTypeIconFile + pde.icns + CFBundleTypeName + Energia Source File + CFBundleTypeMIMETypes + + text/plain + + CFBundleTypeOSTypes + + TEXT + + CFBundleTypeRole + Editor + + + Java + + VMOptions + + -Xms128M + -Xmx256M + + MainClass + processing.app.Base + JVMVersion + 1.5* + ClassPath + $JAVAROOT/pde.jar:$JAVAROOT/core.jar:$JAVAROOT/antlr.jar:$JAVAROOT/ecj.jar:$JAVAROOT/registry.jar:$JAVAROOT/quaqua.jar:$JAVAROOT/RXTXcomm.jar + JVMArchs + + i386 + ppc + + Properties + + javaroot + $JAVAROOT + apple.laf.useScreenMenuBar + true + apple.awt.showGrowBox + false + com.apple.smallTabs + true + apple.awt.Antialiasing + false + apple.awt.TextAntialiasing + true + com.apple.hwaccel + true + apple.awt.use-file-dialog-packages + false + apple.awt.graphics.UseQuartz + true + + + diff --git a/build/macosx/template.app/Contents/Resources/energia.icns b/build/macosx/template.app/Contents/Resources/energia.icns new file mode 100644 index 00000000000..b5c5fa12b80 Binary files /dev/null and b/build/macosx/template.app/Contents/Resources/energia.icns differ diff --git a/build/macosx/template.app/Contents/Resources/pde.icns b/build/macosx/template.app/Contents/Resources/pde.icns old mode 100644 new mode 100755 index d3862982c43..0cd4f9fe7cc Binary files a/build/macosx/template.app/Contents/Resources/pde.icns and b/build/macosx/template.app/Contents/Resources/pde.icns differ diff --git a/build/macosx/template.app/Contents/Resources/processing.icns b/build/macosx/template.app/Contents/Resources/processing.icns deleted file mode 100644 index 0a011db4221..00000000000 Binary files a/build/macosx/template.app/Contents/Resources/processing.icns and /dev/null differ diff --git "a/build/macosx/template.app/Icon\r" "b/build/macosx/template.app/Icon\r" new file mode 100644 index 00000000000..e69de29bb2d diff --git a/build/shared/examples/1.Basics/Blink/Blink.ino b/build/shared/examples/1.Basics/Blink/Blink.ino index 1953c390868..cb9480655e1 100644 --- a/build/shared/examples/1.Basics/Blink/Blink.ino +++ b/build/shared/examples/1.Basics/Blink/Blink.ino @@ -7,13 +7,13 @@ void setup() { // initialize the digital pin as an output. - // Pin 13 has an LED connected on most Arduino boards: - pinMode(13, OUTPUT); + // Pin 14 has an LED connected on most Arduino boards: + pinMode(14, OUTPUT); } void loop() { - digitalWrite(13, HIGH); // set the LED on + digitalWrite(14, HIGH); // set the LED on delay(1000); // wait for a second - digitalWrite(13, LOW); // set the LED off + digitalWrite(14, LOW); // set the LED off delay(1000); // wait for a second } diff --git a/build/shared/examples/1.Basics/DigitalReadSerial/DigitalReadSerial.ino b/build/shared/examples/1.Basics/DigitalReadSerial/DigitalReadSerial.ino index 68e4dc9663f..45bf1ddaa04 100644 --- a/build/shared/examples/1.Basics/DigitalReadSerial/DigitalReadSerial.ino +++ b/build/shared/examples/1.Basics/DigitalReadSerial/DigitalReadSerial.ino @@ -7,11 +7,11 @@ void setup() { Serial.begin(9600); - pinMode(2, INPUT); + pinMode(PUSH2, INPUT_PULLUP); } void loop() { - int sensorValue = digitalRead(2); + int sensorValue = digitalRead(PUSH2); Serial.println(sensorValue); } diff --git a/build/shared/examples/1.Basics/Fade/Fade.ino b/build/shared/examples/1.Basics/Fade/Fade.ino index b47bf43073f..cc9e3bd0e04 100644 --- a/build/shared/examples/1.Basics/Fade/Fade.ino +++ b/build/shared/examples/1.Basics/Fade/Fade.ino @@ -12,12 +12,12 @@ int fadeAmount = 5; // how many points to fade the LED by void setup() { // declare pin 9 to be an output: - pinMode(9, OUTPUT); + pinMode(GREEN_LED, OUTPUT); } void loop() { // set the brightness of pin 9: - analogWrite(9, brightness); + analogWrite(GREEN_LED, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; diff --git a/build/shared/examples/2.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino b/build/shared/examples/2.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino index 014357191d0..bea622a5e72 100644 --- a/build/shared/examples/2.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino +++ b/build/shared/examples/2.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino @@ -14,6 +14,8 @@ by David A. Mellis modified 8 Feb 2010 by Paul Stoffregen + modified 27 Apr 2012 + by Robert Wessels This example code is in the public domain. @@ -23,7 +25,7 @@ // constants won't change. Used here to // set pin numbers: -const int ledPin = 13; // the number of the LED pin +const int ledPin = GREEN_LED; // the number of the LED pin // Variables will change: int ledState = LOW; // ledState used to set the LED diff --git a/build/shared/examples/2.Digital/Button/Button.ino b/build/shared/examples/2.Digital/Button/Button.ino index e019fca3129..91e15f2659c 100644 --- a/build/shared/examples/2.Digital/Button/Button.ino +++ b/build/shared/examples/2.Digital/Button/Button.ino @@ -18,6 +18,8 @@ by DojoDave modified 30 Aug 2011 by Tom Igoe + modified Apr 27 2012 + by Robert Wessels This example code is in the public domain. @@ -26,8 +28,8 @@ // constants won't change. They're used here to // set pin numbers: -const int buttonPin = 2; // the number of the pushbutton pin -const int ledPin = 13; // the number of the LED pin +const int buttonPin = PUSH2; // the number of the pushbutton pin +const int ledPin = GREEN_LED; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status @@ -36,7 +38,7 @@ void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: - pinMode(buttonPin, INPUT); + pinMode(buttonPin, INPUT_PULLUP); } void loop(){ @@ -53,4 +55,4 @@ void loop(){ // turn LED off: digitalWrite(ledPin, LOW); } -} \ No newline at end of file +} diff --git a/build/shared/examples/2.Digital/Debounce/Debounce.ino b/build/shared/examples/2.Digital/Debounce/Debounce.ino index 89416b26921..962dbf0e9a4 100644 --- a/build/shared/examples/2.Digital/Debounce/Debounce.ino +++ b/build/shared/examples/2.Digital/Debounce/Debounce.ino @@ -19,6 +19,8 @@ by David A. Mellis modified 30 Aug 2011 by Limor Fried + modified 27 Apr 2012 + Robert Wessels This example code is in the public domain. @@ -27,8 +29,8 @@ This example code is in the public domain. // constants won't change. They're used here to // set pin numbers: -const int buttonPin = 2; // the number of the pushbutton pin -const int ledPin = 13; // the number of the LED pin +const int buttonPin = PUSH2; // the number of the pushbutton pin +const int ledPin = GREEN_LED; // the number of the LED pin // Variables will change: int ledState = HIGH; // the current state of the output pin diff --git a/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino index 6f540e9ffeb..6dd82279d8a 100644 --- a/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino +++ b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino @@ -2,18 +2,20 @@ Input Pullup Serial This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a - digital input on pin 2 and prints the results to the serial monitor. + digital input on pin 5 and prints the results to the serial monitor. The circuit: - * Momentary switch attached from pin 2 to ground - * Built-in LED on pin 13 + * Momentary switch attached from pin 5 to ground + * Built-in LED on pin 14 Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal - 20K-ohm resistor is pulled to 5V. This configuration causes the input to + resistor is pulled to 3.3V. This configuration causes the input to read HIGH when the switch is open, and LOW when it is closed. created 14 March 2012 by Scott Fitzgerald + modified 27 Apr 2012 + Robert Wessels http://www.arduino.cc/en/Tutorial/InputPullupSerial @@ -24,9 +26,9 @@ void setup(){ //start serial connection Serial.begin(9600); - //configure pin2 as an input and enable the internal pull-up resistor - pinMode(2, INPUT_PULLUP); - pinMode(13, OUTPUT); + //configure pin 5 as an input and enable the internal pull-up resistor + pinMode(PUSH2, INPUT_PULLUP); + pinMode(GREEN_LED, OUTPUT); } @@ -41,10 +43,10 @@ void loop(){ // and LOW when it's pressed. Turn on pin 13 when the // button's pressed, and off when it's not: if (sensorVal == HIGH) { - digitalWrite(13, LOW); + digitalWrite(GREEN_LED, LOW); } else { - digitalWrite(13, HIGH); + digitalWrite(GREEN_LED, HIGH); } } diff --git a/build/shared/examples/2.Digital/StateChangeDetection/StateChangeDetection.ino b/build/shared/examples/2.Digital/StateChangeDetection/StateChangeDetection.ino index 30bb3c40555..7f530e88486 100644 --- a/build/shared/examples/2.Digital/StateChangeDetection/StateChangeDetection.ino +++ b/build/shared/examples/2.Digital/StateChangeDetection/StateChangeDetection.ino @@ -10,14 +10,14 @@ and on to off. The circuit: - * pushbutton attached to pin 2 from +5V - * 10K resistor attached to pin 2 from ground - * LED attached from pin 13 to ground (or use the built-in LED on - most Arduino boards) + * pushbutton attached to pin 5 from GND + * LED attached from pin 14 to ground through a 470 Ohm resistor created 27 Sep 2005 modified 30 Aug 2011 by Tom Igoe + modified 27 Apr 2012 + Robert Wessels This example code is in the public domain. @@ -26,8 +26,8 @@ This example code is in the public domain. */ // this constant won't change: -const int buttonPin = 2; // the pin that the pushbutton is attached to -const int ledPin = 13; // the pin that the LED is attached to +const int buttonPin = PUSH2; // the pin that the pushbutton is attached to +const int ledPin = RED_LED; // the pin that the LED is attached to // Variables will change: int buttonPushCounter = 0; // counter for the number of button presses @@ -36,7 +36,7 @@ int lastButtonState = 0; // previous state of the button void setup() { // initialize the button pin as a input: - pinMode(buttonPin, INPUT); + pinMode(buttonPin, INPUT_PULLUP); // initialize the LED as an output: pinMode(ledPin, OUTPUT); // initialize serial communication: diff --git a/build/shared/lib/about.jpg b/build/shared/lib/about.jpg index 0b168bba1b7..4751b98886a 100644 Binary files a/build/shared/lib/about.jpg and b/build/shared/lib/about.jpg differ diff --git a/build/shared/lib/preferences.txt b/build/shared/lib/preferences.txt index 51043bbbf26..e0a67b97fd2 100755 --- a/build/shared/lib/preferences.txt +++ b/build/shared/lib/preferences.txt @@ -242,8 +242,8 @@ run.present.exclusive = false run.present.exclusive.macosx = true # ARDUINO PREFERENCES -board = uno -target = arduino +board = lpmsp430g2231 +target = msp430 programmer = arduino:avrispmkii diff --git a/build/shared/lib/theme/buttons.gif b/build/shared/lib/theme/buttons.gif index 4de0905d23d..c556071c7a5 100644 Binary files a/build/shared/lib/theme/buttons.gif and b/build/shared/lib/theme/buttons.gif differ diff --git a/build/shared/lib/theme/resize.gif b/build/shared/lib/theme/resize.gif index ed31c0ad89d..b29fd56c9ab 100644 Binary files a/build/shared/lib/theme/resize.gif and b/build/shared/lib/theme/resize.gif differ diff --git a/build/shared/lib/theme/tab-sel-left.gif b/build/shared/lib/theme/tab-sel-left.gif index 252ebcc6d68..de010147149 100644 Binary files a/build/shared/lib/theme/tab-sel-left.gif and b/build/shared/lib/theme/tab-sel-left.gif differ diff --git a/build/shared/lib/theme/tab-sel-menu.gif b/build/shared/lib/theme/tab-sel-menu.gif index 3b213f4a779..1bcf6eed74f 100644 Binary files a/build/shared/lib/theme/tab-sel-menu.gif and b/build/shared/lib/theme/tab-sel-menu.gif differ diff --git a/build/shared/lib/theme/tab-sel-mid.gif b/build/shared/lib/theme/tab-sel-mid.gif index 4bd19a0c3b1..7f20298c7d1 100644 Binary files a/build/shared/lib/theme/tab-sel-mid.gif and b/build/shared/lib/theme/tab-sel-mid.gif differ diff --git a/build/shared/lib/theme/tab-sel-right.gif b/build/shared/lib/theme/tab-sel-right.gif index 4ceb3ed808e..f33f13f6fbc 100644 Binary files a/build/shared/lib/theme/tab-sel-right.gif and b/build/shared/lib/theme/tab-sel-right.gif differ diff --git a/build/shared/lib/theme/tab-unsel-left.gif b/build/shared/lib/theme/tab-unsel-left.gif index cdc98861ff7..ae75c22da68 100644 Binary files a/build/shared/lib/theme/tab-unsel-left.gif and b/build/shared/lib/theme/tab-unsel-left.gif differ diff --git a/build/shared/lib/theme/tab-unsel-menu.gif b/build/shared/lib/theme/tab-unsel-menu.gif index 3c917711833..e5e3d92cfa7 100644 Binary files a/build/shared/lib/theme/tab-unsel-menu.gif and b/build/shared/lib/theme/tab-unsel-menu.gif differ diff --git a/build/shared/lib/theme/tab-unsel-mid.gif b/build/shared/lib/theme/tab-unsel-mid.gif index c538ad2fedf..ccf95a00045 100644 Binary files a/build/shared/lib/theme/tab-unsel-mid.gif and b/build/shared/lib/theme/tab-unsel-mid.gif differ diff --git a/build/shared/lib/theme/tab-unsel-right.gif b/build/shared/lib/theme/tab-unsel-right.gif index 3150eb5ea4a..7b438ae2d6e 100644 Binary files a/build/shared/lib/theme/tab-unsel-right.gif and b/build/shared/lib/theme/tab-unsel-right.gif differ diff --git a/build/shared/lib/theme/theme.txt b/build/shared/lib/theme/theme.txt index 98a8ef7a58e..a7ec095b796 100644 --- a/build/shared/lib/theme/theme.txt +++ b/build/shared/lib/theme/theme.txt @@ -1,35 +1,35 @@ # GUI - STATUS -status.notice.fgcolor = #002325 -status.notice.bgcolor = #17A1A5 -status.error.fgcolor = #FFFFFF -status.error.bgcolor = #E34C00 +status.notice.fgcolor = #000000 +status.notice.bgcolor = #666666 +status.error.fgcolor = #ffffff +status.error.bgcolor = #666666 status.edit.fgcolor = #000000 -status.edit.bgcolor = #F1B500 +status.edit.bgcolor = #7e0000 status.font = SansSerif,plain,12 # GUI - TABS # settings for the tabs at the top # (tab images are stored in the lib/theme folder) -header.bgcolor = #17A1A5 -header.text.selected.color = #005B5B -header.text.unselected.color = #007e82 +header.bgcolor = #666666 +header.text.selected.color = #ffffff +header.text.unselected.color = #000000 header.text.font = SansSerif,plain,12 # GUI - CONSOLE -console.font = Monospaced,plain,11 -console.font.macosx = Monaco,plain,10 +console.font = Monospaced,plain,10 +console.font.macosx = Monaco,plain,12 console.color = #000000 -console.output.color = #eeeeee -console.error.color = #E34C00 +console.output.color = #cccccc +console.error.color = #ffcc00 # GUI - BUTTONS -buttons.bgcolor = #006468 +buttons.bgcolor = #7e0000 buttons.status.font = SansSerif,plain,12 buttons.status.color = #ffffff -# GUI - LINESTATUS +# GUI - LINESTATUS linestatus.color = #ffffff -linestatus.bgcolor = #006468 +linestatus.bgcolor = #7e0000 # EDITOR - DETAILS @@ -66,26 +66,26 @@ editor.brackethighlight.color = #006699 # TEXT - KEYWORDS # e.g abstract, final, private -editor.keyword1.style = #cc6600,plain +editor.keyword1.style = #ff0000,plain # e.g. beginShape, point, line -editor.keyword2.style = #cc6600,plain +editor.keyword2.style = #ff8000,plain # e.g. byte, char, short, color -editor.keyword3.style = #cc6600,bold +editor.keyword3.style = #8b308b,bold # TEXT - LITERALS # constants: e.g. null, true, this, RGB, TWO_PI -editor.literal1.style = #006699,plain - -# p5 built in variables: e.g. mouseX, width, pixels -editor.literal2.style = #006699,plain +editor.literal1.style = #0066FF,plain # http://arduino.cc/ editor.url.style = #0000ff,underlined +# p5 built in variables: e.g. mouseX, width, pixels +editor.literal2.style = #8800cc,plain + # e.g. + - = / editor.operator.style = #000000,plain @@ -95,8 +95,8 @@ editor.label.style = #7e7e7e,bold # TEXT - COMMENTS -editor.comment1.style = #7e7e7e,plain -editor.comment2.style = #7e7e7e,plain +editor.comment1.style = #007f00,plain +editor.comment2.style = #007f00,plain # LINE STATUS - editor line number status bar at the bottom of the screen diff --git a/build/windows/dist/drivers/EZ430-UART/430cdc.cat b/build/windows/dist/drivers/EZ430-UART/430cdc.cat new file mode 100755 index 00000000000..f647fe06fe1 Binary files /dev/null and b/build/windows/dist/drivers/EZ430-UART/430cdc.cat differ diff --git a/build/windows/dist/drivers/EZ430-UART/430cdc.inf b/build/windows/dist/drivers/EZ430-UART/430cdc.inf new file mode 100755 index 00000000000..51ca830fc47 --- /dev/null +++ b/build/windows/dist/drivers/EZ430-UART/430cdc.inf @@ -0,0 +1,102 @@ +; Copyright (c) 2007 Texas Instruments +; MSP430 Application UART Installation file for Win2000/XP/Vista +; +; Port drivers setup +; +; Supported operating systems: +; Windows 32-bit and 64-bit + +[Version] +Signature="$Windows NT$" +CatalogFile=430CDC.cat +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%TI% +LayoutFile=layout.inf +DriverVer=12/11/2007, 1.3 + +[Manufacturer] +%TI%=DeviceList, NTamd64 + +[DestinationDirs] +DefaultDestDir=12 + +[SourceDisksFiles] + +[SourceDisksNames] + +[DeviceList] +%DESCRIPTION%=TIUSB, USB\Vid_0451&Pid_F432&MI_00 +%DESCRIPTION%=TIUSB, USB\Vid_0451&Pid_F433 +%DESCRIPTION%=TIUSB, USB\Vid_0451&Pid_F434&MI_00 +%DESCRIPTION%=TIUSB, USB\Vid_0451&Pid_F435&MI_00 +%DESCRIPTION%=TIUSB, USB\Vid_0451&Pid_F436&MI_00 +%DESCRIPTION%=TIUSB, USB\Vid_0451&Pid_F437&MI_00 +%DESCRIPTION%=TIUSB, USB\Vid_0451&Pid_F438&MI_00 + +[DeviceList.NTamd64] +%DESCRIPTION%=TIUSB.NTamd64, USB\Vid_0451&Pid_F432&MI_00 +%DESCRIPTION%=TIUSB.NTamd64, USB\Vid_0451&Pid_F433 +%DESCRIPTION%=TIUSB.NTamd64, USB\Vid_0451&Pid_F434&MI_00 +%DESCRIPTION%=TIUSB.NTamd64, USB\Vid_0451&Pid_F435&MI_00 +%DESCRIPTION%=TIUSB.NTamd64, USB\Vid_0451&Pid_F436&MI_00 +%DESCRIPTION%=TIUSB.NTamd64, USB\Vid_0451&Pid_F437&MI_00 +%DESCRIPTION%=TIUSB.NTamd64, USB\Vid_0451&Pid_F438&MI_00 + +;------------------------------------------------------------------------------ +; Windows 32-bit Sections +;------------------------------------------------------------------------------ + +[TIUSB.nt] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles +AddReg=TIUSB.nt.AddReg + +[DriverCopyFiles] +usbser.sys,,,0x20 + +[TIUSB.nt.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,usbser.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[TIUSB.nt.Services] +AddService=usbser, 0x00000002, DriverService + +[TIUSB.nt.HW] +include=mdmcpq.inf + +[DriverService] +DisplayName=%DESCRIPTION% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\usbser.sys + +;------------------------------------------------------------------------------ +; Windows 64-bit Sections +;------------------------------------------------------------------------------ + +[TIUSB.NTamd64] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles +AddReg=TIUSB.NTamd64.AddReg + +[TIUSB.NTamd64.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,usbser.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[TIUSB.NTamd64.Services] +AddService=usbser, 0x00000002, DriverService + +[TIUSB.NTamd64.HW] +include=mdmcpq.inf + +;------------------------------------------------------------------------------ +; String Definitions +;------------------------------------------------------------------------------ + +[Strings] +TI="Texas Instruments" +DESCRIPTION="MSP430 Application UART" diff --git a/build/windows/dist/drivers/EZ430-UART/DPinst.exe b/build/windows/dist/drivers/EZ430-UART/DPinst.exe new file mode 100755 index 00000000000..f4d9174e2b2 Binary files /dev/null and b/build/windows/dist/drivers/EZ430-UART/DPinst.exe differ diff --git a/build/windows/dist/drivers/EZ430-UART/preinstalCDC.exe b/build/windows/dist/drivers/EZ430-UART/preinstalCDC.exe new file mode 100755 index 00000000000..32167f70050 Binary files /dev/null and b/build/windows/dist/drivers/EZ430-UART/preinstalCDC.exe differ diff --git a/build/windows/launcher/about.bmp b/build/windows/launcher/about.bmp index 19b6904b84b..8deba0998d6 100755 Binary files a/build/windows/launcher/about.bmp and b/build/windows/launcher/about.bmp differ diff --git a/build/windows/launcher/application.ico b/build/windows/launcher/application.ico index a9f3a7acbe5..56459e517f1 100644 Binary files a/build/windows/launcher/application.ico and b/build/windows/launcher/application.ico differ diff --git a/build/windows/launcher/config.xml b/build/windows/launcher/config.xml index ba29d3a0673..1032a5f47a6 100755 --- a/build/windows/launcher/config.xml +++ b/build/windows/launcher/config.xml @@ -2,7 +2,7 @@ true gui lib - arduino.exe + energia.exe . diff --git a/build/windows/msp430_tools.zip b/build/windows/msp430_tools.zip new file mode 100755 index 00000000000..8a385882c18 Binary files /dev/null and b/build/windows/msp430_tools.zip differ diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 9504a471a69..4d9dcd93de0 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -6956,22 +6956,46 @@ public void componentResized(ComponentEvent e) { /** * GIF image of the Processing logo. */ - static public final byte[] ICON_IMAGE = { - 71, 73, 70, 56, 57, 97, 16, 0, 16, 0, -60, 0, 0, 0, 0, 0, - 0, 0, -127, 0, -127, 0, 0, -127, -127, -127, 0, 0, -127, 0, -127, -127, - -127, 0, -127, -127, -127, -63, -63, -63, 0, 0, -1, 0, -1, 0, 0, -1, - -1, -1, 0, 0, -1, 0, -1, -1, -1, 0, -1, -1, -1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, -7, 4, - 9, 0, 0, 16, 0, 44, 0, 0, 0, 0, 16, 0, 16, 0, 0, 5, - 75, 32, 36, -118, -57, 96, 14, -57, -88, 66, -27, -23, -90, -86, 43, -97, - 99, 59, -65, -30, 125, -77, 3, -14, -4, 8, -109, 15, -120, -22, 61, 78, - 15, -124, 15, 25, 28, 28, 93, 63, -45, 115, -22, -116, 90, -83, 82, 89, - -44, -103, 61, 44, -91, -54, -89, 19, -111, 50, 18, -51, -55, 1, 73, -121, - -53, -79, 77, 43, -101, 12, -74, -30, -99, -24, -94, 16, 0, 59, - }; - + static public final byte[] ICON_IMAGE = { + 71 ,73 ,70 ,56 ,57 ,97 ,16 ,0 ,16 ,0 ,-58 ,97 ,0 ,0 ,0 + ,0 ,8 ,8 ,8 ,67 ,0 ,0 ,74 ,0 ,0 ,83 ,0 ,0 ,84 ,0 + ,0 ,73 ,4 ,4 ,88 ,0 ,0 ,91 ,0 ,0 ,66 ,7 ,7 ,92 ,0 + ,0 ,93 ,0 ,0 ,96 ,0 ,0 ,101 ,0 ,0 ,107 ,0 ,0 ,111 ,0 + ,0 ,113 ,0 ,0 ,124 ,0 ,0 ,125 ,0 ,0 ,126 ,0 ,0 ,127 ,0 + ,0 ,121 ,2 ,2 ,-127 ,0 ,0 ,-126 ,0 ,0 ,119 ,4 ,4 ,-122 ,0 + ,0 ,-120 ,0 ,0 ,-119 ,0 ,0 ,105 ,9 ,9 ,-114 ,0 ,0 ,117 ,7 + ,7 ,-113 ,0 ,0 ,-112 ,0 ,0 ,-111 ,0 ,0 ,-109 ,0 ,0 ,-106 ,0 + ,0 ,101 ,14 ,14 ,-103 ,0 ,0 ,-101 ,0 ,0 ,-99 ,0 ,0 ,-98 ,0 + ,0 ,-97 ,0 ,0 ,-96 ,0 ,0 ,-95 ,0 ,0 ,-93 ,0 ,0 ,-92 ,0 + ,0 ,-104 ,4 ,4 ,-87 ,0 ,0 ,-83 ,0 ,0 ,-79 ,0 ,0 ,122 ,15 + ,15 ,-76 ,0 ,0 ,-122 ,13 ,13 ,-73 ,0 ,0 ,-71 ,0 ,0 ,-70 ,0 + ,0 ,-69 ,0 ,0 ,-68 ,0 ,0 ,-120 ,15 ,15 ,-63 ,0 ,0 ,-61 ,0 + ,0 ,-60 ,0 ,0 ,-58 ,0 ,0 ,-82 ,7 ,7 ,-56 ,0 ,0 ,-55 ,0 + ,0 ,-110 ,15 ,15 ,-52 ,0 ,0 ,-51 ,0 ,0 ,-45 ,0 ,0 ,-63 ,6 + ,6 ,-79 ,11 ,11 ,-36 ,0 ,0 ,-34 ,0 ,0 ,-43 ,6 ,6 ,-20 ,0 + ,0 ,-58 ,13 ,14 ,-112 ,30 ,30 ,-47 ,13 ,13 ,-51 ,16 ,16 ,-102 ,30 + ,30 ,-24 ,9 ,9 ,-41 ,14 ,14 ,65 ,65 ,65 ,98 ,80 ,80 ,-109 ,89 + ,89 ,124 ,-122 ,-122 ,-86 ,127 ,127 ,-98 ,-98 ,-98 ,-98 ,-96 ,-96 ,-90 ,-90 + ,-90 ,-77 ,-77 ,-77 ,-76 ,-70 ,-70 ,-63 ,-65 ,-65 ,-62 ,-62 ,-62 ,-56 ,-56 + ,-56 ,-36 ,-36 ,-36 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 + ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 + ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 + ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 + ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 + ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 + ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,33 ,-7 ,4 ,1 ,10 ,0 ,127 ,0 + ,44 ,0 ,0 ,0 ,0 ,16 ,0 ,16 ,0 ,0 ,7 ,-115 ,-128 ,127 ,-126 + ,-125 ,-124 ,-126 ,88 ,-123 ,-120 ,-125 ,96 ,97 ,-119 ,-120 ,0 ,83 ,91 ,-115 + ,79 ,74 ,72 ,75 ,9 ,0 ,-104 ,-119 ,70 ,62 ,67 ,68 ,30 ,97 ,95 + ,1 ,-119 ,71 ,53 ,57 ,64 ,87 ,89 ,90 ,97 ,80 ,81 ,-120 ,44 ,48 + ,51 ,24 ,85 ,92 ,94 ,86 ,54 ,73 ,-123 ,66 ,35 ,41 ,47 ,39 ,60 + ,7 ,84 ,93 ,67 ,69 ,82 ,-124 ,58 ,27 ,33 ,40 ,22 ,20 ,42 ,37 + ,77 ,61 ,65 ,78 ,-124 ,50 ,18 ,26 ,12 ,13 ,25 ,17 ,35 ,55 ,56 + ,59 ,76 ,-123 ,15 ,10 ,5 ,32 ,8 ,23 ,43 ,47 ,49 ,53 ,-120 ,28 + ,3 ,10 ,8 ,11 ,31 ,34 ,38 ,45 ,63 ,-119 ,6 ,12 ,4 ,11 ,19 + ,25 ,29 ,46 ,-115 ,127 ,36 ,4 ,56 ,-128 ,80 ,-127 ,-58 ,-65 ,-125 ,8 + ,19 ,5 ,2 ,0 ,59 + }; /** * main() method for running this class from the command line. diff --git a/examples/1.Basics/DualBlink_430/DualBlink_430.ino b/examples/1.Basics/DualBlink_430/DualBlink_430.ino new file mode 100644 index 00000000000..ccea6acc544 --- /dev/null +++ b/examples/1.Basics/DualBlink_430/DualBlink_430.ino @@ -0,0 +1,39 @@ +// +// DualBlink_430 +// +// © Rei VILO 2012 +// +// Revision +// Rei VILO, May 21, 2012 - Updated with GREEN_LED, RED_LED and PUSH2 +// + +void setup() { + // initialise digital pins as outputs + pinMode(RED_LED, OUTPUT); + pinMode(GREEN_LED, OUTPUT); +} + +void loop() { + digitalWrite(RED_LED, HIGH); // set the LED on + delay(1000); // wait for a second + digitalWrite(GREEN_LED, HIGH); // set the LED on + digitalWrite(RED_LED, LOW); // set the LED off + delay(2000); + digitalWrite(RED_LED, HIGH); + delay(3000); + digitalWrite(GREEN_LED, LOW); + digitalWrite(RED_LED, LOW); + delay(500); + digitalWrite(GREEN_LED, HIGH); + digitalWrite(RED_LED, HIGH); + delay(500); + digitalWrite(GREEN_LED, LOW); + digitalWrite(RED_LED, LOW); + delay(500); + digitalWrite(GREEN_LED, HIGH); + digitalWrite(RED_LED, HIGH); + delay(500); + digitalWrite(GREEN_LED, LOW); + digitalWrite(RED_LED, LOW); + delay(500); +} diff --git a/examples/1.Basics/micros_430/micros_430.ino b/examples/1.Basics/micros_430/micros_430.ino new file mode 100644 index 00000000000..d73dc455b8a --- /dev/null +++ b/examples/1.Basics/micros_430/micros_430.ino @@ -0,0 +1,54 @@ +// +// micros_430.ino +// Sketch +// ---------------------------------- +// Developed with embedXcode +// +// Project micros +// Created by Rei VILO on 30/05/12 +// Copyright © 2012 http://embeddedcomputing.weebly.com +// Licence CC = BY SA NC +// +// +// Based on Serial_430 +// © Rei VILO 2012 +// PUSH2 on pin 5 +// Press push 2 to end and clear the serial port +// + +// Core library +#if defined(__MSP430G2452__) +#include "Energia.h" +#else +#error MSP540G2452 required +#endif + +#include "TimerSerial.h" +TimerSerial mySerial; + +void setup() { + mySerial.begin(); + mySerial.print("\n\n\n*** Serial test starts \n"); + mySerial.print("PUSH2 to end\n"); + pinMode(PUSH2, INPUT_PULLUP); +} + + +void loop() { + + mySerial.print(1.0*millis(), 0); + mySerial.print("\t "); + mySerial.println(1.0*micros(), 0); + delay(500); + + if (digitalRead(PUSH2)==LOW) { + mySerial.print("\n\n*** Serial test ends. \n"); + mySerial.end(); + while(true); // endless loop + } +} + + + + + diff --git a/examples/2.Digital/PushButton_430/PushButton_430.ino b/examples/2.Digital/PushButton_430/PushButton_430.ino new file mode 100644 index 00000000000..c2f1c49833e --- /dev/null +++ b/examples/2.Digital/PushButton_430/PushButton_430.ino @@ -0,0 +1,41 @@ +// +// PushButton_430 +// +// © Rei VILO 2012 +// +// RED_LED on pin 2 +// GREEN_LED on pin 14 +// PUSH2 on pin 5 +// +// Press push 2 to light on +// red -> green -> red+green -> none -> ... +// +// Revision +// Rei VILO, May 21, 2012 - Updated with GREEN_LED, RED_LED and PUSH2 + +void setup() { + // initialise digital pins as outputs + pinMode(RED_LED, OUTPUT); + pinMode(GREEN_LED, OUTPUT); + pinMode(PUSH2, INPUT_PULLUP); + lights(0); +} + +void lights(uint8_t ui) { + digitalWrite(RED_LED, bitRead(ui, 0) ? HIGH: LOW); + digitalWrite(GREEN_LED, bitRead(ui, 1) ? HIGH: LOW); +} + +uint8_t var = 0; + +void loop() { + + if (digitalRead(PUSH2)==LOW) { + while (digitalRead(PUSH2)==LOW); + var++; + var%=4; + lights(var); + delay(100); + } +} + diff --git a/examples/3.Analog/AnalogInput_InternalThermometer_430/AnalogInput_InternalThermometer_430.ino b/examples/3.Analog/AnalogInput_InternalThermometer_430/AnalogInput_InternalThermometer_430.ino new file mode 100644 index 00000000000..a042d89abac --- /dev/null +++ b/examples/3.Analog/AnalogInput_InternalThermometer_430/AnalogInput_InternalThermometer_430.ino @@ -0,0 +1,107 @@ +// +// AnalogInput_InternalThermometer_430 +// Analog Input - MSP430 Internal Thermometer +// +// Demonstrates analog input by reading the internal temperature sensor. +// +// Created by Robert Wessels +// modified 7 March 2012 +// By Robert Wessels +// +// This example code is in the public domain. +// +// Revision: +// Rei VILO, Mar 12, 2012 - One decimal place +// Rei VILO, Mar 13, 2012 - More precise algorithm +// Rei VILO, Mar 14, 2012 - Average +// Rei VILO, May 21, 2012 - Updated with GREEN_LED, RED_LED and PUSH2 +// Press push 2 to end +// Tested on msp430g2452 and msp430g2553 +// 2196 bytes + +#include + +// RED_LED, GREEN_LED, TEMPSENSOR, PUSH2 already defined +#define NUMBER 4 // take number / 2 + +TimerSerial mySerial; +int ledState = HIGH; +uint8_t i = 0; +uint32_t average = 0; +uint32_t values[NUMBER]; +uint8_t j = 0; +boolean flag = false; + + +void setup() { + pinMode(RED_LED, OUTPUT); + pinMode(GREEN_LED, OUTPUT); + analogReference(INTERNAL1V5); + analogRead(TEMPSENSOR); // first reading usually wrong + + mySerial.begin(); + pinMode(PUSH2, INPUT_PULLUP); + + digitalWrite(RED_LED, HIGH); + digitalWrite(GREEN_LED, LOW); + + + mySerial.print("\n\n\n*** MSP430 Thermometer \n"); + mySerial.print("Press PUSH2 to end\n"); + mySerial.print("instant\taverage\n"); + + for (j=0; j> 16; + average += values[j]; + + // Print measure + printDec(values[j]); + mySerial.print("\t"); + + // Print average + if (flag) printDec(average/NUMBER); + mySerial.print("\n"); + + j++; + if (j==NUMBER) flag=true; + j %= NUMBER; + } + + if (digitalRead(PUSH2)==LOW) { + mySerial.print("\n\n*** End \n"); + mySerial.end(); + while(true); // endless loop + } + delay(100); + + i++; +} + + + + + + + + diff --git a/examples/4.Communication/Serial_430/Serial_430.ino b/examples/4.Communication/Serial_430/Serial_430.ino new file mode 100644 index 00000000000..32d5841672c --- /dev/null +++ b/examples/4.Communication/Serial_430/Serial_430.ino @@ -0,0 +1,49 @@ +// +// Serial_430 +// +// © Rei VILO 2012 +// +// PUSH2 on pin 5 +// +// Key in text and press Enter for loopback +// Press push 2 to end +// Buffer size = 16, of which Enter +// +// Revision +// Rei VILO, May 21, 2012 - Updated with GREEN_LED, RED_LED and PUSH2 +// + +#include "TimerSerial.h" + +TimerSerial mySerial; + +void setup() { + mySerial.begin(); + mySerial.print("\n\n\n*** Serial test starts \n"); + mySerial.print("PUSH2 to end\n"); + pinMode(PUSH2, INPUT_PULLUP); +} + + +void loop() { + + if (mySerial.available()) { + mySerial.print(char(mySerial.read())); + } + else { + mySerial.print("."); + delay(500); + } + + if (digitalRead(PUSH2)==LOW) { + mySerial.print("\n\n*** Serial test ends. \n"); + mySerial.end(); + while(true); // endless loop + } +} + + + + + + diff --git a/examples/6.Sensors/I2C_TMP102_Thermometer_430/I2C_TMP102_Thermometer_430.ino b/examples/6.Sensors/I2C_TMP102_Thermometer_430/I2C_TMP102_Thermometer_430.ino new file mode 100644 index 00000000000..1e40adc7600 --- /dev/null +++ b/examples/6.Sensors/I2C_TMP102_Thermometer_430/I2C_TMP102_Thermometer_430.ino @@ -0,0 +1,77 @@ +// +// I2C_TMP102_Thermometer_430 +// +// © Rei VILO 2012 +// +// PUSH2 on pin 5 +// +// Uses I2C thermometer +// Texas Instrument TMP102 with strap ADDR0 - SCL +// +// Press push 2 to end +// +// Tested on msp430g2452 +// Binary sketch size = 3004 bytes out of 8192 bytes +// +// Revision +// Rei VILO, May 21, 2012 - Updated with GREEN_LED, RED_LED and PUSH2 +// + +#include "Wire.h" +#include "TimerSerial.h" + +// PUSH2 alreadey defined +#define _address 0x4b // strap ADDR0 - SCL + +TimerSerial mySerial; + +void setup() { + mySerial.begin(); + mySerial.print("\n\n\n*** Thermometer \n"); + mySerial.print("Press PUSH2 to end\n"); + pinMode(PUSH2, INPUT_PULLUP); + + Wire.begin(); +} + +int16_t t; + +void loop() { + Wire.beginTransmission(_address); + Wire.write(0b00000000); + Wire.endTransmission(); + + Wire.beginTransmission(_address); + Wire.requestFrom(_address, 2); + t=(Wire.read() << 8 | Wire.read()) >> 4; + + Wire.endTransmission(); + if (t>0b100000000000) t -= 4096; + + // Float adds 6 kB + // mySerial.print(t*0.0625, DEC); + // mySerial.print("\n"); + + // Integer + t *= 10; // one decimal place + t += 8; // rounding + mySerial.print(t/160, DEC); + mySerial.print("."); + mySerial.print((t%160)/16, DEC); + mySerial.print("\n"); + + delay(500); + + // PUSH2 required to avoid USB freeze for next upload + if (digitalRead(PUSH2)==LOW) { + mySerial.print("\n*** End\n"); + mySerial.end(); + while(true); // endless loop + } +} + + + + + + diff --git a/examples/6.Sensors/I2C_TMP102_Thermometer_430/TMP102.pdf b/examples/6.Sensors/I2C_TMP102_Thermometer_430/TMP102.pdf new file mode 100644 index 00000000000..bf6de563bd0 Binary files /dev/null and b/examples/6.Sensors/I2C_TMP102_Thermometer_430/TMP102.pdf differ diff --git a/examples/7.Display/led8x8display_430/font.c b/examples/7.Display/led8x8display_430/font.c new file mode 100644 index 00000000000..a244d28c60e --- /dev/null +++ b/examples/7.Display/led8x8display_430/font.c @@ -0,0 +1,108 @@ +//#include "font.h" + +const unsigned char FontLookup [][5] = +{ + { 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp 00 + { 0x00, 0x00, 0x2f, 0x00, 0x00 }, // ! 01 + { 0x00, 0x07, 0x00, 0x07, 0x00 }, // " 02 + { 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // # 03 + { 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $ 04 + { 0xc4, 0xc8, 0x10, 0x26, 0x46 }, // % 05 + { 0x36, 0x49, 0x55, 0x22, 0x50 }, // & 06 + { 0x00, 0x05, 0x03, 0x00, 0x00 }, // ' 07 + { 0x00, 0x1c, 0x22, 0x41, 0x00 }, // ( 08 + { 0x00, 0x41, 0x22, 0x1c, 0x00 }, // ) 09 + { 0x14, 0x08, 0x3E, 0x08, 0x14 }, // * 10 + { 0x08, 0x08, 0x3E, 0x08, 0x08 }, // + 11 + { 0x00, 0x00, 0x50, 0x30, 0x00 }, // , 12 + { 0x10, 0x10, 0x10, 0x10, 0x10 }, // - 13 + { 0x00, 0x60, 0x60, 0x00, 0x00 }, // . 14 + { 0x20, 0x10, 0x08, 0x04, 0x02 }, // / 15 + { 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0 16 + { 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1 17 + { 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2 18 + { 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3 19 + { 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4 20 + { 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5 21 + { 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6 22 + { 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7 23 + { 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8 24 + { 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9 25 + { 0x00, 0x36, 0x36, 0x00, 0x00 }, // : 26 + { 0x00, 0x56, 0x36, 0x00, 0x00 }, // ; 27 + { 0x08, 0x14, 0x22, 0x41, 0x00 }, // < 28 + { 0x14, 0x14, 0x14, 0x14, 0x14 }, // = 29 + { 0x00, 0x41, 0x22, 0x14, 0x08 }, // > 30 + { 0x02, 0x01, 0x51, 0x09, 0x06 }, // ? 31 + { 0x32, 0x49, 0x59, 0x51, 0x3E }, // @ 32 + { 0x7E, 0x11, 0x11, 0x11, 0x7E }, // A 33 + { 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B 34 + { 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C 35 + { 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D 36 + { 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E 37 + { 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F 38 + { 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G 39 + { 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H 40 + { 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I 41 + { 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J 42 + { 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K 43 + { 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L 44 + { 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M 45 + { 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N 46 + { 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O 47 + { 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P 48 + { 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q 49 + { 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R 50 + { 0x46, 0x49, 0x49, 0x49, 0x31 }, // S 51 + { 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T 52 + { 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U 53 + { 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V 54 + { 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W 55 + { 0x63, 0x14, 0x08, 0x14, 0x63 }, // X 56 + { 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y 57 + { 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z 58 + { 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [ 59 + { 0x55, 0x2A, 0x55, 0x2A, 0x55 }, //55 60 + { 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ] 61 + { 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^ 62 + { 0x40, 0x40, 0x40, 0x40, 0x40 }, // _ 63 + { 0x00, 0x01, 0x02, 0x04, 0x00 }, // ' 64 + { 0x20, 0x54, 0x54, 0x54, 0x78 }, // a 65 + { 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b 66 + { 0x38, 0x44, 0x44, 0x44, 0x20 }, // c 67 + { 0x38, 0x44, 0x44, 0x48, 0x7F }, // d 68 + { 0x38, 0x54, 0x54, 0x54, 0x18 }, // e 69 + { 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f 70 + { 0x0C, 0x52, 0x52, 0x52, 0x3E }, // g 71 + { 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h 72 + { 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i 73 + { 0x20, 0x40, 0x44, 0x3D, 0x00 }, // j 74 + { 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k 75 + { 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l 76 + { 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m 77 + { 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n 78 + { 0x38, 0x44, 0x44, 0x44, 0x38 }, // o 79 + { 0x7C, 0x14, 0x14, 0x14, 0x08 }, // p 80 + { 0x08, 0x14, 0x14, 0x18, 0x7C }, // q 81 + { 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r 82 + { 0x48, 0x54, 0x54, 0x54, 0x20 }, // s 83 + { 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t 84 + { 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u 85 + { 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v 86 + { 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w 87 + { 0x44, 0x28, 0x10, 0x28, 0x44 }, // x 88 + { 0x0C, 0x50, 0x50, 0x50, 0x3C }, // y 89 + { 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z 90 + { 0x08, 0x6C, 0x6A, 0x19, 0x08 }, // { 91 + { 0x30, 0x4E, 0x61, 0x4E, 0x30 }, // | 92 + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } // # 93 +}; + +// Return pointer to font character +unsigned char *fontPtr(char c) +{ + if ( c < ' ' || c-' ' > 93 ) + return (unsigned char*)FontLookup[0]; + else + return (unsigned char*)FontLookup[(unsigned char)(c-' ')]; +} diff --git a/examples/7.Display/led8x8display_430/font.h b/examples/7.Display/led8x8display_430/font.h new file mode 100644 index 00000000000..8a2630b8783 --- /dev/null +++ b/examples/7.Display/led8x8display_430/font.h @@ -0,0 +1,7 @@ +#ifndef FONT_H +#define FONT_H +extern "C" { +extern const unsigned char FontLookup [][5]; +extern unsigned char *fontPtr(char); +} +#endif diff --git a/examples/7.Display/led8x8display_430/led8x8display_430.ino b/examples/7.Display/led8x8display_430/led8x8display_430.ino new file mode 100644 index 00000000000..2f5b3c339c5 --- /dev/null +++ b/examples/7.Display/led8x8display_430/led8x8display_430.ino @@ -0,0 +1,234 @@ +/* + * Energia test program for Olimex MSP430-LED boosterpack + * http://www.olimex.com/dev/msp-led8x8.html + * + * Copyright (c) 2012, Peter Brier (pbrier.nl - gmail.com) + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * README + * ~~~~~~ + * + * The 8x8 led array is connected via two shift registers + * 16 bits need to be shifted out, and latched. + * Bit 7..0 (the first bits shifted out) control the high side of the array (columns) + * Bit 15..8 (the last bits shifted out) control the low side of the array (row data) + * + * To display an image you need to constantly update the display: scanning the rows + * and update the colum data accordingly + * + * This program uses "bit banging" to shift out the data. Some uC have a nice SPI peripheral + * to do this without burning CPU cycles. We're not using that (at the moment). + * + * This demo also uses the MIC and Buzzer (some kind of scope) + * + * TODO + * ~~~~ + * - Make some defines to desichain more displays + */ +#include "font.h" + +// MIC and Buzzer +#define AIN 0 // Note: AIN0 == pin2 +#define BUZ1 3 +#define BUZ2 4 + +// The 8x8 led matrix +#define LATCH 6 +#define CLOCK 7 +#define DATA 14 +#define DELAYTIME 1 // microseconds to wait after setting pin + + +// The string to display: +const char *str = "}} Hello World... }}"; + + +// Image buffer, you can modify the bits and they will be displayed on the 8x8 matrix with the sendImage() function +unsigned char image[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + + +/** +*** setup() +*** Enable the output pins +**/ +void setup() +{ + pinMode(BUZ1, OUTPUT); + pinMode(BUZ2, OUTPUT); // note: also switch + pinMode(CLOCK, OUTPUT); + pinMode(DATA, OUTPUT); + pinMode(LATCH, OUTPUT); + pinMode(PUSH2, INPUT_PULLUP); + analogReference(INTERNAL1V5); +} + +// Read switch status +boolean button() +{ + return digitalRead(PUSH2) == 0; +} + +// send 16 bits to LED tile (bits 0..7 are column, 8..15 are row) +void sendData(unsigned short data) +{ + for(unsigned short i=0; i<16; i++) + { + if ( data & ((unsigned short)1< 20 ) // shift in new line + { + a=0; + now = analogRead(AIN)/2; + if ( now < 0 ) now = -now; + avg = (15 * avg + now) / 16; + val = ABS(avg-prev); + shiftLeft( 128>>val ); + if ( button() ) + avg = 0; + tone(100*val); + prev = avg; + } + } +} + +// Sinewave example +void sineWave() +{ + static const unsigned char wave[] = {4,5,6,6,7,7,7,6,6,5,4,2,1,1,0,0,0,1,1,2,4}; + unsigned char j = 0, q; + for(int i=0; i<100;i++) + { + j = i % sizeof(wave); + tone(300+200*wave[j]); + shiftLeft(1 << wave[j]); + for(q=0; q<20; q++) sendImage(image); + } +} + + +// display a text on the 8x8 display +void showText(const char *txt) +{ + int a =0, i=0, j=0; + while(1) + { + sendImage(image); + if ( a++ > 60 ) // shift in new line + { + a=0; + if ( j < 5 ) // copy character + shiftLeft( *(fontPtr(txt[i]) + (unsigned int)j) ); + else + { + shiftLeft(0); // blank line + sendImage(image); + tone(500); + } + if ( ++j > 5 ) // next character + { + j = 0; + if ( ++i >= strlen(txt) ) + return; + } + } + } +} diff --git a/hardware/msp430/boards.txt b/hardware/msp430/boards.txt new file mode 100644 index 00000000000..ce095218b5e --- /dev/null +++ b/hardware/msp430/boards.txt @@ -0,0 +1,32 @@ +############################################################## +lpmsp430g2452.name=LaunchPad w/ msp430g2452 +lpmsp430g2452.upload.protocol=rf2500 +lpmsp430g2452.upload.maximum_size=8192 +lpmsp430g2452.bootloader.lock_bits=0x0F +lpmsp430g2452.build.mcu=msp430g2452 +lpmsp430g2452.build.f_cpu=16000000L +lpmsp430g2452.build.core=msp430 +lpmsp430g2452.build.variant=launchpad + +############################################################## + +lpmsp430g2231.name=LaunchPad w/ msp430g2231 +lpmsp430g2231.upload.protocol=rf2500 +lpmsp430g2231.upload.maximum_size=2048 +lpmsp430g2231.bootloader.lock_bits=0x0F +lpmsp430g2231.build.mcu=msp430g2231 +lpmsp430g2231.build.f_cpu=1000000L +lpmsp430g2231.build.core=msp430 +lpmsp430g2231.build.variant=launchpad + +############################################################## + +lpmsp430g2553.name=LaunchPad w/ msp430g2553 +lpmsp430g2553.upload.protocol=rf2500 +lpmsp430g2553.upload.maximum_size=16384 +lpmsp430g2553.bootloader.lock_bits=0x0F +lpmsp430g2553.build.mcu=msp430g2553 +lpmsp430g2553.build.f_cpu=16000000L +lpmsp430g2553.build.core=msp430 +lpmsp430g2553.build.variant=launchpad +############################################################## diff --git a/hardware/msp430/cores/msp430/Energia.h b/hardware/msp430/cores/msp430/Energia.h new file mode 100644 index 00000000000..7320a5bd336 --- /dev/null +++ b/hardware/msp430/cores/msp430/Energia.h @@ -0,0 +1,178 @@ +#ifndef Energia_h +#define Energia_h + +#include +#include +#include +#include + +#include "binary.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +#define NOT_A_PORT 0 +#define NOT_A_PIN 0 +#define NOT_ON_TIMER 0 + +#define HIGH 0x1 +#define LOW 0x0 + +#define LSBFIRST 0 +#define MSBFIRST 1 + +#define FALLING 1 +#define RISING 0 + +#define INPUT 0x0 +#define OUTPUT 0x1 +#define INPUT_PULLUP 0x2 +#define INPUT_PULLDOWN 0x3 + +#define true 0x1 +#define false 0x0 + +#define PI 3.1415926535897932384626433832795 +#define HALF_PI 1.5707963267948966192313216916398 +#define TWO_PI 6.283185307179586476925286766559 +#define DEG_TO_RAD 0.017453292519943295769236907684886 +#define RAD_TO_DEG 57.295779513082320876798154814105 + +#if defined(__MSP430_HAS_ADC10__) +#define DEFAULT SREF_0 +#define INTERNAL1V5 SREF_1 + REFON +#define INTERNAL2V5 SREF_1 + REFON + REF2_5V +#define EXTERNAL SREF_2 +#endif + +#define P1 1 +#define P2 2 +#define P3 3 +#define P4 4 +#define P5 5 +#define P6 6 +#define P7 7 + +#define T0A0 0 +#define T0A1 1 +#define T0A2 2 +#define T1A0 3 +#define T1A1 4 +#define T1A2 5 +#define T1A3 6 +#define T1A4 7 +#define T1A5 8 +#define T2A0 9 +#define T2A1 10 +#define T2A2 11 + +typedef uint8_t boolean; +typedef uint8_t byte; + +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + +#define interrupts() __bis_SR_register(GIE) +#define noInterrupts() __bic_SR_register(GIE) + +#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) +#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) +#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) + +#define lowByte(w) ((uint8_t) ((w) & 0xff)) +#define highByte(w) ((uint8_t) ((w) >> 8)) + +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) +#define bitSet(value, bit) ((value) |= (1UL << (bit))) +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) + + +typedef unsigned int word; + +#define bit(b) (1UL << (b)) + +void init(void); +void setup(void); +void loop(void); + +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); +uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); +void pinMode(uint8_t, uint8_t); +void digitalWrite(uint8_t, uint8_t); +int digitalRead(uint8_t); +uint16_t analogRead(uint8_t); +void analogWrite(uint8_t, int); +void analogReference(uint16_t); +void analogFrequency(uint32_t); +void analogResolution(uint16_t); + + + +void delay(uint32_t milliseconds); + +void attachInterrupt(uint8_t, void (*)(void), int mode); +void detachInterrupt(uint8_t); + +extern const uint8_t digital_pin_to_timer[]; +extern const uint8_t digital_pin_to_port[]; +extern const uint8_t digital_pin_to_bit_mask[]; +extern const uint16_t port_to_sel[]; +extern const uint16_t port_to_sel2[]; +extern const uint16_t port_to_input[]; + +#define digitalPinToPort(P) ( digital_pin_to_port[P] ) +#define digitalPinToBitMask(P) ( digital_pin_to_bit_mask[P] ) +#define digitalPinToTimer(P) ( digital_pin_to_timer[P] ) +#define portDirRegister(P) ( (volatile uint16_t *)( port_to_dir[P]) ) +#define portSelRegister(P) ( (volatile uint16_t *)( port_to_sel[P]) ) +#define portSel2Register(P) ( (volatile uint16_t *)( port_to_sel2[P]) ) +#define portRenRegister(P) ( (volatile uint16_t *)( port_to_ren[P]) ) +#define portOutputRegister(P) ( (volatile uint16_t *)( port_to_output[P]) ) +#define portInputRegister(P) ( (volatile uint16_t *)( port_to_input[P]) ) +#define digitalPinToTimer(P) ( digital_pin_to_timer[P] ) + +// Implemented in wiring.c +void delayMicroseconds(unsigned int us); +unsigned long micros(); +unsigned long millis(); + +#ifdef __cplusplus +} // extern "C" +#endif + +#ifdef __cplusplus +#include "WCharacter.h" +#include "WString.h" +#include "HardwareSerial.h" + +uint16_t makeWord(uint16_t w); +uint16_t makeWord(byte h, byte l); + +#define word(...) makeWord(__VA_ARGS__) + +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); + +void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); +void noTone(uint8_t _pin); + +// WMath prototypes +long random(long); +long random(long, long); +void randomSeed(unsigned int); +long map(long, long, long, long, long); + +#endif + +#include "pins_energia.h" + +#endif + + diff --git a/hardware/msp430/cores/msp430/HardwareSerial.cpp b/hardware/msp430/cores/msp430/HardwareSerial.cpp new file mode 100644 index 00000000000..a0c4e21b7c0 --- /dev/null +++ b/hardware/msp430/cores/msp430/HardwareSerial.cpp @@ -0,0 +1,221 @@ +/* + ************************************************************************ + * HardwareSerial.cpp + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + HardwareSerial.cpp - Hardware serial library for Wiring + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Modified 23 November 2006 by David A. Mellis + Modified 28 September 2010 by Mark Sproul +*/ + +#include +#include +#include +#include +#include "Energia.h" +#include "wiring_private.h" + +#if defined(__MSP430_HAS_USCI__) + +#include "HardwareSerial.h" + +HardwareSerial *SerialPtr; + +/** + * Receive Data (RXD) at P1.1 + */ +#define RXD BIT1 + +/** + * Receive Data (TXD) at P1.2 + */ +#define TXD BIT2 + + +#define SERIAL_BUFFER_SIZE 16 + +struct ring_buffer +{ + unsigned char buffer[SERIAL_BUFFER_SIZE]; + volatile unsigned int head; + volatile unsigned int tail; +}; + +ring_buffer rx_buffer = { { 0 }, 0, 0 }; +ring_buffer tx_buffer = { { 0 }, 0, 0 }; + +inline void store_char(unsigned char c, ring_buffer *buffer) +{ + unsigned int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE; + + // if we should be storing the received character into the location + // just before the tail (meaning that the head would advance to the + // current location of the tail), we're about to overflow the buffer + // and so we don't write the character or advance the head. + if (i != buffer->tail) { + buffer->buffer[buffer->head] = c; + buffer->head = i; + } +} + +// Constructors //////////////////////////////////////////////////////////////// + +HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer) +{ + _rx_buffer = rx_buffer; + _tx_buffer = tx_buffer; +} + +// Public Methods ////////////////////////////////////////////////////////////// +#define SMCLK F_CPU //SMCLK = F_CPU for now + +void HardwareSerial::begin(unsigned long baud) +{ + unsigned int divider; + unsigned char mod, oversampling; + + if (SMCLK/baud>=48) { // requires SMCLK for oversampling + oversampling = 1; + } + else { + oversampling= 0; + } + + divider=(SMCLK<<4)/baud; + + if(!oversampling) { + mod = ((divider&0xF)+1)&0xE; // UCBRSx (bit 1-3) + divider >>=4; + } else { + mod = ((divider&0xf8)+0x8)&0xf0; // UCBRFx (bit 4-7) + divider>>=8; + } + + SerialPtr = this; + P1SEL = RXD + TXD; + P1SEL2 = RXD + TXD; + + UCA0CTL1 = UCSWRST; + UCA0CTL1 = UCSSEL_2; //SMCLK + UCA0CTL0 = 0; + UCA0ABCTL = 0; + UCA0BR0 = divider; + UCA0BR1 = divider>>8; + UCA0MCTL = (oversampling ? UCOS16:0) | mod; + UCA0CTL1 &= ~UCSWRST; + UC0IE = UCA0RXIE; +} + +void HardwareSerial::end() +{ + // wait for transmission of outgoing data + while (_tx_buffer->head != _tx_buffer->tail); + + _rx_buffer->head = _rx_buffer->tail; +} + +int HardwareSerial::available(void) +{ + return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE; +} + +int HardwareSerial::peek(void) +{ + if (_rx_buffer->head == _rx_buffer->tail) { + return -1; + } else { + return _rx_buffer->buffer[_rx_buffer->tail]; + } +} + +int HardwareSerial::read(void) +{ + // if the head isn't ahead of the tail, we don't have any characters + if (_rx_buffer->head == _rx_buffer->tail) { + return -1; + } else { + unsigned char c = _rx_buffer->buffer[_rx_buffer->tail]; + _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE; + return c; + } +} + +void HardwareSerial::flush() +{ + while (_tx_buffer->head != _tx_buffer->tail); +} + +size_t HardwareSerial::write(uint8_t c) +{ + unsigned int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE; + + // If the output buffer is full, there's nothing for it other than to + // wait for the interrupt handler to empty it a bit + // ???: return 0 here instead? + while (i == _tx_buffer->tail); + + _tx_buffer->buffer[_tx_buffer->head] = c; + _tx_buffer->head = i; + + IE2 |= UCA0TXIE; + + return 1; +} + +void HardwareSerial::ProcessRXInt(void) +{ + unsigned char c = UCA0RXBUF; + store_char(c, &rx_buffer); +} + +__attribute__((interrupt(USCIAB0RX_VECTOR))) +void HardwareSerial::USCI0RX_ISR(void) +{ + SerialPtr->ProcessRXInt(); +} + +void HardwareSerial::ProcessTXInt(void) +{ + if (tx_buffer.head == tx_buffer.tail) { + // Buffer empty, so disable interrupts + IE2 &= ~UCA0TXIE; + return; + } + + unsigned char c = tx_buffer.buffer[tx_buffer.tail]; + tx_buffer.tail = (tx_buffer.tail + 1) % SERIAL_BUFFER_SIZE; + UCA0TXBUF = c; +} + +__attribute__((interrupt(USCIAB0TX_VECTOR))) +void HardwareSerial::USCI0TX_ISR(void) +{ + SerialPtr->ProcessTXInt(); +} + +// Preinstantiate Objects ////////////////////////////////////////////////////// + +HardwareSerial Serial(&rx_buffer, &tx_buffer); + +#endif diff --git a/hardware/msp430/cores/msp430/HardwareSerial.h b/hardware/msp430/cores/msp430/HardwareSerial.h new file mode 100644 index 00000000000..bbb9e5ecae6 --- /dev/null +++ b/hardware/msp430/cores/msp430/HardwareSerial.h @@ -0,0 +1,64 @@ +/* + ************************************************************************ + * TimerSerial.h + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + HardwareSerial.cpp - Hardware serial library for Wiring + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef HardwareSerial_h +#define HardwareSerial_h + +#include + +#include "Stream.h" + +struct ring_buffer; + +class HardwareSerial : public Stream +{ + private: + uint8_t lock; + ring_buffer *_rx_buffer; + ring_buffer *_tx_buffer; + static void USCI0RX_ISR (void); + static void USCI0TX_ISR (void); + void ProcessTXInt(void); + void ProcessRXInt(void); + public: + HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer); + void begin(unsigned long); + void end(); + virtual int available(void); + virtual int peek(void); + virtual int read(void); + virtual void flush(void); + virtual size_t write(uint8_t); + using Print::write; // pull in write(str) and write(buf, size) from Print +}; + +extern HardwareSerial Serial; + +extern void serialEventRun(void) __attribute__((weak)); + +#endif diff --git a/hardware/msp430/cores/msp430/Print.cpp b/hardware/msp430/cores/msp430/Print.cpp new file mode 100644 index 00000000000..18c48f18f44 --- /dev/null +++ b/hardware/msp430/cores/msp430/Print.cpp @@ -0,0 +1,252 @@ +/* + Print.cpp - Base class that provides print() and println() + Copyright (c) 2008 David A. Mellis. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Modified 23 November 2006 by David A. Mellis + Modified for msp403 2012 by Robert Wessels + */ + +#include +#include +#include +#include +#include "Energia.h" + +#include "Print.h" + +// Public Methods ////////////////////////////////////////////////////////////// + +/* default implementation: may be overridden */ +size_t Print::write(const uint8_t *buffer, size_t size) +{ + size_t n = 0; + while (size--) { + n += write(*buffer++); + } + return n; +} + +size_t Print::print(const String &s) +{ + size_t n = 0; + for (uint16_t i = 0; i < s.length(); i++) { + n += write(s[i]); + } + return n; +} + +size_t Print::print(const char str[]) +{ + return write(str); +} + +size_t Print::print(char c) +{ + return write(c); +} + +size_t Print::print(unsigned char b, int base) +{ + return print((unsigned long) b, base); +} + +size_t Print::print(int n, int base) +{ + return print((long) n, base); +} + +size_t Print::print(unsigned int n, int base) +{ + return print((unsigned long) n, base); +} + +size_t Print::print(long n, int base) +{ + if (base == 0) { + return write(n); + } else if (base == 10) { + if (n < 0) { + int t = print('-'); + n = -n; + return printNumber(n, 10) + t; + } + return printNumber(n, 10); + } else { + return printNumber(n, base); + } +} + +size_t Print::print(unsigned long n, int base) +{ + if (base == 0) return write(n); + else return printNumber(n, base); +} + +size_t Print::print(double n, int digits) +{ + return printFloat(n, digits); +} + +//size_t Print::println(const __FlashStringHelper *ifsh) +//{ +// size_t n = print(ifsh); +// n += println(); +// return n; +//} + +size_t Print::print(const Printable& x) +{ + return x.printTo(*this); +} + +size_t Print::println(void) +{ + size_t n = print('\r'); + n += print('\n'); + return n; +} + +size_t Print::println(const String &s) +{ + size_t n = print(s); + n += println(); + return n; +} + +size_t Print::println(const char c[]) +{ + size_t n = print(c); + n += println(); + return n; +} + +size_t Print::println(char c) +{ + size_t n = print(c); + n += println(); + return n; +} + +size_t Print::println(unsigned char b, int base) +{ + size_t n = print(b, base); + n += println(); + return n; +} + +size_t Print::println(int num, int base) +{ + size_t n = print(num, base); + n += println(); + return n; +} + +size_t Print::println(unsigned int num, int base) +{ + size_t n = print(num, base); + n += println(); + return n; +} + +size_t Print::println(long num, int base) +{ + size_t n = print(num, base); + n += println(); + return n; +} + +size_t Print::println(unsigned long num, int base) +{ + size_t n = print(num, base); + n += println(); + return n; +} + +size_t Print::println(double num, int digits) +{ + size_t n = print(num, digits); + n += println(); + return n; +} + +size_t Print::println(const Printable& x) +{ + size_t n = print(x); + n += println(); + return n; +} + +// Private Methods ///////////////////////////////////////////////////////////// + +size_t Print::printNumber(unsigned long n, uint8_t base) { + char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. + char *str = &buf[sizeof(buf) - 1]; + + *str = '\0'; + + // prevent crash if called with base == 1 + if (base < 2) base = 10; + + do { + unsigned long m = n; + n /= base; + char c = m - base * n; + *--str = c < 10 ? c + '0' : c + 'A' - 10; + } while(n); + + return write(str); +} + +size_t Print::printFloat(double number, uint8_t digits) +{ + size_t n = 0; + + // Handle negative numbers + if (number < 0.0) + { + n += print('-'); + number = -number; + } + + // Round correctly so that print(1.999, 2) prints as "2.00" + double rounding = 0.5; + for (uint8_t i=0; i 0) { + n += print("."); + } + + // Extract digits from the remainder one at a time + while (digits-- > 0) + { + remainder *= 10.0; + int toPrint = int(remainder); + n += print(toPrint); + remainder -= toPrint; + } + + return n; +} diff --git a/hardware/msp430/cores/msp430/Print.h b/hardware/msp430/cores/msp430/Print.h new file mode 100644 index 00000000000..69aace9786b --- /dev/null +++ b/hardware/msp430/cores/msp430/Print.h @@ -0,0 +1,78 @@ +/* + Print.h - Base class that provides print() and println() + Copyright (c) 2008 David A. Mellis. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Print_h +#define Print_h + +#include +#include // for size_t + +#include "WString.h" +#include "Printable.h" + +#define DEC 10 +#define HEX 16 +#define OCT 8 +#define BIN 2 + +class Print +{ + private: + int write_error; + size_t printNumber(unsigned long, uint8_t); + size_t printFloat(double, uint8_t); + protected: + void setWriteError(int err = 1) { write_error = err; } + public: + Print() : write_error(0) {} + + int getWriteError() { return write_error; } + void clearWriteError() { setWriteError(0); } + + virtual size_t write(uint8_t) = 0; + size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); } + virtual size_t write(const uint8_t *buffer, size_t size); + + //size_t print(const __FlashStringHelper *); + size_t print(const String &); + size_t print(const char[]); + size_t print(char); + size_t print(unsigned char, int = DEC); + size_t print(int, int = DEC); + size_t print(unsigned int, int = DEC); + size_t print(long, int = DEC); + size_t print(unsigned long, int = DEC); + size_t print(double, int = 2); + size_t print(const Printable&); + + //size_t println(const __FlashStringHelper *); + size_t println(const String &s); + size_t println(const char[]); + size_t println(char); + size_t println(unsigned char, int = DEC); + size_t println(int, int = DEC); + size_t println(unsigned int, int = DEC); + size_t println(long, int = DEC); + size_t println(unsigned long, int = DEC); + size_t println(double, int = 2); + size_t println(const Printable&); + size_t println(void); +}; + +#endif diff --git a/hardware/msp430/cores/msp430/Printable.h b/hardware/msp430/cores/msp430/Printable.h new file mode 100644 index 00000000000..d03c9af62c4 --- /dev/null +++ b/hardware/msp430/cores/msp430/Printable.h @@ -0,0 +1,40 @@ +/* + Printable.h - Interface class that allows printing of complex types + Copyright (c) 2011 Adrian McEwen. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Printable_h +#define Printable_h + +#include + +class Print; + +/** The Printable class provides a way for new classes to allow themselves to be printed. + By deriving from Printable and implementing the printTo method, it will then be possible + for users to print out instances of this class by passing them into the usual + Print::print and Print::println methods. +*/ + +class Printable +{ + public: + virtual size_t printTo(Print& p) const = 0; +}; + +#endif + diff --git a/hardware/msp430/cores/msp430/Stream.cpp b/hardware/msp430/cores/msp430/Stream.cpp new file mode 100644 index 00000000000..c7d1863f161 --- /dev/null +++ b/hardware/msp430/cores/msp430/Stream.cpp @@ -0,0 +1,246 @@ +/* + Stream.cpp - adds parsing methods to Stream class + Copyright (c) 2008 David A. Mellis. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Created July 2011 + parsing functions based on TextFinder library by Michael Margolis + */ + +#include "Energia.h" +#include "Stream.h" + +#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait +#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field + +// private method to read stream with timeout +int Stream::timedRead() +{ + int c; + _startMillis = millis(); + do { + c = read(); + if (c >= 0) return c; + } while(millis() - _startMillis < _timeout); + return -1; // -1 indicates timeout +} + +// private method to peek stream with timeout +int Stream::timedPeek() +{ + int c; + _startMillis = millis(); + do { + c = peek(); + if (c >= 0) return c; + } while(millis() - _startMillis < _timeout); + return -1; // -1 indicates timeout +} + +// returns peek of the next digit in the stream or -1 if timeout +// discards non-numeric characters +int Stream::peekNextDigit() +{ + int c; + while (1) { + c = timedPeek(); + if (c < 0) return c; // timeout + if (c == '-') return c; + if (c >= '0' && c <= '9') return c; + read(); // discard non-numeric + } +} + +// Public Methods +////////////////////////////////////////////////////////////// + +void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait +{ + _timeout = timeout; +} + + // find returns true if the target string is found +bool Stream::find(char *target) +{ + return findUntil(target, NULL); +} + +// reads data from the stream until the target string of given length is found +// returns true if target string is found, false if timed out +bool Stream::find(char *target, size_t length) +{ + return findUntil(target, length, NULL, 0); +} + +// as find but search ends if the terminator string is found +bool Stream::findUntil(char *target, char *terminator) +{ + return findUntil(target, strlen(target), terminator, strlen(terminator)); +} + +// reads data from the stream until the target string of the given length is found +// search terminated if the terminator string is found +// returns true if target string is found, false if terminated or timed out +bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen) +{ + size_t index = 0; // maximum target string length is 64k bytes! + size_t termIndex = 0; + int c; + + if( *target == 0) + return true; // return true if target is a null string + while( (c = timedRead()) > 0){ + + if(c != target[index]) + index = 0; // reset index if any char does not match + + if( c == target[index]){ + //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); + if(++index >= targetLen){ // return true if all chars in the target match + return true; + } + } + + if(termLen > 0 && c == terminator[termIndex]){ + if(++termIndex >= termLen) + return false; // return false if terminate string found before target string + } + else + termIndex = 0; + } + return false; +} + + +// returns the first valid (long) integer value from the current position. +// initial characters that are not digits (or the minus sign) are skipped +// function is terminated by the first character that is not a digit. +long Stream::parseInt() +{ + return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) +} + +// as above but a given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +long Stream::parseInt(char skipChar) +{ + boolean isNegative = false; + long value = 0; + int c; + + c = peekNextDigit(); + // ignore non numeric leading characters + if(c < 0) + return 0; // zero returned if timeout + + do{ + if(c == skipChar) + ; // ignore this charactor + else if(c == '-') + isNegative = true; + else if(c >= '0' && c <= '9') // is c a digit? + value = value * 10 + c - '0'; + read(); // consume the character we got with peek + c = timedPeek(); + } + while( (c >= '0' && c <= '9') || c == skipChar ); + + if(isNegative) + value = -value; + return value; +} + + +// as parseInt but returns a floating point value +float Stream::parseFloat() +{ + return parseFloat(NO_SKIP_CHAR); +} + +// as above but the given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +float Stream::parseFloat(char skipChar){ + boolean isNegative = false; + boolean isFraction = false; + long value = 0; + char c; + float fraction = 1.0; + + c = peekNextDigit(); + // ignore non numeric leading characters + if(c < 0) + return 0; // zero returned if timeout + + do{ + if(c == skipChar) + ; // ignore + else if(c == '-') + isNegative = true; + else if (c == '.') + isFraction = true; + else if(c >= '0' && c <= '9') { // is c a digit? + value = value * 10 + c - '0'; + if(isFraction) + fraction *= 0.1; + } + read(); // consume the character we got with peek + c = timedPeek(); + } + while( (c >= '0' && c <= '9') || c == '.' || c == skipChar ); + + if(isNegative) + value = -value; + if(isFraction) + return value * fraction; + else + return value; +} + +// read characters from stream into buffer +// terminates if length characters have been read, or timeout (see setTimeout) +// returns the number of characters placed in the buffer +// the buffer is NOT null terminated. +// +size_t Stream::readBytes(char *buffer, size_t length) +{ + size_t count = 0; + while (count < length) { + int c = timedRead(); + if (c < 0) break; + *buffer++ = (char)c; + count++; + } + return count; +} + + +// as readBytes with terminator character +// terminates if length characters have been read, timeout, or if the terminator character detected +// returns the number of characters placed in the buffer (0 means no valid data found) + +size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) +{ + if (length < 1) return 0; + size_t index = 0; + while (index < length) { + int c = timedRead(); + if (c < 0 || c == terminator) break; + *buffer++ = (char)c; + index++; + } + return index; // return number of characters, not including null terminator +} + diff --git a/hardware/msp430/cores/msp430/Stream.h b/hardware/msp430/cores/msp430/Stream.h new file mode 100644 index 00000000000..13f11bee022 --- /dev/null +++ b/hardware/msp430/cores/msp430/Stream.h @@ -0,0 +1,94 @@ +/* + Stream.h - base class for character-based streams. + Copyright (c) 2010 David A. Mellis. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + parsing functions based on TextFinder library by Michael Margolis +*/ + +#ifndef Stream_h +#define Stream_h + +#include +#include "Print.h" + +// compatability macros for testing +/* +#define getInt() parseInt() +#define getInt(skipChar) parseInt(skipchar) +#define getFloat() parseFloat() +#define getFloat(skipChar) parseFloat(skipChar) +#define getString( pre_string, post_string, buffer, length) +readBytesBetween( pre_string, terminator, buffer, length) +*/ + +class Stream : public Print +{ + private: + unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read + unsigned long _startMillis; // used for timeout measurement + int timedRead(); // private method to read stream with timeout + int timedPeek(); // private method to peek stream with timeout + int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout + + public: + virtual int available() = 0; + virtual int read() = 0; + virtual int peek() = 0; + virtual void flush() = 0; + + Stream() {_timeout=1000;} + +// parsing methods + + void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second + + bool find(char *target); // reads data from the stream until the target string is found + // returns true if target string is found, false if timed out (see setTimeout) + + bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found + // returns true if target string is found, false if timed out + + bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found + + bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found + + + long parseInt(); // returns the first valid (long) integer value from the current position. + // initial characters that are not digits (or the minus sign) are skipped + // integer is terminated by the first character that is not a digit. + + float parseFloat(); // float version of parseInt + + size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer + // terminates if length characters have been read or timeout (see setTimeout) + // returns the number of characters placed in the buffer (0 means no valid data found) + + size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character + // terminates if length characters have been read, timeout, or if the terminator character detected + // returns the number of characters placed in the buffer (0 means no valid data found) + + // Arduino String functions to be added here + + protected: + long parseInt(char skipChar); // as above but the given skipChar is ignored + // as above but the given skipChar is ignored + // this allows format characters (typically commas) in values to be ignored + + float parseFloat(char skipChar); // as above but the given skipChar is ignored +}; + +#endif diff --git a/hardware/msp430/cores/msp430/WCharacter.h b/hardware/msp430/cores/msp430/WCharacter.h new file mode 100644 index 00000000000..074539ceebb --- /dev/null +++ b/hardware/msp430/cores/msp430/WCharacter.h @@ -0,0 +1,170 @@ +/* + WCharacter.h - Character utility functions for Wiring & Arduino + Copyright (c) 2010 Hernando Barragan. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef Character_h +#define Character_h + +#include + +// WCharacter.h prototypes +inline boolean isAlphaNumeric(int c) __attribute__((always_inline)); +inline boolean isAlpha(int c) __attribute__((always_inline)); +inline boolean isAscii(int c) __attribute__((always_inline)); +inline boolean isWhitespace(int c) __attribute__((always_inline)); +inline boolean isControl(int c) __attribute__((always_inline)); +inline boolean isDigit(int c) __attribute__((always_inline)); +inline boolean isGraph(int c) __attribute__((always_inline)); +inline boolean isLowerCase(int c) __attribute__((always_inline)); +inline boolean isPrintable(int c) __attribute__((always_inline)); +inline boolean isPunct(int c) __attribute__((always_inline)); +inline boolean isSpace(int c) __attribute__((always_inline)); +inline boolean isUpperCase(int c) __attribute__((always_inline)); +inline boolean isHexadecimalDigit(int c) __attribute__((always_inline)); +inline int toAscii(int c) __attribute__((always_inline)); +inline int toLowerCase(int c) __attribute__((always_inline)); +inline int toUpperCase(int c)__attribute__((always_inline)); + + +// Checks for an alphanumeric character. +// It is equivalent to (isalpha(c) || isdigit(c)). +inline boolean isAlphaNumeric(int c) +{ + return ( isalnum(c) == 0 ? false : true); +} + + +// Checks for an alphabetic character. +// It is equivalent to (isupper(c) || islower(c)). +inline boolean isAlpha(int c) +{ + return ( isalpha(c) == 0 ? false : true); +} + + +// Checks whether c is a 7-bit unsigned char value +// that fits into the ASCII character set. +inline boolean isAscii(int c) +{ + return ( isascii (c) == 0 ? false : true); +} + + +// Checks for a blank character, that is, a space or a tab. +inline boolean isWhitespace(int c) +{ + return ( isblank (c) == 0 ? false : true); +} + + +// Checks for a control character. +inline boolean isControl(int c) +{ + return ( iscntrl (c) == 0 ? false : true); +} + + +// Checks for a digit (0 through 9). +inline boolean isDigit(int c) +{ + return ( isdigit (c) == 0 ? false : true); +} + + +//TODO: mspgcc does not seem to have isgraph?!? + +//// Checks for any printable character except space. +//inline boolean isGraph(int c) +//{ +// return ( isgraph (c) == 0 ? false : true); +//} + + +// Checks for a lower-case character. +inline boolean isLowerCase(int c) +{ + return (islower (c) == 0 ? false : true); +} + + +// Checks for any printable character including space. +inline boolean isPrintable(int c) +{ + return ( isprint (c) == 0 ? false : true); +} + + +// Checks for any printable character which is not a space +// or an alphanumeric character. +inline boolean isPunct(int c) +{ + return ( ispunct (c) == 0 ? false : true); +} + + +// Checks for white-space characters. For the avr-libc library, +// these are: space, formfeed ('\f'), newline ('\n'), carriage +// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). +inline boolean isSpace(int c) +{ + return ( isspace (c) == 0 ? false : true); +} + + +// Checks for an uppercase letter. +inline boolean isUpperCase(int c) +{ + return ( isupper (c) == 0 ? false : true); +} + + +// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 +// 8 9 a b c d e f A B C D E F. +inline boolean isHexadecimalDigit(int c) +{ + return ( isxdigit (c) == 0 ? false : true); +} + + +// Converts c to a 7-bit unsigned char value that fits into the +// ASCII character set, by clearing the high-order bits. +inline int toAscii(int c) +{ + return toascii (c); +} + + +// Warning: +// Many people will be unhappy if you use this function. +// This function will convert accented letters into random +// characters. + +// Converts the letter c to lower case, if possible. +inline int toLowerCase(int c) +{ + return tolower (c); +} + + +// Converts the letter c to upper case, if possible. +inline int toUpperCase(int c) +{ + return toupper (c); +} + +#endif diff --git a/hardware/msp430/cores/msp430/WInterrupts.c b/hardware/msp430/cores/msp430/WInterrupts.c new file mode 100644 index 00000000000..bce2afebed0 --- /dev/null +++ b/hardware/msp430/cores/msp430/WInterrupts.c @@ -0,0 +1,138 @@ +/* + ************************************************************************ + * WInterrupts.c + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + + WInterrupts.c Part of the Wiring project - http://wiring.uniandes.edu.co + + Copyright (c) 2004-05 Hernando Barragan + + 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 + + Modified 24 November 2006 by David A. Mellis + Modified 1 August 2010 by Mark Sproul +*/ + +#include +#include + +#include "wiring_private.h" + +#ifndef BV +#define BV(x) (1 << (x)) +#endif + +#define bit_pos(A) ((A) == 1u << 0 ? 0 \ +: (A) == 1u << 1 ? 1 \ +: (A) == 1u << 2 ? 2 \ +: (A) == 1u << 3 ? 3 \ +: (A) == 1u << 4 ? 4 \ +: (A) == 1u << 5 ? 5 \ +: (A) == 1u << 6 ? 6 \ +: (A) == 1u << 7 ? 7 \ +: 0) + +#define NUM_INTS_PER_PORT 8 +static volatile voidFuncPtr intFuncP1[NUM_INTS_PER_PORT]; +#if defined(__MSP430_HAS_PORT2_R__) +static volatile voidFuncPtr intFuncP2[NUM_INTS_PER_PORT]; +#endif + +void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { + uint8_t bit = digitalPinToBitMask(interruptNum); + uint8_t port = digitalPinToPort(interruptNum); + + + if ((port == NOT_A_PIN) || !((mode == FALLING) || (mode == RISING))) return; + + __dint(); + + switch(port) { + case P1: + P1IE |= bit; + P1IFG &= ~bit; + P1IES = mode ? P1IES | bit : P1IES & ~bit; + intFuncP1[bit_pos(bit)] = userFunc; + break; + #if defined(__MSP430_HAS_PORT2_R__) + case P2: + P2IE |= bit; + P2IFG &= bit; + P2IES = mode ? P2IES | bit : P2IES & ~bit; + intFuncP2[bit_pos(bit)] = userFunc; + break; + #endif + default: + break; + } + + __eint(); +} + +void detachInterrupt(uint8_t interruptNum) { + uint8_t bit = digitalPinToBitMask(interruptNum); + uint8_t port = digitalPinToPort(interruptNum); + + if (port == NOT_A_PIN) return; + + switch(port) { + case P1: + P1IE &= ~bit; + intFuncP1[bit_pos(bit)] = 0; + break; + #if defined(__MSP430_HAS_PORT2_R__) + case P2: + P2IE &= ~bit; + intFuncP2[bit_pos(bit)] = 0; + break; + #endif + default: + break; + } +} + + +__attribute__((interrupt(PORT1_VECTOR))) +void Port_1(void) +{ + uint8_t i; + for(i = 0; i < 8; i++) { + if((P1IFG & BV(i)) && intFuncP1[i]) { + intFuncP1[i](); + P1IFG &= ~BV(i); + } + } +} + +#if defined(__MSP430_HAS_PORT2_R__) +__attribute__((interrupt(PORT2_VECTOR))) +void Port_2(void) +{ + uint8_t i; + for(i = 0; i < 8; i++) { + if((P2IFG & BV(i)) && intFuncP2[i]) { + intFuncP2[i](); + P2IFG &= ~BV(i); + } + } +} +#endif diff --git a/hardware/msp430/cores/msp430/WMath.cpp b/hardware/msp430/cores/msp430/WMath.cpp new file mode 100644 index 00000000000..b4ce2de3454 --- /dev/null +++ b/hardware/msp430/cores/msp430/WMath.cpp @@ -0,0 +1,61 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Wiring project - http://wiring.org.co + Copyright (c) 2004-06 Hernando Barragan + Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ + + 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$ +*/ + +extern "C" { + #include "stdlib.h" +} +#if 0 +void randomSeed(unsigned int seed) +{ + if (seed != 0) { + srandom(seed); + } +} + +long random(long howbig) +{ + if (howbig == 0) { + return 0; + } + return random() % howbig; +} + +long random(long howsmall, long howbig) +{ + if (howsmall >= howbig) { + return howsmall; + } + long diff = howbig - howsmall; + return random(diff) + howsmall; +} +#endif + +long map(long x, long in_min, long in_max, long out_min, long out_max) +{ + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} + +unsigned int makeWord(unsigned int w) { return w; } +unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } diff --git a/hardware/msp430/cores/msp430/WString.cpp b/hardware/msp430/cores/msp430/WString.cpp new file mode 100644 index 00000000000..6dc1a737604 --- /dev/null +++ b/hardware/msp430/cores/msp430/WString.cpp @@ -0,0 +1,648 @@ +/* + WString.cpp - String library for Wiring & Arduino + ...mostly rewritten by Paul Stoffregen... + Copyright (c) 2009-10 Hernando Barragan. All rights reserved. + Copyright 2011, Paul Stoffregen, paul@pjrc.com + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "WString.h" + + +/*********************************************/ +/* Constructors */ +/*********************************************/ + +String::String(const char *cstr) +{ + init(); + if (cstr) copy(cstr, strlen(cstr)); +} + +String::String(const String &value) +{ + init(); + *this = value; +} + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +String::String(String &&rval) +{ + init(); + move(rval); +} +String::String(StringSumHelper &&rval) +{ + init(); + move(rval); +} +#endif + +String::String(char c) +{ + init(); + char buf[2]; + buf[0] = c; + buf[1] = 0; + *this = buf; +} + +String::String(unsigned char value, unsigned char base) +{ + init(); + char buf[9]; + utoa(value, buf, base); + *this = buf; +} + +String::String(int value, unsigned char base) +{ + init(); + char buf[18]; + itoa(value, buf, base); + *this = buf; +} + +String::String(unsigned int value, unsigned char base) +{ + init(); + char buf[17]; + utoa(value, buf, base); + *this = buf; +} + +String::String(long value, unsigned char base) +{ + init(); + char buf[34]; + ltoa(value, buf, base); + *this = buf; +} + +String::String(unsigned long value, unsigned char base) +{ + init(); + char buf[33]; + ultoa(value, buf, base); + *this = buf; +} + +String::~String() +{ + free(buffer); +} + +/*********************************************/ +/* Memory Management */ +/*********************************************/ + +inline void String::init(void) +{ + buffer = NULL; + capacity = 0; + len = 0; + flags = 0; +} + +void String::invalidate(void) +{ + if (buffer) free(buffer); + buffer = NULL; + capacity = len = 0; +} + +unsigned char String::reserve(unsigned int size) +{ + if (buffer && capacity >= size) return 1; + if (changeBuffer(size)) { + if (len == 0) buffer[0] = 0; + return 1; + } + return 0; +} + +unsigned char String::changeBuffer(unsigned int maxStrLen) +{ + //char *newbuffer = (char *)realloc(buffer, maxStrLen + 1); + char *newbuffer = (char *)malloc(maxStrLen + 1); + + if (newbuffer) { + free(buffer); + buffer = newbuffer; + capacity = maxStrLen; + return 1; + } + return 0; +} + +/*********************************************/ +/* Copy and Move */ +/*********************************************/ + +String & String::copy(const char *cstr, unsigned int length) +{ + if (!reserve(length)) { + invalidate(); + return *this; + } + len = length; + strcpy(buffer, cstr); + return *this; +} + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +void String::move(String &rhs) +{ + if (buffer) { + if (capacity >= rhs.len) { + strcpy(buffer, rhs.buffer); + len = rhs.len; + rhs.len = 0; + return; + } else { + free(buffer); + } + } + buffer = rhs.buffer; + capacity = rhs.capacity; + len = rhs.len; + rhs.buffer = NULL; + rhs.capacity = 0; + rhs.len = 0; +} +#endif + +String & String::operator = (const String &rhs) +{ + if (this == &rhs) return *this; + + if (rhs.buffer) copy(rhs.buffer, rhs.len); + else invalidate(); + + return *this; +} + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +String & String::operator = (String &&rval) +{ + if (this != &rval) move(rval); + return *this; +} + +String & String::operator = (StringSumHelper &&rval) +{ + if (this != &rval) move(rval); + return *this; +} +#endif + +String & String::operator = (const char *cstr) +{ + if (cstr) copy(cstr, strlen(cstr)); + else invalidate(); + + return *this; +} + +/*********************************************/ +/* concat */ +/*********************************************/ + +unsigned char String::concat(const String &s) +{ + return concat(s.buffer, s.len); +} + +unsigned char String::concat(const char *cstr, unsigned int length) +{ + unsigned int newlen = len + length; + if (!cstr) return 0; + if (length == 0) return 1; + if (!reserve(newlen)) return 0; + strcpy(buffer + len, cstr); + len = newlen; + return 1; +} + +unsigned char String::concat(const char *cstr) +{ + if (!cstr) return 0; + return concat(cstr, strlen(cstr)); +} + +unsigned char String::concat(char c) +{ + char buf[2]; + buf[0] = c; + buf[1] = 0; + return concat(buf, 1); +} + +unsigned char String::concat(unsigned char num) +{ + char buf[4]; + itoa(num, buf, 10); + return concat(buf, strlen(buf)); +} + +unsigned char String::concat(int num) +{ + char buf[7]; + itoa(num, buf, 10); + return concat(buf, strlen(buf)); +} + +unsigned char String::concat(unsigned int num) +{ + char buf[6]; + utoa(num, buf, 10); + return concat(buf, strlen(buf)); +} + +unsigned char String::concat(long num) +{ + char buf[12]; + ltoa(num, buf, 10); + return concat(buf, strlen(buf)); +} + +unsigned char String::concat(unsigned long num) +{ + char buf[11]; + ultoa(num, buf, 10); + return concat(buf, strlen(buf)); +} + +/*********************************************/ +/* Concatenate */ +/*********************************************/ + +StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs) +{ + StringSumHelper &a = const_cast(lhs); + if (!a.concat(rhs.buffer, rhs.len)) a.invalidate(); + return a; +} + +StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr) +{ + StringSumHelper &a = const_cast(lhs); + if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate(); + return a; +} + +StringSumHelper & operator + (const StringSumHelper &lhs, char c) +{ + StringSumHelper &a = const_cast(lhs); + if (!a.concat(c)) a.invalidate(); + return a; +} + +StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num) +{ + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) a.invalidate(); + return a; +} + +StringSumHelper & operator + (const StringSumHelper &lhs, int num) +{ + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) a.invalidate(); + return a; +} + +StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num) +{ + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) a.invalidate(); + return a; +} + +StringSumHelper & operator + (const StringSumHelper &lhs, long num) +{ + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) a.invalidate(); + return a; +} + +StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num) +{ + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) a.invalidate(); + return a; +} + +/*********************************************/ +/* Comparison */ +/*********************************************/ + +int String::compareTo(const String &s) const +{ + if (!buffer || !s.buffer) { + if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer; + if (buffer && len > 0) return *(unsigned char *)buffer; + return 0; + } + return strcmp(buffer, s.buffer); +} + +unsigned char String::equals(const String &s2) const +{ + return (len == s2.len && compareTo(s2) == 0); +} + +unsigned char String::equals(const char *cstr) const +{ + if (len == 0) return (cstr == NULL || *cstr == 0); + if (cstr == NULL) return buffer[0] == 0; + return strcmp(buffer, cstr) == 0; +} + +unsigned char String::operator<(const String &rhs) const +{ + return compareTo(rhs) < 0; +} + +unsigned char String::operator>(const String &rhs) const +{ + return compareTo(rhs) > 0; +} + +unsigned char String::operator<=(const String &rhs) const +{ + return compareTo(rhs) <= 0; +} + +unsigned char String::operator>=(const String &rhs) const +{ + return compareTo(rhs) >= 0; +} + +unsigned char String::equalsIgnoreCase( const String &s2 ) const +{ + if (this == &s2) return 1; + if (len != s2.len) return 0; + if (len == 0) return 1; + const char *p1 = buffer; + const char *p2 = s2.buffer; + while (*p1) { + if (tolower(*p1++) != tolower(*p2++)) return 0; + } + return 1; +} + +unsigned char String::startsWith( const String &s2 ) const +{ + if (len < s2.len) return 0; + return startsWith(s2, 0); +} + +unsigned char String::startsWith( const String &s2, unsigned int offset ) const +{ + if (offset > len - s2.len || !buffer || !s2.buffer) return 0; + return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0; +} + +unsigned char String::endsWith( const String &s2 ) const +{ + if ( len < s2.len || !buffer || !s2.buffer) return 0; + return strcmp(&buffer[len - s2.len], s2.buffer) == 0; +} + +/*********************************************/ +/* Character Access */ +/*********************************************/ + +char String::charAt(unsigned int loc) const +{ + return operator[](loc); +} + +void String::setCharAt(unsigned int loc, char c) +{ + if (loc < len) buffer[loc] = c; +} + +char & String::operator[](unsigned int index) +{ + static char dummy_writable_char; + if (index >= len || !buffer) { + dummy_writable_char = 0; + return dummy_writable_char; + } + return buffer[index]; +} + +char String::operator[]( unsigned int index ) const +{ + if (index >= len || !buffer) return 0; + return buffer[index]; +} + +void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const +{ + if (!bufsize || !buf) return; + if (index >= len) { + buf[0] = 0; + return; + } + unsigned int n = bufsize - 1; + if (n > len - index) n = len - index; + strncpy((char *)buf, buffer + index, n); + buf[n] = 0; +} + +/*********************************************/ +/* Search */ +/*********************************************/ + +int String::indexOf(char c) const +{ + return indexOf(c, 0); +} + +int String::indexOf( char ch, unsigned int fromIndex ) const +{ + if (fromIndex >= len) return -1; + const char* temp = strchr(buffer + fromIndex, ch); + if (temp == NULL) return -1; + return temp - buffer; +} + +int String::indexOf(const String &s2) const +{ + return indexOf(s2, 0); +} + +int String::indexOf(const String &s2, unsigned int fromIndex) const +{ + if (fromIndex >= len) return -1; + const char *found = strstr(buffer + fromIndex, s2.buffer); + if (found == NULL) return -1; + return found - buffer; +} + +int String::lastIndexOf( char theChar ) const +{ + return lastIndexOf(theChar, len - 1); +} + +int String::lastIndexOf(char ch, unsigned int fromIndex) const +{ + if (fromIndex >= len) return -1; + char tempchar = buffer[fromIndex + 1]; + buffer[fromIndex + 1] = '\0'; + char* temp = strrchr( buffer, ch ); + buffer[fromIndex + 1] = tempchar; + if (temp == NULL) return -1; + return temp - buffer; +} + +int String::lastIndexOf(const String &s2) const +{ + return lastIndexOf(s2, len - s2.len); +} + +int String::lastIndexOf(const String &s2, unsigned int fromIndex) const +{ + if (s2.len == 0 || len == 0 || s2.len > len) return -1; + if (fromIndex >= len) fromIndex = len - 1; + int found = -1; + for (char *p = buffer; p <= buffer + fromIndex; p++) { + p = strstr(p, s2.buffer); + if (!p) break; + if ((unsigned int)(p - buffer) <= fromIndex) found = p - buffer; + } + return found; +} + +String String::substring( unsigned int left ) const +{ + return substring(left, len); +} + +String String::substring(unsigned int left, unsigned int right) const +{ + if (left > right) { + unsigned int temp = right; + right = left; + left = temp; + } + String out; + if (left > len) return out; + if (right > len) right = len; + char temp = buffer[right]; // save the replaced character + buffer[right] = '\0'; + out = buffer + left; // pointer arithmetic + buffer[right] = temp; //restore character + return out; +} + +/*********************************************/ +/* Modification */ +/*********************************************/ + +void String::replace(char find, char replace) +{ + if (!buffer) return; + for (char *p = buffer; *p; p++) { + if (*p == find) *p = replace; + } +} + +void String::replace(const String& find, const String& replace) +{ + if (len == 0 || find.len == 0) return; + int diff = replace.len - find.len; + char *readFrom = buffer; + char *foundAt; + if (diff == 0) { + while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { + memcpy(foundAt, replace.buffer, replace.len); + readFrom = foundAt + replace.len; + } + } else if (diff < 0) { + char *writeTo = buffer; + while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { + unsigned int n = foundAt - readFrom; + memcpy(writeTo, readFrom, n); + writeTo += n; + memcpy(writeTo, replace.buffer, replace.len); + writeTo += replace.len; + readFrom = foundAt + find.len; + len += diff; + } + strcpy(writeTo, readFrom); + } else { + unsigned int size = len; // compute size needed for result + while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { + readFrom = foundAt + find.len; + size += diff; + } + if (size == len) return; + if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! + int index = len - 1; + while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { + readFrom = buffer + index + find.len; + memmove(readFrom + diff, readFrom, len - (readFrom - buffer)); + len += diff; + buffer[len] = 0; + memcpy(buffer + index, replace.buffer, replace.len); + index--; + } + } +} + +void String::toLowerCase(void) +{ + if (!buffer) return; + for (char *p = buffer; *p; p++) { + *p = tolower(*p); + } +} + +void String::toUpperCase(void) +{ + if (!buffer) return; + for (char *p = buffer; *p; p++) { + *p = toupper(*p); + } +} + +void String::trim(void) +{ + if (!buffer || len == 0) return; + char *begin = buffer; + while (isspace(*begin)) begin++; + char *end = buffer + len - 1; + while (isspace(*end) && end >= begin) end--; + len = end + 1 - begin; + if (begin > buffer) memcpy(buffer, begin, len); + buffer[len] = 0; +} + +/*********************************************/ +/* Parsing / Conversion */ +/*********************************************/ + +long String::toInt(void) const +{ + if (buffer) return atol(buffer); + return 0; +} + + diff --git a/hardware/msp430/cores/msp430/WString.h b/hardware/msp430/cores/msp430/WString.h new file mode 100644 index 00000000000..73d1213d94c --- /dev/null +++ b/hardware/msp430/cores/msp430/WString.h @@ -0,0 +1,204 @@ +/* + WString.h - String library for Wiring & Arduino + ...mostly rewritten by Paul Stoffregen... + Copyright (c) 2009-10 Hernando Barragan. All right reserved. + Copyright 2011, Paul Stoffregen, paul@pjrc.com + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef String_class_h +#define String_class_h +#ifdef __cplusplus + +#include +#include +#include + +// When compiling programs with this class, the following gcc parameters +// dramatically increase performance and memory (RAM) efficiency, typically +// with little or no increase in code size. +// -felide-constructors +// -std=c++0x + +//class __FlashStringHelper; +//#define F(string_literal) (reinterpret_cast<__FlashStringHelper *>(PSTR(string_literal))) + +// An inherited class for holding the result of a concatenation. These +// result objects are assumed to be writable by subsequent concatenations. +class StringSumHelper; + +// The string class +class String +{ + // use a function pointer to allow for "if (s)" without the + // complications of an operator bool(). for more information, see: + // http://www.artima.com/cppsource/safebool.html + typedef void (String::*StringIfHelperType)() const; + void StringIfHelper() const {} + +public: + // constructors + // creates a copy of the initial value. + // if the initial value is null or invalid, or if memory allocation + // fails, the string will be marked as invalid (i.e. "if (s)" will + // be false). + String(const char *cstr = ""); + String(const String &str); + #ifdef __GXX_EXPERIMENTAL_CXX0X__ + String(String &&rval); + String(StringSumHelper &&rval); + #endif + explicit String(char c); + explicit String(unsigned char, unsigned char base=10); + explicit String(int, unsigned char base=10); + explicit String(unsigned int, unsigned char base=10); + explicit String(long, unsigned char base=10); + explicit String(unsigned long, unsigned char base=10); + ~String(void); + + // memory management + // return true on success, false on failure (in which case, the string + // is left unchanged). reserve(0), if successful, will validate an + // invalid string (i.e., "if (s)" will be true afterwards) + unsigned char reserve(unsigned int size); + inline unsigned int length(void) const {return len;} + + // creates a copy of the assigned value. if the value is null or + // invalid, or if the memory allocation fails, the string will be + // marked as invalid ("if (s)" will be false). + String & operator = (const String &rhs); + String & operator = (const char *cstr); + #ifdef __GXX_EXPERIMENTAL_CXX0X__ + String & operator = (String &&rval); + String & operator = (StringSumHelper &&rval); + #endif + + // concatenate (works w/ built-in types) + + // returns true on success, false on failure (in which case, the string + // is left unchanged). if the argument is null or invalid, the + // concatenation is considered unsucessful. + unsigned char concat(const String &str); + unsigned char concat(const char *cstr); + unsigned char concat(char c); + unsigned char concat(unsigned char c); + unsigned char concat(int num); + unsigned char concat(unsigned int num); + unsigned char concat(long num); + unsigned char concat(unsigned long num); + + // if there's not enough memory for the concatenated value, the string + // will be left unchanged (but this isn't signalled in any way) + String & operator += (const String &rhs) {concat(rhs); return (*this);} + String & operator += (const char *cstr) {concat(cstr); return (*this);} + String & operator += (char c) {concat(c); return (*this);} + String & operator += (unsigned char num) {concat(num); return (*this);} + String & operator += (int num) {concat(num); return (*this);} + String & operator += (unsigned int num) {concat(num); return (*this);} + String & operator += (long num) {concat(num); return (*this);} + String & operator += (unsigned long num) {concat(num); return (*this);} + + friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); + friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); + friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); + friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); + friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); + friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num); + friend StringSumHelper & operator + (const StringSumHelper &lhs, long num); + friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); + + // comparison (only works w/ Strings and "strings") + operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } + int compareTo(const String &s) const; + unsigned char equals(const String &s) const; + unsigned char equals(const char *cstr) const; + unsigned char operator == (const String &rhs) const {return equals(rhs);} + unsigned char operator == (const char *cstr) const {return equals(cstr);} + unsigned char operator != (const String &rhs) const {return !equals(rhs);} + unsigned char operator != (const char *cstr) const {return !equals(cstr);} + unsigned char operator < (const String &rhs) const; + unsigned char operator > (const String &rhs) const; + unsigned char operator <= (const String &rhs) const; + unsigned char operator >= (const String &rhs) const; + unsigned char equalsIgnoreCase(const String &s) const; + unsigned char startsWith( const String &prefix) const; + unsigned char startsWith(const String &prefix, unsigned int offset) const; + unsigned char endsWith(const String &suffix) const; + + // character acccess + char charAt(unsigned int index) const; + void setCharAt(unsigned int index, char c); + char operator [] (unsigned int index) const; + char& operator [] (unsigned int index); + void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; + void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const + {getBytes((unsigned char *)buf, bufsize, index);} + + // search + int indexOf( char ch ) const; + int indexOf( char ch, unsigned int fromIndex ) const; + int indexOf( const String &str ) const; + int indexOf( const String &str, unsigned int fromIndex ) const; + int lastIndexOf( char ch ) const; + int lastIndexOf( char ch, unsigned int fromIndex ) const; + int lastIndexOf( const String &str ) const; + int lastIndexOf( const String &str, unsigned int fromIndex ) const; + String substring( unsigned int beginIndex ) const; + String substring( unsigned int beginIndex, unsigned int endIndex ) const; + + // modification + void replace(char find, char replace); + void replace(const String& find, const String& replace); + void toLowerCase(void); + void toUpperCase(void); + void trim(void); + + // parsing/conversion + long toInt(void) const; + +protected: + char *buffer; // the actual char array + unsigned int capacity; // the array length minus one (for the '\0') + unsigned int len; // the String length (not counting the '\0') + unsigned char flags; // unused, for future features +protected: + void init(void); + void invalidate(void); + unsigned char changeBuffer(unsigned int maxStrLen); + unsigned char concat(const char *cstr, unsigned int length); + + // copy and move + String & copy(const char *cstr, unsigned int length); + #ifdef __GXX_EXPERIMENTAL_CXX0X__ + void move(String &rhs); + #endif +}; + +class StringSumHelper : public String +{ +public: + StringSumHelper(const String &s) : String(s) {} + StringSumHelper(const char *p) : String(p) {} + StringSumHelper(char c) : String(c) {} + StringSumHelper(unsigned char num) : String(num) {} + StringSumHelper(int num) : String(num) {} + StringSumHelper(unsigned int num) : String(num) {} + StringSumHelper(long num) : String(num) {} + StringSumHelper(unsigned long num) : String(num) {} +}; + +#endif // __cplusplus +#endif // String_class_h diff --git a/hardware/msp430/cores/msp430/binary.h b/hardware/msp430/cores/msp430/binary.h new file mode 100644 index 00000000000..af1498033ab --- /dev/null +++ b/hardware/msp430/cores/msp430/binary.h @@ -0,0 +1,515 @@ +#ifndef Binary_h +#define Binary_h + +#define B0 0 +#define B00 0 +#define B000 0 +#define B0000 0 +#define B00000 0 +#define B000000 0 +#define B0000000 0 +#define B00000000 0 +#define B1 1 +#define B01 1 +#define B001 1 +#define B0001 1 +#define B00001 1 +#define B000001 1 +#define B0000001 1 +#define B00000001 1 +#define B10 2 +#define B010 2 +#define B0010 2 +#define B00010 2 +#define B000010 2 +#define B0000010 2 +#define B00000010 2 +#define B11 3 +#define B011 3 +#define B0011 3 +#define B00011 3 +#define B000011 3 +#define B0000011 3 +#define B00000011 3 +#define B100 4 +#define B0100 4 +#define B00100 4 +#define B000100 4 +#define B0000100 4 +#define B00000100 4 +#define B101 5 +#define B0101 5 +#define B00101 5 +#define B000101 5 +#define B0000101 5 +#define B00000101 5 +#define B110 6 +#define B0110 6 +#define B00110 6 +#define B000110 6 +#define B0000110 6 +#define B00000110 6 +#define B111 7 +#define B0111 7 +#define B00111 7 +#define B000111 7 +#define B0000111 7 +#define B00000111 7 +#define B1000 8 +#define B01000 8 +#define B001000 8 +#define B0001000 8 +#define B00001000 8 +#define B1001 9 +#define B01001 9 +#define B001001 9 +#define B0001001 9 +#define B00001001 9 +#define B1010 10 +#define B01010 10 +#define B001010 10 +#define B0001010 10 +#define B00001010 10 +#define B1011 11 +#define B01011 11 +#define B001011 11 +#define B0001011 11 +#define B00001011 11 +#define B1100 12 +#define B01100 12 +#define B001100 12 +#define B0001100 12 +#define B00001100 12 +#define B1101 13 +#define B01101 13 +#define B001101 13 +#define B0001101 13 +#define B00001101 13 +#define B1110 14 +#define B01110 14 +#define B001110 14 +#define B0001110 14 +#define B00001110 14 +#define B1111 15 +#define B01111 15 +#define B001111 15 +#define B0001111 15 +#define B00001111 15 +#define B10000 16 +#define B010000 16 +#define B0010000 16 +#define B00010000 16 +#define B10001 17 +#define B010001 17 +#define B0010001 17 +#define B00010001 17 +#define B10010 18 +#define B010010 18 +#define B0010010 18 +#define B00010010 18 +#define B10011 19 +#define B010011 19 +#define B0010011 19 +#define B00010011 19 +#define B10100 20 +#define B010100 20 +#define B0010100 20 +#define B00010100 20 +#define B10101 21 +#define B010101 21 +#define B0010101 21 +#define B00010101 21 +#define B10110 22 +#define B010110 22 +#define B0010110 22 +#define B00010110 22 +#define B10111 23 +#define B010111 23 +#define B0010111 23 +#define B00010111 23 +#define B11000 24 +#define B011000 24 +#define B0011000 24 +#define B00011000 24 +#define B11001 25 +#define B011001 25 +#define B0011001 25 +#define B00011001 25 +#define B11010 26 +#define B011010 26 +#define B0011010 26 +#define B00011010 26 +#define B11011 27 +#define B011011 27 +#define B0011011 27 +#define B00011011 27 +#define B11100 28 +#define B011100 28 +#define B0011100 28 +#define B00011100 28 +#define B11101 29 +#define B011101 29 +#define B0011101 29 +#define B00011101 29 +#define B11110 30 +#define B011110 30 +#define B0011110 30 +#define B00011110 30 +#define B11111 31 +#define B011111 31 +#define B0011111 31 +#define B00011111 31 +#define B100000 32 +#define B0100000 32 +#define B00100000 32 +#define B100001 33 +#define B0100001 33 +#define B00100001 33 +#define B100010 34 +#define B0100010 34 +#define B00100010 34 +#define B100011 35 +#define B0100011 35 +#define B00100011 35 +#define B100100 36 +#define B0100100 36 +#define B00100100 36 +#define B100101 37 +#define B0100101 37 +#define B00100101 37 +#define B100110 38 +#define B0100110 38 +#define B00100110 38 +#define B100111 39 +#define B0100111 39 +#define B00100111 39 +#define B101000 40 +#define B0101000 40 +#define B00101000 40 +#define B101001 41 +#define B0101001 41 +#define B00101001 41 +#define B101010 42 +#define B0101010 42 +#define B00101010 42 +#define B101011 43 +#define B0101011 43 +#define B00101011 43 +#define B101100 44 +#define B0101100 44 +#define B00101100 44 +#define B101101 45 +#define B0101101 45 +#define B00101101 45 +#define B101110 46 +#define B0101110 46 +#define B00101110 46 +#define B101111 47 +#define B0101111 47 +#define B00101111 47 +#define B110000 48 +#define B0110000 48 +#define B00110000 48 +#define B110001 49 +#define B0110001 49 +#define B00110001 49 +#define B110010 50 +#define B0110010 50 +#define B00110010 50 +#define B110011 51 +#define B0110011 51 +#define B00110011 51 +#define B110100 52 +#define B0110100 52 +#define B00110100 52 +#define B110101 53 +#define B0110101 53 +#define B00110101 53 +#define B110110 54 +#define B0110110 54 +#define B00110110 54 +#define B110111 55 +#define B0110111 55 +#define B00110111 55 +#define B111000 56 +#define B0111000 56 +#define B00111000 56 +#define B111001 57 +#define B0111001 57 +#define B00111001 57 +#define B111010 58 +#define B0111010 58 +#define B00111010 58 +#define B111011 59 +#define B0111011 59 +#define B00111011 59 +#define B111100 60 +#define B0111100 60 +#define B00111100 60 +#define B111101 61 +#define B0111101 61 +#define B00111101 61 +#define B111110 62 +#define B0111110 62 +#define B00111110 62 +#define B111111 63 +#define B0111111 63 +#define B00111111 63 +#define B1000000 64 +#define B01000000 64 +#define B1000001 65 +#define B01000001 65 +#define B1000010 66 +#define B01000010 66 +#define B1000011 67 +#define B01000011 67 +#define B1000100 68 +#define B01000100 68 +#define B1000101 69 +#define B01000101 69 +#define B1000110 70 +#define B01000110 70 +#define B1000111 71 +#define B01000111 71 +#define B1001000 72 +#define B01001000 72 +#define B1001001 73 +#define B01001001 73 +#define B1001010 74 +#define B01001010 74 +#define B1001011 75 +#define B01001011 75 +#define B1001100 76 +#define B01001100 76 +#define B1001101 77 +#define B01001101 77 +#define B1001110 78 +#define B01001110 78 +#define B1001111 79 +#define B01001111 79 +#define B1010000 80 +#define B01010000 80 +#define B1010001 81 +#define B01010001 81 +#define B1010010 82 +#define B01010010 82 +#define B1010011 83 +#define B01010011 83 +#define B1010100 84 +#define B01010100 84 +#define B1010101 85 +#define B01010101 85 +#define B1010110 86 +#define B01010110 86 +#define B1010111 87 +#define B01010111 87 +#define B1011000 88 +#define B01011000 88 +#define B1011001 89 +#define B01011001 89 +#define B1011010 90 +#define B01011010 90 +#define B1011011 91 +#define B01011011 91 +#define B1011100 92 +#define B01011100 92 +#define B1011101 93 +#define B01011101 93 +#define B1011110 94 +#define B01011110 94 +#define B1011111 95 +#define B01011111 95 +#define B1100000 96 +#define B01100000 96 +#define B1100001 97 +#define B01100001 97 +#define B1100010 98 +#define B01100010 98 +#define B1100011 99 +#define B01100011 99 +#define B1100100 100 +#define B01100100 100 +#define B1100101 101 +#define B01100101 101 +#define B1100110 102 +#define B01100110 102 +#define B1100111 103 +#define B01100111 103 +#define B1101000 104 +#define B01101000 104 +#define B1101001 105 +#define B01101001 105 +#define B1101010 106 +#define B01101010 106 +#define B1101011 107 +#define B01101011 107 +#define B1101100 108 +#define B01101100 108 +#define B1101101 109 +#define B01101101 109 +#define B1101110 110 +#define B01101110 110 +#define B1101111 111 +#define B01101111 111 +#define B1110000 112 +#define B01110000 112 +#define B1110001 113 +#define B01110001 113 +#define B1110010 114 +#define B01110010 114 +#define B1110011 115 +#define B01110011 115 +#define B1110100 116 +#define B01110100 116 +#define B1110101 117 +#define B01110101 117 +#define B1110110 118 +#define B01110110 118 +#define B1110111 119 +#define B01110111 119 +#define B1111000 120 +#define B01111000 120 +#define B1111001 121 +#define B01111001 121 +#define B1111010 122 +#define B01111010 122 +#define B1111011 123 +#define B01111011 123 +#define B1111100 124 +#define B01111100 124 +#define B1111101 125 +#define B01111101 125 +#define B1111110 126 +#define B01111110 126 +#define B1111111 127 +#define B01111111 127 +#define B10000000 128 +#define B10000001 129 +#define B10000010 130 +#define B10000011 131 +#define B10000100 132 +#define B10000101 133 +#define B10000110 134 +#define B10000111 135 +#define B10001000 136 +#define B10001001 137 +#define B10001010 138 +#define B10001011 139 +#define B10001100 140 +#define B10001101 141 +#define B10001110 142 +#define B10001111 143 +#define B10010000 144 +#define B10010001 145 +#define B10010010 146 +#define B10010011 147 +#define B10010100 148 +#define B10010101 149 +#define B10010110 150 +#define B10010111 151 +#define B10011000 152 +#define B10011001 153 +#define B10011010 154 +#define B10011011 155 +#define B10011100 156 +#define B10011101 157 +#define B10011110 158 +#define B10011111 159 +#define B10100000 160 +#define B10100001 161 +#define B10100010 162 +#define B10100011 163 +#define B10100100 164 +#define B10100101 165 +#define B10100110 166 +#define B10100111 167 +#define B10101000 168 +#define B10101001 169 +#define B10101010 170 +#define B10101011 171 +#define B10101100 172 +#define B10101101 173 +#define B10101110 174 +#define B10101111 175 +#define B10110000 176 +#define B10110001 177 +#define B10110010 178 +#define B10110011 179 +#define B10110100 180 +#define B10110101 181 +#define B10110110 182 +#define B10110111 183 +#define B10111000 184 +#define B10111001 185 +#define B10111010 186 +#define B10111011 187 +#define B10111100 188 +#define B10111101 189 +#define B10111110 190 +#define B10111111 191 +#define B11000000 192 +#define B11000001 193 +#define B11000010 194 +#define B11000011 195 +#define B11000100 196 +#define B11000101 197 +#define B11000110 198 +#define B11000111 199 +#define B11001000 200 +#define B11001001 201 +#define B11001010 202 +#define B11001011 203 +#define B11001100 204 +#define B11001101 205 +#define B11001110 206 +#define B11001111 207 +#define B11010000 208 +#define B11010001 209 +#define B11010010 210 +#define B11010011 211 +#define B11010100 212 +#define B11010101 213 +#define B11010110 214 +#define B11010111 215 +#define B11011000 216 +#define B11011001 217 +#define B11011010 218 +#define B11011011 219 +#define B11011100 220 +#define B11011101 221 +#define B11011110 222 +#define B11011111 223 +#define B11100000 224 +#define B11100001 225 +#define B11100010 226 +#define B11100011 227 +#define B11100100 228 +#define B11100101 229 +#define B11100110 230 +#define B11100111 231 +#define B11101000 232 +#define B11101001 233 +#define B11101010 234 +#define B11101011 235 +#define B11101100 236 +#define B11101101 237 +#define B11101110 238 +#define B11101111 239 +#define B11110000 240 +#define B11110001 241 +#define B11110010 242 +#define B11110011 243 +#define B11110100 244 +#define B11110101 245 +#define B11110110 246 +#define B11110111 247 +#define B11111000 248 +#define B11111001 249 +#define B11111010 250 +#define B11111011 251 +#define B11111100 252 +#define B11111101 253 +#define B11111110 254 +#define B11111111 255 + +#endif diff --git a/hardware/msp430/cores/msp430/main.cpp b/hardware/msp430/cores/msp430/main.cpp new file mode 100644 index 00000000000..1062bf97dba --- /dev/null +++ b/hardware/msp430/cores/msp430/main.cpp @@ -0,0 +1,15 @@ +#include + +int main(void) +{ + init(); + + setup(); + + for (;;) { + loop(); + } + + return 0; +} + diff --git a/hardware/msp430/cores/msp430/new.cpp b/hardware/msp430/cores/msp430/new.cpp new file mode 100644 index 00000000000..0f6d4220ef7 --- /dev/null +++ b/hardware/msp430/cores/msp430/new.cpp @@ -0,0 +1,18 @@ +#include + +void * operator new(size_t size) +{ + return malloc(size); +} + +void operator delete(void * ptr) +{ + free(ptr); +} + +int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);}; +void __cxa_guard_release (__guard *g) {*(char *)g = 1;}; +void __cxa_guard_abort (__guard *) {}; + +void __cxa_pure_virtual(void) {}; + diff --git a/hardware/msp430/cores/msp430/new.h b/hardware/msp430/cores/msp430/new.h new file mode 100644 index 00000000000..cd940ce8b26 --- /dev/null +++ b/hardware/msp430/cores/msp430/new.h @@ -0,0 +1,22 @@ +/* Header to define new/delete operators as they aren't provided by avr-gcc by default + Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453 + */ + +#ifndef NEW_H +#define NEW_H + +#include + +void * operator new(size_t size); +void operator delete(void * ptr); + +__extension__ typedef int __guard __attribute__((mode (__DI__))); + +extern "C" int __cxa_guard_acquire(__guard *); +extern "C" void __cxa_guard_release (__guard *); +extern "C" void __cxa_guard_abort (__guard *); + +extern "C" void __cxa_pure_virtual(void); + +#endif + diff --git a/hardware/msp430/cores/msp430/wiring.c b/hardware/msp430/cores/msp430/wiring.c new file mode 100644 index 00000000000..c0e74a41ecc --- /dev/null +++ b/hardware/msp430/cores/msp430/wiring.c @@ -0,0 +1,183 @@ +/* + ************************************************************************ + * wiring.c + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + wiring.c - Partial implementation of the Wiring API for the ATmega8. + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 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 +*/ +#include "Energia.h" + +void initClocks(void); +void enableWatchDogIntervalMode(void); +void disableWatchDog(void); + +void init() +{ + disableWatchDog(); + initClocks(); + enableWatchDogIntervalMode(); + __eint(); +} + +void disableWatchDog(void) +{ + /* Diable watchdog timer */ + WDTCTL = WDTPW | WDTHOLD; +} + +void enableWatchDogIntervalMode(void) +{ + /* WDT Password + WDT interval mode + Watchdog clock source /512 + source from SMCLK + * Note that we WDT is running in interval mode. WDT will not trigger a reset on expire in this mode. */ + WDTCTL = WDTPW + WDTTMSEL + WDTIS1; + + /* WDT interrupt enable */ + IE1 |= WDTIE; +} + +void initClocks(void) +{ +#if defined(CALBC1_16MHZ_) && F_CPU >= 16000000L + BCSCTL1 = CALBC1_16MHZ; + DCOCTL = CALDCO_16MHZ; +#elif defined(CALBC1_12MHZ_) && (F_CPU >= 12000000L) + BCSCTL1 = CALBC1_12MHZ; + DCOCTL = CALDCO_12MHZ; +#elif defined(CALBC1_8MHZ_) && (F_CPU >= 8000000L) + BCSCTL1 = CALBC1_8MHZ; + DCOCTL = CALDCO_8MHZ; +#elif defined(CALBC1_1MHZ_) && (F_CPU >= 1000000L) + BCSCTL1 = CALBC1_1MHZ; + DCOCTL = CALDCO_1MHZ; +#else + #warning No Suitable Frequency found! +#endif + /* SMCLK = DCO / DIVS = nMHz */ + BCSCTL2 &= ~(DIVS_0); + /* ACLK = VLO = ~ 12 KHz */ + BCSCTL3 |= LFXT1S_2; +} + +#define SMCLK_FREQUENCY F_CPU +#define WDT_DIVIDER 512 + +const uint32_t WDT_FREQUENCY = SMCLK_FREQUENCY / WDT_DIVIDER; +volatile uint32_t wdtCounter = 0; + +unsigned long micros() +{ + return (1000 * wdtCounter) / (WDT_FREQUENCY / 1000); +} + +unsigned long millis() +{ + return wdtCounter / (WDT_FREQUENCY / 1000); +} + +/* Delay for the given number of microseconds. Assumes a 1, 8 or 16 MHz clock. */ +void delayMicroseconds(unsigned int us) +{ +#if F_CPU >= 20000000L + /* For a one-microsecond delay, simply wait 2 cycle and return. The overhead + * of the function call yields a delay of exactly one microsecond. */ + __asm__ __volatile__ ( + "nop" "\n\t" + "nop"); + if (--us == 0) + return; + + /* The following loop takes a 1/5 of a microsecond (4 cycles) + * per iteration, so execute it five times for each microsecond of + * delay requested. */ + us = (us<<2) + us; // x5 us + + /* Account for the time taken in the preceeding commands. */ + us -= 2; + +#elif F_CPU >= 16000000L + /* For the 16 MHz clock on most boards */ + + /* For a one-microsecond delay, simply return. the overhead + * of the function call yields a delay of approximately 1 1/8 us. */ + if (--us == 0) + return; + + /* The following loop takes a quarter of a microsecond (4 cycles) + * per iteration, so execute it four times for each microsecond of + * delay requested. */ + us <<= 2; + + /* Account for the time taken in the preceeding commands. */ + us -= 2; +#else + /* For the 1 MHz */ + + /* For a one- or two-microsecond delay, simply return. the overhead of + * the function calls takes more than two microseconds. can't just + * subtract two, since us is unsigned; we'd overflow. */ + if (--us == 0) + return; + if (--us == 0) + return; + + /* The following loop takes 4 microsecond (4 cycles) + * per iteration, so execute it ones for each 4 microsecond of + * delay requested. */ + us >>= 2; + + /* Partially compensate for the time taken by the preceeding commands. + * we can't subtract any more than this or we'd overflow w/ small delays. */ + us--; +#endif + + /* Busy wait */ + __asm__ __volatile__ ( + /* even steven */ + "L1: nop \n\t" + /* 1 instruction */ + "dec.w %[us] \n\t" + /* 2 instructions */ + "jnz L1 \n\t" + : [us] "=r" (us) : "[us]" (us) + ); +} + +/* (ab)use the WDT */ +void delay(uint32_t milliseconds) +{ + uint32_t wakeTime = wdtCounter + (milliseconds * (WDT_FREQUENCY / 1000)); + while(wdtCounter < wakeTime) + /* Wait for WDT interrupt in LMP0 */ + __bis_status_register(LPM0_bits+GIE); +} + +__attribute__((interrupt(WDT_VECTOR))) +void watchdog_isr (void) +{ + wdtCounter++; + /* Exit from LMP3 on reti (this includes LMP0) */ + __bic_status_register_on_exit(LPM3_bits); +} diff --git a/hardware/msp430/cores/msp430/wiring_analog.c b/hardware/msp430/cores/msp430/wiring_analog.c new file mode 100644 index 00000000000..1bb25398c29 --- /dev/null +++ b/hardware/msp430/cores/msp430/wiring_analog.c @@ -0,0 +1,200 @@ +/* + ************************************************************************ + * wiring_analog.c + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + wiring_analog.c - analog input and output + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 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 +*/ + +#include "wiring_private.h" +#include "pins_energia.h" + +uint16_t analog_reference = DEFAULT, analog_period = F_CPU/490, analog_div = 0, analog_res=255; // devide clock with 0, 2, 4, 8 + +void analogReference(uint16_t mode) +{ + // can't actually set the register here because the default setting + // will connect AVCC and the AREF pin, which would cause a short if + // there's something connected to AREF. + analog_reference = mode; +} + +//TODO: Can be a lot more efficiant. +// - lower clock rated / input devider to conserve Energia. +// - pin configuration logic. + +// Note set frequency before sending analog value +// Lowest fequency is defined by clock frequency F_CPU, and max counter value 2^16-1 +// fmin = F_CPU / 2^16 +void analogFrequency(uint32_t freq) +{ + if ( freq <= F_CPU/(4*65334L) ) { analog_div = ID_3; freq *=8; } + else if ( freq <= F_CPU/(2*65334L) ) { analog_div = ID_2; freq *=4; } + else if ( freq <= F_CPU/(4*65334L) ) { analog_div = ID_1; freq *=2; } + analog_period = F_CPU/freq; +} + +// Set the resulution (nr of counts for 100%), default = 255, large values may not work at all frequencies +void analogResolution(uint16_t res) +{ + analog_res = res; +} + +//Arduino specifies ~490 Hz for analog out PWM so we follow suit. +#define PWM_PERIOD analog_period // F_CPU/490 +#define PWM_DUTY(x) ( (unsigned long)x*PWM_PERIOD / (unsigned long)analog_res ) +void analogWrite(uint8_t pin, int val) +{ + pinMode(pin, OUTPUT); // pin as output + + if (val == 0) + { + digitalWrite(pin, LOW); // set pin to LOW when duty cycle is 0 + // digitalWrite will take care of invalid pins + } + else if (val == 255) + { + digitalWrite(pin, HIGH); // set pin HIGH when duty cycle is 255 + // digitalWrite will take care of invalid pins + } + else + { + + uint8_t bit = digitalPinToBitMask(pin); // get pin bit + uint8_t port = digitalPinToPort(pin); // get pin port + volatile uint16_t *sel; + volatile uint16_t *sel2; + + if (port == NOT_A_PORT) return; // pin on timer? + + sel = portSelRegister(port); // get the port function select register address + *sel |= bit; // set bit in pin function select register + + //TODO: Firgure out a better way to determine if SEL2 needs to be set + if(bit == BV(4) && port == P1) { + sel2 = portSel2Register(port); // get the port function select register address + *sel2 |= bit; + } + switch(digitalPinToTimer(pin)) { // which timer and CCR? + //case: T0A0 // CCR0 used as period register + case T0A1: // Timer0 / CCR1 + TA0CCR0 = PWM_PERIOD; // PWM Period + TA0CCTL1 = OUTMOD_7; // reset/set + TA0CCR1 = PWM_DUTY(val); // PWM duty cycle + TA0CTL = TASSEL_2 + MC_1 + analog_div; // SMCLK, up mode + break; +#if defined(__MSP430_HAS_TA3__) + case T0A2: // Timer0 / CCR1 + TA0CCR0 = PWM_PERIOD; // PWM Period + TA0CCTL2 = OUTMOD_7; // reset/set + TA0CCR2 = PWM_DUTY(val); // PWM duty cycle + TA0CTL = TASSEL_2 + MC_1+ analog_div; // SMCLK, up mode + break; +#endif +#if defined(__MSP430_HAS_T1A3__) + //case: T1A0 // CCR0 used as period register + case T1A1: // Timer0 / CCR1 + TA1CCR0 = PWM_PERIOD; // PWM Period + TA1CCTL1 = OUTMOD_7; // reset/set + TA1CCR1 = PWM_DUTY(val); // PWM duty cycle + TA1CTL = TASSEL_2 + MC_1+ analog_div; // SMCLK, up mode + break; + case T1A2: // Timer0 / CCR1 + TA1CCR0 = PWM_PERIOD; // PWM Period + TA1CCTL2 = OUTMOD_7; // reset/set + TA1CCR2 = PWM_DUTY(val); // PWM duty cycle + TA1CTL = TASSEL_2 + MC_1+ analog_div; // SMCLK, up mode + break; +#endif +#if defined(__MSP430_HAS_T2A3__) + //case: T2A0 // CCR0 used as period register + case T2A1: // Timer0 / CCR1 + TA2CCR0 = PWM_PERIOD; // PWM Period + TA2CCTL1 = OUTMOD_7; // reset/set + TA2CCR1 = PWM_DUTY(val); // PWM duty cycle + TA2CTL = TASSEL_2 + MC_1+ analog_div; // SMCLK, up mode + break; + case T2A2: // Timer0 / CCR1 + TA2CCR0 = PWM_PERIOD; // PWM Period + TA2CCTL2 = OUTMOD_7; // reset/set + TA2CCR2 = PWM_DUTY(val); // PWM duty cycle + TA2CTL = TASSEL_2 + MC_1+ analog_div; // SMCLK, up mode + break; +#endif + case NOT_ON_TIMER: // not on a timer output pin + default: // or TxA0 pin + if (val < 128) { + digitalWrite(pin, LOW); // + } else { + digitalWrite(pin, HIGH); + } + } + } +} + +uint16_t analogRead(uint8_t pin) +{ + +// make sure we have an ADC +#if defined(__MSP430_HAS_ADC10__) + // 0000 A0 + // 0001 A1 + // 0010 A2 + // 0011 A3 + // 0100 A4 + // 0101 A5 + // 0110 A6 + // 0111 A7 + // 1010 Internal temperature sensor + + //TODO: Only int. temp. sensor requires Tsample > 30us. + // The below ADC configuration applies this rule to all channels right now. + // ADC10CLK = 5MHz / 5 = 1Mhz + // Tsample = S&H / ADC10CLK = 64 / 1 MHz = 64 us + // Tconver = 13 / ADC10CLK = 13 / 1 MHz = 13 us + // Total time per sample = Tconvert + Tsample = 64 + 13 = 67 us = ~15k samples / sec + if(pin > 7 && pin != 10) // ADC on pin? + return 0; + ADC10CTL0 &= ~ENC; // disable ADC + ADC10CTL0 = analog_reference + // set analog reference + ADC10ON + ADC10SHT_3 + ADC10IE; // turn ADC ON; sample + hold @ 64 × ADC10CLKs; Enable interrupts + ADC10CTL1 = ADC10SSEL_0 + ADC10DIV_5 + // ADC10OSC as ADC10CLK (~5MHz) / 5 + (pin << 12); // select channel + __delay_cycles (128); // Delay to allow Ref to settle + ADC10CTL0 |= ENC + ADC10SC; // enable ADC and start conversion + __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled + return ADC10MEM; // return sampled value after returning to active mode in ADC10_ISR +#else + // no ADC + return 0; +#endif +} + +__attribute__((interrupt(ADC10_VECTOR))) +void ADC10_ISR(void) +{ + __bic_SR_register_on_exit(CPUOFF); // return to active mode +} diff --git a/hardware/msp430/cores/msp430/wiring_digital.c b/hardware/msp430/cores/msp430/wiring_digital.c new file mode 100644 index 00000000000..b4d6cef814a --- /dev/null +++ b/hardware/msp430/cores/msp430/wiring_digital.c @@ -0,0 +1,92 @@ +/* + ************************************************************************ + * HardwareSerial.cpp + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + wiring_digital.c - digital input and output functions + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 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 +*/ + +#define ARDUINO_MAIN +#include "wiring_private.h" +#include "pins_energia.h" + +void pinMode(uint8_t pin, uint8_t mode) +{ + uint8_t bit = digitalPinToBitMask(pin); + uint8_t port = digitalPinToPort(pin); + + volatile uint16_t *dir; + volatile uint16_t *ren; + volatile uint16_t *out; + + if (port == NOT_A_PORT) return; + + dir = portDirRegister(port); + ren = portRenRegister(port); + out = portOutputRegister(port); + + if (mode == INPUT) { + *dir &= ~bit; + } else if (mode == INPUT_PULLUP) { + *dir &= ~bit; + *out |= bit; + *ren |= bit; + } else if (mode == INPUT_PULLDOWN) { + *dir &= ~bit; + *out &= ~bit; + *ren |= bit; + } else { + *dir |= bit; + } +} + +int digitalRead(uint8_t pin) +{ + uint8_t bit = digitalPinToBitMask(pin); + uint8_t port = digitalPinToPort(pin); + + if (port == NOT_A_PORT) return LOW; + + if (*portInputRegister(port) & bit) return HIGH; + return LOW; +} + +void digitalWrite(uint8_t pin, uint8_t val) +{ + uint8_t bit = digitalPinToBitMask(pin); + uint8_t port = digitalPinToPort(pin); + volatile uint16_t *out; + + if (port == NOT_A_PORT) return; + + out = portOutputRegister(port); + + if (val == LOW) { + *out &= ~bit; + } else { + *out |= bit; + } +} diff --git a/hardware/msp430/cores/msp430/wiring_private.h b/hardware/msp430/cores/msp430/wiring_private.h new file mode 100644 index 00000000000..9ed8c6f2a59 --- /dev/null +++ b/hardware/msp430/cores/msp430/wiring_private.h @@ -0,0 +1,60 @@ +/* + ************************************************************************ + * wiring_private.h + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + wiring_private.h - Internal header file. + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 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: wiring.h 239 2007-01-12 17:58:39Z mellis $ +*/ + +#ifndef WiringPrivate_h +#define WiringPrivate_h + +#include "Energia.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +// TODO: This is a hack and needs cleaning up. Not all pins are available on the board +//.Change this to a more intelligent number of interrupt selection + +#if defined(__MSP430_HAS_PORT1_R__) +#define EXTERNAL_NUM_INTERRUPTS 8 +#elif defined(__MSP430_HAS_PORT2_R__) +#define EXTERNAL_NUM_INTERRUPTS 16 +#else +#define EXTERNAL_NUM_INTERRUPTS 8 +#endif + +typedef void (*voidFuncPtr)(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif diff --git a/hardware/msp430/cores/msp430/wiring_pulse.c b/hardware/msp430/cores/msp430/wiring_pulse.c new file mode 100755 index 00000000000..6375717c430 --- /dev/null +++ b/hardware/msp430/cores/msp430/wiring_pulse.c @@ -0,0 +1,76 @@ +/* + ************************************************************************ + * wiring_pulse.c + * + * Energia core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + wiring_pulse.c - pulseIn() function + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 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 +*/ + +#include "wiring_private.h" +#include "pins_energia.h" + +/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH + * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds + * to 3 minutes in length, but must be called at least a few dozen microseconds + * before the start of the pulse. */ +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) +{ + // cache the port and bit of the pin in order to speed up the + // pulse width measuring loop and achieve finer resolution. calling + // digitalRead() instead yields much coarser resolution. + uint8_t bit = digitalPinToBitMask(pin); + uint8_t port = digitalPinToPort(pin); + uint8_t stateMask = (state ? bit : 0); + unsigned long width = 0; // keep initialization out of time critical area + + // convert the timeout from microseconds to a number of times through + // the initial loop; it takes 11 clock cycles per iteration. + unsigned long numloops = 0; + unsigned long maxloops = microsecondsToClockCycles(timeout) / 11; + + // wait for any previous pulse to end + while ((*portInputRegister(port) & bit) == stateMask) + if (numloops++ == maxloops) + return 0; + + // wait for the pulse to start + while ((*portInputRegister(port) & bit) != stateMask) + if (numloops++ == maxloops) + return 0; + + // wait for the pulse to stop + while ((*portInputRegister(port) & bit) == stateMask) { + if (numloops++ == maxloops) + return 0; + width++; + } + + // convert the reading to microseconds. The loop has been determined + // to be 13 clock cycles long and have about 11 clocks between the edge + // and the start of the loop. There will be some error introduced by + // the interrupt handlers. + return clockCyclesToMicroseconds(width * 13 + 11); +} diff --git a/hardware/msp430/cores/msp430/wiring_shift.c b/hardware/msp430/cores/msp430/wiring_shift.c new file mode 100755 index 00000000000..30d2b56c536 --- /dev/null +++ b/hardware/msp430/cores/msp430/wiring_shift.c @@ -0,0 +1,63 @@ +/* + ************************************************************************ + * wiring_shift.c + * + * Energia core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + wiring_shift.c - shiftOut() function + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 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 + +*/ + +#include "wiring_private.h" + +uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { + uint8_t value = 0; + uint8_t i; + + for (i = 0; i < 8; ++i) { + digitalWrite(clockPin, HIGH); + if (bitOrder == LSBFIRST) + value |= digitalRead(dataPin) << i; + else + value |= digitalRead(dataPin) << (7 - i); + digitalWrite(clockPin, LOW); + } + return value; +} + +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) +{ + uint8_t i; + + for (i = 0; i < 8; i++) { + if (bitOrder == LSBFIRST) + digitalWrite(dataPin, !!(val & (1 << i))); + else + digitalWrite(dataPin, !!(val & (1 << (7 - i)))); + + digitalWrite(clockPin, HIGH); + digitalWrite(clockPin, LOW); + } +} diff --git a/hardware/msp430/libraries/SPI/SPI.cpp b/hardware/msp430/libraries/SPI/SPI.cpp new file mode 100644 index 00000000000..bcb73237185 --- /dev/null +++ b/hardware/msp430/libraries/SPI/SPI.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010 by Cristian Maglie + * SPI Master library for arduino. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + * + * 2012-04-29 rick@kimballsoftware.com - added msp430 support. + * + */ + +#include + +#include "SPI.h" + +SPIClass SPI; + +void SPIClass::begin() +{ + spi_initialize(); +} + +void SPIClass::end() +{ + spi_disable(); +} + +void SPIClass::setBitOrder(uint8_t bitOrder) +{ + spi_set_bitorder(bitOrder); +} + +void SPIClass::setDataMode(uint8_t mode) +{ + spi_set_datamode(mode); +} + +void SPIClass::setClockDivider(uint8_t rate) +{ + spi_set_divisor(rate); +} diff --git a/hardware/msp430/libraries/SPI/SPI.h b/hardware/msp430/libraries/SPI/SPI.h new file mode 100644 index 00000000000..28b47eb9de3 --- /dev/null +++ b/hardware/msp430/libraries/SPI/SPI.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2010 by Cristian Maglie + * SPI Master library for arduino. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + * + * 2012-04-29 rick@kimballsoftware.com - added msp430 support. + * + */ + +#ifndef _SPI_H_INCLUDED +#define _SPI_H_INCLUDED + +#include +#include + +#if defined(__MSP430_HAS_USCI__) || defined(__MSP430_HAS_USI__) +#include "utility/spi_430.h" +#endif + +#define SPI_MODE0 0 +#define SPI_MODE1 1 +#define SPI_MODE2 2 +#define SPI_MODE3 4 + +class SPIClass { +public: + inline static uint8_t transfer(uint8_t _data); + + // SPI Configuration methods + + static void begin(); // Default + static void end(); + + static void setBitOrder(uint8_t); + static void setDataMode(uint8_t); + static void setClockDivider(uint8_t); + + inline static void attachInterrupt(); + inline static void detachInterrupt(); +}; + +extern SPIClass SPI; + +uint8_t SPIClass::transfer(uint8_t _data) { + return spi_send(_data); +} + +void SPIClass::attachInterrupt() { + /* undocumented in Arduino 1.0 */ +} + +void SPIClass::detachInterrupt() { + /* undocumented in Arduino 1.0 */ +} + +#endif diff --git a/hardware/msp430/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/hardware/msp430/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino new file mode 100644 index 00000000000..66568ea2865 --- /dev/null +++ b/hardware/msp430/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -0,0 +1,146 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Shows the output of a Barometric Pressure Sensor on a + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + Circuit: + SCP1000 sensor attached to pins 6, 7, 10 - 13: + DRDY: pin 6 + CSB: pin 8 + MOSI: pin 14/15 + MISO: pin 15/14 * need to level convert this + SCK: pin 7 + + created 31 July 2010 + modified 14 August 2010 + by Tom Igoe + + modified 2 May 2012 + Rick Kimball - changed pin # for msp430 + + */ + +// the sensor communicates using SPI, so include the library: +#include + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; // 3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; // 16 least significant bits of pressure +const int TEMPERATURE = 0x21; // 16 bit temperature reading +const byte READ = 0b11111100; // SCP1000's read command +const byte WRITE = 0b00000010; // SCP1000's write command + +// pins used for the connection with the sensor +// the other you need are controlled by the SPI library): +const int dataReadyPin = 9; // P2.1 +const int chipSelectPin = 8; // P2.0 + +void setup() { + Serial.begin(9600); + + // start the SPI library: + SPI.begin(); + + // initialize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + // give the sensor time to set up: + delay(100); +} + +void loop() { + //Select High Resolution Mode + writeRegister(0x03, 0x0A); + + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + float realTemp = (float)tempData / 20.0; + Serial.print("Temp[C]="); + Serial.print(realTemp); + + + //Read the pressure data highest 3 bits: + byte pressure_data_high = readRegister(0x1F, 1); + pressure_data_high &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressure_data_low = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + long pressure = ((pressure_data_high << 16) | pressure_data_low)/4; + + // display the temperature: + Serial.println("\tPressure [Pa]=" + String(pressure)); + } +} + +//Read from or write to register from the SCP1000: +unsigned int readRegister(byte thisRegister, int bytesToRead ) { + byte inByte = 0; // incoming byte from the SPI + unsigned int result = 0; // result to return + Serial.print(thisRegister, BIN); + Serial.print("\t"); + // SCP1000 expects the register name in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the address and the command into one byte + byte dataToSend = thisRegister & READ; + Serial.println(thisRegister, BIN); + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(dataToSend); + // send a value of 0 to read the first byte returned: + result = SPI.transfer(0x00); + // decrement the number of bytes left to read: + bytesToRead--; + // if you still have another byte to read: + if (bytesToRead > 0) { + // shift the first byte left, then get the second byte: + result = result << 8; + inByte = SPI.transfer(0x00); + // combine the byte you just got with the previous one: + result = result | inByte; + // decrement the number of bytes left to read: + bytesToRead--; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return(result); +} + + +//Sends a write command to SCP1000 + +void writeRegister(byte thisRegister, byte thisValue) { + + // SCP1000 expects the register address in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the register address and the command into one byte: + byte dataToSend = thisRegister | WRITE; + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(dataToSend); //Send register location + SPI.transfer(thisValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} diff --git a/hardware/msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/hardware/msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino new file mode 100644 index 00000000000..d808a68254d --- /dev/null +++ b/hardware/msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -0,0 +1,73 @@ +/* + Digital Pot Control + + This example controls an Analog Devices AD5206 digital potentiometer. + The AD5206 has 6 potentiometer channels. Each channel's pins are labeled + A - connect this to voltage + W - this is the pot's wiper, which changes when you set it + B - connect this to ground. + + The AD5206 is SPI-compatible,and to command it, you send two bytes, + one with the channel number (0 - 5) and one with the resistance value for the + channel (0 - 255). + + The circuit: + * All A pins of AD5206 connected to +5V + * All B pins of AD5206 connected to ground + * An LED and a 220-ohm resisor in series connected from each W pin to ground + * CS - to digital pin 8 (SS pin) P2.0 + * SDI - to digital pin 14/15 (MOSI pin USI/USCI) P1.6/P1.7 + * CLK - to digital pin 7 (SCK pin) P1.5 + + created 10 Aug 2010 + by Tom Igoe + + modified 2 May 2012 - changed SS pin + by Rick Kimball + + Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 + +*/ + + +// include the SPI library: +#include + +// set pin 8 as the slave select for the digital pot: +const int slaveSelectPin = SS; + +void setup() { + // set the slaveSelectPin as an output: + pinMode (slaveSelectPin, OUTPUT); + // initialize SPI: + SPI.begin(); +} + +void loop() { + // go through the six channels of the digital pot: + for (int channel = 0; channel < 6; channel++) { + // change the resistance on this channel from min to max: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, level); + delay(10); + } + // wait a second at the top: + delay(100); + // change the resistance on this channel from max to min: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, 255 - level); + delay(10); + } + } + +} + +int digitalPotWrite(int address, int value) { + // take the SS pin low to select the chip: + digitalWrite(slaveSelectPin,LOW); + // send in the address and value via SPI: + SPI.transfer(address); + SPI.transfer(value); + // take the SS pin high to de-select the chip: + digitalWrite(slaveSelectPin,HIGH); +} \ No newline at end of file diff --git a/hardware/msp430/libraries/SPI/keywords.txt b/hardware/msp430/libraries/SPI/keywords.txt new file mode 100644 index 00000000000..fa7616581aa --- /dev/null +++ b/hardware/msp430/libraries/SPI/keywords.txt @@ -0,0 +1,36 @@ +####################################### +# Syntax Coloring Map SPI +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +SPI KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +begin KEYWORD2 +end KEYWORD2 +transfer KEYWORD2 +setBitOrder KEYWORD2 +setDataMode KEYWORD2 +setClockDivider KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### +SPI_CLOCK_DIV4 LITERAL1 +SPI_CLOCK_DIV16 LITERAL1 +SPI_CLOCK_DIV64 LITERAL1 +SPI_CLOCK_DIV128 LITERAL1 +SPI_CLOCK_DIV2 LITERAL1 +SPI_CLOCK_DIV8 LITERAL1 +SPI_CLOCK_DIV32 LITERAL1 +SPI_CLOCK_DIV64 LITERAL1 +SPI_MODE0 LITERAL1 +SPI_MODE1 LITERAL1 +SPI_MODE2 LITERAL1 +SPI_MODE3 LITERAL1 \ No newline at end of file diff --git a/hardware/msp430/libraries/SPI/utility/spi_430.h b/hardware/msp430/libraries/SPI/utility/spi_430.h new file mode 100644 index 00000000000..262759a1db8 --- /dev/null +++ b/hardware/msp430/libraries/SPI/utility/spi_430.h @@ -0,0 +1,50 @@ +/* + * spi_430.h - common function declarations for different SPI implementations + * + * Copyright (c) 2012 by Rick Kimball + * spi abstraction api for msp430 + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + * + */ + +#ifndef _SPI_430_H_ +#define _SPI_430_H_ + +#if defined(__MSP430_HAS_USCI__) + +#define SPI_CLOCK_DIV1 1 +#define SPI_CLOCK_DIV2 2 +#define SPI_CLOCK_DIV4 4 +#define SPI_CLOCK_DIV8 8 +#define SPI_CLOCK_DIV16 16 +#define SPI_CLOCK_DIV32 32 +#define SPI_CLOCK_DIV64 64 +#define SPI_CLOCK_DIV128 128 + +#elif defined(__MSP430_HAS_USI__) + +#define SPI_CLOCK_DIV1 0 +#define SPI_CLOCK_DIV2 USIDIV_1 +#define SPI_CLOCK_DIV4 USIDIV_2 +#define SPI_CLOCK_DIV8 USIDIV_3 +#define SPI_CLOCK_DIV16 USIDIV_4 +#define SPI_CLOCK_DIV32 USIDIV_5 +#define SPI_CLOCK_DIV64 USIDIV_6 +#define SPI_CLOCK_DIV128 USIDIV_7 + +#else + #error "SPI not supported by hardware on this chip" +#endif + +void spi_initialize(void); +void spi_disable(void); +uint8_t spi_send(const uint8_t); +void spi_set_bitorder(const uint8_t); +void spi_set_datamode(const uint8_t); +void spi_set_divisor(const uint16_t clkdivider); + +#endif /*_SPI_430_H_*/ diff --git a/hardware/msp430/libraries/SPI/utility/usci_spi.cpp b/hardware/msp430/libraries/SPI/utility/usci_spi.cpp new file mode 100644 index 00000000000..25d715710e8 --- /dev/null +++ b/hardware/msp430/libraries/SPI/utility/usci_spi.cpp @@ -0,0 +1,133 @@ +/** + * File: usci_spi.c - msp430 USCI SPI implementation + * + * Copyright (c) 2012 by Rick Kimball + * spi abstraction api for msp430 + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include "spi_430.h" + +#ifdef __MSP430_HAS_USCI__ + +/** + * USCI flags for various the SPI MODEs + * + * Note: The msp430 UCCKPL tracks the CPOL value. However, + * the UCCKPH flag is inverted when compared to the CPHA + * value described in Motorola documentation. + */ + +#define SPI_MODE_0 (UCCKPH) /* CPOL=0 CPHA=0 */ +#define SPI_MODE_1 (0) /* CPOL=0 CPHA=1 */ +#define SPI_MODE_2 (UCCKPL | UCCKPH) /* CPOL=1 CPHA=0 */ +#define SPI_MODE_3 (UCCKPL) /* CPOL=1 CPHA=1 */ + +#define SPI_MODE_MASK (UCCKPL | UCCKPH) + +/** + * spi_initialize() - Configure USCI UCB0 for SPI mode + * + * P2.0 - CS (active low) + * P1.5 - SCLK + * P1.6 - MISO aka SOMI + * P1.7 - MOSI aka SIMO + * + */ +void spi_initialize(void) +{ + UCB0CTL1 = UCSWRST | UCSSEL_2; // Put USCI in reset mode, source USCI clock from SMCLK + UCB0CTL0 = SPI_MODE_0 | UCMSB | UCSYNC | UCMST; // Use SPI MODE 0 - CPOL=0 CPHA=0 + + P1OUT |= (BIT5 | BIT7); // SPI output pins low + P1SEL |= BIT5 | BIT6 | BIT7; // configure P1.5, P1.6, P1.7 for USCI + P1SEL2 |= BIT5 | BIT6 | BIT7; // more required SPI configuration + + UCB0BR0 = SPI_CLOCK_DIV4 & 0xFF; // set initial speed to 4MHz + UCB0BR1 = (SPI_CLOCK_DIV4 >> 8 ) & 0xFF; + + UCB0CTL1 &= ~UCSWRST; // release USCI for operation +} + +/** + * spi_disable() - put USCI into reset mode + */ +void spi_disable(void) +{ + UCB0CTL1 |= UCSWRST; // Put USCI in reset mode +} + +/** + * spi_send() - send a byte and recv response + */ +uint8_t spi_send(const uint8_t _data) +{ + while (!(UC0IFG & UCB0TXIFG)) + ; // wait for previous tx to complete + + UCB0TXBUF = _data; // setting TXBUF clears the TXIFG flag + + while (!(UC0IFG & UCB0RXIFG)) + ; // wait for an rx character? + + return UCB0RXBUF; // reading clears RXIFG flag +} + +/***SPI_MODE_0 + * spi_set_divisor() - set new clock divider for USCI + * + * USCI speed is based on the SMCLK divided by BR0 and BR1 + * + */ +void spi_set_divisor(const uint16_t clkdiv) +{ + UCB0CTL1 |= UCSWRST; // go into reset state + UCB0BR0 = clkdiv & 0xFF; + UCB0BR1 = (clkdiv >> 8 ) & 0xFF; + UCB0CTL1 &= ~UCSWRST; // release for operation +} + +/** + * spi_set_bitorder(LSBFIRST=0 | MSBFIRST=1) + */ +void spi_set_bitorder(const uint8_t order) +{ + UCB0CTL1 |= UCSWRST; // go into reset state + UCB0CTL0 = (UCB0CTL0 & ~UCMSB) | ((order == 1 /*MSBFIRST*/) ? UCMSB : 0); /* MSBFIRST = 1 */ + UCB0CTL1 &= ~UCSWRST; // release for operation +} + +/** + * spi_set_datamode() - mode 0 - 3 + */ +void spi_set_datamode(const uint8_t mode) +{ + UCB0CTL1 |= UCSWRST; // go into reset state + switch(mode) { + case 0: /* SPI_MODE0 */ + UCB0CTL0 = (UCB0CTL0 & ~SPI_MODE_MASK) | SPI_MODE_0; + break; + case 1: /* SPI_MODE1 */ + UCB0CTL0 = (UCB0CTL0 & ~SPI_MODE_MASK) | SPI_MODE_1; + break; + case 2: /* SPI_MODE2 */ + UCB0CTL0 = (UCB0CTL0 & ~SPI_MODE_MASK) | SPI_MODE_2; + break; + case 4: /* SPI_MODE3 */ + UCB0CTL0 = (UCB0CTL0 & ~SPI_MODE_MASK) | SPI_MODE_3; + break; + default: + break; + } + UCB0CTL1 &= ~UCSWRST; // release for operation +} +#else + //#error "Error! This device doesn't have a USCI peripheral" +#endif diff --git a/hardware/msp430/libraries/SPI/utility/usi_spi.cpp b/hardware/msp430/libraries/SPI/utility/usi_spi.cpp new file mode 100644 index 00000000000..114ef814b90 --- /dev/null +++ b/hardware/msp430/libraries/SPI/utility/usi_spi.cpp @@ -0,0 +1,134 @@ +/** + * File: usi_spi.c - msp430 USI SPI implementation + * + * Copyright (c) 2012 by Rick Kimball + * spi abstraction api for msp430 + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include "spi_430.h" + +#ifdef __MSP430_HAS_USI__ +/** + * USI flags for various the SPI MODEs + * + * Note: The msp430 USICKPL tracks the CPOL value. However, + * the USICKPH flag is inverted when compared to the CPHA + * value described in Motorola documentation. + */ + +#define SPI_MODE_0 (USICKPH) /* CPOL=0 CPHA=0 */ +#define SPI_MODE_1 (0) /* CPOL=0 CPHA=1 */ +#define SPI_MODE_2 (USICKPL | USICKPH) /* CPOL=1 CPHA=0 */ +#define SPI_MODE_3 (USICKPL) /* CPOL=1 CPHA=1 */ + +#define SPI_MODE_MASK (USICKPL | USICKPH) +#define SPI_DIV_MASK (USIDIV0 | USIDIV1 | USIDIV2) +#define SPI_LSBMSB_MASK USILSB + +/** + * spi_initialize() - Configure USI for SPI mode + * + * P2.0 - CS (active low) + * P1.5 - SCLK + * P1.6 - MOSI aka SIMO + * P1.7 - MISO aka SOMI + */ + +void spi_initialize(void) +{ + USICTL0 |= USISWRST; // put USI in reset mode, source USI clock from SMCLK + USICTL0 |= USIPE5 | USIPE6 | USIPE7 | USIMST | USIOE; + USICTL1 |= SPI_MODE_0; // use SPI MODE 0 - CPOL=0 CPHA=0 + USICKCTL = USIDIV_2 | USISSEL_2; // default speed 4MHz 16MHz/4 + + P1OUT |= BIT5 | BIT6; // SPI OUTPUT PINS LOW + P1DIR = (P1DIR & ~BIT7) | BIT5 | BIT6; // configure P1.5, P1.6, P1.7 for USI + + USICTL0 &= ~USISWRST; // release USI for operation +} + +void spi_disable(void) +{ + USICTL0 |= USISWRST; // put USI in reset mode +} + +/** + * spi_send() - send a byte and recv response + */ +uint8_t spi_send(const uint8_t _data) +{ + USISRL = _data; + USICNT = 8; + + while (!(USIIFG & USICTL1)) + ; // wait for an inbound character + + return USISRL; // reading clears RXIFG flag +} + +/** + * spi_set_divisor() - set new clock divider for USI + * + * There are a fixed set of valid values for clock divisors + * see the slau144 for details. DIV by 2/4/8 .. 128 + */ + +void spi_set_divisor(const uint16_t clkdiv) +{ + USICTL0 |= USISWRST; // put USI in reset mode + USICKCTL = (USICKCTL & ~SPI_DIV_MASK) | clkdiv; + USICTL0 &= ~USISWRST; // release for operation +} + +/** + * spi_set_bitorder (enum LSBFIRST=0|MSBFIRST=1) + * + * Note: this should use the LSBFIRST/MSBFIRST defines however + * it doesn't to allow this code to compile without Energia. + * + */ +void spi_set_bitorder(const uint8_t order) +{ + USICTL0 |= USISWRST; // put USI in reset mode + USICTL0 = (USICTL0 & ~SPI_LSBMSB_MASK) | ((order == 1 /*MSBFIRST*/) ? 0 : USILSB); /* MSBFIRST = 1 */ + USICTL0 &= ~USISWRST; // release for operation +} + +/** + * spi_set_datamode() - Motorola SPI Mode 0 ... 3 + * + * mode is really an enum SPI_MODE0 ... SPI_MODE3 as defined in + * the Energia header file. + */ +void spi_set_datamode(const uint8_t mode) +{ + USICTL0 |= USISWRST; // put USI in reset mode while we make changes + switch(mode) { + case 0: /* SPI_MODE0 */ + USICTL1 = (USICTL1 & ~SPI_MODE_MASK) | SPI_MODE_0; + break; + case 1: /* SPI_MODE1 */ + USICTL1 = (USICTL1 & ~SPI_MODE_MASK) | SPI_MODE_1; + break; + case 2: /* SPI_MODE2 */ + USICTL1 = (USICTL1 & ~SPI_MODE_MASK) | SPI_MODE_2; + break; + case 4: /* SPI_MODE3 */ + USICTL1 = (USICTL1 & ~SPI_MODE_MASK) | SPI_MODE_3; + break; + default: + break; + } + USICTL0 &= ~USISWRST; // release for operation +} +#else + //#warning "Error! This device doesn't have a USI peripheral" +#endif diff --git a/hardware/msp430/libraries/TimerSerial/TimerSerial.cpp b/hardware/msp430/libraries/TimerSerial/TimerSerial.cpp new file mode 100644 index 00000000000..b748ff9f804 --- /dev/null +++ b/hardware/msp430/libraries/TimerSerial/TimerSerial.cpp @@ -0,0 +1,230 @@ +/* + ************************************************************************ + * TimerSerial.cpp + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + HardwareSerial.cpp - Hardware serial library for Wiring + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + and + msp430softserial by Rick Kimball + https://github.com/RickKimball + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "Energia.h" +#include "TimerSerial.h" + +ring_buffer tx_buffer = { {0}, 0, 0}; +ring_buffer rx_buffer = { {0}, 0, 0}; +volatile unsigned int USARTTXBUF; + +TimerSerial::TimerSerial() +{ + _tx_buffer = &tx_buffer; + _rx_buffer = &rx_buffer; +} + +TimerSerial::~TimerSerial() +{ + end(); +} + +void TimerSerial::begin() +{ + P1OUT |= TX_PIN | RX_PIN; // Initialize all GPIO + P1SEL |= TX_PIN + RX_PIN; // Enabled Timer ISR function for TXD/RXD pins + P1DIR |= TX_PIN; // Enable TX_PIN for output + + TACCTL0 = OUT; // Set TXD Idle state as Mark = '1', +3.3 volts normal + TACCTL1 = SCS + CM1 + CAP + CCIE; // Sync TACLK and MCLK, Detect Neg Edge, Enable Capture mode and RX Interrupt + + TACTL = TASSEL_2 + MC_2 + TACLR; // Clock TIMERA from SMCLK, run in continuous mode counting from to 0-0xFFFF + + _SoftSerial_RxDebugPinInit(); +} + +void TimerSerial::end() +{ + P1SEL = ~TX_PIN; // P1 functions select to default + P1DIR = ~TX_PIN; // Input +} + +int TimerSerial::read() +{ + int c = -1; + __dint(); // Disable interrupts to protect head and tail values + // This prevents the RX_ISR from modifying them + // while we are trying to read and modify + + if (_rx_buffer->head != _rx_buffer->tail) { + c = (uint8_t) _rx_buffer->buffer[_rx_buffer->tail]; + _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE; + } + + __eint(); // Enable interrupts + + return c; +} + +int TimerSerial::available() +{ + int cnt; + + __dint(); // Disable interrupts to protect head and tail values + // This prevents the RX_ISR from modifying them + // while we are trying to read and modify + + cnt = (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE; + + __eint(); //Enable interrupts + + return cnt; +} + +void TimerSerial::flush() +{ + while (_tx_buffer->head != _tx_buffer->tail); +} + +int TimerSerial::peek() +{ + if (_rx_buffer->head == _rx_buffer->tail) { + return -1; + } else { + return _rx_buffer->buffer[_rx_buffer->tail]; + } +} + +#define store_rxchar(c) { \ + unsigned int i = (unsigned int)(rx_buffer.head + 1) % SERIAL_BUFFER_SIZE; \ + if ( i != rx_buffer.tail ) { \ + rx_buffer.buffer[rx_buffer.head] = c; \ + rx_buffer.head = i; \ + } \ +} + +void TimerSerial::Transmit() +{ + // make the next output at least TICKS_PER_BIT in the future + // so we don't stomp on the the stop bit from our previous xmt + + TACCR0 = TAR; // resync with current TimerA clock + TACCR0 += TICKS_PER_BIT; // setup the next timer tick + TACCTL0 = OUTMOD0 + CCIE; // set TX_PIN HIGH and reenable interrupts + + // now that we have set the next interrupt in motion + // we quickly need to set the TX data. Hopefully the + // next 2 lines happens before the next timer tick. + + // Note: This code makes great use of multiple peripherals + // + // In the code above, we start with a busy wait on the CCIE + // interrupt flag. As soon as it is available, we setup the next + // send time and then enable the interrupt. Until that time happens, + // we have a few free cycles available to stuff the start and stop bits + // into the data buffer before the timer ISR kicks in and handles + // the event. Note: if you are using a really slow clock or a really + // fast baud rate you could run into problems if the interrupt is + // triggered before you have finished with the USARTTXBUF + + USARTTXBUF |= 0x100; // Add the stop bit '1' + USARTTXBUF <<= 1; // Add the start bit '0' +} + + +size_t TimerSerial::write(uint8_t b) +{ + // TIMERA0 disables the interrupt flag when it has sent + // the final stop bit. While a transmit is in progress the + // interrupt is enabled + while (TACCTL0 & CCIE) { + ; // wait for previous xmit to finish + } + + USARTTXBUF = b; + Transmit(); + return 1; +} + +#ifndef TIMERA0_VECTOR +#define TIMERA0_VECTOR TIMER0_A0_VECTOR +#endif /* TIMER0_A0_VECTOR */ + +//Timer A0 interrupt service routine +__attribute__((interrupt(TIMERA0_VECTOR))) +void TimerSerial::TxIsr(void) +{ + static uint8_t txBitCnt = 10; // 1 Start bit + 8 data bits + 1 stop bit + + if (txBitCnt == 0) { // All bits TXed? + TACCTL0 &= ~CCIE; // disable interrupt, used as a flag to SoftSerial_xmit + txBitCnt = 10; // Re-load bit counter + } else { + TACCR0 += TICKS_PER_BIT; // setup next time to send a bit + + if (USARTTXBUF & 0x01) { // look at LSB and decide what to send + TACCTL0 &= ~OUTMOD2; // TX Mark '1' + } else { + TACCTL0 |= OUTMOD2; // TX Space '0' + } + USARTTXBUF >>= 1; // pull in the next bit to send + txBitCnt--; + } +} + +#ifndef TIMERA1_VECTOR +#define TIMERA1_VECTOR TIMER0_A1_VECTOR +#endif /* TIMER0_A0_VECTOR */ + +//Timer A1 interrupt service routine +__attribute__((interrupt(TIMERA1_VECTOR))) +void TimerSerial::RxIsr(void) +{ + static unsigned char rxBitCnt = 8; + static unsigned char rxData = 0; + +#ifdef TIMER0_A1_VECTOR + if ( TA0IV == TA0IV_TACCR1 ) { // this mcu has multiple TIMERA peripherals +#else + if ( TAIV == TAIV_TACCR1 ) { +#endif + _SoftSerial_ToggleRxDebugPin(); // watch RXDEBUG_PIN with a scope to see sample timing + TACCR1 += TICKS_PER_BIT; // Setup next time to sample + if (TACCTL1 & CAP) { // Is this the start bit? + _SoftSerial_ToggleRxDebugPin(); // push it high to make a nice wave + TACCTL1 &= ~CAP; // Switch capture to compare mode + TACCR1 += TICKS_PER_BIT_DIV2; // Sample from the middle of D0 + } + else { + rxData >>= 1; + if (TACCTL1 & SCCI) { // Get bit waiting in receive latch + rxData |= 0x80; + } + rxBitCnt--; + if (rxBitCnt == 0) { // All bits RXed? + store_rxchar(rxData); // Store in ring_buffer + rxBitCnt = 8; // Re-load bit counter + TACCTL1 |= CAP; // Switch compare to capture mode + TACCR1 += TICKS_PER_BIT; // account for the stop bit + } + } + } +} diff --git a/hardware/msp430/libraries/TimerSerial/TimerSerial.h b/hardware/msp430/libraries/TimerSerial/TimerSerial.h new file mode 100644 index 00000000000..ac61cec8d81 --- /dev/null +++ b/hardware/msp430/libraries/TimerSerial/TimerSerial.h @@ -0,0 +1,94 @@ +/* + TimerSerial.h - Timer based serial library for MSP430 + Copyright (c) 2012 Robert Wessels. All right reserved. + Modeled after Nicholas Zambetti's HardwareSerial. + and + msp430softserial by Rick Kimball + https://github.com/RickKimball/msp430softserial/ + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef TimerSerial_h +#define TimerSerial_h + +#include +#include + +//TODO: Size should depend on how much RAM we have. 16 should be OK for most cases. + +#define SERIAL_BUFFER_SIZE 16 + +#define TX_PIN BIT1 // TXD on P1.1 +#define RX_PIN BIT2 // RXD on P1.2 + +// TODO: support other baud rates +#define TICKS_PER_BIT (F_CPU / 9600) // 9600 Baud +#define TICKS_PER_BIT_DIV2 (F_CPU / (9600*2)) // Time for half a bit. + +struct ring_buffer +{ + unsigned char buffer[SERIAL_BUFFER_SIZE]; + volatile unsigned int head; + volatile unsigned int tail; +}; + +//#define ENABLE_RXDEBUG_PIN 1 + +#define RXDEBUG_PIN_PORT P1 // P1 +#define RXDEBUG_PIN BIT6 // P1.6 + +#ifdef ENABLE_RXDEBUG_PIN +#define _SoftSerial_RxDebugPinInit() { \ + P1OUT |= RXDEBUG_PIN; \ + P1DIR |= RXDEBUG_PIN; \ +} + +#define _SoftSerial_ToggleRxDebugPin() { \ + P1OUT ^= RXDEBUG_PIN; \ +} + +#else +#define _SoftSerial_RxDebugPinInit() +#define _SoftSerial_ToggleRxDebugPin() +#endif + +class TimerSerial : public Stream +{ +private: + ring_buffer *_rx_buffer; + ring_buffer *_tx_buffer; + + void Transmit(void); + static void TxIsr (void); + static void RxIsr (void); + void ProcessTxIsr(void); + void ProcessRxIsr(void); + +public: + TimerSerial(void); + ~TimerSerial(void); + void begin(void); + void end(void); + + virtual size_t write(uint8_t byte); + virtual int read(void); + virtual int available(void); + virtual void flush(void); + virtual int peek(void); + + using Print::write; +}; +#endif diff --git a/hardware/msp430/libraries/TimerSerial/examples/TimerSerialExample/TimerSerialExample.ino b/hardware/msp430/libraries/TimerSerial/examples/TimerSerialExample/TimerSerialExample.ino new file mode 100644 index 00000000000..162a2f8eed6 --- /dev/null +++ b/hardware/msp430/libraries/TimerSerial/examples/TimerSerialExample/TimerSerialExample.ino @@ -0,0 +1,27 @@ +/* + Timer based serial test + + Echo back whatever is recieved. + + The circuit: + * TX is digital pin 3 (on Launchpad this is connected to the USB UART) + * RX is digital pin 4 (on Launchpad this is connected to the USB UART) + + This example code is in the public domain. + + */ +#include + +TimerSerial mySerial; // Create a new TimerSerial object + +void setup() +{ + mySerial.begin(); // only 9600 baud is supported + mySerial.println("Hello, world?"); +} + +void loop() // run over and over +{ + if (mySerial.available()) + mySerial.write(mySerial.read()); +} diff --git a/hardware/msp430/libraries/TimerSerial/keywords.txt b/hardware/msp430/libraries/TimerSerial/keywords.txt new file mode 100755 index 00000000000..032f51b6a3d --- /dev/null +++ b/hardware/msp430/libraries/TimerSerial/keywords.txt @@ -0,0 +1,25 @@ +####################################### +# Syntax Coloring Map for NewSoftSerial +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +TimerSerial KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +end KEYWORD2 +read KEYWORD2 +available KEYWORD2 +flush KEYWORD2 +listen KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/hardware/msp430/libraries/Wire/Wire.cpp b/hardware/msp430/libraries/Wire/Wire.cpp new file mode 100644 index 00000000000..e2027a9aee6 --- /dev/null +++ b/hardware/msp430/libraries/Wire/Wire.cpp @@ -0,0 +1,274 @@ +/* + ************************************************************************ + * Wire.cpp + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + TwoWire.cpp - TWI/I2C library for Wiring & Arduino + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +extern "C" { + #include + #include + #include + #include "twi.h" +} + +#include "Wire.h" + +// Initialize Class Variables ////////////////////////////////////////////////// + +uint8_t TwoWire::rxBuffer[BUFFER_LENGTH]; +uint8_t TwoWire::rxBufferIndex = 0; +uint8_t TwoWire::rxBufferLength = 0; + +uint8_t TwoWire::txAddress = 0; +uint8_t TwoWire::txBuffer[BUFFER_LENGTH]; +uint8_t TwoWire::txBufferIndex = 0; +uint8_t TwoWire::txBufferLength = 0; + +uint8_t TwoWire::transmitting = 0; +void (*TwoWire::user_onRequest)(void); +void (*TwoWire::user_onReceive)(int); + +// Constructors //////////////////////////////////////////////////////////////// + +TwoWire::TwoWire() +{ +} + +// Public Methods ////////////////////////////////////////////////////////////// + +void TwoWire::begin(void) +{ + rxBufferIndex = 0; + rxBufferLength = 0; + + txBufferIndex = 0; + txBufferLength = 0; + + twi_init(); +} + +void TwoWire::begin(uint8_t address) +{ + twi_setAddress(address); + twi_attachSlaveTxEvent(onRequestService); + twi_attachSlaveRxEvent(onReceiveService); + begin(); +} + +void TwoWire::begin(int address) +{ + begin((uint8_t)address); +} + +uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) +{ + // clamp to buffer length + if(quantity > BUFFER_LENGTH){ + quantity = BUFFER_LENGTH; + } + // perform blocking read into buffer + uint8_t read = twi_readFrom(address, rxBuffer, quantity); + // set rx buffer iterator vars + rxBufferIndex = 0; + rxBufferLength = read; + + return read; +} + +uint8_t TwoWire::requestFrom(int address, int quantity) +{ + return requestFrom((uint8_t)address, (uint8_t)quantity); +} + +void TwoWire::beginTransmission(uint8_t address) +{ + // indicate that we are transmitting + transmitting = 1; + // set address of targeted slave + txAddress = address; + // reset tx buffer iterator vars + txBufferIndex = 0; + txBufferLength = 0; +} + +void TwoWire::beginTransmission(int address) +{ + beginTransmission((uint8_t)address); +} + +uint8_t TwoWire::endTransmission(void) +{ + // transmit buffer (blocking) + int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1); + // reset tx buffer iterator vars + txBufferIndex = 0; + txBufferLength = 0; + // indicate that we are done transmitting + transmitting = 0; + return ret; +} + +// must be called in: +// slave tx event callback +// or after beginTransmission(address) +size_t TwoWire::write(uint8_t data) +{ + if(transmitting){ + // in master transmitter mode + // don't bother if buffer is full + if(txBufferLength >= BUFFER_LENGTH){ + setWriteError(); + return 0; + } + // put byte in tx buffer + txBuffer[txBufferIndex] = data; + ++txBufferIndex; + // update amount in buffer + txBufferLength = txBufferIndex; + }else{ + // in slave send mode + // reply to master + twi_transmit(&data, 1); + } + return 1; +} + +// must be called in: +// slave tx event callback +// or after beginTransmission(address) +size_t TwoWire::write(const uint8_t *data, size_t quantity) +{ + if(transmitting){ + // in master transmitter mode + for(size_t i = 0; i < quantity; ++i){ + write(data[i]); + } + }else{ + // in slave send mode + // reply to master + twi_transmit(data, quantity); + } + return quantity; +} + +// must be called in: +// slave rx event callback +// or after requestFrom(address, numBytes) +int TwoWire::available(void) +{ + return rxBufferLength - rxBufferIndex; +} + +// must be called in: +// slave rx event callback +// or after requestFrom(address, numBytes) +int TwoWire::read(void) +{ + int value = -1; + + // get each successive byte on each call + if(rxBufferIndex < rxBufferLength){ + value = rxBuffer[rxBufferIndex]; + ++rxBufferIndex; + } + + return value; +} + +// must be called in: +// slave rx event callback +// or after requestFrom(address, numBytes) +int TwoWire::peek(void) +{ + int value = -1; + + if(rxBufferIndex < rxBufferLength){ + value = rxBuffer[rxBufferIndex]; + } + + return value; +} + +void TwoWire::flush(void) +{ + // XXX: to be implemented. +} + +// behind the scenes function that is called when data is received +void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes) +{ + // don't bother if user hasn't registered a callback + if(!user_onReceive){ + return; + } + // don't bother if rx buffer is in use by a master requestFrom() op + // i know this drops data, but it allows for slight stupidity + // meaning, they may not have read all the master requestFrom() data yet + if(rxBufferIndex < rxBufferLength){ + return; + } + // copy twi rx buffer into local read buffer + // this enables new reads to happen in parallel + for(uint8_t i = 0; i < numBytes; ++i){ + rxBuffer[i] = inBytes[i]; + } + // set rx iterator vars + rxBufferIndex = 0; + rxBufferLength = numBytes; + // alert user program + user_onReceive(numBytes); +} + +// behind the scenes function that is called when data is requested +void TwoWire::onRequestService(void) +{ + // don't bother if user hasn't registered a callback + if(!user_onRequest){ + return; + } + // reset tx buffer iterator vars + // !!! this will kill any pending pre-master sendTo() activity + txBufferIndex = 0; + txBufferLength = 0; + // alert user program + user_onRequest(); +} + +// sets function called on slave write +void TwoWire::onReceive( void (*function)(int) ) +{ + user_onReceive = function; +} + +// sets function called on slave read +void TwoWire::onRequest( void (*function)(void) ) +{ + user_onRequest = function; +} + +// Preinstantiate Objects ////////////////////////////////////////////////////// + +TwoWire Wire = TwoWire(); + diff --git a/hardware/msp430/libraries/Wire/Wire.h b/hardware/msp430/libraries/Wire/Wire.h new file mode 100644 index 00000000000..7f560ee7803 --- /dev/null +++ b/hardware/msp430/libraries/Wire/Wire.h @@ -0,0 +1,83 @@ +/* + ************************************************************************ + * Wire.h + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + TwoWire.h - TWI/I2C library for Arduino & Wiring + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef TwoWire_h +#define TwoWire_h + +#include +#include "Stream.h" + +#define BUFFER_LENGTH 16 + +class TwoWire : public Stream +{ + private: + static uint8_t rxBuffer[]; + static uint8_t rxBufferIndex; + static uint8_t rxBufferLength; + + static uint8_t txAddress; + static uint8_t txBuffer[]; + static uint8_t txBufferIndex; + static uint8_t txBufferLength; + + static uint8_t transmitting; + static void (*user_onRequest)(void); + static void (*user_onReceive)(int); + static void onRequestService(void); + static void onReceiveService(uint8_t*, int); + public: + TwoWire(); + void begin(); + void begin(uint8_t); + void begin(int); + void beginTransmission(uint8_t); + void beginTransmission(int); + uint8_t endTransmission(void); + uint8_t requestFrom(uint8_t, uint8_t); + uint8_t requestFrom(int, int); + virtual size_t write(uint8_t); + virtual size_t write(const uint8_t *, size_t); + virtual int available(void); + virtual int read(void); + virtual int peek(void); + virtual void flush(void); + void onReceive( void (*)(int) ); + void onRequest( void (*)(void) ); + + inline size_t write(unsigned long n) { return write((uint8_t)n); } + inline size_t write(long n) { return write((uint8_t)n); } + inline size_t write(unsigned int n) { return write((uint8_t)n); } + inline size_t write(int n) { return write((uint8_t)n); } + using Print::write; +}; + +extern TwoWire Wire; + +#endif + diff --git a/hardware/msp430/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/hardware/msp430/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino new file mode 100644 index 00000000000..9c41c18f16b --- /dev/null +++ b/hardware/msp430/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -0,0 +1,87 @@ +// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder +// by Nicholas Zambetti +// and James Tichenor + +// Demonstrates use of the Wire library reading data from the +// Devantech Utrasonic Rangers SFR08 and SFR10 + +// Created 29 April 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial communication at 9600bps +} + +int reading = 0; + +void loop() +{ + // step 1: instruct sensor to read echoes + Wire.beginTransmission(112); // transmit to device #112 (0x70) + // the address specified in the datasheet is 224 (0xE0) + // but i2c adressing uses the high 7 bits so it's 112 + Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) + Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) + // use 0x51 for centimeters + // use 0x52 for ping microseconds + Wire.endTransmission(); // stop transmitting + + // step 2: wait for readings to happen + delay(70); // datasheet suggests at least 65 milliseconds + + // step 3: instruct sensor to return a particular echo reading + Wire.beginTransmission(112); // transmit to device #112 + Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) + Wire.endTransmission(); // stop transmitting + + // step 4: request reading from sensor + Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 + + // step 5: receive reading from sensor + if(2 <= Wire.available()) // if two bytes were received + { + reading = Wire.read(); // receive high byte (overwrites previous reading) + reading = reading << 8; // shift high byte to be high 8 bits + reading |= Wire.read(); // receive low byte as lower 8 bits + Serial.println(reading); // print the reading + } + + delay(250); // wait a bit since people have to read the output :) +} + + +/* + +// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) +// usage: changeAddress(0x70, 0xE6); + +void changeAddress(byte oldAddress, byte newAddress) +{ + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA0)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xAA)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA5)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(newAddress); + Wire.endTransmission(); +} + +*/ diff --git a/hardware/msp430/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/hardware/msp430/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino new file mode 100644 index 00000000000..38da1c543b8 --- /dev/null +++ b/hardware/msp430/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -0,0 +1,39 @@ +// I2C Digital Potentiometer +// by Nicholas Zambetti +// and Shawn Bonkowski + +// Demonstrates use of the Wire library +// Controls AD5171 digital potentiometer via I2C/TWI + +// Created 31 March 2006 + +// This example code is in the public domain. + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) +} + +byte val = 0; + +void loop() +{ + Wire.beginTransmission(44); // transmit to device #44 (0x2c) + // device address is specified in datasheet + Wire.write(byte(0x00)); // sends instruction byte + Wire.write(val); // sends potentiometer value byte + Wire.endTransmission(); // stop transmitting + + val++; // increment value + if(val == 64) // if reached 64th position (max) + { + val = 0; // start over from lowest value + } + delay(500); +} + diff --git a/hardware/msp430/libraries/Wire/examples/master_reader/master_reader.ino b/hardware/msp430/libraries/Wire/examples/master_reader/master_reader.ino new file mode 100644 index 00000000000..4124d7d6b7b --- /dev/null +++ b/hardware/msp430/libraries/Wire/examples/master_reader/master_reader.ino @@ -0,0 +1,32 @@ +// Wire Master Reader +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Reads data from an I2C/TWI slave device +// Refer to the "Wire Slave Sender" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial for output +} + +void loop() +{ + Wire.requestFrom(2, 6); // request 6 bytes from slave device #2 + + while(Wire.available()) // slave may send less than requested + { + char c = Wire.read(); // receive a byte as character + Serial.print(c); // print the character + } + + delay(500); +} diff --git a/hardware/msp430/libraries/Wire/examples/master_writer/master_writer.ino b/hardware/msp430/libraries/Wire/examples/master_writer/master_writer.ino new file mode 100644 index 00000000000..ccaa0361bd1 --- /dev/null +++ b/hardware/msp430/libraries/Wire/examples/master_writer/master_writer.ino @@ -0,0 +1,31 @@ +// Wire Master Writer +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Writes data to an I2C/TWI slave device +// Refer to the "Wire Slave Receiver" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) +} + +byte x = 0; + +void loop() +{ + Wire.beginTransmission(4); // transmit to device #4 + Wire.write("x is "); // sends five bytes + Wire.write(x); // sends one byte + Wire.endTransmission(); // stop transmitting + + x++; + delay(500); +} diff --git a/hardware/msp430/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/hardware/msp430/libraries/Wire/examples/slave_receiver/slave_receiver.ino new file mode 100644 index 00000000000..60dd4bddeb1 --- /dev/null +++ b/hardware/msp430/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -0,0 +1,38 @@ +// Wire Slave Receiver +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Receives data as an I2C/TWI slave device +// Refer to the "Wire Master Writer" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(4); // join i2c bus with address #4 + Wire.onReceive(receiveEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() +{ + delay(100); +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) +{ + while(1 < Wire.available()) // loop through all but the last + { + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); // print the integer +} diff --git a/hardware/msp430/libraries/Wire/examples/slave_sender/slave_sender.ino b/hardware/msp430/libraries/Wire/examples/slave_sender/slave_sender.ino new file mode 100644 index 00000000000..d3b238af90a --- /dev/null +++ b/hardware/msp430/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -0,0 +1,32 @@ +// Wire Slave Sender +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Sends data as an I2C/TWI slave device +// Refer to the "Wire Master Reader" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(2); // join i2c bus with address #2 + Wire.onRequest(requestEvent); // register event +} + +void loop() +{ + delay(100); +} + +// function that executes whenever data is requested by master +// this function is registered as an event, see setup() +void requestEvent() +{ + Wire.write("hello "); // respond with message of 6 bytes + // as expected by master +} diff --git a/hardware/msp430/libraries/Wire/keywords.txt b/hardware/msp430/libraries/Wire/keywords.txt new file mode 100644 index 00000000000..12f129b9908 --- /dev/null +++ b/hardware/msp430/libraries/Wire/keywords.txt @@ -0,0 +1,31 @@ +####################################### +# Syntax Coloring Map For Wire +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +beginTransmission KEYWORD2 +endTransmission KEYWORD2 +requestFrom KEYWORD2 +send KEYWORD2 +receive KEYWORD2 +onReceive KEYWORD2 +onRequest KEYWORD2 + +####################################### +# Instances (KEYWORD2) +####################################### + +Wire KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/hardware/msp430/libraries/Wire/utility/twi.c b/hardware/msp430/libraries/Wire/utility/twi.c new file mode 100644 index 00000000000..b924868c674 --- /dev/null +++ b/hardware/msp430/libraries/Wire/utility/twi.c @@ -0,0 +1,447 @@ +/* + ************************************************************************ + * twi.c + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + twi.c - TWI/I2C library for Wiring & Arduino + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include +#include "Energia.h" // for digitalWrite + +#ifndef cbi +#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) +#endif + +#ifndef sbi +#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) +#endif + +#include "pins_energia.h" +#include "twi.h" + +static volatile uint8_t twi_state; +static uint8_t twi_slarw; +static uint8_t twi_my_addr; + +static void (*twi_onSlaveTransmit)(void); +static void (*twi_onSlaveReceive)(uint8_t*, int); + +static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH]; +static volatile uint8_t twi_masterBufferIndex; +static uint8_t twi_masterBufferLength; + +static uint8_t twi_txBuffer[TWI_BUFFER_LENGTH]; +static volatile uint8_t twi_txBufferIndex; +static volatile uint8_t twi_txBufferLength; + +//static uint8_t twi_rxBuffer[TWI_BUFFER_LENGTH]; +static volatile uint8_t twi_rxBufferIndex; + +static volatile uint8_t twi_error; + +/* + * Function twi_init + * Desc readys twi pins and sets twi bitrate + * Input none + * Output none + */ +void twi_init(void) +{ + + __bic_SR_register(GIE); + P1OUT = 0xC0; // P1.6 & P1.7 Pullups, others to 0 + P1REN |= 0xC0; // P1.6 & P1.7 Pullups + + USICTL0 = USIPE6+USIPE7+USIMST+USISWRST; // SDA/SCL + USICTL1 = USII2C+USIIE; // Enable I2C mode & USI interrupt + USICKCTL = USIDIV_7+USISSEL_2+USICKPL; // USI clk: SCL = SMCLK/128 + USICNT |= USIIFGCC; // Disable automatic clear control + USICTL0 &= ~USISWRST; // Enable USI + USICTL1 &= ~USIIFG; // Clear pending flag + __bis_SR_register(GIE); +} + +/* + * Function twi_setAddress + * Desc sets slave address and enables interrupt + * Input none + * Output none + */ +void twi_setAddress(uint8_t address) +{ + twi_my_addr = address << 1; + //TODO: enable start detect interrupt to kick off the state machine +} + +/* + * Function twi_readFrom + * Desc attempts to become twi bus master and read a + * series of bytes from a device on the bus + * Input address: 7bit i2c device address + * data: pointer to byte array + * length: number of bytes to read into array + * Output number of bytes read + */ +uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length) +{ + uint8_t i; + + USICTL0 |= USIMST; // USI master mode + // ensure data will fit into buffer + if(TWI_BUFFER_LENGTH < length){ + return 0; + } + + // initialize buffer iteration vars + twi_masterBufferIndex = 0; + twi_masterBufferLength = length-1; // This is not intuitive, read on... + // On receive, the previously configured ACK/NACK setting is transmitted in + // response to the received byte before the interrupt is signalled. + // Therefor we must actually set NACK when the _next_ to last byte is + // received, causing that NACK to be sent in response to receiving the last + // expected byte of data. + + // build sla+w, slave device address + w bit + twi_slarw = 1; + twi_slarw |= address << 1; + + // send start condition + twi_state = TWI_SND_START; + // this will trigger an interrupt kicking off the state machine in the isr + USICTL1 |= USIIFG; + + // wait for read operation to complete + while(twi_state != TWI_IDLE){ + continue; + } + + if (twi_masterBufferIndex < length) + length = twi_masterBufferIndex; + + // copy twi buffer to data + for(i = 0; i < length; ++i){ + data[i] = twi_masterBuffer[i]; + } + + return length; +} + +/* + * Function twi_writeTo + * Desc attempts to become twi bus master and write a + * series of bytes to a device on the bus + * Input address: 7bit i2c device address + * data: pointer to byte array + * length: number of bytes in array + * wait: boolean indicating to wait for write or not + * Output 0 .. success + * 1 .. length to long for buffer + * 2 .. address send, NACK received + * 3 .. data send, NACK received + * 4 .. other twi error (lost bus arbitration, bus error, ..) + */ +uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait) +{ + uint8_t i; + twi_error = TWI_ERRROR_NO_ERROR; + USICTL0 |= USIMST; // USI master mode + if(length == 0) { + return 0; + } + + // ensure data will fit into buffer + if(length > TWI_BUFFER_LENGTH){ + return TWI_ERROR_BUF_TO_LONG; + } + + + // initialize buffer iteration vars + twi_masterBufferIndex = 0; + twi_masterBufferLength = length; + + // copy data to twi buffer + for(i = 0; i < length; ++i){ + twi_masterBuffer[i] = data[i]; + } + + // build sla+w, slave device address + w bit + twi_slarw = 0; + twi_slarw |= address << 1; + twi_state = TWI_SND_START; + // this will trigger an interrupt kicking off the state machine in the isr + USICTL1 |= USIIFG; + + while(twi_state != TWI_IDLE) + { + continue; + } + + return twi_error; +} + +/* + * Function twi_transmit + * Desc fills slave tx buffer with data + * must be called in slave tx event callback + * Input data: pointer to byte array + * length: number of bytes in array + * Output 1 length too long for buffer + * 2 not slave transmitter + * 0 ok + */ +uint8_t twi_transmit(const uint8_t* data, uint8_t length) +{ + uint8_t i; + + // ensure data will fit into buffer + if(TWI_BUFFER_LENGTH < length){ + return 1; + } + // set length and copy data into tx buffer + twi_txBufferLength = length; + for(i = 0; i < length; ++i){ + twi_txBuffer[i] = data[i]; + } + + return 0; +} + +/* + * Function twi_attachSlaveRxEvent + * Desc sets function called before a slave read operation + * Input function: callback function to use + * Output none + */ +void twi_attachSlaveRxEvent( void (*function)(uint8_t*, int) ) +{ + twi_onSlaveReceive = function; +} + +/* + * Function twi_attachSlaveTxEvent + * Desc sets function called before a slave write operation + * Input function: callback function to use + * Output none + */ +void twi_attachSlaveTxEvent( void (*function)(void) ) +{ + twi_onSlaveTransmit = function; +} + +/* + * Function twi_start + * Desc sends start condition + * Input tx: 1 indicated tx, 0 indicated rx + * Output none + */ +void twi_start() +{ +} + +void twi_send() { + USISRL = 0xaa; // Load data byte + USICNT |= 0x08; // Bit counter = 8, start TX +} +/* + * Function twi_stop + * Desc relinquishes bus master status + * Input none + * Output none + */ +void twi_stop(void) +{ + USICTL0 |= USIOE; + USISRL = 0x00; + USICNT |= 0x01; +} + +/* + * Function twi_releaseBus + * Desc releases bus control + * Input none + * Output none + */ +void twi_releaseBus(void) +{ + +} + +#if 0 +//__attribute__((interrupt(USI_VECTOR))) +void USI_ISR(void) +{ + switch(twi_state){ + // All Master + case TWI_SND_START:// sent start condition + USISRL = 0x00; // Generate Start Condition... + USICTL0 |= USIGE+USIOE; + USICTL0 &= ~USIGE; + USISRL = twi_slarw; + USICNT = (USICNT & 0xE0) + 0x08; + twi_state = TWI_RECV_SLA_ACK; + + break; + case TWI_RECV_SLA_ACK: // reveive (N)ACK + + USICTL0 &= ~USIOE; // SDA = input + USICNT |= 0x01; // Bit counter=1 + twi_state = TWI_PROC_SLA_ACK; + break; + case TWI_PROC_SLA_ACK: + if ((USISRL & 0x01) || (twi_masterBufferIndex == twi_masterBufferLength)){ + if(twi_masterBufferIndex == 0) { + //we haven't advance so must be an address NACK + twi_error = TWI_ERROR_ADDR_NACK; + } else if (twi_masterBufferIndex < twi_masterBufferLength){ + twi_error = TWI_ERROR_DATA_NACK; + } + twi_stop(); + twi_state = TWI_EXIT; + } else { // ACK received + USICTL0 |= USIOE; + USISRL = twi_masterBuffer[twi_masterBufferIndex++]; + USICNT |= 0x08; + twi_state = TWI_RECV_SLA_ACK; + } + // if receive data set counter to 8 and SDA to in + // then go to receive data processing stage + + break; + //case TWI_PROC_SLA_DATA: + // if not the last byte, + case TWI_EXIT: + USISRL = 0x0FF; // USISRL = 1 to drive SDA high + USICTL0 |= USIGE; // Transparent latch enabled + USICTL0 &= ~(USIGE+USIOE); // Latch/SDA output disabled + twi_state = TWI_IDLE; //Idle + break; + } + + USICTL1 &= ~USIIFG; // !!!Clear pending flag!!! + +} +#endif + +void send_start() +{ + USISRL = 0x00; // Generate Start Condition... + USICTL0 |= USIGE+USIOE; + USICTL0 &= ~USIGE; + USISRL = twi_slarw; + USICNT = (USICNT & 0xE0) + 0x08; +} + +__attribute__((interrupt(USI_VECTOR))) +void foo(void) +{ + switch(twi_state){ + + // Master transmit / receive + case TWI_SND_START: + send_start(); + twi_state = TWI_PREP_SLA_ADDR_ACK; + break; + case TWI_PREP_SLA_ADDR_ACK: // reveive (N)ACK + USICTL0 &= ~USIOE; // SDA = input + USICNT |= 0x01; // Bit counter=1 + twi_state = TWI_MT_PROC_ADDR_ACK; + break; + case TWI_MT_PROC_ADDR_ACK: + if (USISRL & 0x01) { + twi_error = TWI_ERROR_ADDR_NACK; + twi_stop(); + twi_state = TWI_EXIT; + break; + } + if(twi_slarw & 1) + goto mtre; + else + goto mtpd; + // else fall through and process data ACK; + case TWI_MT_PREP_DATA_ACK: // reveive (N)ACK + USICTL0 &= ~USIOE; // SDA = input + USICNT |= 0x01; // Bit counter=1 + twi_state = TWI_MT_PROC_DATA_ACK; + break; + case TWI_MT_PROC_DATA_ACK: +mtpd: + if (USISRL & 0x01) { + twi_error = TWI_ERROR_DATA_NACK; + twi_stop(); + twi_state = TWI_EXIT; + break; + } + + if(twi_masterBufferIndex == twi_masterBufferLength) { + twi_stop(); + twi_state = TWI_EXIT; + break; + } + + USICTL0 |= USIOE; + USISRL = twi_masterBuffer[twi_masterBufferIndex++]; + USICNT |= 0x08; + twi_state = TWI_MT_PREP_DATA_ACK; + break; + // Master receiver +mtre: + case TWI_MR_PREP_DATA_RECV: + USICTL0 &= ~USIOE; // SDA input + USICNT |= 0x08; // Bit counter = 8, RX data + twi_state = TWI_MR_PROC_DATA_RECV; + break; + case TWI_MR_PROC_DATA_RECV: + USICTL0 |= USIOE; // SDA output + twi_masterBuffer[twi_masterBufferIndex++] = USISRL; + if(twi_masterBufferIndex > twi_masterBufferLength ) { + USISRL = 0xFF; // that was the last byte send NACK + twi_state = TWI_MR_PREP_STOP; + } else { + USISRL = 0x00; // keep on receiving and send ACK + twi_state = TWI_MR_PREP_DATA_RECV; + } + USICNT |= 0x01; + break; + case TWI_MR_PREP_STOP: + twi_stop(); + twi_state = TWI_EXIT; + break; + // Slave receiver + // Slave transmitter + // All + case TWI_EXIT: + USISRL = 0x0FF; // USISRL = 1 to drive SDA high + USICTL0 |= USIGE; // Transparent latch enabled + USICTL0 &= ~(USIGE+USIOE); // Latch/SDA output disabled + twi_state = TWI_IDLE; //Idle + break; + + default: + break;//should not happen handle error + } + + USICTL1 &= ~USIIFG; // !!!Clear pending flag!!! + +} diff --git a/hardware/msp430/libraries/Wire/utility/twi.h b/hardware/msp430/libraries/Wire/utility/twi.h new file mode 100644 index 00000000000..42b4c3ecb5d --- /dev/null +++ b/hardware/msp430/libraries/Wire/utility/twi.h @@ -0,0 +1,79 @@ +/* + ************************************************************************ + * twi.h + * + * Arduino core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * + *********************************************************************** + Derived from: + twi.h - TWI/I2C library for Wiring & Arduino + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef twi_h +#define twi_h + +#include + +#ifndef __MSP430_HAS_USI__ +#error "********** USI not available" +#endif + +#include + +#ifndef TWI_FREQ +#define TWI_FREQ 100000L +#endif + +#ifndef TWI_BUFFER_LENGTH +#define TWI_BUFFER_LENGTH 16 +#endif + +#define TWI_SND_START 0 +#define TWI_PREP_SLA_ADDR_ACK 1 +#define TWI_MT_PROC_ADDR_ACK 2 +#define TWI_MT_PREP_DATA_ACK 3 +#define TWI_MT_PROC_DATA_ACK 4 +#define TWI_MR_PREP_DATA_RECV 5 +#define TWI_MR_PROC_DATA_RECV 6 +#define TWI_MR_PREP_STOP 7 +#define TWI_EXIT 8 +#define TWI_IDLE 9 + +#define TWI_ERRROR_NO_ERROR 0 +#define TWI_ERROR_BUF_TO_LONG 1 +#define TWI_ERROR_ADDR_NACK 2 +#define TWI_ERROR_DATA_NACK 3 +#define TWI_ERROR_OTHER 4 + + + +void twi_init(void); +void twi_setAddress(uint8_t); +uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t); +uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t); +uint8_t twi_transmit(const uint8_t*, uint8_t); +void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) ); +void twi_attachSlaveTxEvent( void (*)(void) ); +void twi_reply(uint8_t); +void twi_stop(void); +void twi_releaseBus(void); + +#endif + diff --git a/hardware/msp430/programmers.txt b/hardware/msp430/programmers.txt new file mode 100644 index 00000000000..90719104093 --- /dev/null +++ b/hardware/msp430/programmers.txt @@ -0,0 +1,4 @@ +# See: http://code.google.com/p/arduino/wiki/Platforms + +rf2500.name=rf2500 +rf2500.protocol=rf2500 diff --git a/hardware/msp430/variants/launchpad/pins_energia.h b/hardware/msp430/variants/launchpad/pins_energia.h new file mode 100644 index 00000000000..8e1a7758f95 --- /dev/null +++ b/hardware/msp430/variants/launchpad/pins_energia.h @@ -0,0 +1,245 @@ +/* + ************************************************************************ + * pins_energia.h + * + * Energia core files for MSP430 + * Copyright (c) 2012 Robert Wessels. All right reserved. + * + * Contribution: Rei VILO + * + *********************************************************************** + Derived from: + pins_arduino.h - Pin definition functions for Arduino + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2007 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 +*/ + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h +#ifndef BV +#define BV(x) (1 << (x)) +#endif + +#if defined(__MSP430_HAS_USCI__) +static const uint8_t SS = 8; /* P2.0 */ +static const uint8_t SCK = 7; /* P1.5 */ +static const uint8_t MOSI = 15; /* P1.7 */ +static const uint8_t MISO = 14; /* P1.6 */ +#endif + +#if defined(__MSP430_HAS_USI__) +static const uint8_t SS = 8; /* P2.0 */ +static const uint8_t SCK = 7; /* P1.5 */ +static const uint8_t MOSI = 14; /* P1.6 */ +static const uint8_t MISO = 15; /* P1.7 */ +#endif + +static const uint8_t A0 = 0; +static const uint8_t A1 = 1; +static const uint8_t A2 = 2; +static const uint8_t A3 = 3; +static const uint8_t A4 = 4; +static const uint8_t A5 = 5; +static const uint8_t A6 = 6; +static const uint8_t A7 = 7; +static const uint8_t A10 = 10; // special. This is the internal temp sensor + +// +-\/-+ +// VCC 1| |20 GND +// (A0) P1.0 2| |19 XIN +// (A1) P1.1 3| |18 XOUT +// (A2) P1.2 4| |17 TEST +// (A3) P1.3 5| |16 RST# +// (A4) P1.4 6| |15 P1.7 (A7) (SCL) (MISO) depends on chip +// (A5) P1.5 7| |14 P1.6 (A6) (SDA) (MOSI) +// P2.0 8| |13 P2.5 +// P2.1 9| |12 P2.4 +// P2.2 10| |11 P2.3 +// +----+ +// + +// Pin names based on the silkscreen +// +static const uint8_t P1_0 = 2; +static const uint8_t P1_1 = 3; +static const uint8_t P1_2 = 4; +static const uint8_t P1_3 = 5; +static const uint8_t P1_4 = 6; +static const uint8_t P1_5 = 7; +static const uint8_t P2_0 = 8; +static const uint8_t P2_1 = 9; +static const uint8_t P2_2 = 10; +static const uint8_t P2_3 = 11; +static const uint8_t P2_4 = 12; +static const uint8_t P2_5 = 13; +static const uint8_t P1_6 = 14; +static const uint8_t P1_7 = 15; + +static const uint8_t RED_LED = 2; +static const uint8_t GREEN_LED = 14; +static const uint8_t PUSH2 = 5; +static const uint8_t TEMPSENSOR = 10; // depends on chip + + +#ifdef ARDUINO_MAIN + +const uint16_t port_to_dir[] = { + NOT_A_PORT, + (uint16_t) &P1DIR, + (uint16_t) &P2DIR, +#ifdef __MSP430_HAS_PORT3_R__ + (uint16_t) &P3DIR, +#endif +}; + +const uint16_t port_to_sel[] = { + NOT_A_PORT, + (uint16_t) &P1SEL, + (uint16_t) &P2SEL, +#ifdef __MSP430_HAS_PORT3_R__ + (uint16_t) &P3SEL, +#endif +}; + +const uint16_t port_to_ren[] = { + NOT_A_PORT, + (uint16_t) &P1REN, + (uint16_t) &P2REN, +#ifdef __MSP430_HAS_PORT3_R__ + (uint16_t) &P3REN, +#endif +}; + +const uint16_t port_to_sel2[] = { + NOT_A_PORT, +#ifdef P1SEL2_ + (uint16_t) &P1SEL2, +#else + NOT_A_PORT, +#endif +#ifdef P2SEL2_ + (uint16_t) &P2SEL2, +#else + NOT_A_PORT, +#endif +#ifdef P3SEL2_ + (uint16_t) &P3SEL2, +#else + NOT_A_PORT, +#endif +}; + +const uint16_t port_to_input[] = { + NOT_A_PORT, + (uint16_t) &P1IN, + (uint16_t) &P2IN, +#ifdef __MSP430_HAS_PORT3_R__ + (uint16_t) &P3IN, +#endif +}; +const uint16_t port_to_output[] = { + NOT_A_PORT, + (uint16_t) &P1OUT, + (uint16_t) &P2OUT, +#ifdef __MSP430_HAS_PORT3_R__ + (uint16_t) &P3OUT, +#endif +}; + +/* + * Defines for devices with 2x TA3 timers (e.g. MSP430g2553). On the 20pin devices, upto 3 analog outputs are available + * T0A1, T1A1 and T1A2 + */ +const uint8_t digital_pin_to_timer[] = { + NOT_ON_TIMER, /* dummy */ + NOT_ON_TIMER, /* 1 - VCC */ + NOT_ON_TIMER, /* 2 - P1.0 */ + T0A0, /* 3 - P1.1, note: A0 output cannot be used with analogWrite */ + T0A1, /* 4 - P1.2 */ + NOT_ON_TIMER, /* 5 - P1.3 */ + NOT_ON_TIMER, /* 6 - P1.4 note: special case. Leaving as no timer due to difficulty determining if available */ + T0A0, /* 7 - P1.5 note: A0 output cannot be used with analogWrite */ +#if defined(__MSP430_HAS_T1A3__) + T1A0, /* 8 - P2.0 note: A0 output cannot be used with analogWrite */ + T1A1, /* 9 - P2.1 */ + T1A1, /* 10 - P2.3 */ + T1A0, /* 11 - P2.4 note: A0 output cannot be used with analogWrite */ + T1A2, /* 12 - P2.5 */ + T1A2, /* 13 - P2.6 */ +#else + NOT_ON_TIMER, /* 8 - P2.0 */ + NOT_ON_TIMER, /* 9 - P2.1 */ + NOT_ON_TIMER, /* 10 - P2.3 */ + NOT_ON_TIMER, /* 11 - P2.4 */ + NOT_ON_TIMER, /* 12 - P2.5 */ + NOT_ON_TIMER, /* 13 - P2.6 */ +#endif + T0A1, /* 14 - P1.6 */ + NOT_ON_TIMER, /* 15 - P1.7 */ + NOT_ON_TIMER, /* 16 - /RESET */ + NOT_ON_TIMER, /* 17 - TEST */ + NOT_ON_TIMER, /* 18 - XOUT - P2.7 */ + T0A1, /* 18 - XIN - P2.6: */ + NOT_ON_TIMER, /* 20 - GND */ +}; + +const uint8_t digital_pin_to_port[] = { + NOT_A_PIN, /* dummy */ + NOT_A_PIN, /* 1 */ + P1, /* 2 */ + P1, /* 3 */ + P1, /* 4 */ + P1, /* 5 */ + P1, /* 6 */ + P1, /* 7 */ + P2, /* 8 */ + P2, /* 9 */ + P2, /* 10 */ + P2, /* 11 */ + P2, /* 12 */ + P2, /* 13 */ + P1, /* 14 */ + P1, /* 15 */ +}; + +const uint8_t digital_pin_to_bit_mask[] = { + NOT_A_PIN, /* 0, pin count starts at 1 */ + NOT_A_PIN, /* 1, VCC */ + BV(0), /* 2, port P1.0 */ + BV(1), /* 3, port P1.1 */ + BV(2), /* 4, port P1.2 */ + BV(3), /* 5, port P1.3*/ + BV(4), /* 6, port P1.4 */ + BV(5), /* 7, port P1.5 */ + BV(0), /* 8, port P2.0 */ + BV(1), /* 9, port P2.1 */ + BV(2), /* 10, port P2.2 */ + BV(3), /* 11, port P2.3 */ + BV(4), /* 12, port P2.4 */ + BV(5), /* 13, port P2.5 */ + BV(6), /* 14, port P1.6 */ + BV(7), /* 15, port P1.7 */ + NOT_A_PIN, /* 16, RST */ + NOT_A_PIN, /* 17, TEST */ + NOT_A_PIN, /* 18, XOUT */ + NOT_A_PIN, /* 19, XIN */ + NOT_A_PIN, /* 20, GND */ +}; +#endif +#endif diff --git a/license.txt b/license.txt index fe2dac072f2..5ae733088a2 100644 --- a/license.txt +++ b/license.txt @@ -1,10 +1,10 @@ -this file includes licensing information for parts of arduino. +This file includes licensing information for parts of energia. first, the gnu general public license, which covers the main body -of the processing/arduino code (in general, all the stuff inside the 'app' +of the processing/energia code (in general, all the stuff inside the 'app' and 'core' subfolders). -next, the gnu lesser general public license that covers the arduino core +next, the gnu lesser general public license that covers the energia core and libraries. diff --git a/readme.txt b/readme.txt index 4777293e680..30ea1464fad 100644 --- a/readme.txt +++ b/readme.txt @@ -1,32 +1,7 @@ -Arduino is an open-source physical computing platform based on a simple i/o -board and a development environment that implements the Processing/Wiring -language. Arduino can be used to develop stand-alone interactive objects or -can be connected to software on your computer (e.g. Flash, Processing, MaxMSP). -The boards can be assembled by hand or purchased preassembled; the open-source -IDE can be downloaded for free. +Energia is a fork of Arduino for the Texas Instruments MSP430 Micro Controller. -For more information, see the website at: http://www.arduino.cc/ -or the forums at: http://arduino.cc/forum/ +For more information, see the website at: http://energia.github.com/Energia/ +and the https://github.com/energia/Energia To report a bug in the software, go to: -http://code.google.com/p/arduino/issues/list - -For other suggestions, use the forum: -http://arduino.cc/forum/index.php/board,21.0.html - -INSTALLATION -Detailed instructions are in reference/Guide_Windows.html and -reference/Guide_MacOSX.html. For Linux, see the Arduino playground: -http://www.arduino.cc/playground/Learning/Linux - -CREDITS -Arduino is an open source project, supported by many. - -The Arduino team is composed of Massimo Banzi, David Cuartielles, Tom Igoe, -Gianluca Martino, and David A. Mellis. - -Arduino uses the GNU avr-gcc toolchain, avrdude, avr-libc, and code from -Processing and Wiring. - -Icon and about image designed by ToDo: http://www.todo.to.it/ - +https://github.com/energia/Energia/issues diff --git a/todo.txt b/todo.txt index 3a248a7ea2f..dddc0c776d2 100644 --- a/todo.txt +++ b/todo.txt @@ -1,201 +1,43 @@ -0101 arduino +0101E0006 energia + +[U] = Assigned and under development +[X] = Completed +[?] = Unassigned and needs work +[ ] = Unassigned and needs an owner + +-= Higest priority first =- + +[ ] + [ ] OS X serial driver bug + [ ] Windows driver compatibility with mspdebug / mspdebug compatibility with mspdebug + +@ Core functionality + Time + [ ] micros() + + Advanced I/O + [ ] tone() + [ ] noTone() + + Random Numbers + [ ] randomSeed() + [ ] random() + + +@ Libraries + Follow Arduino/Wiring API's if a Library exists + - http://arduino.cc/en/Reference/Libraries + - http://arduino.cc/playground/Main/LibraryList + - http://www.pjrc.com/teensy/td_libs.html + [ ] USCI I2C master/slave + [ ] USI I2C slave (master implemented but needs work) + [X] SPI support (needs testing) + [ ] CapTouch library + [ ] IRremote + +@ Documentation + [ ] Know issues list + [X] Bug fix / new feature review process + [ ] Incompatibilities + [X] Coding Style Guide -Fix Linux make.sh, etc. scripts -Test on Linux. - -AVR - -Ethernet library: - - integrate DHCP support - - client.connect() returns 0 when connection is successful? http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238295170 - - call Server.begin() from Ethernet.begin() instead of in user's sketch? - - add method for receiving notification of new client connections to a server - - add method for receiving notification of data written to a client - - add method for receiving notification of client disconnections -Incorporate mikalhart's new SoftwareSerial library. -Consider making abs() not a macro. See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234908504 -Improve shiftOut() performance: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1216659239/0 -Add String library. -Add Encoder library. -Bootloader: - - disable watch dog timer - - fix eeprom writing: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1202157667/15 -Support pin change interrupts. -Switch pwm output on pins 5 and 6 to phase-correct mode, if possible. -Add parameter to shiftOut() for specifying a number of bits. -Add parameter to Serial.print[ln](x, BIN) for specifying number of bits. -Support PROGMEM strings in Serial.print(): http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1227919972 -Should Serial.print(b) send the ASCII digits of the byte? -Add weak attribute to signal handlers: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1203798214 -Floating point support in the map() function. -Fix delayMicroseconds(0). -Add sleep function(s). -Add SPI library. -Add OneWire library. -Add pulseOut(), etc. functions from Wiring. -Switch to ServoTimer2 library? http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1222201226/0#5 -Add ContinuousServo class that inherits from Servo? -LiquidCrystal library: - - support going to the next line with println(). -Supporting EEMEM directive by changing compiler command line: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1202157667 -Include Arduino as AVR-ISP sketch in hardware/firmwares. -Move type definitions into WConstants.h. -Change core and libraries to use Arduino types (e.g. byte, boolean). - -COMPUTER - -Clear serial monitor button when the serial monitor opens. -Disable checking for updates. -Test the upload.using parameter to upload with a programmer. -Add keyboard shortcut for opening the serial monitor. -Escape characters with copy as html. -Support libraries in the SKETCH/code folder? -Test bootloader burning w/ an AVRISP. -Enable verbose output if shift (or alt?) is held down when pressing run or upload. -Add support for third-party boards in the user's sketchbook folder. -Add support for third-party cores in the user's sketchbook folder. -Re-enable (and fix) the Commander. -Move selection of Linux look and feel from Base.java to arduino.sh script. -Check RAM usage of sketches: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1224729260/0#0 -Improve preprocessing of sketches: - - Better determine which header files are included (not commented out). - - Remember the original locations of function prototypes to highlight the correct line on error. -Multiple sketch windows. -Avoid library conflicts by only linking in the library whose name matches that of the #included header file. -Easier library discovery and installation ("Add library..." menu item). -Easier board installation ("Add board..." menu item) -Comprehensive board management: - - Enabled and disabled boards. - - Dialog for enabling, disabling, adding, deleting, and possibly editing boards. - - Board descriptions (e.g. explaining differences between boards). -Allow for libraries in /libraries. -Allow for boards in /boards. -Divide boards.txt into multiple text files. -Allow for core in /cores. -Clean up Library and LibraryManager. -Compile libraries dynamically (with compilation of sketch and core files). -Library builds should respect build.verbose. -Detect dependencies between libraries. -Byte-based serial monitor. -Line termination options in the serial monitor. -Clear character should clear serial monitor. -Incorporate serial-net proxy. -Changing font size should change serial monitor font size. -Deal with shorter screens (e.g. ASUS EEPC). -Investigate method for auto-detecting serial port on Windows (javax.usb?) - - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1225226642 -Guess serial port on the Mac and Linux. -Automatic detection of baud rate for serial monitor (based on the call to Serial.begin() in the current sketch). -Improve, generally, the upload experience (e.g. faster program start after upload, keep-alive messages to bootloader from IDE, shorter bootloader timeout if possible, progress bar) -Allow uploading of .hex files. -Allow for arbitrary compilation command line arguments. -Find in reference should give same message for missing page as for missing page association. -Test find in reference on libraries. -Change background color while using external editor: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1229567785 - -Compiler.java - - Eliminate the need to pass a Target into the compiler by having the Compiler determine the current target (by checking the preferences directly)? - - Delete the unneeded static functions (for classpath translation, etc.) from the bottom of the file. - -Sketch.java - - add system-wide include path in preprocess()? - - should find libraries in the code/ sub-folder of the sketch folder - - do sketches really need to get built in the applet/ sub-folder when uploading? - -PreProcessor.java - - split write() into writeHeader() and write() as in Processing? - - add getExtraImports() function instead of having Sketch grab them directly. - -Base.java - - add keywords from libraries to the syntax coloring - -Editor.java - - allow the Board and Serial port to differ across editor windows. This will require creating a separate instance of the menu for each window, and passing the selections into the sketch when compiling or uploading. - - send the current board and serial port selections to the sketch (which will forward them to the compiler) when compiling or uploading (this should eliminate the need for the Target class, since the compiler will be able to find the target path and its source files itself) - - remove references to the Runner and runtime - -DEVELOPMENT - -Revise the icon. -Don't recompile the Processing core if the work/ directory exists. -RXTX version patched to not hang with bluetooth serial ports: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237179908 -Add licenses for included open source libraries: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234595391 -Make run.bat not open a command line window: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1223883872 -Update version of the FTDI drivers (Windows). -Remove AVR ISP and giveio drivers (Windows). -Include the executable installer for the FTDI drivers (Windows). -Revise fetch.sh to look for version specific pages (names suffixed with, e.g., "-0007") -Move to ant for build process. - -DOCUMENTATION / SITE CONFIGURATION - -Multi-language plugin. -Work on opening up website to public editing. -Create form for submitting workshops. -Create form for submitting projects. - -DOCUMENTATION / META - -Create community section of site. -List of examples we'd like to have. -Style guide for examples, references, and foundations. -Add a Nordic board to the forum. -Add a German board to the forum. - -DOCUMENTATION / NAVIGATION - -Create About section. -Remove Board page. -Move Environment into the Reference section (which should be renamed Programming). - -DOCUMENTATION / FOUNDATIONS - -Better documentation of the Arduino BT. -Tutorial about serial communication. - -DOCUMENTATION / REFERENCE - -Remove parameters from the function links on the reference page. -Document Matrix and Sprite libraries on the Arduino site. -Document Wire.endTransmission() return values: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228240199 - -DOCUMENTATION / EXAMPLES - -Photos: - - Loop - - Analog Input (potentiometer and LDR on analog input 0) -Consistency: - - ledpin vs. ledPin - - value vs. val -Add a Brightness example where an analog input controls the analog output. -Graph example should use an intermediate variable. -Button example says pin 7 but uses pin 2. -Split Loop example in two (one that does loops, another that does arrays). -Add LiquidCrystal library examples. -Add Ethernet library examples. -Add Wire library examples. -Add examples using specific hardware (simple analog sensors, optocouplers, etc.) -Examples should demonstrate use of functions. -Add I2C EEPROM example using Wire library. -Update pictures to use Arduino Diecimila. -Create diagrams and schematics for the examples. - -DOCUMENTATION / GETTING STARTED - -Arduino feature list (in Getting Started > Introduction). -Main "getting started" link should automatically load page for the user's operating system. -Consider deleting many of the pictures in the howto's as they just make it harder to see the instructions without adding much (e.g. the pictures of files in folders). -Tell people not to put the board on a Powerbook. -People don't know what a jumper is. -Add picture of the RX/TX LEDs flashing. -Show a picture of the LED flashing. - -DOCUMENTATION / TROUBLESHOOTING - -Add explanation of how to work around auto-reset. - -DOCUMENTATION / HACKING - -Burning bootloader without an AVRISP: http://www.geocities.jp/arduino_diecimila/bootloader/index_en.html -Documentation for moving from Arduino to custom PCBs. -Write advanced library tutorial.