Skip to content

Commit

Permalink
port,etc: RP2040 platform
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jul 14, 2024
1 parent f724432 commit ea5cdbd
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions examples/PingClient/PingClient.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <WiFiClientSecureBearSSL.h>
#define CHIP ESP
#elif defined(ARDUINO_ARCH_ESP32)
#include <NetworkClientSecure.h>
#include <WiFi.h>
#define CHIP ESP
#elif defined(ARDUINO_ARCH_RP2040)
#include <WiFi.h>
#include <WiFiClientSecureBearSSL.h>
#define CHIP rp2040
#endif
#include <esp8266ndn.h>

Expand All @@ -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)
Expand All @@ -47,7 +55,7 @@ setup() {
#endif
auto fchResponse = esp8266ndn::fchQuery(fchSocketClient);
if (!fchResponse.ok) {
ESP.restart();
CHIP.restart();
}
transport.beginTunnel(fchResponse.ip);
}
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/app/autoconfig.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#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"

#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#elif defined(ARDUINO_ARCH_ESP32)
#elif defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040)
#include <HTTPClient.h>
#include <WiFi.h>
#endif
Expand Down
9 changes: 7 additions & 2 deletions src/app/autoconfig.hpp
Original file line number Diff line number Diff line change
@@ -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 <IPAddress.h>
#include <WString.h>

#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)
Expand All @@ -16,6 +16,11 @@

class ESP8266NDN_NetworkClient;

#if defined(ARDUINO_ARCH_RP2040)
using arduino::IPAddress;
using arduino::String;
#endif

namespace esp8266ndn {

struct FchResponse {
Expand Down
10 changes: 10 additions & 0 deletions src/port/choose.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/port/fs.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "fs.hpp"
#include <algorithm>
#include <cstring>

#if defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_RP2040)
#include <LittleFS.h>
#define FSPORT_FILESYSTEM (::LittleFS)
#define FSPORT_READ ("r")
Expand Down
6 changes: 3 additions & 3 deletions src/transport/udp-transport.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions src/transport/udp-transport.hpp
Original file line number Diff line number Diff line change
@@ -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 <ESP8266WiFi.h>
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_RP2040)
#include <WiFiUdp.h>
#define ESP8266NDN_NetworkUDP WiFiUDP
#elif defined(ARDUINO_ARCH_ESP32)
Expand Down

0 comments on commit ea5cdbd

Please sign in to comment.