Skip to content

Commit

Permalink
RP2040: an experiment with AirLift adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Feb 27, 2024
1 parent b60944c commit 4218a35
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 18 deletions.
70 changes: 59 additions & 11 deletions software/firmware/source/SoftRF/src/driver/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,68 @@ void WiFi_setup()
// 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"));
if (station_ssid.length() > 0) {
// ... Try to connect to WiFi station.
WiFi.begin(station_ssid.c_str(), station_psk.c_str());

// ... Pritn new SSID
Serial.print(F("new SSID: "));
Serial.println(WiFi.SSID());

Serial.println(F("Wait for WiFi connection."));

// ... Give Wi-Fi 10-20 seconds to connect to station.
unsigned long startTime = millis();
while (WiFi.status() != WL_CONNECTED &&
millis() - startTime < WIFI_STA_TIMEOUT)
{
Serial.write('.'); Serial.flush();
//Serial.print(WiFi.status());
delay(500);
}
Serial.println();

Serial.print(F("Setting soft-AP ... "));
Serial.println(WiFi.beginAP(host_name.c_str(), ap_default_psk) == WL_AP_LISTENING ?
F("Ready") : F("Failed!"));
// Check connection
if (WiFi.status() == WL_CONNECTED) {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

#if !defined(ARDUINO_RASPBERRY_PI_PICO)
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
#endif /* ARDUINO_RASPBERRY_PI_PICO */

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
} else {
Serial.println(F("Can not connect to WiFi station. Go into AP mode."));
}
}

Serial.print(F("IP address: "));
Serial.println(WiFi.softAPIP());
if (WiFi.status() != WL_CONNECTED) {
// Go into software AP mode.
Serial.print(F("Setting soft-AP configuration ... "));
WiFi.config(local_IP, gateway, gateway, subnet);
Serial.println(F("Ready"));

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);
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);

Serial.print(F("Setting soft-AP ... "));
Serial.println(WiFi.beginAP(host_name.c_str(), ap_default_psk) == WL_AP_LISTENING ?
F("Ready") : F("Failed!"));

delay(10);

// Serial.print(F("IP address: "));
// Serial.println(WiFi.softAPIP());
}

Uni_Udp.begin(RFlocalPort);
Serial.print(F("UDP server has started at port: "));
Expand Down
19 changes: 13 additions & 6 deletions software/firmware/source/SoftRF/src/platform/RP2040.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ static void RP2040_msc_flush_cb (void)
}
#endif /* ARDUINO_ARCH_MBED */

#if defined(ARDUINO_RASPBERRY_PI_PICO) && !defined(EXCLUDE_WIFI)
SPIClassRP2040 SPI0(spi0, PIN_SPI0_MISO, PIN_SPI0_SS, PIN_SPI0_SCK, PIN_SPI0_MOSI);
#endif /* EXCLUDE_WIFI */

static void RP2040_setup()
{
#if !defined(ARDUINO_ARCH_MBED)
Expand Down Expand Up @@ -279,6 +283,9 @@ static void RP2040_setup()

#if defined(ARDUINO_RASPBERRY_PI_PICO)
RP2040_board = RP2040_RPIPICO;
#if !defined(EXCLUDE_WIFI)
WiFi.setPins(PIN_SPI0_SS, D26, D24, D20, &SPI0);
#endif /* EXCLUDE_WIFI */
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
RP2040_board = rp2040.isPicoW() ? RP2040_RPIPICO_W : RP2040_RPIPICO;
#endif /* ARDUINO_RASPBERRY_PI_PICO */
Expand Down Expand Up @@ -601,7 +608,7 @@ static uint32_t RP2040_maxSketchSpace()

static void RP2040_WiFi_set_param(int ndx, int value)
{
#if !defined(EXCLUDE_WIFI)
#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI)
switch (ndx)
{
case WIFI_PARAM_TX_POWER:
Expand Down Expand Up @@ -630,7 +637,7 @@ static void RP2040_WiFi_set_param(int ndx, int value)
#endif /* EXCLUDE_WIFI */
}

#if !defined(EXCLUDE_WIFI)
#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI)
#include <dhcpserver/dhcpserver.h>
#endif /* EXCLUDE_WIFI */

Expand All @@ -641,7 +648,7 @@ union rp2040_ip {

static void RP2040_WiFi_transmit_UDP(int port, byte *buf, size_t size)
{
#if !defined(EXCLUDE_WIFI)
#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI)
union rp2040_ip ipv4;
IPAddress ClientIP;
ipv4.addr = (uint32_t) WiFi.localIP();
Expand Down Expand Up @@ -677,15 +684,15 @@ static void RP2040_WiFi_transmit_UDP(int port, byte *buf, size_t size)

static void RP2040_WiFiUDP_stopAll()
{
#if !defined(EXCLUDE_WIFI)
#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI)
WiFiUDP::stopAll();
#endif /* EXCLUDE_WIFI */
}

static bool RP2040_WiFi_hostname(String aHostname)
{
bool rval = false;
#if !defined(EXCLUDE_WIFI)
#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI)
if (RP2040_board == RP2040_RPIPICO_W) {
WiFi.hostname(aHostname.c_str());
rval = true;
Expand All @@ -696,7 +703,7 @@ static bool RP2040_WiFi_hostname(String aHostname)

static int RP2040_WiFi_clients_count()
{
#if !defined(EXCLUDE_WIFI)
#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI)
WiFiMode_t mode = WiFi.getMode();

switch (mode)
Expand Down
10 changes: 9 additions & 1 deletion software/firmware/source/SoftRF/src/platform/RP2040.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,21 @@ struct rst_info {
#define USE_WIFI_CUSTOM true
#include <ESP8266WiFi.h>
#define Serial_setDebugOutput(x) ({})
#define WIFI_STA_TIMEOUT 20000
#define WIFI_STA_TIMEOUT 20000

/* Experimental */
#define ENABLE_PROL
//#define ENABLE_BT_VOICE
#else
#define EXCLUDE_WIFI
//#define EXCLUDE_OTA
//#define USE_ARDUINO_WIFI
//#define USE_WIFI_NINA false
//#define USE_WIFI_CUSTOM true
//#include <WiFiNINA.h>
//#define Serial_setDebugOutput(x) ({})
//#define WIFI_STA_TIMEOUT 20000

#define EXCLUDE_BLUETOOTH
#endif /* ARDUINO_RASPBERRY_PI_PICO_W */

Expand Down
2 changes: 2 additions & 0 deletions software/firmware/source/SoftRF/src/platform/SAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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
16 changes: 16 additions & 0 deletions software/firmware/source/SoftRF/src/ui/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,23 @@ void handleSettings() {
server.sendHeader(String(F("Cache-Control")), String(F("no-cache, no-store, must-revalidate")));
server.sendHeader(String(F("Pragma")), String(F("no-cache")));
server.sendHeader(String(F("Expires")), String(F("-1")));
#if !defined(USE_ARDUINO_WIFI)
server.send ( 200, "text/html", Settings_temp );
#else
char *content = Settings_temp;
size_t bytes_left = strlen(Settings_temp);
size_t chunk_size;

server.setContentLength(bytes_left);
server.send(200, String(F("text/html")), "");

do {
chunk_size = bytes_left > JS_MAX_CHUNK_SIZE ? JS_MAX_CHUNK_SIZE : bytes_left;
server.sendContent(content, chunk_size);
content += chunk_size;
bytes_left -= chunk_size;
} while (bytes_left > 0) ;
#endif /* USE_ARDUINO_WIFI */
SoC->swSer_enableRx(true);
free(Settings_temp);
}
Expand Down

0 comments on commit 4218a35

Please sign in to comment.