[gnoduino] add initial support for arduino 1.0
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnoduino] add initial support for arduino 1.0
- Date: Wed, 29 Feb 2012 21:18:03 +0000 (UTC)
commit f9c1941c9619826cb8da190f33522c23a1200eba
Author: Lucian Langa <lucilanga gnome org>
Date: Wed Feb 29 22:15:33 2012 +0100
add initial support for arduino 1.0
src/board.py | 5 +++++
src/compiler.py | 48 +++++++++++++++++++++++++++++++++++++++++-------
src/misc.py | 26 ++++++++++++++++++++++++++
src/preproc.py | 4 ++--
4 files changed, 74 insertions(+), 9 deletions(-)
---
diff --git a/src/board.py b/src/board.py
index ed3e30d..526bb05 100644
--- a/src/board.py
+++ b/src/board.py
@@ -91,6 +91,11 @@ class Board(object):
def getPath(self, id):
return self.boards[id]['path']
+ def getVariant(self, id):
+ try:
+ return self.boards[id]['variant']
+ except KeyError: return ""
+
def getBootloader(self, id):
return self.boards[id]['file']
diff --git a/src/compiler.py b/src/compiler.py
index 9ae78ec..45615eb 100644
--- a/src/compiler.py
+++ b/src/compiler.py
@@ -1,5 +1,5 @@
# Arduino python implementation
-# Copyright (C) 2010 Lucian Langa <cooly gnome eu org>
+# Copyright (C) 2010-2012 Lucian Langa <cooly gnome eu org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -48,8 +48,6 @@ cobj = [
"wiring_shift.c",
"wiring_analog.c",
"wiring_pulse.c",
-# "wiring_serial.c",
- "pins_arduino.c",
"WInterrupts.c",
"wiring.c"
]
@@ -62,6 +60,15 @@ cppobj = [
"Tone.cpp"
]
+cppobj_additional = [
+ "new.cpp",
+ "WString.cpp",
+ "CDC.cpp",
+ "Stream.cpp",
+ "IPAddress.cpp",
+ "USBCore.cpp"
+ ]
+
defc = [
"/usr/bin/avr-gcc",
"-c",
@@ -141,7 +148,9 @@ def compile(tw, id, output, notify):
compline=[j for j in defc]
compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
- compline.append("-I"+misc.getArduinoPath())
+ compline.extend(misc.getArduinoIncludes())
+ if misc.getArduinoVersion >= 100:
+ compline.append("-DARDUINO=100")
compline.append(os.path.join(misc.getArduinoPath(), i))
compline.append("-o"+id+"/"+i+".o")
misc.printMessageLn(output, ' '.join(compline))
@@ -159,7 +168,29 @@ def compile(tw, id, output, notify):
compline = [j for j in defcpp]
compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
- compline.append("-I" + misc.getArduinoPath())
+ compline.extend(misc.getArduinoIncludes())
+ if misc.getArduinoVersion >= 100:
+ compline.append("-DARDUINO=100")
+ compline.append(os.path.join(misc.getArduinoPath(), i))
+ compline.append("-o"+id+"/"+i+".o")
+ misc.printMessageLn(output, ' '.join(compline))
+ misc.printLogMessageLn(' '.join(compline))
+ (run, sout) = misc.runProg(compline)
+ misc.printLogMessageLn(sout)
+ if run == False:
+ misc.printErrorLn(notify, output, _("Compile Error"), sout)
+ raise NameError("compile error")
+ else:
+ misc.printMessageLn(output, sout)
+ """compile C++ additional (1.0) targets"""
+ misc.printLogMessageLn('processing C++ additional targets')
+ for i in cppobj_additional:
+ compline = [j for j in defcpp]
+ compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
+ compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
+ compline.extend(misc.getArduinoIncludes())
+ if misc.getArduinoVersion >= 100:
+ compline.append("-DARDUINO=100")
compline.append(os.path.join(misc.getArduinoPath(), i))
compline.append("-o"+id+"/"+i+".o")
misc.printMessageLn(output, ' '.join(compline))
@@ -173,7 +204,10 @@ def compile(tw, id, output, notify):
misc.printMessageLn(output, sout)
"""generate archive objects"""
misc.printLogMessageLn('generating ar objects')
- for i in cobj+cppobj:
+ objects = cobj + cppobj
+ if misc.getArduinoVersion() >= 100:
+ objects = objects + cppobj_additional
+ for i in objects:
compline = [j for j in defar]
compline.append(id+"/core.a")
compline.append(id+"/"+i+".o")
@@ -192,7 +226,7 @@ def compile(tw, id, output, notify):
compline=[j for j in defcpp]
compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
- compline.append("-I" + misc.getArduinoPath())
+ compline.extend(misc.getArduinoIncludes())
flags = []
flags = preproc.generateCFlags(id, cont)
compline.extend(flags)
diff --git a/src/misc.py b/src/misc.py
index 2c4fb0b..cc41d8c 100644
--- a/src/misc.py
+++ b/src/misc.py
@@ -30,6 +30,7 @@ import gettext
import sys
_ = gettext.gettext
+import board
import config
import prefs
@@ -57,9 +58,34 @@ def getArduinoFile(filename):
def getArduinoPath():
return get_path("hardware/arduino/cores/arduino")
+def getArduinoVariantPath():
+ b = board.Board()
+ return get_path("hardware/arduino/variants/"+b.getVariant(b.getBoard()))
+
+def getArduinoIncludes():
+ includes = ["-I" + getArduinoPath()]
+ if getArduinoVersion() >= 100:
+ includes += ["-I" + getArduinoVariantPath()]
+ return includes
+
def getArduinoBootPath():
return get_path("hardware/arduino/bootloaders")
+def getArduinoVersion():
+ """this is far from something accurate but for now
+ we just need to differentiate beween 1.0 and pre 1.0
+ versions of arduino"""
+ if os.path.isfile(getArduinoFile("hardware/arduino/cores/arduino/Arduino.h")):
+ return 100
+ if os.path.isfile(getArduinoFile("hardware/arduino/cores/arduino/WProgram.h")):
+ return 22
+
+def getArduinoAPIFile():
+ if getArduinoVersion() >= 100:
+ return "Arduino.h"
+ else:
+ return "WProgram.h"
+
def getArduinoLibsPath():
return get_path("libraries", default="")
diff --git a/src/preproc.py b/src/preproc.py
index c688d36..b7dd0fd 100644
--- a/src/preproc.py
+++ b/src/preproc.py
@@ -89,9 +89,9 @@ def addHeaders(path, b):
fs = firstStatement(cont)
if fs != None:
proto = findPrototype(cont)
- result = cont[:fs:]+"\n#include \"WProgram.h\"\n" + proto + cont[fs:]+"\n\n"
+ result = cont[:fs:]+"\n#include \""+misc.getArduinoAPIFile()+"\"\n" + proto + cont[fs:]+"\n\n"
else:
- result = "\n#include \"WProgram.h\"\n"+cont+"\n\n"
+ result = "\n#include \""+misc.getArduinoAPIFile()+"\"\n"+cont+"\n\n"
of = tempfile.mktemp(".cpp", "", path)
w = file(of, "w")
w.write(result)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]