| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | # Copyright (C) Ivan Kravets <me@ikravets.com> | 
					
						
							|  |  |  | # See LICENSE for details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  |     Builder for Teensy boards | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 20:13:21 +02:00
										 |  |  | from os.path import isfile, join | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  | from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default, | 
					
						
							|  |  |  |                           DefaultEnvironment, SConscript) | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | env = DefaultEnvironment() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy": | 
					
						
							| 
									
										
										
										
											2015-02-23 21:02:40 +02:00
										 |  |  |     SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "baseavr.py"))) | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3": | 
					
						
							| 
									
										
										
										
											2015-02-23 21:02:40 +02:00
										 |  |  |     SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py"))) | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | env.Append( | 
					
						
							|  |  |  |     CPPDEFINES=[ | 
					
						
							|  |  |  |         "USB_SERIAL", | 
					
						
							| 
									
										
										
										
											2015-02-05 20:13:21 +02:00
										 |  |  |         "LAYOUT_US_ENGLISH" | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CXXFLAGS=[ | 
					
						
							| 
									
										
										
										
											2015-02-24 18:15:45 +02:00
										 |  |  |         "-std=gnu++0x", | 
					
						
							|  |  |  |         "-felide-constructors" | 
					
						
							| 
									
										
										
										
											2015-04-06 20:22:03 +03:00
										 |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     LINKFLAGS=[ | 
					
						
							|  |  |  |         "-Wl,--gc-sections,--relax,--defsym=__rtc_localtime=$UNIX_TIME", | 
					
						
							|  |  |  |         "--specs=nano.specs" | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     LIBS=["m"] | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 20:13:21 +02:00
										 |  |  | if isfile(env.subst(join( | 
					
						
							|  |  |  |         "$PIOPACKAGES_DIR", "tool-teensy", "teensy_loader_cli"))): | 
					
						
							|  |  |  |     env.Append( | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  |         UPLOADER=join( | 
					
						
							|  |  |  |             "$PIOPACKAGES_DIR", "tool-teensy", "teensy_loader_cli"), | 
					
						
							| 
									
										
										
										
											2015-02-05 20:13:21 +02:00
										 |  |  |         UPLOADERFLAGS=[ | 
					
						
							|  |  |  |             "-mmcu=$BOARD_MCU", | 
					
						
							|  |  |  |             "-w",  # wait for device to apear | 
					
						
							|  |  |  |             "-v"   # verbose output | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES' | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     env.Append( | 
					
						
							|  |  |  |         UPLOADER=join( | 
					
						
							|  |  |  |             "$PIOPACKAGES_DIR", "tool-teensy", "teensy_post_compile"), | 
					
						
							|  |  |  |         UPLOADERFLAGS=[ | 
					
						
							|  |  |  |             "-file=firmware", | 
					
						
							|  |  |  |             '-path="$BUILD_DIR"', | 
					
						
							|  |  |  |             '-tools="%s"' % join("$PIOPACKAGES_DIR", "tool-teensy") | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS' | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # Target: Build executable and linkable firmware | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-09 12:22:24 +02:00
										 |  |  | target_elf = env.BuildFirmware() | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  | # Target: Build the firmware file | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-19 10:38:09 +02:00
										 |  |  | if "uploadlazy" in COMMAND_LINE_TARGETS: | 
					
						
							|  |  |  |     target_firm = join("$BUILD_DIR", "firmware.hex") | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | else: | 
					
						
							| 
									
										
										
										
											2015-02-19 10:38:09 +02:00
										 |  |  |     target_firm = env.ElfToHex(join("$BUILD_DIR", "firmware"), target_elf) | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-09 19:57:39 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # Target: Print binary size | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD") | 
					
						
							|  |  |  | AlwaysBuild(target_size) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  | # Target: Upload by default firmware file | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-23 19:01:03 +02:00
										 |  |  | upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADHEXCMD") | 
					
						
							| 
									
										
										
										
											2015-02-04 20:39:38 +02:00
										 |  |  | AlwaysBuild(upload) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Define targets | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  | Default([target_firm, target_size]) |