From de7052f2c0147435880148bffc2575e8bb66c68d Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Fri, 23 Feb 2024 12:07:19 +0300 Subject: [PATCH] Academy: build of Wi-Fi infra for 'Uno R4 WiFi' targget --- .../source/SoftRF/src/driver/WiFi.cpp | 57 +++++++++++++++++++ .../source/SoftRF/src/platform/RA4M1.cpp | 2 + .../source/SoftRF/src/platform/RA4M1.h | 5 +- .../firmware/source/SoftRF/src/system/OTA.cpp | 2 +- .../source/SoftRF/src/system/Time.cpp | 2 +- .../firmware/source/SoftRF/src/ui/Web.cpp | 2 +- .../libraries/LibAPRS_ESP32/LibAPRS.cpp | 4 +- 7 files changed, 68 insertions(+), 6 deletions(-) diff --git a/software/firmware/source/SoftRF/src/driver/WiFi.cpp b/software/firmware/source/SoftRF/src/driver/WiFi.cpp index 7edfa77ef..c1f461874 100644 --- a/software/firmware/source/SoftRF/src/driver/WiFi.cpp +++ b/software/firmware/source/SoftRF/src/driver/WiFi.cpp @@ -105,6 +105,58 @@ void Raw_Transmit_UDP() SoC->WiFi_transmit_UDP(RELAY_DST_PORT, (byte *)UDPpacketBuffer, len + 1); } +#if defined(USE_ARDUINO_WIFI) +#include + +void WiFi_setup() +{ + // Set Hostname. + host_name += "-"; + host_name += String((SoC->getChipId() & 0xFFFFFF), HEX); + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + WiFi.setHostname(host_name.c_str()); + + // Print hostname. + Serial.println("Hostname: " + host_name); + + Serial.print(F("Setting soft-AP configuration ... ")); + WiFi.config(local_IP, gateway, gateway, subnet); + Serial.println(F("Ready")); + + Serial.print(F("Setting soft-AP ... ")); + Serial.println(WiFi.beginAP(host_name.c_str(), ap_default_psk) == WL_AP_LISTENING ? + F("Ready") : F("Failed!")); + + Serial.print(F("IP address: ")); + Serial.println(WiFi.softAPIP()); + + SoC->WiFi_set_param(WIFI_PARAM_TX_POWER, WIFI_TX_POWER_MED); // 10 dBm + SoC->WiFi_set_param(WIFI_PARAM_DHCP_LEASE_TIME, WIFI_DHCP_LEASE_HRS); + delay(10); + + Uni_Udp.begin(RFlocalPort); + Serial.print(F("UDP server has started at port: ")); + Serial.println(RFlocalPort); + +#if defined(POWER_SAVING_WIFI_TIMEOUT) + WiFi_No_Clients_Time_ms = millis(); +#endif +} + +#else /* USE_ARDUINO_WIFI */ + /** * @brief Arduino setup function. */ @@ -197,6 +249,7 @@ void WiFi_setup() RID_Time_Marker = millis(); #endif /* ENABLE_REMOTE_ID */ } +#endif /* USE_ARDUINO_WIFI */ void WiFi_loop() { @@ -240,7 +293,11 @@ void WiFi_fini() { Uni_Udp.stop(); +#if defined(USE_ARDUINO_WIFI) + WiFi.end(); +#else WiFi.mode(WIFI_OFF); +#endif /* USE_ARDUINO_WIFI */ } #endif /* EXCLUDE_WIFI */ diff --git a/software/firmware/source/SoftRF/src/platform/RA4M1.cpp b/software/firmware/source/SoftRF/src/platform/RA4M1.cpp index c39ac4172..869363a66 100644 --- a/software/firmware/source/SoftRF/src/platform/RA4M1.cpp +++ b/software/firmware/source/SoftRF/src/platform/RA4M1.cpp @@ -64,7 +64,9 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIX_NUM, SOC_GPIO_PIN_LED, NEO_GRB + NEO_KHZ800); #endif /* EXCLUDE_LED_RING */ +#if defined(EXCLUDE_WIFI) char UDPpacketBuffer[4]; // Dummy definition to satisfy build sequence +#endif /* EXCLUDE_WIFI */ static struct rst_info reset_info = { .reason = REASON_DEFAULT_RST, diff --git a/software/firmware/source/SoftRF/src/platform/RA4M1.h b/software/firmware/source/SoftRF/src/platform/RA4M1.h index 6f55b3f7e..82b6c4b9f 100644 --- a/software/firmware/source/SoftRF/src/platform/RA4M1.h +++ b/software/firmware/source/SoftRF/src/platform/RA4M1.h @@ -131,7 +131,10 @@ struct rst_info { #if defined(ARDUINO_UNOR4_MINIMA) #define EXCLUDE_WIFI #elif defined(ARDUINO_UNOR4_WIFI) -#define EXCLUDE_WIFI /* TODO */ +#define USE_ARDUINO_WIFI +#define EXCLUDE_OTA +#define EXCLUDE_WEBUI /* TODO */ +#define Serial_setDebugOutput(x) ({}) #endif #define EXCLUDE_CC13XX diff --git a/software/firmware/source/SoftRF/src/system/OTA.cpp b/software/firmware/source/SoftRF/src/system/OTA.cpp index fa729159d..07f93efed 100644 --- a/software/firmware/source/SoftRF/src/system/OTA.cpp +++ b/software/firmware/source/SoftRF/src/system/OTA.cpp @@ -18,7 +18,7 @@ #include "SoC.h" -#if defined(EXCLUDE_WIFI) +#if defined(EXCLUDE_WIFI) || defined(EXCLUDE_OTA) void OTA_setup() {} void OTA_loop() {} #else diff --git a/software/firmware/source/SoftRF/src/system/Time.cpp b/software/firmware/source/SoftRF/src/system/Time.cpp index 8a36a96b1..0326556df 100644 --- a/software/firmware/source/SoftRF/src/system/Time.cpp +++ b/software/firmware/source/SoftRF/src/system/Time.cpp @@ -19,7 +19,7 @@ #include "SoC.h" #include "Time.h" -#if defined(EXCLUDE_WIFI) +#if defined(EXCLUDE_WIFI) || defined(USE_ARDUINO_WIFI) void Time_setup() {} #else diff --git a/software/firmware/source/SoftRF/src/ui/Web.cpp b/software/firmware/source/SoftRF/src/ui/Web.cpp index 84fe76e59..83d838d33 100644 --- a/software/firmware/source/SoftRF/src/ui/Web.cpp +++ b/software/firmware/source/SoftRF/src/ui/Web.cpp @@ -18,7 +18,7 @@ #include "../system/SoC.h" -#if defined(EXCLUDE_WIFI) +#if defined(EXCLUDE_WIFI) || defined(EXCLUDE_WEBUI) void Web_setup() {} void Web_loop() {} void Web_fini() {} diff --git a/software/firmware/source/libraries/LibAPRS_ESP32/LibAPRS.cpp b/software/firmware/source/libraries/LibAPRS_ESP32/LibAPRS.cpp index 025fe96f3..279799017 100644 --- a/software/firmware/source/libraries/LibAPRS_ESP32/LibAPRS.cpp +++ b/software/firmware/source/libraries/LibAPRS_ESP32/LibAPRS.cpp @@ -11,7 +11,7 @@ // extern "C" { // //#include "user_interface.h" // }uint32_t freemem = system_get_free_heap_size(); -Afsk modem; +Afsk modem_afsk; AX25Ctx AX25; extern void aprs_msg_callback(struct AX25Msg *msg); extern APRS_led_callback_t AFSK_Tx_LED_Callback; @@ -76,7 +76,7 @@ void aprs_msg_callback(struct AX25Msg *msg) { void APRS_init(bool rx) { - AFSK_init(&modem, rx); + AFSK_init(&modem_afsk, rx); ax25_init(&AX25, aprs_msg_callback); }