From 47de4a955bbfa9b601706181aa6243f625d86cae Mon Sep 17 00:00:00 2001 From: Gamenight77 Date: Tue, 27 May 2025 18:45:09 +0200 Subject: [PATCH] Update FPGA constraints and reintroduce WiFi functionality with touch sensor reset handling --- .../constraints/fpga_wifi_led.cst | 4 +- .../src/esp32/{ => wifi_esp32}/wifi_esp32.ino | 38 +++++++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-) rename Semaine_7/ESP32/leds_commands/src/esp32/{ => wifi_esp32}/wifi_esp32.ino (73%) diff --git a/Semaine_7/ESP32/leds_commands/constraints/fpga_wifi_led.cst b/Semaine_7/ESP32/leds_commands/constraints/fpga_wifi_led.cst index f5e531f..8bdd959 100644 --- a/Semaine_7/ESP32/leds_commands/constraints/fpga_wifi_led.cst +++ b/Semaine_7/ESP32/leds_commands/constraints/fpga_wifi_led.cst @@ -1,7 +1,7 @@ -IO_LOC "o_tx" 69; +IO_LOC "o_tx" 73; IO_PORT "o_tx" IO_TYPE=LVCMOS33 PULL_MODE=UP BANK_VCCIO=3.3; -IO_LOC "i_rx" 70; +IO_LOC "i_rx" 74; IO_PORT "i_rx" IO_TYPE=LVCMOS33 PULL_MODE=UP BANK_VCCIO=3.3; IO_LOC "i_clk" 4; diff --git a/Semaine_7/ESP32/leds_commands/src/esp32/wifi_esp32.ino b/Semaine_7/ESP32/leds_commands/src/esp32/wifi_esp32/wifi_esp32.ino similarity index 73% rename from Semaine_7/ESP32/leds_commands/src/esp32/wifi_esp32.ino rename to Semaine_7/ESP32/leds_commands/src/esp32/wifi_esp32/wifi_esp32.ino index b469920..279ae59 100644 --- a/Semaine_7/ESP32/leds_commands/src/esp32/wifi_esp32.ino +++ b/Semaine_7/ESP32/leds_commands/src/esp32/wifi_esp32/wifi_esp32.ino @@ -16,23 +16,37 @@ const int touchThreshold = 30; // Adjust based on testing (lower value = touch d const unsigned long resetHoldTime = 5000; // 5 seconds to trigger reset unsigned long touchStartTime = 0; bool touchDetected = false; + +// UART pins for FPGA communication +const int UART_RX_PIN = 16; // GPIO16 - RX from FPGA +const int UART_TX_PIN = 17; // GPIO17 - TX to FPGA +const int UART_BAUD = 115200; void setup() { - // Initialize Serial for UART communication (115200 baud) + // Initialize Serial for USB debugging (115200 baud) Serial.begin(115200); + + // Initialize Serial2 for FPGA communication + Serial2.begin(UART_BAUD, SERIAL_8N1, UART_RX_PIN, UART_TX_PIN); + + Serial.println("ESP32 starting..."); + // Initialize WiFiManager WiFiManager wifiManager; + // Check for touch sensor reset if (checkTouchReset()) { wifiManager.resetSettings(); Serial.println("WiFi settings reset due to touch sensor"); ESP.restart(); // Restart to apply reset } + // Connect to WiFi using WiFiManager (creates AP if no saved credentials) if (!wifiManager.autoConnect("ESP32_AP")) { Serial.println("Failed to connect to WiFi and hit timeout"); ESP.restart(); } + Serial.println("WiFi connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); @@ -54,16 +68,24 @@ void loop() { } } - // Relay data from TCP client to UART + // Relay data from TCP client to FPGA UART while (client.connected() && client.available()) { - char c = client.read(); - Serial.write(c); // Send to UART + uint8_t data = client.read(); + Serial2.write(data); // Send to FPGA via Serial2 + + // Debug: show what we're sending to FPGA + Serial.print("Sent to FPGA: 0x"); + Serial.println(data, HEX); } - // Relay data from UART to TCP client - while (Serial.available() && client.connected()) { - char c = Serial.read(); - client.write(c); // Send to TCP client + // Relay data from FPGA UART to TCP client + while (Serial2.available() && client.connected()) { + uint8_t data = Serial2.read(); + client.write(data); // Send to TCP client + + // Debug: show what we received from FPGA + Serial.print("Received from FPGA: 0x"); + Serial.println(data, HEX); } // Handle client disconnection