summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-12-05 22:45:53 -0500
committerDan Halbert <halbert@halwitz.org>2019-12-05 22:45:53 -0500
commit40434d691934cf7f5792f91ce0288beb568bab85 (patch)
treee2f7d0191685f0b519e98c3e1551626fbbf49585 /tools
parent1505da784f228d43df41a773cfe504e7e4da330a (diff)
parent15886b1505d854d76e353b9c5261568c7065d2bf (diff)
wip
Diffstat (limited to 'tools')
-rw-r--r--tools/build_board_info.py1
-rw-r--r--tools/build_memory_info.py8
-rwxr-xr-xtools/gen_ld_files.py39
-rw-r--r--tools/gen_usb_descriptor.py28
4 files changed, 47 insertions, 29 deletions
diff --git a/tools/build_board_info.py b/tools/build_board_info.py
index efa481a63..710cdb0c2 100644
--- a/tools/build_board_info.py
+++ b/tools/build_board_info.py
@@ -48,6 +48,7 @@ extension_by_board = {
aliases_by_board = {
"circuitplayground_express": ["circuitplayground_express_4h", "circuitplayground_express_digikey_pycon2019"],
+ "pybadge": ["edgebadge"],
"gemma_m0": ["gemma_m0_pycon2018"],
"pewpew10": ["pewpew13"]
}
diff --git a/tools/build_memory_info.py b/tools/build_memory_info.py
index a8f84bbb6..0dcd5f6e4 100644
--- a/tools/build_memory_info.py
+++ b/tools/build_memory_info.py
@@ -50,7 +50,7 @@ regions = {}
with open(sys.argv[1], "r") as f:
for line in f:
line = line.strip()
- if line.startswith(("FLASH", "RAM")):
+ if line.startswith(("FLASH_FIRMWARE", "RAM")):
regions[line.split()[0]] = line.split("=")[-1]
for region in regions:
@@ -61,10 +61,10 @@ for region in regions:
space = M_PATTERN.sub(M_REPLACE, space)
regions[region] = eval(space)
-free_flash = regions["FLASH"] - text - data
+free_flash = regions["FLASH_FIRMWARE"] - text - data
free_ram = regions["RAM"] - data - bss
-print(free_flash, "bytes free in flash out of", regions["FLASH"], "bytes (", regions["FLASH"] / 1024, "kb ).")
-print(free_ram, "bytes free in ram for stack out of", regions["RAM"], "bytes (", regions["RAM"] / 1024, "kb ).")
+print("{} bytes free in flash firmware space out of {} bytes ({}kB).".format(free_flash, regions["FLASH_FIRMWARE"], regions["FLASH_FIRMWARE"] / 1024))
+print("{} bytes free in ram for stack out of {} bytes ({}kB).".format(free_ram, regions["RAM"], regions["RAM"] / 1024))
print()
# Check that we have free flash space. GCC doesn't fail when the text + data
diff --git a/tools/gen_ld_files.py b/tools/gen_ld_files.py
index fc80d46c9..c2ac812bc 100755
--- a/tools/gen_ld_files.py
+++ b/tools/gen_ld_files.py
@@ -17,26 +17,39 @@ args = parser.parse_args()
defines = {}
-# We're looking for lines like this:
-# <expression> ///DEFINE_VALUE NAME_OF_VALUE <optional Python lambda expression to transform value>
-VALUE_LINE_RE = re.compile(r'^([^/].*); ///DEFINE_VALUE (\w+)(.*)$')
-
+#
+REMOVE_UL_RE = re.compile('([0-9]+)UL')
+def remove_UL(s):
+ return REMOVE_UL_RE.sub(r'\1', s)
+
+# We skip all lines before
+# // START_LD_DEFINES
+# Then we look for lines like this:
+# /*NAME_OF_VALUE=*/ NAME_OF_VALUE;
+VALUE_LINE_RE = re.compile(r'^/\*\s*(\w+)\s*=\*/\s*(.*);\s*$')
+
+start_processing = False
for line in args.defines:
- match = VALUE_LINE_RE.match(line.strip())
- if match:
- value = match.group(1).strip()
- name = match.group(2)
- lambda_exp = match.group(3).strip()
- # Apply the given lambda to the value if it is present, else just store the value.
- defines[match.group(2)] = eval(lambda_exp)(value) if lambda_exp else value
-
-#print(defines)
+ line = line.strip()
+ if line == '// START_LD_DEFINES':
+ start_processing = True
+ continue
+ if start_processing:
+ match = VALUE_LINE_RE.match(line)
+ if match:
+ name = match.group(1)
+ value = match.group(2).strip()
+ defines[name] = remove_UL(value)
+
fail = False
for template_file in args.template_files:
ld_template_basename = os.path.basename(template_file.name)
ld_pathname = os.path.join(args.out_dir, ld_template_basename.replace('.template.ld', '.ld'))
with open(ld_pathname, 'w') as output:
+ for k,v in defines.items():
+ print('/*', k, '=', v, '*/', file=output)
+ print(file=output)
try:
output.write(Template(template_file.read()).substitute(defines))
except KeyError as e:
diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py
index 21a480f99..5e25528f9 100644
--- a/tools/gen_usb_descriptor.py
+++ b/tools/gen_usb_descriptor.py
@@ -8,6 +8,7 @@ sys.path.append("../../tools/usb_descriptor")
from adafruit_usb_descriptor import audio, audio10, cdc, hid, midi, msc, standard, util
import hid_report_descriptors
+DEFAULT_INTERFACE_NAME = 'CircuitPython'
ALL_DEVICES='CDC,MSC,AUDIO,HID'
ALL_DEVICES_SET=frozenset(ALL_DEVICES.split(','))
DEFAULT_DEVICES='CDC,MSC,AUDIO,HID'
@@ -32,6 +33,9 @@ parser.add_argument('--devices', type=lambda l: tuple(l.split(',')), default=DEF
help='devices to include in descriptor (AUDIO includes MIDI support)')
parser.add_argument('--hid_devices', type=lambda l: tuple(l.split(',')), default=DEFAULT_HID_DEVICES,
help='HID devices to include in HID report descriptor')
+parser.add_argument('--interface_name', type=str,
+ help='The name/prefix to use in the interface descriptions',
+ default=DEFAULT_INTERFACE_NAME)
parser.add_argument('--msc_max_packet_size', type=int, default=64,
help='Max packet size for MSC')
parser.add_argument('--no-renumber_endpoints', dest='renumber_endpoints', action='store_false',
@@ -151,7 +155,7 @@ cdc_comm_interface = standard.InterfaceDescriptor(
bInterfaceClass=cdc.CDC_CLASS_COMM, # Communications Device Class
bInterfaceSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model
bInterfaceProtocol=cdc.CDC_PROTOCOL_NONE,
- iInterface=StringIndex.index("CircuitPython CDC control"),
+ iInterface=StringIndex.index("{} CDC control".format(args.interface_name)),
subdescriptors=[
cdc.Header(
description="CDC comm",
@@ -172,7 +176,7 @@ cdc_comm_interface = standard.InterfaceDescriptor(
cdc_data_interface = standard.InterfaceDescriptor(
description="CDC data",
bInterfaceClass=cdc.CDC_CLASS_DATA,
- iInterface=StringIndex.index("CircuitPython CDC data"),
+ iInterface=StringIndex.index("{} CDC data".format(args.interface_name)),
subdescriptors=[
standard.EndpointDescriptor(
description="CDC data out",
@@ -192,7 +196,7 @@ msc_interfaces = [
bInterfaceClass=msc.MSC_CLASS,
bInterfaceSubClass=msc.MSC_SUBCLASS_TRANSPARENT,
bInterfaceProtocol=msc.MSC_PROTOCOL_BULK,
- iInterface=StringIndex.index("CircuitPython Mass Storage"),
+ iInterface=StringIndex.index("{} Mass Storage".format(args.interface_name)),
subdescriptors=[
standard.EndpointDescriptor(
description="MSC in",
@@ -256,7 +260,7 @@ hid_interfaces = [
bInterfaceClass=hid.HID_CLASS,
bInterfaceSubClass=hid.HID_SUBCLASS_NOBOOT,
bInterfaceProtocol=hid.HID_PROTOCOL_NONE,
- iInterface=StringIndex.index("CircuitPython HID"),
+ iInterface=StringIndex.index("{} HID".format(args.interface_name)),
subdescriptors=[
hid.HIDDescriptor(
description="HID",
@@ -272,9 +276,9 @@ hid_interfaces = [
# USB OUT -> midi_in_jack_emb -> midi_out_jack_ext -> CircuitPython
midi_in_jack_emb = midi.InJackDescriptor(
- description="MIDI PC -> CircuitPython",
+ description="MIDI PC -> {}".format(args.interface_name),
bJackType=midi.JACK_TYPE_EMBEDDED,
- iJack=StringIndex.index("CircuitPython usb_midi.ports[0]"))
+ iJack=StringIndex.index("{} usb_midi.ports[0]".format(args.interface_name)))
midi_out_jack_ext = midi.OutJackDescriptor(
description="MIDI data out to user code.",
bJackType=midi.JACK_TYPE_EXTERNAL,
@@ -287,10 +291,10 @@ midi_in_jack_ext = midi.InJackDescriptor(
bJackType=midi.JACK_TYPE_EXTERNAL,
iJack=0)
midi_out_jack_emb = midi.OutJackDescriptor(
- description="MIDI PC <- CircuitPython",
+ description="MIDI PC <- {}".format(args.interface_name),
bJackType=midi.JACK_TYPE_EMBEDDED,
input_pins=[(midi_in_jack_ext, 1)],
- iJack=StringIndex.index("CircuitPython usb_midi.ports[1]"))
+ iJack=StringIndex.index("{} usb_midi.ports[1]".format(args.interface_name)))
audio_midi_interface = standard.InterfaceDescriptor(
@@ -298,7 +302,7 @@ audio_midi_interface = standard.InterfaceDescriptor(
bInterfaceClass=audio.AUDIO_CLASS_DEVICE,
bInterfaceSubClass=audio.AUDIO_SUBCLASS_MIDI_STREAMING,
bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1,
- iInterface=StringIndex.index("CircuitPython MIDI"),
+ iInterface=StringIndex.index("{} MIDI".format(args.interface_name)),
subdescriptors=[
midi.Header(
jacks_and_elements=[
@@ -309,12 +313,12 @@ audio_midi_interface = standard.InterfaceDescriptor(
],
),
standard.EndpointDescriptor(
- description="MIDI data out to CircuitPython",
+ description="MIDI data out to {}".format(args.interface_name),
bEndpointAddress=args.midi_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK),
midi.DataEndpointDescriptor(baAssocJack=[midi_in_jack_emb]),
standard.EndpointDescriptor(
- description="MIDI data in from CircuitPython",
+ description="MIDI data in from {}".format(args.interface_name),
bEndpointAddress=args.midi_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval = 0x0),
@@ -334,7 +338,7 @@ audio_control_interface = standard.InterfaceDescriptor(
bInterfaceClass=audio.AUDIO_CLASS_DEVICE,
bInterfaceSubClass=audio.AUDIO_SUBCLASS_CONTROL,
bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1,
- iInterface=StringIndex.index("CircuitPython Audio"),
+ iInterface=StringIndex.index("{} Audio".format(args.interface_name)),
subdescriptors=[
cs_ac_interface,
])