Implement dynamic hardware auto-detection in board_config.py to support both Hosyond and Waveshare RLCD boards out-of-the-box
This commit is contained in:
@@ -1,41 +1,34 @@
|
||||
# This file is executed on every boot (including wake-boot from deepsleep)
|
||||
import time
|
||||
import sys
|
||||
import board_config
|
||||
import wifi_config
|
||||
|
||||
try:
|
||||
import network
|
||||
has_network = True
|
||||
except ImportError:
|
||||
has_network = False
|
||||
if sys.platform == 'rp2':
|
||||
import st7796 as display_module
|
||||
else:
|
||||
import ili9341 as display_module
|
||||
from machine import Pin, SPI
|
||||
import wifi_config
|
||||
|
||||
def connect_wifi():
|
||||
if sys.platform == 'rp2':
|
||||
# Skip display and connection setup on RP2 (no network/Wi-Fi hardware)
|
||||
# Keep the sleep window to make REPL interruption easy
|
||||
time.sleep(1.5)
|
||||
return
|
||||
|
||||
# Initialize display to show connection progress
|
||||
display = None
|
||||
try:
|
||||
# ESP32-S3 configuration for Hosyond Board
|
||||
spi = SPI(1, baudrate=40000000, polarity=0, phase=0, sck=Pin(12), mosi=Pin(11), miso=Pin(13))
|
||||
display = display_module.ILI9341(spi, cs=Pin(10), dc=Pin(46), bl=Pin(45), rst=None)
|
||||
display.clear(0)
|
||||
|
||||
display.text("Hosyond ESP32-S3", 10, 10, 1)
|
||||
display.line(10, 20, 310, 20, 1)
|
||||
display.text("Connecting to Wi-Fi...", 10, 35, 1)
|
||||
display.text(f"SSID: {wifi_config.WIFI_SSID}", 10, 50, 1)
|
||||
display.show()
|
||||
except Exception as e:
|
||||
print("Display init failed in boot.py:", e)
|
||||
# Use the pre-initialized display from board_config
|
||||
display = board_config.display_instance
|
||||
if display:
|
||||
try:
|
||||
display.clear(0)
|
||||
board_name = "ESP32-S3 " + str(board_config.BOARD_TYPE)
|
||||
display.text(board_name, 10, 10, 1)
|
||||
display.line(10, 20, display.width - 10, 20, 1)
|
||||
display.text("Connecting to Wi-Fi...", 10, 35, 1)
|
||||
display.text(f"SSID: {wifi_config.WIFI_SSID}", 10, 50, 1)
|
||||
display.show()
|
||||
except Exception as e:
|
||||
print("Display setup failed in boot.py:", e)
|
||||
|
||||
# Initialize Wi-Fi Station
|
||||
if not has_network:
|
||||
@@ -62,34 +55,45 @@ def connect_wifi():
|
||||
timeout -= 1
|
||||
print("Connecting...")
|
||||
if display:
|
||||
display.text(".", dot_x, 70, 1)
|
||||
dot_x += 10
|
||||
display.show()
|
||||
try:
|
||||
display.text(".", dot_x, 70, 1)
|
||||
dot_x += 10
|
||||
display.show()
|
||||
except:
|
||||
pass
|
||||
|
||||
if wlan.isconnected():
|
||||
ip = wlan.ifconfig()[0]
|
||||
print(f"Wi-Fi Connected! IP Address: {ip}")
|
||||
if display:
|
||||
display.clear(0)
|
||||
display.text("Hosyond ESP32-S3", 10, 10, 1)
|
||||
display.line(10, 20, 310, 20, 1)
|
||||
display.text("Wi-Fi Status: Connected!", 10, 35, 1)
|
||||
display.text(f"SSID: {wifi_config.WIFI_SSID}", 10, 50, 1)
|
||||
display.text(f"IP: {ip}", 10, 65, 1)
|
||||
display.text("Starting MCP Server...", 10, 90, 1)
|
||||
display.show()
|
||||
time.sleep(1.5)
|
||||
try:
|
||||
display.clear(0)
|
||||
board_name = "ESP32-S3 " + str(board_config.BOARD_TYPE)
|
||||
display.text(board_name, 10, 10, 1)
|
||||
display.line(10, 20, display.width - 10, 20, 1)
|
||||
display.text("Wi-Fi Status: Connected!", 10, 35, 1)
|
||||
display.text(f"SSID: {wifi_config.WIFI_SSID}", 10, 50, 1)
|
||||
display.text(f"IP: {ip}", 10, 65, 1)
|
||||
display.text("Starting MCP Server...", 10, 90, 1)
|
||||
display.show()
|
||||
time.sleep(1.5)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
print("Wi-Fi Connection Failed.")
|
||||
if display:
|
||||
display.clear(0)
|
||||
display.text("Hosyond ESP32-S3", 10, 10, 1)
|
||||
display.line(10, 20, 310, 20, 1)
|
||||
display.text("Wi-Fi Status: Failed!", 10, 35, 1)
|
||||
display.text("Check credentials in:", 10, 55, 1)
|
||||
display.text("wifi_config.py", 20, 70, 1)
|
||||
display.text("Starting offline...", 10, 95, 1)
|
||||
display.show()
|
||||
time.sleep(2)
|
||||
try:
|
||||
display.clear(0)
|
||||
board_name = "ESP32-S3 " + str(board_config.BOARD_TYPE)
|
||||
display.text(board_name, 10, 10, 1)
|
||||
display.line(10, 20, display.width - 10, 20, 1)
|
||||
display.text("Wi-Fi Status: Failed!", 10, 35, 1)
|
||||
display.text("Check credentials in:", 10, 55, 1)
|
||||
display.text("wifi_config.py", 20, 70, 1)
|
||||
display.text("Starting offline...", 10, 95, 1)
|
||||
display.show()
|
||||
time.sleep(2)
|
||||
except:
|
||||
pass
|
||||
|
||||
connect_wifi()
|
||||
|
||||
Reference in New Issue
Block a user