From dadf22f07a97536aa00daa410ac82962974e858a Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Mon, 5 Dec 2022 11:13:21 +0100 Subject: [PATCH] boards/arduino-mega2560: add TTY_BOARD_FILTER This allows automatically selecting TTY actually belonging to an Arduino Mega2560 if `MOST_RECENT_PORT=1` is set. Note: Unless `ARDUINO_MEGA2560_COMPAT_WITH_CLONES` is set to `0`, this will fall back to detecting any cheap USB UART bridge typically found in Arduino Mega 2560 clones if no genuine Arduino Mega is found. --- boards/arduino-mega2560/Makefile.include | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/boards/arduino-mega2560/Makefile.include b/boards/arduino-mega2560/Makefile.include index c8e3852dbc..f8c28919ff 100644 --- a/boards/arduino-mega2560/Makefile.include +++ b/boards/arduino-mega2560/Makefile.include @@ -3,4 +3,34 @@ BAUD ?= 9600 ARDUINO_MEGA2560_BOOTLOADER ?= stk500v2 +# If port selection via ttys.py is enabled by `MOST_RECENT_PORT=1`, filter +# USB serials to only select boards that identify as Arduino Mega 2560 or +# ad Arduino Mega ADK (a special official Mega flavor that is compatible) +TTY_BOARD_FILTER := --vendor 'Arduino' --model-db 'Mega 2560|Mega ADK' + +# Same, but for clones using a cheap USB <--> UART chip rather than the +# ATmega16U2 +TTY_BOARD_FILTER_CLONE := --driver 'cp210x|ch341' + +# If set to 1, auto-detection of TTYs will also allow clones. This has a slight +# disadvantage for users of genuine Arduino Mega 2560: If the board is not +# plugged in, it will fall back to a detection that may yield false positives. +# However, most people will plug in their boards correctly prior to typing +# `make term`, so this is only a small loss for users of genuine +# Arduino Mega 2560 but a big win for users of cheap clones. Still, users that +# only will ever use genuine Arduino Mega 2560 boards can disable this via their +# .profile or .bashrc if they want. +ARDUINO_MEGA2560_COMPAT_WITH_CLONES ?= 1 + +ifeq (1,$(ARDUINO_MEGA2560_COMPAT_WITH_CLONES)) + TTY_SELECT_CMD := $(RIOTTOOLS)/usb-serial/ttys.py \ + --most-recent \ + --format path \ + $(TTY_BOARD_FILTER) || \ + $(RIOTTOOLS)/usb-serial/ttys.py \ + --most-recent \ + --format path \ + $(TTY_BOARD_FILTER_CLONE) +endif + include $(RIOTBOARD)/common/arduino-atmega/Makefile.include