From 932acd3048f7b171d5dc7829fcbcea63b5cc1bea Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 25 Jan 2019 19:02:01 -0500 Subject: [PATCH] usbserial: Allow USB ids to be specified via Kconfig Signed-off-by: Kevin O'Connor --- src/Kconfig | 16 ++++++++++++++++ src/generic/usb_cdc.c | 12 +++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Kconfig b/src/Kconfig index f667dae4..6f98b8c8 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -47,6 +47,22 @@ config SERIAL_BAUD Specify the baud rate of the serial port. This should be set to 250000. Read the FAQ before changing this value. +# Generic configuration options for USB +menu "USB ids" + depends on USBSERIAL + +config USB_VENDOR_ID + hex "USB vendor ID" + default 0x2341 +config USB_DEVICE_ID + hex "USB device ID" + default 0xabcd +config USB_SERIAL_NUMBER + string "USB serial number" + default "12345" + +endmenu + # Step timing customization config CUSTOM_STEP_DELAY bool "Specify a custom step pulse duration" diff --git a/src/generic/usb_cdc.c b/src/generic/usb_cdc.c index 878cc857..c995db49 100644 --- a/src/generic/usb_cdc.c +++ b/src/generic/usb_cdc.c @@ -5,6 +5,7 @@ // This file may be distributed under the terms of the GNU GPLv3 license. #include // memmove +#include "autoconf.h" // CONFIG_USB_VENDOR_ID #include "board/pgm.h" // PROGMEM #include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN #include "byteorder.h" // cpu_to_le16 @@ -14,10 +15,6 @@ #include "sched.h" // sched_wake_task #include "usb_cdc.h" // usb_notify_ep0 -// XXX - move to Kconfig -#define CONFIG_USB_VENDOR_ID 0x2341 -#define CONFIG_USB_PRODUCT_ID 0xabcd - /**************************************************************** * Message block sending @@ -124,10 +121,11 @@ DECL_TASK(usb_bulk_out_task); * USB descriptors ****************************************************************/ -// XXX - move to Kconfig +#define CONCAT1(a, b) a ## b +#define CONCAT(a, b) CONCAT1(a, b) #define USB_STR_MANUFACTURER u"Klipper" #define USB_STR_PRODUCT u"Klipper firmware" -#define USB_STR_SERIAL u"12345" +#define USB_STR_SERIAL CONCAT(u,CONFIG_USB_SERIAL_NUMBER) // String descriptors enum { @@ -177,7 +175,7 @@ static const struct usb_device_descriptor cdc_device_descriptor PROGMEM = { .bDeviceClass = USB_CLASS_COMM, .bMaxPacketSize0 = USB_CDC_EP0_SIZE, .idVendor = cpu_to_le16(CONFIG_USB_VENDOR_ID), - .idProduct = cpu_to_le16(CONFIG_USB_PRODUCT_ID), + .idProduct = cpu_to_le16(CONFIG_USB_DEVICE_ID), .bcdDevice = cpu_to_le16(0x0100), .iManufacturer = USB_STR_ID_MANUFACTURER, .iProduct = USB_STR_ID_PRODUCT,