diff --git a/app/src/processing/app/debug/ArmCompiler.java b/app/src/processing/app/debug/ArmCompiler.java index 2a2c44f..3078e27 100644 --- a/app/src/processing/app/debug/ArmCompiler.java +++ b/app/src/processing/app/debug/ArmCompiler.java @@ -43,8 +43,13 @@ public class ArmCompiler extends Compiler { public ArmCompiler() { } private boolean messagesNonError = false; // THIS IS SUCH A HACK. - private List hackErrors = null; + + // well, if we're using fields as a global variable hack, we might + // as well be consistent + private Map boardPrefs; + private File corePath; + /** * Compile for ARM with make * @@ -52,303 +57,341 @@ public ArmCompiler() { } * @param buildPath Where the temporary files live and will be built from. * @param primaryClassName the name of the combined sketch file w/ extension * @return true if successful. - * @throws RunnerException Only if there's a problem. Only then. + * @throws RunnerException iff there's a problem. */ - public boolean compile(Sketch sketch, - String buildPath, - String primaryClassName, - boolean verbose, - List compileErrors) + @Override + public boolean compile + (Sketch sketch, String buildPath, String primaryClassName, + boolean verbose, List compileErrors) throws RunnerException { + this.sketch = sketch; this.buildPath = buildPath; + createFolder(new File(buildPath)); this.primaryClassName = primaryClassName; this.verbose = verbose; this.hackErrors = compileErrors; // the pms object isn't used for anything but storage MessageStream pms = new MessageStream(this); - String armBasePath = Base.getArmBasePath(); - Map boardPreferences; try { - boardPreferences = Base.getBoardPreferences(); + this.boardPrefs = Base.getBoardPreferences(); } catch (NullPointerException npe) { - Base.showWarning("No board selected", "please choose one from the Tools menu.",npe); - return false; + Base.showWarning("No board selected", + "please choose one from the Tools menu.", + npe); + return false; } - String core = boardPreferences.get("build.core"); - String corePath; + String core = boardPrefs.get("build.core"); if (core.indexOf(':') == -1) { Target t = Base.getTarget(); File coreFolder = new File(new File(t.getFolder(), "cores"), core); - corePath = coreFolder.getAbsolutePath(); + this.corePath = new File(coreFolder.getAbsolutePath()); } else { Target t = Base.targetsTable.get(core.substring(0, core.indexOf(':'))); File coresFolder = new File(t.getFolder(), "cores"); - File coreFolder = new File(coresFolder, core.substring(core.indexOf(':') + 1)); - corePath = coreFolder.getAbsolutePath(); + File coreFolder = new File(coresFolder, + core.substring(core.indexOf(':') + 1)); + this.corePath = new File(coreFolder.getAbsolutePath()); } List objectFiles = new ArrayList(); + List includePaths = new ArrayList(Arrays.asList(corePath)); - List includePaths = new ArrayList(); - includePaths.add(corePath); - String runtimeLibraryName = buildPath + File.separator + "core.a"; - - // 1. compile the target (core), outputting .o files to and - // then collecting them into the core.a library file. + // 1. compile the core (e.g. libmaple for a Maple target), + // outputting .o files to buildPath. System.out.print("\tCompiling core...\n"); + objectFiles.addAll(compileFiles(buildPath, includePaths, + corePath.getAbsolutePath(), true)); - objectFiles.addAll( - compileFiles(armBasePath, buildPath, includePaths, - findFilesInPath(corePath, "S", true), - findFilesInPath(corePath, "c", true), - findFilesInPath(corePath, "cpp", true), - boardPreferences)); - - - // 2. compile the libraries, outputting .o files to: - // // - - // use library directories as include paths for all libraries - for (File file : sketch.getImportedLibraries()) { - includePaths.add(file.getPath()); - } - - System.out.print("\tCompiling any libs...\n"); - for (File libraryFolder : sketch.getImportedLibraries()) { - File outputFolder = new File(buildPath, libraryFolder.getName()); - File utilityFolder = new File(libraryFolder, "utility"); - createFolder(outputFolder); - // this library can use includes in its utility/ folder - includePaths.add(utilityFolder.getAbsolutePath()); - objectFiles.addAll( - compileFiles(armBasePath, outputFolder.getAbsolutePath(), includePaths, - findFilesInFolder(libraryFolder, "S", false), - findFilesInFolder(libraryFolder, "c", false), - findFilesInFolder(libraryFolder, "cpp", false), - boardPreferences)); - outputFolder = new File(outputFolder, "utility"); - createFolder(outputFolder); - objectFiles.addAll( - compileFiles(armBasePath, outputFolder.getAbsolutePath(), includePaths, - findFilesInFolder(utilityFolder, "S", false), - findFilesInFolder(utilityFolder, "c", false), - findFilesInFolder(utilityFolder, "cpp", false), - boardPreferences)); - // other libraries should not see this library's utility/ folder - includePaths.remove(includePaths.size() - 1); - } + // 2. compile the libraries, updating includePaths as necessary. + objectFiles.addAll(compileLibraries(includePaths)); // 3. compile the sketch (already in the buildPath) + System.out.println("\tCompiling the sketch..."); + objectFiles.addAll(compileFiles(buildPath, includePaths, + buildPath, false)); - System.out.print("\tCompiling the sketch...\n"); - objectFiles.addAll( - compileFiles(armBasePath, buildPath, includePaths, - findFilesInPath(buildPath, "S", false), - findFilesInPath(buildPath, "c", false), - findFilesInPath(buildPath, "cpp", false), - boardPreferences)); - - // 4. link it all together into the .elf file - //System.out.print("Linking compiled \n"); - String linkerInclude = "-L"+corePath; - String linkerScript = "-T"+corePath+File.separator+boardPreferences.get("build.linker"); - //String mapOut = "-Map="+buildPath+File.separator+primaryClassName+".map"; - List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { - armBasePath + "arm-none-eabi-gcc", - linkerScript, - linkerInclude, - "-mcpu=cortex-m3", - "-mthumb", - "-Xlinker", - // mapOut, - "--gc-sections", - "--print-gc-sections", - "--march=armv7-m", - "-Wall", - "-o", - buildPath + File.separator + primaryClassName + ".out" - })); - - for (File file : objectFiles) { - //System.out.println(file); - baseCommandLinker.add(file.getAbsolutePath()); - } + // 4. link it all together into the .bin file + File binFile = linkFiles(objectFiles); - baseCommandLinker.add("-L" + buildPath); - System.out.print("\trunning linker asynchronously...\n"); - execAsynchronously(baseCommandLinker); - - List commandObjCopy = new ArrayList(Arrays.asList(new String[] { - armBasePath + "arm-none-eabi-objcopy", - "-v", - "-Obinary", - buildPath + File.separator + primaryClassName + ".out", - buildPath + File.separator + primaryClassName + ".bin" - })); - - System.out.print("\trunning obj copy asynchronously...\n"); - execAsynchronously(commandObjCopy); - - List commandSize = new ArrayList(Arrays.asList(new String[] { - armBasePath + "arm-none-eabi-size", - "--target=binary", - "-A", - buildPath + File.separator + primaryClassName + ".bin" - })); - - System.out.print("\trunning size asynchronously...\n"); - messagesNonError = true; - System.out.println(); - execAsynchronously(commandSize); - messagesNonError = false; + // 5. compute binary sizes and report to user + sizeBinary(binFile); return true; } - private List compileFiles(String avrBasePath, - String buildPath, List includePaths, - List sSources, - List cSources, List cppSources, - Map boardPreferences) + /** + * @return List of object paths created as a result of compilation. + */ + private List compileFiles(String buildPath, List includePaths, + String sourcePath, boolean recurse) throws RunnerException { + // getCommandCompilerFoo will destructively modify objectPaths + // with any object files the command produces. List objectPaths = new ArrayList(); - - for (File file : sSources) { - String objectPath = buildPath + File.separator + file.getName() + ".o"; - objectPaths.add(new File(objectPath)); - execAsynchronously(getCommandCompilerS(avrBasePath, includePaths, + + // Compile assembly files + for (File file : findFilesInPath(sourcePath, "S", recurse)) { + execAsynchronously(getCommandCompilerS(includePaths, file.getAbsolutePath(), - objectPath, - boardPreferences)); + buildPath, + objectPaths)); } - - for (File file : cSources) { - String objectPath = buildPath + File.separator + file.getName() + ".o"; - objectPaths.add(new File(objectPath)); - execAsynchronously(getCommandCompilerC(avrBasePath, includePaths, - file.getAbsolutePath(), - objectPath, - boardPreferences)); + + // Compile C files + for (File file : findFilesInPath(sourcePath, "c", recurse)) { + execAsynchronously(getCommandCompilerC(includePaths, + file.getAbsolutePath(), + buildPath, + objectPaths)); } - for (File file : cppSources) { - String objectPath = buildPath + File.separator + file.getName() + ".o"; - objectPaths.add(new File(objectPath)); - execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths, - file.getAbsolutePath(), - objectPath, - boardPreferences)); + // Compile C++ files + for (File file : findFilesInPath(sourcePath, "cpp", recurse)) { + execAsynchronously(getCommandCompilerCPP(includePaths, + file.getAbsolutePath(), + buildPath, + objectPaths)); } - + return objectPaths; } + /** + * Destructively modifies includePaths to reflect any library + * includes, which will be of the form + * // + * + * @return List of object files created. + */ + private List compileLibraries(List includePaths) + throws RunnerException { - ///////////////////////////////////////////////////////////////////////////// + List objectFiles = new ArrayList(); - static private List getCommandCompilerS(String armBasePath, List includePaths, - String sourceName, String objectName, Map boardPreferences) { - - List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { - armBasePath + "arm-none-eabi-gcc", - "-mthumb", - //"-g", - "-mcpu=cortex-m3", - "-assembler-with-cpp", - "-Wall", - "-Os", - // "-g", - "-DF_CPU=" + boardPreferences.get("build.f_cpu"), - "-D"+ boardPreferences.get("build.vect"), - "-DBOARD_"+ boardPreferences.get("build.board"), - "-DMCU_"+ boardPreferences.get("build.mcu"), - "-DARDUINO=" + Base.REVISION, - })); - - for (int i = 0; i < includePaths.size(); i++) { - baseCommandCompiler.add("-I" + (String) includePaths.get(i)); + List importedLibs = sketch.getImportedLibraries(); + if (!importedLibs.isEmpty()) { + List libNames = new ArrayList(); + for (File lib: importedLibs) libNames.add(lib.getName()); + String libString = libNames.toString(); + libString = libString.substring(1, libString.length()-1); + System.out.println("\tCompiling libraries: " + libString); + + // use library directories as include paths for all libraries + includePaths.addAll(importedLibs); + + for (File libraryFolder: importedLibs) { + File outputFolder = new File(buildPath, libraryFolder.getName()); + File utilityFolder = new File(libraryFolder, "utility"); + createFolder(outputFolder); + // libraries can have private includes in their utility/ folders + includePaths.add(utilityFolder); + + objectFiles.addAll + (compileFiles(outputFolder.getAbsolutePath(), includePaths, + libraryFolder.getAbsolutePath(), false)); + + outputFolder = new File(outputFolder, "utility"); + createFolder(outputFolder); + + objectFiles.addAll + (compileFiles(outputFolder.getAbsolutePath(), includePaths, + utilityFolder.getAbsolutePath(), false)); + + // other libraries should not see this library's utility/ folder + includePaths.remove(includePaths.size() - 1); + } + } else { + System.out.println("\tNo libraries to compile."); } - baseCommandCompiler.add(sourceName); - baseCommandCompiler.add("-o"+ objectName); + return objectFiles; + } + + /** + * Runs the linker script on the compiled sketch. + * @return the .bin file generated by the linker script. + */ + private File linkFiles(List objectFiles) throws RunnerException { + System.out.println("\tLinking..."); + + File linkerScript = new File(corePath, boardPrefs.get("build.linker")); + File elf = new File(buildPath, primaryClassName + ".elf"); + File bin = new File(buildPath, primaryClassName + ".bin"); + + // Run the linker + List linkCommand = new ArrayList + (Arrays.asList + (Base.getArmBasePath() + "arm-none-eabi-g++", + "-T" + linkerScript.getAbsolutePath(), + "-L" + corePath.getAbsolutePath(), + "-mcpu=cortex-m3", + "-mthumb", + "-Xlinker", + "--gc-sections", + "--print-gc-sections", + "--march=armv7-m", + "-Wall", + "-o", elf.getAbsolutePath())); + + for (File f: objectFiles) linkCommand.add(f.getAbsolutePath()); + + linkCommand.add("-L" + buildPath); + + execAsynchronously(linkCommand); + + // Run objcopy + List objcopyCommand = new ArrayList + (Arrays.asList + (Base.getArmBasePath() + "arm-none-eabi-objcopy", + "-v", + "-Obinary", + elf.getAbsolutePath(), + bin.getAbsolutePath())); + + execAsynchronously(objcopyCommand); + + return bin; + } + + private void sizeBinary(File binFile) throws RunnerException { + System.out.println("\tComputing sketch size..."); - return baseCommandCompiler; + List command = new ArrayList + (Arrays.asList(Base.getArmBasePath() + "arm-none-eabi-size", + "--target=binary", + "-A", + binFile.getAbsolutePath())); + + messagesNonError = true; + System.out.println(); + execAsynchronously(command); + messagesNonError = false; } - - static private List getCommandCompilerC(String armBasePath, List includePaths, - String sourceName, String objectName, Map boardPreferences) { + ///////////////////////////////////////////////////////////////////////////// + + private List getCommandCompilerS + (List includePaths, String sourceName, String buildPath, + List hackObjectPaths) { + + String buildBase = getBuildBase(sourceName); + File depsFile = new File(buildBase + ".d"); + File objFile = new File(buildBase + ".o"); - List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { - armBasePath + "arm-none-eabi-gcc"})); + hackObjectPaths.add(objFile); - for (int i = 0; i < includePaths.size(); i++) { - baseCommandCompiler.add("-I" + (String) includePaths.get(i)); + List command = new ArrayList(); + + command.addAll + (Arrays.asList + (Base.getArmBasePath() + "arm-none-eabi-gcc", + "-mcpu=cortex-m3", + "-march=armv7-m", + "-mthumb", + "-DBOARD_" + boardPrefs.get("build.board"), + "-DMCU_" + boardPrefs.get("build.mcu"), + "-x", "assembler-with-cpp", + "-o", objFile.getAbsolutePath(), + "-c", + sourceName)); + + return command; + } + + + private List getCommandCompilerC + (List includePaths, String sourceName, String buildPath, + List hackObjectPaths) { + + String buildBase = getBuildBase(sourceName); + File depsFile = new File(buildBase + ".d"); + File objFile = new File(buildBase + ".o"); + + hackObjectPaths.add(objFile); + + List command = new ArrayList(); + + command.addAll + (Arrays.asList + (Base.getArmBasePath() + "arm-none-eabi-gcc", + "-Os", + "-g", + "-mcpu=cortex-m3", + "-mthumb", + "-march=armv7-m", + "-nostdlib", + "-ffunction-sections", + "-fdata-sections", + "-Wl,--gc-sections", + "-DBOARD_" + boardPrefs.get("build.board"), + "-DMCU_" + boardPrefs.get("build.mcu"), + "-D" + boardPrefs.get("build.vect"), + "-DARDUINO=" + Base.REVISION)); + + for (File i: includePaths) { + command.add("-I" + i.getAbsolutePath()); } - baseCommandCompiler.add("-c"); - baseCommandCompiler.add("-Os"); - baseCommandCompiler.add("-g"); - baseCommandCompiler.add("-mcpu=cortex-m3"); - baseCommandCompiler.add("-mthumb"); - baseCommandCompiler.add("-march=armv7-m"); - baseCommandCompiler.add("-nostdlib"); - baseCommandCompiler.add("-ffunction-sections"); - baseCommandCompiler.add("-fdata-sections"); - baseCommandCompiler.add("-Wl,--gc-sections"); - baseCommandCompiler.add("-DF_CPU=" + boardPreferences.get("build.f_cpu")); - baseCommandCompiler.add("-D" + boardPreferences.get("build.vect")); - baseCommandCompiler.add("-DBOARD_" + boardPreferences.get("build.board")); - baseCommandCompiler.add("-DMCU_" + boardPreferences.get("build.mcu")); - baseCommandCompiler.add("-DARDUINO=" + Base.REVISION); - baseCommandCompiler.add("-c"); - - baseCommandCompiler.add(sourceName); - baseCommandCompiler.add("-o"+ objectName); - - return baseCommandCompiler; + command.addAll + (Arrays.asList + ("-o", objFile.getAbsolutePath(), + "-c", + sourceName)); + + return command; } - - static private List getCommandCompilerCPP(String armBasePath, - List includePaths, String sourceName, String objectName, - Map boardPreferences) { - - List baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] { - armBasePath + "arm-none-eabi-gcc"})); - - for (int i = 0; i < includePaths.size(); i++) { - baseCommandCompilerCPP.add("-I" + (String) includePaths.get(i)); + + private List getCommandCompilerCPP + (List includePaths, String sourceName, String buildPath, + List hackObjectPaths) { + + String buildBase = getBuildBase(sourceName); + File depsFile = new File(buildBase + ".d"); + File objFile = new File(buildBase + ".o"); + + hackObjectPaths.add(objFile); + + List command = new ArrayList(); + + command.addAll + (Arrays.asList + (Base.getArmBasePath() + "arm-none-eabi-g++", + "-Os", + "-g", + "-mcpu=cortex-m3", + "-mthumb", + "-march=armv7-m", + "-nostdlib", + "-ffunction-sections", + "-fdata-sections", + "-Wl,--gc-sections", + "-DBOARD_" + boardPrefs.get("build.board"), + "-DMCU_" + boardPrefs.get("build.mcu"))); + + for (File i: includePaths) { + command.add("-I" + i.getAbsolutePath()); } - baseCommandCompilerCPP.add("-c"); - baseCommandCompilerCPP.add("-Os"); - baseCommandCompilerCPP.add("-g"); - baseCommandCompilerCPP.add("-mcpu=cortex-m3"); - baseCommandCompilerCPP.add("-mthumb"); - baseCommandCompilerCPP.add("-march=armv7-m"); - baseCommandCompilerCPP.add("-nostdlib"); - baseCommandCompilerCPP.add("-ffunction-sections"); - baseCommandCompilerCPP.add("-fdata-sections"); - baseCommandCompilerCPP.add("-Wl,--gc-sections"); - baseCommandCompilerCPP.add("-DF_CPU=" + boardPreferences.get("build.f_cpu")); - baseCommandCompilerCPP.add("-D" + boardPreferences.get("build.vect")); - baseCommandCompilerCPP.add("-DBOARD_"+ boardPreferences.get("build.board")); - baseCommandCompilerCPP.add("-DMCU_"+ boardPreferences.get("build.mcu")); - baseCommandCompilerCPP.add("-DARDUINO=" + Base.REVISION); - baseCommandCompilerCPP.add("-fno-rtti"); - baseCommandCompilerCPP.add("-fno-exceptions"); - baseCommandCompilerCPP.add("-Wall"); - baseCommandCompilerCPP.add("-c"); - - baseCommandCompilerCPP.add(sourceName); - baseCommandCompilerCPP.add("-o"+ objectName); - - return baseCommandCompilerCPP; + command.addAll(Arrays.asList("-fno-rtti", "-fno-exceptions", "-Wall")); + + command.addAll + (Arrays.asList + ("-o", objFile.getAbsolutePath(), + "-c", + sourceName)); + + return command; + } + + private String getBuildBase(String sourceFile) { + File f = new File(sourceFile); + String s = f.getName(); + return buildPath + File.separator + s.substring(0, s.lastIndexOf('.')); } /** @@ -432,9 +475,9 @@ public void message(String s) { System.err.print(s1); return; } - + //System.out.println("pde / line number: " + lineNumber); - + if (fileIndex == 0) { // main class, figure out which tab for (int i = 1; i < sketch.getCodeCount(); i++) { if (sketch.getCode(i).isExtension("pde")) { @@ -444,10 +487,11 @@ public void message(String s) { } } } - // OLD to do: DAM: if the lineNumber is less than sketch.getCode(0).getPreprocOffset() - // we shouldn't subtract anything from it, as the error is above the - // location where the function prototypes and #include "WProgram.h" - // were inserted. + // OLD to do: DAM: if the lineNumber is less than + // sketch.getCode(0).getPreprocOffset() we shouldn't subtract + // anything from it, as the error is above the location where + // the function prototypes and #include "WProgram.h" were + // inserted. lineNumber -= sketch.getCode(fileIndex).getPreprocOffset(); } @@ -490,7 +534,7 @@ public void message(String s) { // are probably associated with the first error message, // which is already in the status bar, and are likely to be // of interest to the user, so spit them to the console. -// + // if (!secondErrorFound) { System.err.println(s); } diff --git a/libraries/LiquidCrystal/LiquidCrystal.cpp b/libraries/LiquidCrystal/LiquidCrystal.cpp index b7f5e85..52f0308 100755 --- a/libraries/LiquidCrystal/LiquidCrystal.cpp +++ b/libraries/LiquidCrystal/LiquidCrystal.cpp @@ -7,17 +7,17 @@ // When the display powers up, it is configured as follows: // // 1. Display clear -// 2. Function set: -// DL = 1; 8-bit interface data -// N = 0; 1-line display -// F = 0; 5x8 dot character font -// 3. Display on/off control: -// D = 0; Display off -// C = 0; Cursor off -// B = 0; Blinking off -// 4. Entry mode set: -// I/D = 1; Increment by 1 -// S = 0; No shift +// 2. Function set: +// DL = 1; 8-bit interface data +// N = 0; 1-line display +// F = 0; 5x8 dot character font +// 3. Display on/off control: +// D = 0; Display off +// C = 0; Cursor off +// B = 0; Blinking off +// 4. Entry mode set: +// I/D = 1; Increment by 1 +// S = 0; No shift // // Note, however, that resetting the Arduino doesn't reset the LCD, so we // can't assume that its in that state when a sketch starts (and the @@ -28,62 +28,62 @@ // that should be fixed in the 0.0.7 release of the libmaple. [bnewbold] LiquidCrystal::LiquidCrystal(uint8 rs, uint8 rw, uint8 enable, - uint8 d0, uint8 d1, uint8 d2, uint8 d3, - uint8 d4, uint8 d5, uint8 d6, uint8 d7) + uint8 d0, uint8 d1, uint8 d2, uint8 d3, + uint8 d4, uint8 d5, uint8 d6, uint8 d7) { init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7); } LiquidCrystal::LiquidCrystal(uint8 rs, uint8 enable, - uint8 d0, uint8 d1, uint8 d2, uint8 d3, - uint8 d4, uint8 d5, uint8 d6, uint8 d7) + uint8 d0, uint8 d1, uint8 d2, uint8 d3, + uint8 d4, uint8 d5, uint8 d6, uint8 d7) { init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7); } LiquidCrystal::LiquidCrystal(uint8 rs, uint8 rw, uint8 enable, - uint8 d0, uint8 d1, uint8 d2, uint8 d3) + uint8 d0, uint8 d1, uint8 d2, uint8 d3) { init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0); } LiquidCrystal::LiquidCrystal(uint8 rs, uint8 enable, - uint8 d0, uint8 d1, uint8 d2, uint8 d3) + uint8 d0, uint8 d1, uint8 d2, uint8 d3) { init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0); } void LiquidCrystal::init(uint8 fourbitmode, uint8 rs, uint8 rw, uint8 enable, - uint8 d0, uint8 d1, uint8 d2, uint8 d3, - uint8 d4, uint8 d5, uint8 d6, uint8 d7) + uint8 d0, uint8 d1, uint8 d2, uint8 d3, + uint8 d4, uint8 d5, uint8 d6, uint8 d7) { _rs_pin = rs; _rw_pin = rw; _enable_pin = enable; - + _data_pins[0] = d0; _data_pins[1] = d1; _data_pins[2] = d2; - _data_pins[3] = d3; + _data_pins[3] = d3; _data_pins[4] = d4; _data_pins[5] = d5; _data_pins[6] = d6; - _data_pins[7] = d7; + _data_pins[7] = d7; pinMode(_rs_pin, OUTPUT); // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# - if (_rw_pin != 255) { + if (_rw_pin != 255) { pinMode(_rw_pin, OUTPUT); } pinMode(_enable_pin, OUTPUT); - + if (fourbitmode) _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; - else + else _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; - // TODO: bnewbold, re-enable this? - begin(16, 1); + // TODO: bnewbold, re-enable this? + begin(16, 1); } void LiquidCrystal::begin(uint8 cols, uint8 lines, uint8 dotsize) { @@ -101,15 +101,15 @@ void LiquidCrystal::begin(uint8 cols, uint8 lines, uint8 dotsize) { // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // according to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 - delay(50); // Maple mod - //delayMicroseconds(50000); + delay(50); // Maple mod + //delayMicroseconds(50000); // Now we pull both RS and R/W low to begin commands digitalWrite(_rs_pin, LOW); digitalWrite(_enable_pin, LOW); - if (_rw_pin != 255) { + if (_rw_pin != 255) { digitalWrite(_rw_pin, LOW); } - + //put the LCD into 4 bit or 8 bit mode if (! (_displayfunction & LCD_8BITMODE)) { // this is according to the hitachi HD44780 datasheet @@ -117,33 +117,33 @@ void LiquidCrystal::begin(uint8 cols, uint8 lines, uint8 dotsize) { // we start in 8bit mode, try to set 4 bit mode write4bits(0x03); - delay(5); // Maple mod + delay(5); // Maple mod //delayMicroseconds(4500); // wait min 4.1ms // second try write4bits(0x03); - delay(5); // Maple mod + delay(5); // Maple mod //delayMicroseconds(4500); // wait min 4.1ms - + // third go! - write4bits(0x03); - delay(1); // Maple mod + write4bits(0x03); + delay(1); // Maple mod //delayMicroseconds(150); // finally, set to 8-bit interface - write4bits(0x02); + write4bits(0x02); } else { // this is according to the hitachi HD44780 datasheet // page 45 figure 23 // Send function set command sequence command(LCD_FUNCTIONSET | _displayfunction); - delay(5); // Maple mod + delay(5); // Maple mod //delayMicroseconds(4500); // wait more than 4.1ms // second try command(LCD_FUNCTIONSET | _displayfunction); - delay(1); // Maple mod + delay(1); // Maple mod //delayMicroseconds(150); // third go @@ -151,10 +151,10 @@ void LiquidCrystal::begin(uint8 cols, uint8 lines, uint8 dotsize) { } // finally, set # lines, font size, etc. - command(LCD_FUNCTIONSET | _displayfunction); + command(LCD_FUNCTIONSET | _displayfunction); // turn the display on with no cursor or blinking default - _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; + _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // clear it off @@ -171,14 +171,14 @@ void LiquidCrystal::begin(uint8 cols, uint8 lines, uint8 dotsize) { void LiquidCrystal::clear() { command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero - delay(2); // Maple mod + delay(2); // Maple mod //delayMicroseconds(2000); // this command takes a long time! } void LiquidCrystal::home() { command(LCD_RETURNHOME); // set cursor position to zero - delay(2); // Maple mod + delay(2); // Maple mod //delayMicroseconds(2000); // this command takes a long time! } @@ -188,7 +188,7 @@ void LiquidCrystal::setCursor(uint8 col, uint8 row) if ( row > _numlines ) { row = _numlines-1; // we count rows starting w/0 } - + command(LCD_SETDDRAMADDR | (col + row_offsets[row])); } @@ -281,12 +281,12 @@ void LiquidCrystal::send(uint8 value, uint8 mode) { digitalWrite(_rs_pin, mode); // if there is a RW pin indicated, set it low to Write - if (_rw_pin != 255) { + if (_rw_pin != 255) { digitalWrite(_rw_pin, LOW); } - + if (_displayfunction & LCD_8BITMODE) { - write8bits(value); + write8bits(value); } else { write4bits(value>>4); write4bits(value); @@ -295,13 +295,13 @@ void LiquidCrystal::send(uint8 value, uint8 mode) { void LiquidCrystal::pulseEnable(void) { digitalWrite(_enable_pin, LOW); - delay(1); // Maple mod - //delayMicroseconds(1); + delay(1); // Maple mod + //delayMicroseconds(1); digitalWrite(_enable_pin, HIGH); - delay(1); // Maple mod + delay(1); // Maple mod //delayMicroseconds(1); // enable pulse must be >450ns digitalWrite(_enable_pin, LOW); - delay(1); // Maple mod + delay(1); // Maple mod //delayMicroseconds(100); // commands need > 37us to settle } @@ -319,6 +319,6 @@ void LiquidCrystal::write8bits(uint8 value) { pinMode(_data_pins[i], OUTPUT); digitalWrite(_data_pins[i], (value >> i) & 0x01); } - + pulseEnable(); } diff --git a/libraries/LiquidCrystal/LiquidCrystal.h b/libraries/LiquidCrystal/LiquidCrystal.h index a35a673..0baf543 100755 --- a/libraries/LiquidCrystal/LiquidCrystal.h +++ b/libraries/LiquidCrystal/LiquidCrystal.h @@ -45,21 +45,21 @@ class LiquidCrystal : public Print { public: - LiquidCrystal(uint8 rs, uint8 enable, \ - uint8 d0, uint8 d1, uint8 d2, uint8 d3, \ - uint8 d4, uint8 d5, uint8 d6, uint8 d7); - LiquidCrystal(uint8 rs, uint8 rw, uint8 enable, \ - uint8 d0, uint8 d1, uint8 d2, uint8 d3, \ - uint8 d4, uint8 d5, uint8 d6, uint8 d7); - LiquidCrystal(uint8 rs, uint8 rw, uint8 enable, \ - uint8 d0, uint8 d1, uint8 d2, uint8 d3); - LiquidCrystal(uint8 rs, uint8 enable, \ - uint8 d0, uint8 d1, uint8 d2, uint8 d3); - - void init(uint8 fourbitmode, uint8 rs, uint8 rw, uint8 enable,\ - uint8 d0, uint8 d1, uint8 d2, uint8 d3, \ - uint8 d4, uint8 d5, uint8 d6, uint8 d7); - + LiquidCrystal(uint8 rs, uint8 enable, + uint8 d0, uint8 d1, uint8 d2, uint8 d3, + uint8 d4, uint8 d5, uint8 d6, uint8 d7); + LiquidCrystal(uint8 rs, uint8 rw, uint8 enable, + uint8 d0, uint8 d1, uint8 d2, uint8 d3, + uint8 d4, uint8 d5, uint8 d6, uint8 d7); + LiquidCrystal(uint8 rs, uint8 rw, uint8 enable, + uint8 d0, uint8 d1, uint8 d2, uint8 d3); + LiquidCrystal(uint8 rs, uint8 enable, + uint8 d0, uint8 d1, uint8 d2, uint8 d3); + + void init(uint8 fourbitmode, uint8 rs, uint8 rw, uint8 enable, + uint8 d0, uint8 d1, uint8 d2, uint8 d3, + uint8 d4, uint8 d5, uint8 d6, uint8 d7); + void begin(uint8 cols, uint8 rows, uint8 charsize = LCD_5x8DOTS); void clear(); @@ -79,7 +79,7 @@ class LiquidCrystal : public Print { void noAutoscroll(); void createChar(uint8, uint8[]); - void setCursor(uint8, uint8); + void setCursor(uint8, uint8); virtual void write(uint8); void command(uint8); private: diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 40ced1c..a75172d 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -87,7 +87,7 @@ void i2c_send_nack(Port port) { } uint8 i2c_shift_in(Port port) { - uint8 data; + uint8 data = 0; int i; for (i=0;i<8;i++) { @@ -253,3 +253,7 @@ uint8 TwoWire::readOneByte(uint8 address, uint8 *byte) { return SUCCESS; // no real way of knowing, but be optimistic! } + +// Declare the instance that the users of the library can use +TwoWire Wire; +