|
@@ -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() {
|