From a20bf964360384f824b251d485b41944aa522a88 Mon Sep 17 00:00:00 2001 From: Junxiao Shi Date: Sun, 14 Jul 2024 09:59:45 -0400 Subject: [PATCH] port,etc: RP2040 platform --- .github/workflows/build.yml | 7 +++++++ README.md | 11 ++++++++++- examples/PingClient/PingClient.ino | 14 +++++++++++--- library.properties | 2 +- src/app/autoconfig.cpp | 4 ++-- src/app/autoconfig.hpp | 9 +++++++-- src/port/choose.h | 10 ++++++++++ src/port/fs.cpp | 4 ++-- src/transport/udp-transport.cpp | 6 +++--- src/transport/udp-transport.hpp | 6 ++---- 10 files changed, 55 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b8b87c0..0909f56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,6 +48,13 @@ jobs: sketches: | - examples/BlePingServer - examples/unittest + - chip: RP2040 + fqbn: rp2040:rp2040:rpipicow + platforms: | + - name: rp2040:rp2040 + source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + sketches: | + - examples/PingClient fail-fast: false name: ${{ matrix.chip }} runs-on: ubuntu-22.04 diff --git a/README.md b/README.md index f823f35..66745ee 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,16 @@ [![GitHub Workflow status](https://img.shields.io/github/actions/workflow/status/yoursunny/esp8266ndn/build.yml?style=flat)](https://github.com/yoursunny/esp8266ndn/actions) [![GitHub code size](https://img.shields.io/github/languages/code-size/yoursunny/esp8266ndn?style=flat)](https://github.com/yoursunny/esp8266ndn) -**esp8266ndn** library enables [Named Data Networking](https://named-data.net/) application development in Arduino environment. It supports [ESP8266](https://github.com/esp8266/Arduino), [ESP32 series](https://github.com/espressif/arduino-esp32) (3.x core), and [Adafruit nRF52](https://github.com/adafruit/Adafruit_nRF52_Arduino) microcontrollers. +**esp8266ndn** library enables [Named Data Networking](https://named-data.net/) application development in Arduino environment. + +It supports these microcontrollers: + +* [ESP8266](https://github.com/esp8266/Arduino) +* [ESP32 series](https://github.com/espressif/arduino-esp32) (3.x core) +* [nRF52](https://github.com/adafruit/Adafruit_nRF52_Arduino) +* [RP2040](https://github.com/earlephilhower/arduino-pico) + +Related links: * [Doxygen documentation](https://esp8266ndn.ndn.today/) * [#esp8266ndn on Twitter](https://twitter.com/hashtag/esp8266ndn) for announcements diff --git a/examples/PingClient/PingClient.ino b/examples/PingClient/PingClient.ino index 5b2b2f9..77b43be 100644 --- a/examples/PingClient/PingClient.ino +++ b/examples/PingClient/PingClient.ino @@ -1,9 +1,15 @@ #if defined(ARDUINO_ARCH_ESP8266) #include #include +#define CHIP ESP #elif defined(ARDUINO_ARCH_ESP32) #include #include +#define CHIP ESP +#elif defined(ARDUINO_ARCH_RP2040) +#include +#include +#define CHIP rp2040 #endif #include @@ -30,15 +36,17 @@ setup() { WiFi.persistent(false); WiFi.mode(WIFI_STA); +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) WiFi.setSleep(false); +#endif WiFi.begin(WIFI_SSID, WIFI_PASS); if (WiFi.waitForConnectResult() != WL_CONNECTED) { Serial.println(F("WiFi connect failed")); - ESP.restart(); + CHIP.restart(); } delay(1000); -#if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_RP2040) BearSSL::WiFiClientSecure fchSocketClient; fchSocketClient.setInsecure(); #elif defined(ARDUINO_ARCH_ESP32) @@ -47,7 +55,7 @@ setup() { #endif auto fchResponse = esp8266ndn::fchQuery(fchSocketClient); if (!fchResponse.ok) { - ESP.restart(); + CHIP.restart(); } transport.beginTunnel(fchResponse.ip); } diff --git a/library.properties b/library.properties index 19126fe..e54a1eb 100644 --- a/library.properties +++ b/library.properties @@ -6,4 +6,4 @@ sentence=Named Data Networking on ESP8266 and more. paragraph=This library enables NDN application development on ESP8266, ESP32, and nRF52 microcontrollers. category=Communication url=https://yoursunny.com -architectures=esp8266,esp32,nrf52 +architectures=esp8266,esp32,nrf52,rp2040 diff --git a/src/app/autoconfig.cpp b/src/app/autoconfig.cpp index a8b899d..68b4edf 100644 --- a/src/app/autoconfig.cpp +++ b/src/app/autoconfig.cpp @@ -1,4 +1,4 @@ -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) #include "autoconfig.hpp" #include "../core/logger.hpp" @@ -6,7 +6,7 @@ #if defined(ARDUINO_ARCH_ESP8266) #include #include -#elif defined(ARDUINO_ARCH_ESP32) +#elif defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) #include #include #endif diff --git a/src/app/autoconfig.hpp b/src/app/autoconfig.hpp index a684994..323e694 100644 --- a/src/app/autoconfig.hpp +++ b/src/app/autoconfig.hpp @@ -1,12 +1,12 @@ #ifndef ESP8266NDN_APP_AUTOCONFIG_HPP #define ESP8266NDN_APP_AUTOCONFIG_HPP -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) #include #include -#if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_RP2040) #define ESP8266NDN_Network WiFi #define ESP8266NDN_NetworkClient WiFiClient #elif defined(ARDUINO_ARCH_ESP32) @@ -16,6 +16,11 @@ class ESP8266NDN_NetworkClient; +#if defined(ARDUINO_ARCH_RP2040) +using arduino::IPAddress; +using arduino::String; +#endif + namespace esp8266ndn { struct FchResponse { diff --git a/src/port/choose.h b/src/port/choose.h index c6a429f..cfc6e50 100644 --- a/src/port/choose.h +++ b/src/port/choose.h @@ -40,6 +40,16 @@ #define NDNPH_PORT_QUEUE_SIMPLE +#elif defined(ARDUINO_ARCH_RP2040) + +#define NDNPH_PORT_SHA256_CUSTOM +#define ESP8266NDN_PORT_SHA256_BEARSSL + +#define NDNPH_PORT_EC_CUSTOM +#define ESP8266NDN_PORT_EC_UECC + +#define NDNPH_PORT_QUEUE_SIMPLE + #else #error "Unknown ARDUINO_ARCH" diff --git a/src/port/fs.cpp b/src/port/fs.cpp index 1e23b76..ceb926a 100644 --- a/src/port/fs.cpp +++ b/src/port/fs.cpp @@ -1,7 +1,7 @@ #include "fs.hpp" -#include +#include -#if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_RP2040) #include #define FSPORT_FILESYSTEM (::LittleFS) #define FSPORT_READ ("r") diff --git a/src/transport/udp-transport.cpp b/src/transport/udp-transport.cpp index 06313ac..18bee57 100644 --- a/src/transport/udp-transport.cpp +++ b/src/transport/udp-transport.cpp @@ -1,4 +1,4 @@ -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) #include "udp-transport.hpp" #include "../core/logger.hpp" @@ -22,7 +22,7 @@ UdpTransport::UdpTransport(uint8_t* buffer, size_t capacity) bool UdpTransport::beginListen(uint16_t localPort, IPAddress localIp) { end(); -#if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_RP2040) #if LWIP_IPV6 LOG(F("listening on [::]:") << _DEC(localPort)); #else @@ -61,7 +61,7 @@ UdpTransport::beginTunnel(IPAddress remoteIp, uint16_t remotePort, uint16_t loca bool UdpTransport::beginMulticast(IPAddress localIp, uint16_t groupPort) { end(); -#if defined(ARDUINO_ARCH_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_RP2040) LOG(F("joining group ") << MulticastGroup << ':' << _DEC(groupPort) << F(" on ") << localIp); bool ok = m_udp.beginMulticast(localIp, MulticastGroup, groupPort); #elif defined(ARDUINO_ARCH_ESP32) diff --git a/src/transport/udp-transport.hpp b/src/transport/udp-transport.hpp index 796bfe3..249b3a0 100644 --- a/src/transport/udp-transport.hpp +++ b/src/transport/udp-transport.hpp @@ -1,13 +1,11 @@ #ifndef ESP8266NDN_TRANSPORT_UDP_TRANSPORT_HPP #define ESP8266NDN_TRANSPORT_UDP_TRANSPORT_HPP -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) #include "../port/port.hpp" -#if defined(ARDUINO_ARCH_ESP8266) -// cause WiFiUdp.h to use ESP8266WiFi instead of Arduino WiFi library -#include +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_RP2040) #include #define ESP8266NDN_NetworkUDP WiFiUDP #elif defined(ARDUINO_ARCH_ESP32)