浏览代码

esp32: at least try to detect the board version

Try to detect the board version without help from the FPGA by
probing for a pulldown resistor on USB_PWR_EN. Not exactly elegant,
but...
H. Peter Anvin 2 年之前
父节点
当前提交
e54fd66885
共有 5 个文件被更改,包括 36 次插入11 次删除
  1. 6 0
      esp32/max80/common.h
  2. 30 11
      esp32/max80/max80.ino
  3. 二进制
      esp32/output/max80.ino.bin
  4. 二进制
      fpga/output/v1.fw
  5. 二进制
      fpga/output/v2.fw

+ 6 - 0
esp32/max80/common.h

@@ -61,3 +61,9 @@ static inline void suspend(void)
  */
 extern_c void reboot_now(void);
 extern_c int reboot_delayed(void);
+
+/*
+ * Board version
+ */
+extern_c uint8_t max80_board_version;
+

+ 30 - 11
esp32/max80/max80.ino

@@ -12,12 +12,8 @@
 #include <freertos/task_snapshot.h>
 #include <esp_heap_caps.h>
 
-// On board v1, IO7 is N/C.
-// On board v2, IO7 is USB_PWR_EN and has a 36k pulldown.
-static int get_board_version()
-{
-    return 2;			// For now
-}
+#define PIN_USB_PWR_EN		7
+#define PIN_USB_PWR_SINK	8
 
 static void dump_config()
 {
@@ -26,17 +22,38 @@ static void dump_config()
     printf("--- End configuration\n");
 }
 
+uint8_t max80_board_version;
+
 static void init_hw()
 {
     // Start out with disabled shared I/O pins
     for (int i = 1; i <= 18; i++)
 	pinMode(i, INPUT);
 
-    // Configure USB power control
-    pinMode(7, OUTPUT);		// USB_PWR_EN
-    digitalWrite(7, 1);		// Disable power sourcing
-    pinMode(8, OUTPUT);		// USB_PWR_SINK
-    digitalWrite(8, 0);		// This is a power sink
+    // Configure USB power control. Try to detect 36k pulldown
+    // resistor on USB_PWR_EN first, to determine board version 2
+    // (on board v1, this pin in N/C.)
+    //
+    // This detection algorithm is sketchy at best. In the end the
+    // better option probably would be to use the ADC mode of the input
+    // pin...
+    pinMode(PIN_USB_PWR_SINK, OUTPUT);		// IO8: USB_PWR_SINK
+    digitalWrite(PIN_USB_PWR_SINK, 0);		// This is a power sink
+
+    pinMode(PIN_USB_PWR_EN, OUTPUT);
+    digitalWrite(PIN_USB_PWR_EN, 0);
+    delayMicroseconds(100);
+
+    pinMode(PIN_USB_PWR_EN, INPUT_PULLUP);
+    delayMicroseconds(50);
+
+    pinMode(PIN_USB_PWR_EN, INPUT);
+    delayMicroseconds(50);
+
+    max80_board_version = digitalRead(PIN_USB_PWR_EN) ? 1 : 2;
+
+    pinMode(PIN_USB_PWR_EN, OUTPUT);
+    digitalWrite(PIN_USB_PWR_EN, 0);
 
     // Configure LEDs
     led_init();
@@ -44,6 +61,8 @@ static void init_hw()
 
     // Enable external PSRAM for heap
     heap_caps_malloc_extmem_enable(2048); // >= 2K allocations in PSRAM
+
+    printf("[PCB]  MAX80 board version: %u\n", max80_board_version);
 }
 
 void setup() {

二进制
esp32/output/max80.ino.bin


二进制
fpga/output/v1.fw


二进制
fpga/output/v2.fw