Skip to content

Commit bc926b0

Browse files
authored
Merge pull request #6629 from Neradoc/board-extensions-in-boards-dir
Build extensions in mpconfigport and mpconfigboard
2 parents 562cbb1 + 6e5c818 commit bc926b0

File tree

34 files changed

+158
-130
lines changed

34 files changed

+158
-130
lines changed

conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
#modules_support_matrix = shared_bindings_matrix.support_matrix_excluded_boards()
5353
modules_support_matrix = shared_bindings_matrix.support_matrix_by_board()
5454
modules_support_matrix_reverse = defaultdict(list)
55-
for board, modules in modules_support_matrix.items():
56-
for module in modules[0]:
55+
for board, matrix_info in modules_support_matrix.items():
56+
for module in matrix_info["modules"]:
5757
modules_support_matrix_reverse[module].append(board)
5858

5959
modules_support_matrix_reverse = dict(

docs/shared_bindings_matrix.py

Lines changed: 76 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
SUPPORTED_PORTS = ['atmel-samd', 'broadcom', 'cxd56', 'espressif', 'litex', 'mimxrt10xx', 'nrf', 'raspberrypi', 'stm']
3434

35-
aliases_by_board = {
35+
ALIASES_BY_BOARD = {
3636
"circuitplayground_express": [
3737
"circuitplayground_express_4h",
3838
"circuitplayground_express_digikey_pycon2019",
@@ -43,7 +43,7 @@
4343
"pewpew10": ["pewpew13"],
4444
}
4545

46-
aliases_brand_names = {
46+
ALIASES_BRAND_NAMES = {
4747
"circuitplayground_express_4h":
4848
"Adafruit Circuit Playground Express 4-H",
4949
"circuitplayground_express_digikey_pycon2019":
@@ -58,36 +58,64 @@
5858
"PewPew 13",
5959
}
6060

61-
additional_modules = {
61+
ADDITIONAL_MODULES = {
6262
"fontio": "CIRCUITPY_DISPLAYIO",
6363
"terminalio": "CIRCUITPY_DISPLAYIO",
6464
"adafruit_bus_device": "CIRCUITPY_BUSDEVICE",
6565
"adafruit_pixelbuf": "CIRCUITPY_PIXELBUF",
6666
"usb": "CIRCUITPY_USB_HOST",
6767
}
6868

69-
frozen_excludes = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"]
69+
FROZEN_EXCLUDES = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"]
7070
"""Files and dirs at the root of a frozen directory that should be ignored.
7171
This is the same list as in the preprocess_frozen_modules script."""
7272

7373
repository_urls = {}
7474
"""Cache of repository URLs for frozen modules."""
7575

7676
def get_circuitpython_root_dir():
77-
""" The path to the root './circuitpython' directory
77+
""" The path to the root './circuitpython' directory.
7878
"""
7979
file_path = pathlib.Path(__file__).resolve()
8080
root_dir = file_path.parent.parent
8181

8282
return root_dir
8383

8484
def get_shared_bindings():
85-
""" Get a list of modules in shared-bindings based on folder names
85+
""" Get a list of modules in shared-bindings based on folder names.
8686
"""
8787
shared_bindings_dir = get_circuitpython_root_dir() / "shared-bindings"
8888
return [item.name for item in shared_bindings_dir.iterdir()] + ["binascii", "errno", "json", "re", "ulab"]
8989

9090

91+
def get_board_mapping():
92+
"""
93+
Compiles the list of boards from the directories, with aliases and mapping
94+
to the port.
95+
"""
96+
boards = {}
97+
for port in SUPPORTED_PORTS:
98+
board_path = os.path.join("../ports", port, "boards")
99+
for board_path in os.scandir(board_path):
100+
if board_path.is_dir():
101+
board_files = os.listdir(board_path.path)
102+
board_id = board_path.name
103+
aliases = ALIASES_BY_BOARD.get(board_path.name, [])
104+
boards[board_id] = {
105+
"port": port,
106+
"download_count": 0,
107+
"aliases": aliases,
108+
}
109+
for alias in aliases:
110+
boards[alias] = {
111+
"port": port,
112+
"download_count": 0,
113+
"alias": True,
114+
"aliases": [],
115+
}
116+
return boards
117+
118+
91119
def read_mpconfig():
92120
""" Open 'circuitpy_mpconfig.mk' and return the contents.
93121
"""
@@ -112,8 +140,8 @@ def build_module_map():
112140
full_build = False
113141
for module in modules:
114142
full_name = module
115-
if module in additional_modules:
116-
search_identifier = additional_modules[module]
143+
if module in ADDITIONAL_MODULES:
144+
search_identifier = ADDITIONAL_MODULES[module]
117145
else:
118146
search_identifier = 'CIRCUITPY_'+module.lstrip("_").upper()
119147
re_pattern = f"{re.escape(search_identifier)}\s*\??=\s*(.+)"
@@ -204,27 +232,33 @@ def get_repository_url(directory):
204232
repository_urls[directory] = path
205233
return path
206234

207-
def frozen_modules_from_dirs(frozen_mpy_dirs):
235+
def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
208236
"""
209237
Go through the list of frozen directories and extract the python modules.
210238
Paths are of the type:
211239
$(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground
212240
$(TOP)/frozen/circuitpython-stage/meowbit
213241
Python modules are at the root of the path, and are python files or directories
214-
containing python files. Except the ones in the frozen_excludes list.
242+
containing python files. Except the ones in the FROZEN_EXCLUDES list.
215243
"""
216244
frozen_modules = []
217245
for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")):
218246
source_dir = get_circuitpython_root_dir() / frozen_path[7:]
219247
url_repository = get_repository_url(source_dir)
220248
for sub in source_dir.glob("*"):
221-
if sub.name in frozen_excludes:
249+
if sub.name in FROZEN_EXCLUDES:
222250
continue
223251
if sub.name.endswith(".py"):
224-
frozen_modules.append((sub.name[:-3], url_repository))
252+
if withurl:
253+
frozen_modules.append((sub.name[:-3], url_repository))
254+
else:
255+
frozen_modules.append(sub.name[:-3])
225256
continue
226257
if next(sub.glob("**/*.py"), None): # tests if not empty
227-
frozen_modules.append((sub.name, url_repository))
258+
if withurl:
259+
frozen_modules.append((sub.name, url_repository))
260+
else:
261+
frozen_modules.append(sub.name)
228262
return frozen_modules
229263

230264
def lookup_setting(settings, key, default=''):
@@ -244,7 +278,7 @@ def all_ports_all_boards(ports=SUPPORTED_PORTS):
244278
continue
245279
yield (port, entry)
246280

247-
def support_matrix_by_board(use_branded_name=True):
281+
def support_matrix_by_board(use_branded_name=True, withurl=True):
248282
""" Compiles a list of the available core modules available for each
249283
board.
250284
"""
@@ -272,29 +306,49 @@ def support_matrix(arg):
272306
board_modules.append(base[module]['name'])
273307
board_modules.sort()
274308

309+
if "CIRCUITPY_BUILD_EXTENSIONS" in settings:
310+
board_extensions = [
311+
extension.strip() for extension in
312+
settings["CIRCUITPY_BUILD_EXTENSIONS"].split(",")
313+
]
314+
else:
315+
raise OSError(f"Board extensions undefined: {board_name}.")
316+
275317
frozen_modules = []
276318
if "FROZEN_MPY_DIRS" in settings:
277-
frozen_modules = frozen_modules_from_dirs(settings["FROZEN_MPY_DIRS"])
319+
frozen_modules = frozen_modules_from_dirs(settings["FROZEN_MPY_DIRS"], withurl)
278320
if frozen_modules:
279321
frozen_modules.sort()
280322

281323
# generate alias boards too
282-
board_matrix = [(board_name, (board_modules, frozen_modules))]
283-
if entry.name in aliases_by_board:
284-
for alias in aliases_by_board[entry.name]:
324+
board_matrix = [(
325+
board_name, {
326+
"modules": board_modules,
327+
"frozen_libraries": frozen_modules,
328+
"extensions": board_extensions,
329+
}
330+
)]
331+
if entry.name in ALIASES_BY_BOARD:
332+
for alias in ALIASES_BY_BOARD[entry.name]:
285333
if use_branded_name:
286-
if alias in aliases_brand_names:
287-
alias = aliases_brand_names[alias]
334+
if alias in ALIASES_BRAND_NAMES:
335+
alias = ALIASES_BRAND_NAMES[alias]
288336
else:
289337
alias = alias.replace("_"," ").title()
290-
board_matrix.append( (alias, (board_modules, frozen_modules)) )
338+
board_matrix.append((
339+
alias, {
340+
"modules": board_modules,
341+
"frozen_libraries": frozen_modules,
342+
"extensions": board_extensions,
343+
},
344+
))
291345

292346
return board_matrix # this is now a list of (board,modules)
293347

294348
executor = ThreadPoolExecutor(max_workers=os.cpu_count())
295349
mapped_exec = executor.map(support_matrix, all_ports_all_boards())
296350
# flatmap with comprehensions
297-
boards = dict(sorted([board for matrix in mapped_exec for board in matrix]))
351+
boards = dict(sorted([board for matrix in mapped_exec for board in matrix], key=lambda x: x[0]))
298352

299353
return boards
300354

ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ USB_MANUFACTURER = "Arduino"
66
CHIP_VARIANT = SAMD21G18A
77
CHIP_FAMILY = samd21
88

9+
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
10+
911
INTERNAL_FLASH_FILESYSTEM = 1
1012
LONGINT_IMPL = NONE
1113
CIRCUITPY_FULL_BUILD = 0

ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ USB_MANUFACTURER = "Arduino"
66
CHIP_VARIANT = SAMD21G18A
77
CHIP_FAMILY = samd21
88

9+
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
10+
911
INTERNAL_FLASH_FILESYSTEM = 1
1012
LONGINT_IMPL = NONE
1113
CIRCUITPY_FULL_BUILD = 0

ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ USB_MANUFACTURER = "Arduino"
66
CHIP_VARIANT = SAMD21G18A
77
CHIP_FAMILY = samd21
88

9+
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
10+
911
INTERNAL_FLASH_FILESYSTEM = 1
1012
LONGINT_IMPL = NONE
1113
CIRCUITPY_FULL_BUILD = 0

ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ USB_MANUFACTURER = "Arduino"
66
CHIP_VARIANT = SAMD21G18A
77
CHIP_FAMILY = samd21
88

9+
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
10+
911
INTERNAL_FLASH_FILESYSTEM = 1
1012
LONGINT_IMPL = NONE
1113
CIRCUITPY_FULL_BUILD = 0

ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ USB_MANUFACTURER = "Adafruit Industries LLC"
66
CHIP_VARIANT = SAMD21G18A
77
CHIP_FAMILY = samd21
88

9+
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
10+
911
INTERNAL_FLASH_FILESYSTEM = 1
1012
LONGINT_IMPL = NONE
1113
CIRCUITPY_FULL_BUILD = 0

ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ USB_MANUFACTURER = "Adafruit Industries LLC"
66
CHIP_VARIANT = SAMD21G18A
77
CHIP_FAMILY = samd21
88

9+
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
10+
911
INTERNAL_FLASH_FILESYSTEM = 1
1012
LONGINT_IMPL = NONE
1113
CIRCUITPY_FULL_BUILD = 0

ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ USB_MANUFACTURER = "Adafruit Industries LLC"
66
CHIP_VARIANT = SAMD21G18A
77
CHIP_FAMILY = samd21
88

9+
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
10+
911
INTERNAL_FLASH_FILESYSTEM = 1
1012
LONGINT_IMPL = NONE
1113
CIRCUITPY_FULL_BUILD = 0

ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ USB_MANUFACTURER = "Adafruit Industries LLC"
66
CHIP_VARIANT = SAMD21G18A
77
CHIP_FAMILY = samd21
88

9+
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
10+
911
INTERNAL_FLASH_FILESYSTEM = 1
1012
LONGINT_IMPL = NONE
1113
CIRCUITPY_FULL_BUILD = 0

ports/atmel-samd/boards/uchip/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ USB_MANUFACTURER = "Itaca Innovation"
66
CHIP_VARIANT = SAMD21E18A
77
CHIP_FAMILY = samd21
88

9+
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
10+
911
INTERNAL_FLASH_FILESYSTEM = 1
1012
LONGINT_IMPL = NONE
1113
CIRCUITPY_FULL_BUILD = 0

ports/atmel-samd/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,5 @@ CIRCUITPY_RGBMATRIX ?= $(CIRCUITPY_FRAMEBUFFERIO)
133133

134134
endif # same51
135135
######################################################################
136+
137+
CIRCUITPY_BUILD_EXTENSIONS ?= uf2

ports/broadcom/boards/raspberrypi_zero/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ USB_PRODUCT = "Zero"
44
USB_MANUFACTURER = "Raspberry Pi"
55

66
CHIP_VARIANT = "bcm2835"
7+
8+
CIRCUITPY_BUILD_EXTENSIONS = disk.img.zip,kernel.img

ports/broadcom/boards/raspberrypi_zero_w/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ USB_PRODUCT = "Zero W"
44
USB_MANUFACTURER = "Raspberry Pi"
55

66
CHIP_VARIANT = "bcm2835"
7+
8+
CIRCUITPY_BUILD_EXTENSIONS = disk.img.zip,kernel.img

ports/broadcom/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ INTERNAL_FLASH_FILESYSTEM = 1
2424

2525
USB_NUM_ENDPOINT_PAIRS = 8
2626
USB_HIGHSPEED = 1
27+
28+
CIRCUITPY_BUILD_EXTENSIONS ?= disk.img.zip,kernel8.img

ports/cxd56/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ CIRCUITPY_TOUCHIO = 0
2525
CIRCUITPY_USB_HID = 0
2626
CIRCUITPY_USB_MIDI = 0
2727
INTERNAL_LIBM = 1
28+
29+
CIRCUITPY_BUILD_EXTENSIONS ?= spk

ports/espressif/mpconfigport.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CIRCUITPY_PARALLELDISPLAY = 0
4040
# Protomatter needs to support ESP32.
4141
CIRCUITPY_RGBMATRIX = 0
4242
CIRCUITPY_USB = 0
43+
CIRCUITPY_BUILD_EXTENSIONS ?= bin
4344

4445
else ifeq ($(IDF_TARGET),esp32c3)
4546
CIRCUITPY_AESIO = 0
@@ -57,17 +58,20 @@ CIRCUITPY_ROTARYIO = 0
5758
CIRCUITPY_TOUCHIO ?= 1
5859
CIRCUITPY_TOUCHIO_USE_NATIVE = 0
5960
CIRCUITPY_USB = 0
61+
CIRCUITPY_BUILD_EXTENSIONS ?= bin
6062

6163
else ifeq ($(IDF_TARGET),esp32s3)
6264
CIRCUITPY_BLEIO = 1
6365
CIRCUITPY_BLEIO_HCI = 0
6466
CIRCUITPY_IMAGECAPTURE = 0
6567
CIRCUITPY_PARALLELDISPLAY = 0
68+
CIRCUITPY_BUILD_EXTENSIONS ?= bin,uf2
6669

6770
else ifeq ($(IDF_TARGET),esp32s2)
6871
# No BLE on S2
6972
CIRCUITPY_BLEIO = 0
7073
CIRCUITPY_BLEIO_HCI = 0
74+
CIRCUITPY_BUILD_EXTENSIONS ?= bin,uf2
7175
endif
7276

7377
# From ESP32-S2/S3 Technical Reference Manual:

ports/litex/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ CIRCUITPY_SDCARDIO = 0
2929
# Enable USB support
3030
CIRCUITPY_USB_HID = 1
3131
CIRCUITPY_USB_MIDI = 1
32+
33+
CIRCUITPY_BUILD_EXTENSIONS ?= dfu

ports/mimxrt10xx/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ CIRCUITPY_PULSEIO = 0
2121
CIRCUITPY_ROTARYIO = 0
2222
CIRCUITPY_USB_MIDI = 1
2323
LONGINT_IMPL = MPZ
24+
25+
CIRCUITPY_BUILD_EXTENSIONS ?= hex,uf2

ports/nrf/boards/electronut_labs_blip/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ USB_MANUFACTURER = "Electronut Labs"
55

66
MCU_CHIP = nrf52840
77

8+
CIRCUITPY_BUILD_EXTENSIONS = hex
9+
810
INTERNAL_FLASH_FILESYSTEM = 1
911
CIRCUITPY_AUDIOIO = 0
1012
CIRCUITPY_DISPLAYIO = 1

ports/nrf/boards/makerdiary_nrf52840_mdk/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ USB_MANUFACTURER = "makerdiary"
55

66
MCU_CHIP = nrf52840
77

8+
CIRCUITPY_BUILD_EXTENSIONS = hex
9+
810
QSPI_FLASH_FILESYSTEM = 1
911
EXTERNAL_FLASH_DEVICES = "MX25R6435F"

ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ USB_MANUFACTURER = "makerdiary"
55

66
MCU_CHIP = nrf52840
77

8+
CIRCUITPY_BUILD_EXTENSIONS = hex,uf2
9+
810
INTERNAL_FLASH_FILESYSTEM = 1

ports/nrf/boards/microbit_v2/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ CIRCUITPY_CREATION_ID = 0x80D8
33

44
MCU_CHIP = nrf52833
55

6+
CIRCUITPY_BUILD_EXTENSIONS = combined.hex
7+
68
INTERNAL_FLASH_FILESYSTEM = 1
79

810
# USB pins aren't used.

0 commit comments

Comments
 (0)