Skip to content

Commit 4b827b2

Browse files
authored
Merge pull request #2966 from sommersoft/ci_check_vid_pid
Automate USB VID/PID Uniqueness Check
2 parents 9cf9441 + 95e27bb commit 4b827b2

File tree

18 files changed

+164
-16
lines changed

18 files changed

+164
-16
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ jobs:
9191
- name: New boards check
9292
run: python3 -u ci_new_boards_check.py
9393
working-directory: tools
94+
- name: Duplicate USB VID/PID Check
95+
run: python3 -u -m tools.ci_check_duplicate_usb_vid_pid
9496
- name: Build mpy-cross.static-raspbian
9597
run: make -C mpy-cross -j2 -f Makefile.static-raspbian
9698
- uses: actions/upload-artifact@v2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x8015
2+
USB_PID = 0x80D3
33
USB_PRODUCT = "Feather M0 Adalogger"
44
USB_MANUFACTURER = "Adafruit Industries LLC"
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x8023
2+
USB_PID = 0x80D1
33
USB_PRODUCT = "Feather M0 Express"
44
USB_MANUFACTURER = "Adafruit Industries LLC"
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x8015
2+
USB_PID = 0x80D2
33
USB_PRODUCT = "Feather M0 RFM69"
44
USB_MANUFACTURER = "Adafruit Industries LLC"
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x8015
2+
USB_PID = 0x80D4
33
USB_PRODUCT = "Feather M0 RFM9x"
44
USB_MANUFACTURER = "Adafruit Industries LLC"
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x8023
2+
USB_PID = 0x80D0
33
USB_PRODUCT = "Feather RadioFruit Zigbee"
44
USB_MANUFACTURER = "Adafruit Industries LLC"
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x801D
2+
USB_PID = 0x80D5
33
USB_PRODUCT = "PewPew 10.2"
44
USB_MANUFACTURER = "Radomir Dopieralski"
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x801F
2+
USB_PID = 0x80AF
33
USB_PRODUCT = "uGame10"
44
USB_MANUFACTURER = "Radomir Dopieralski"
55

ports/nrf/boards/TG-Watch02A/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x802A
2+
USB_PID = 0x80DB
33
USB_PRODUCT = "TG-Watch02A"
44
USB_MANUFACTURER = "TG-Tech"
55

ports/nrf/boards/electronut_labs_blip/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x803C
2+
USB_PID = 0x80D7
33
USB_PRODUCT = "Blip"
44
USB_MANUFACTURER = "Electronut Labs"
55

ports/nrf/boards/makerdiary_nrf52840_mdk/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x802A
2+
USB_PID = 0x80DC
33
USB_PRODUCT = "nRF52840-MDK"
44
USB_MANUFACTURER = "makerdiary"
55

ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x802A
2+
USB_PID = 0x80DD
33
USB_PRODUCT = "nRF52840-MDK-Dongle"
44
USB_MANUFACTURER = "makerdiary"
55

ports/nrf/boards/pca10056/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x802A
2+
USB_PID = 0x80DA
33
USB_PRODUCT = "PCA10056"
44
USB_MANUFACTURER = "Nordic Semiconductor"
55

ports/nrf/boards/pca10059/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x802A
2+
USB_PID = 0x80D9
33
USB_PRODUCT = "PCA10059"
44
USB_MANUFACTURER = "Nordic Semiconductor"
55

ports/nrf/boards/pca10100/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x802A
2+
USB_PID = 0x80D8
33
USB_PRODUCT = "PCA10100"
44
USB_MANUFACTURER = "Nordic Semiconductor"
55

ports/stm/boards/meowbit_v121/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x805A
2+
USB_PID = 0x80CF
33
USB_PRODUCT = "Meowbit"
44
USB_MANUFACTURER = "Kittenbot"
55

ports/stm/boards/thunderpack/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_VID = 0x239A
2-
USB_PID = 0x806A
2+
USB_PID = 0x8069
33
USB_PRODUCT = "Thunderpack STM32F411"
44
USB_MANUFACTURER = "Jeremy Gillick"
55

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/usr/bin/env python3
2+
#
3+
# This file is part of the MicroPython project, http://micropython.org/
4+
#
5+
# The MIT License (MIT)
6+
#
7+
# Copyright (c) 2020 Michael Schroeder
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in
17+
# all copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
# THE SOFTWARE.
26+
27+
import argparse
28+
import pathlib
29+
import re
30+
import sys
31+
32+
DEFAULT_IGNORELIST = [
33+
"circuitplayground_express",
34+
"circuitplayground_express_crickit",
35+
"circuitplayground_express_displayio",
36+
"pycubed",
37+
"pycubed_mram",
38+
"pygamer",
39+
"pygamer_advance",
40+
"trinket_m0",
41+
"trinket_m0_haxpress",
42+
"sparkfun_qwiic_micro_with_flash",
43+
"sparkfun_qwiic_micro_no_flash",
44+
"feather_m0_express",
45+
"feather_m0_supersized",
46+
"cp32-m4",
47+
"metro_m4_express"
48+
]
49+
50+
cli_parser = argparse.ArgumentParser(description="USB VID/PID Duplicate Checker")
51+
cli_parser.add_argument(
52+
"--ignorelist",
53+
dest="ignorelist",
54+
nargs="?",
55+
action="store",
56+
default=DEFAULT_IGNORELIST,
57+
help=(
58+
"Board names to ignore duplicate VID/PID combinations. Pass an empty "
59+
"string to disable all duplicate ignoring. Defaults are: "
60+
f"{', '.join(DEFAULT_IGNORELIST)}"
61+
)
62+
)
63+
64+
def configboard_files():
65+
""" A pathlib glob search for all ports/*/boards/*/mpconfigboard.mk file
66+
paths.
67+
68+
:returns: A ``pathlib.Path.glob()`` genarator object
69+
"""
70+
working_dir = pathlib.Path().resolve()
71+
if not working_dir.name.startswith("circuitpython"):
72+
raise RuntimeError(
73+
"Please run USB VID/PID duplicate verification at the "
74+
"top-level directory."
75+
)
76+
return working_dir.glob("ports/**/boards/**/mpconfigboard.mk")
77+
78+
def check_vid_pid(files, ignorelist):
79+
""" Compiles a list of USB VID & PID values for all boards, and checks
80+
for duplicates. Exits with ``sys.exit()`` (non-zero exit code)
81+
if duplicates are found, and lists the duplicates.
82+
"""
83+
84+
duplicates_found = False
85+
86+
usb_ids = {}
87+
88+
vid_pattern = re.compile(r"^USB_VID\s*\=\s*(.*)", flags=re.M)
89+
pid_pattern = re.compile(r"^USB_PID\s*\=\s*(.*)", flags=re.M)
90+
91+
for board_config in files:
92+
src_text = board_config.read_text()
93+
94+
usb_vid = vid_pattern.search(src_text)
95+
usb_pid = pid_pattern.search(src_text)
96+
97+
board_name = board_config.parts[-2]
98+
99+
board_ignorelisted = False
100+
if board_name in ignorelist:
101+
board_ignorelisted = True
102+
board_name += " (ignorelisted)"
103+
104+
if usb_vid and usb_pid:
105+
id_group = f"{usb_vid.group(1)}:{usb_pid.group(1)}"
106+
if id_group not in usb_ids:
107+
usb_ids[id_group] = {
108+
"boards": [board_name],
109+
"duplicate": False
110+
}
111+
else:
112+
usb_ids[id_group]['boards'].append(board_name)
113+
if not board_ignorelisted:
114+
usb_ids[id_group]['duplicate'] = True
115+
duplicates_found = True
116+
117+
if duplicates_found:
118+
duplicates = ""
119+
for key, value in usb_ids.items():
120+
if value["duplicate"]:
121+
duplicates += (
122+
f"- VID/PID: {key}\n"
123+
f" Boards: {', '.join(value['boards'])}\n"
124+
)
125+
126+
duplicate_message = (
127+
f"Duplicate VID/PID usage found!\n{duplicates}\n"
128+
f"If you are open source maker, then you can request a PID from http://pid.codes\n"
129+
f"Otherwise, companies should pay the USB-IF for a vendor ID: https://www.usb.org/getting-vendor-id"
130+
)
131+
sys.exit(duplicate_message)
132+
else:
133+
print("No USB PID duplicates found.")
134+
135+
136+
if __name__ == "__main__":
137+
arguments = cli_parser.parse_args()
138+
139+
print("Running USB VID/PID Duplicate Checker...")
140+
print(
141+
f"Ignoring the following boards: {', '.join(arguments.ignorelist)}",
142+
end="\n\n"
143+
)
144+
145+
board_files = configboard_files()
146+
check_vid_pid(board_files, arguments.ignorelist)

0 commit comments

Comments
 (0)