Skip to content

Commit

Permalink
Academy: build of Wi-Fi infra for 'Uno R4 WiFi' targget
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Feb 23, 2024
1 parent d2926c7 commit de7052f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 6 deletions.
57 changes: 57 additions & 0 deletions software/firmware/source/SoftRF/src/driver/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <WiFi.h>

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.
*/
Expand Down Expand Up @@ -197,6 +249,7 @@ void WiFi_setup()
RID_Time_Marker = millis();
#endif /* ENABLE_REMOTE_ID */
}
#endif /* USE_ARDUINO_WIFI */

void WiFi_loop()
{
Expand Down Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions software/firmware/source/SoftRF/src/platform/RA4M1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion software/firmware/source/SoftRF/src/platform/RA4M1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/src/system/OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/src/system/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/src/ui/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
4 changes: 2 additions & 2 deletions software/firmware/source/libraries/LibAPRS_ESP32/LibAPRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit de7052f

Please sign in to comment.