Browse Source

USB: use unofficial USB IDs 4680:088x for both USB interfaces

It is nicer to have the same vendor ID on both interfaces, and VID
0x4680 doesn't seem to be officially assigned ;)
H. Peter Anvin 2 years ago
parent
commit
01a9935e87

+ 3 - 1
esp32/Makefile

@@ -9,6 +9,8 @@ GENFILES      = www.zip
 WWW	      = www
 PORT	     ?= /dev/ttyACM2
 
+build_defines = -DBOARD_HAS_PSRAM
+
 BOARD	      = esp32:esp32:esp32s2usb
 ARDUINO_OPTS  = -b $(BOARD) \
 		--warnings all \
@@ -16,7 +18,7 @@ ARDUINO_OPTS  = -b $(BOARD) \
 		--output-dir       ../output \
 		--build-cache-path ../cache \
 		--build-property 'build.flash_size=4MB' \
-		--build-property 'build.defines=-DBOARD_HAS_PSRAM' \
+		--build-property 'build.defines=$(build_defines)' \
 		--build-property 'build.cdc_on_boot=1' \
 		--build-property 'build.msc_on_boot=0' \
 		--build-property 'build.dfu_on_boot=1' \

+ 78 - 0
esp32/max80/main.cpp

@@ -0,0 +1,78 @@
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "esp_task_wdt.h"
+#include "Arduino.h"
+#if (ARDUINO_USB_CDC_ON_BOOT|ARDUINO_USB_MSC_ON_BOOT|ARDUINO_USB_DFU_ON_BOOT) && !ARDUINO_USB_MODE
+#include "USB.h"
+#if ARDUINO_USB_MSC_ON_BOOT
+#include "FirmwareMSC.h"
+#endif
+#endif
+
+#ifndef ARDUINO_LOOP_STACK_SIZE
+#ifndef CONFIG_ARDUINO_LOOP_STACK_SIZE
+#define ARDUINO_LOOP_STACK_SIZE 8192
+#else
+#define ARDUINO_LOOP_STACK_SIZE CONFIG_ARDUINO_LOOP_STACK_SIZE
+#endif
+#endif
+
+TaskHandle_t loopTaskHandle = NULL;
+
+#if CONFIG_AUTOSTART_ARDUINO
+#if CONFIG_FREERTOS_UNICORE
+void yieldIfNecessary(void){
+    static uint64_t lastYield = 0;
+    uint64_t now = millis();
+    if((now - lastYield) > 2000) {
+        lastYield = now;
+        vTaskDelay(5); //delay 1 RTOS tick
+    }
+}
+#endif
+
+bool loopTaskWDTEnabled;
+
+__attribute__((weak)) size_t getArduinoLoopTaskStackSize(void) {
+    return ARDUINO_LOOP_STACK_SIZE;
+}
+
+void loopTask(void *pvParameters)
+{
+    setup();
+    for(;;) {
+#if CONFIG_FREERTOS_UNICORE
+        yieldIfNecessary();
+#endif
+        if(loopTaskWDTEnabled){
+            esp_task_wdt_reset();
+        }
+        loop();
+        if (serialEventRun) serialEventRun();
+    }
+}
+
+extern void setup_usb_ids();
+
+extern "C" void app_main()
+{
+    setup_usb_ids();		/* Local addition */
+
+#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
+    Serial.begin();
+#endif
+#if ARDUINO_USB_MSC_ON_BOOT && !ARDUINO_USB_MODE
+    MSC_Update.begin();
+#endif
+#if ARDUINO_USB_DFU_ON_BOOT && !ARDUINO_USB_MODE
+    USB.enableDFU();
+#endif
+#if ARDUINO_USB_ON_BOOT && !ARDUINO_USB_MODE
+    USB.begin();
+#endif
+    loopTaskWDTEnabled = false;
+    initArduino();
+    xTaskCreateUniversal(loopTask, "loopTask", getArduinoLoopTaskStackSize(), NULL, 1, &loopTaskHandle, ARDUINO_RUNNING_CORE);
+}
+
+#endif

+ 20 - 0
esp32/max80/max80.ino

@@ -11,10 +11,30 @@
 
 #include <freertos/task_snapshot.h>
 #include <esp_heap_caps.h>
+#include <esp_task_wdt.h>
+#include <esp_mac.h>
+#include <USB.h>
 
 #define PIN_USB_PWR_EN		7
 #define PIN_USB_PWR_SINK	8
 
+void setup_usb_ids()
+{
+    uint8_t mac[8];
+    char serial[16];
+
+    esp_efuse_mac_get_default(mac);
+    snprintf(serial, sizeof serial, "%02X%02X%02X-%02X%02X%02X",
+	     mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+
+    USB.VID(0x4680);
+    USB.PID(0x0882);
+    USB.firmwareVersion(1);	// Do something smarter here
+    USB.productName("MAX80 Network Controller");
+    USB.manufacturerName("Peter & Per");
+    USB.serialNumber(serial);
+}
+
 static void dump_config()
 {
     printf("--- Configuration:\n");

BIN
esp32/output/max80.ino.bin


+ 2 - 2
fpga/max80.qpf

@@ -19,12 +19,12 @@
 #
 # Quartus Prime
 # Version 21.1.0 Build 842 10/21/2021 SJ Lite Edition
-# Date created = 02:29:56  May 20, 2022
+# Date created = 18:01:47  May 25, 2022
 #
 # -------------------------------------------------------------------------- #
 
 QUARTUS_VERSION = "21.1"
-DATE = "02:29:56  May 20, 2022"
+DATE = "18:01:47  May 25, 2022"
 
 # Revisions
 

BIN
fpga/output/v1.fw


BIN
fpga/output/v1.jic


BIN
fpga/output/v1.rbf.gz


BIN
fpga/output/v1.rpd.gz


BIN
fpga/output/v1.sof


BIN
fpga/output/v1.svf.gz


BIN
fpga/output/v1.xsvf.gz


BIN
fpga/output/v2.fw


BIN
fpga/output/v2.jic


BIN
fpga/output/v2.rbf.gz


BIN
fpga/output/v2.rpd.gz


BIN
fpga/output/v2.sof


BIN
fpga/output/v2.svf.gz


BIN
fpga/output/v2.xsvf.gz


+ 2 - 2
fpga/usb/usb_desc.conf

@@ -7,8 +7,8 @@ require '../../iodevs.conf';
 
 usb_languages('en_US', 'sv_SE');
 
-my $vendor_id    = word(0x1d50);
-my $device_id    = word(0x6149);
+my $vendor_id    = word(0x4680); # was: word(0x1d50); [OpenMoko]
+my $device_id    = word(0x0881); # was: word(0x6149); [free public allocations]
 my $version_id   = word(0x0100);
 
 my $serial       = usb_serial('SerialNumberHere'); # 16 characters

+ 4 - 4
fpga/usb/usb_desc.v

@@ -60,10 +60,10 @@ module usb_desc_rom (
 		rom[9'h027] = 8'h00;
 		rom[9'h028] = 8'h00;
 		rom[9'h029] = 8'h08;
-		rom[9'h02a] = 8'h50;
-		rom[9'h02b] = 8'h1d;
-		rom[9'h02c] = 8'h49;
-		rom[9'h02d] = 8'h61;
+		rom[9'h02a] = 8'h80;
+		rom[9'h02b] = 8'h46;
+		rom[9'h02c] = 8'h81;
+		rom[9'h02d] = 8'h08;
 		rom[9'h02e] = 8'h00;
 		rom[9'h02f] = 8'h01;
 		rom[9'h030] = 8'h02;