Skip to content

Commit cf97c13

Browse files
Merge pull request #63 from libretiny-eu/feature/libretiny-support
Add LibreTiny support
2 parents 35b4900 + 33c5bcb commit cf97c13

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ jobs:
7878
- env: ci-arduino-3-latest
7979
board: esp32-c6-devkitc-1
8080

81+
- env: ci-arduino-libretiny
82+
board: generic-bk7231n-qfn32-tuya
83+
- env: ci-arduino-libretiny
84+
board: generic-rtl8710bn-2mb-788k
85+
8186
steps:
8287
- name: Checkout
8388
uses: actions/checkout@v4

platformio.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,12 @@ board = ${sysenv.PIO_BOARD}
4343
[env:ci-arduino-3-latest]
4444
platform = https://github.com/pioarduino/platform-espressif32/releases/download/54.03.20-rc2/platform-espressif32.zip
4545
board = ${sysenv.PIO_BOARD}
46+
47+
[env:ci-arduino-libretiny]
48+
platform = libretiny
49+
board = ${sysenv.PIO_BOARD}
50+
build_flags =
51+
${env.build_flags}
52+
-Wno-unused-parameter
53+
-Wno-unused-variable
54+
-Wno-missing-field-initializers

src/AsyncTCP.cpp

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "AsyncTCP.h"
55

6+
#ifndef LIBRETINY
67
#include <esp_log.h>
78

89
#ifdef ARDUINO
@@ -22,6 +23,18 @@ static unsigned long millis() {
2223
return (unsigned long)(esp_timer_get_time() / 1000ULL);
2324
}
2425
#endif
26+
#endif
27+
28+
#ifdef LIBRETINY
29+
#include <Arduino.h>
30+
// LibreTiny does not support IDF - disable code that expects it to be available
31+
#define ESP_IDF_VERSION_MAJOR (0)
32+
// xTaskCreatePinnedToCore is not available, force single-core operation
33+
#define CONFIG_FREERTOS_UNICORE 1
34+
// ESP watchdog is not available
35+
#undef CONFIG_ASYNC_TCP_USE_WDT
36+
#define CONFIG_ASYNC_TCP_USE_WDT 0
37+
#endif
2538

2639
extern "C" {
2740
#include "lwip/dns.h"
@@ -837,7 +850,11 @@ bool AsyncClient::connect(ip_addr_t addr, uint16_t port) {
837850
tcp_pcb *pcb;
838851
{
839852
tcp_core_guard tcg;
853+
#if LWIP_IPV4 && LWIP_IPV6
840854
pcb = tcp_new_ip_type(addr.type);
855+
#else
856+
pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
857+
#endif
841858
if (!pcb) {
842859
log_e("pcb == NULL");
843860
return false;
@@ -857,8 +874,13 @@ bool AsyncClient::connect(ip_addr_t addr, uint16_t port) {
857874
bool AsyncClient::connect(const IPAddress &ip, uint16_t port) {
858875
ip_addr_t addr;
859876
#if ESP_IDF_VERSION_MAJOR < 5
877+
#if LWIP_IPV4 && LWIP_IPV6
878+
// if both IPv4 and IPv6 are enabled, ip_addr_t has a union field and the address type
860879
addr.u_addr.ip4.addr = ip;
861880
addr.type = IPADDR_TYPE_V4;
881+
#else
882+
addr.addr = ip;
883+
#endif
862884
#else
863885
ip.to_ip_addr_t(&addr);
864886
#endif
@@ -1343,19 +1365,33 @@ uint16_t AsyncClient::getLocalPort() const {
13431365
}
13441366

13451367
ip4_addr_t AsyncClient::getRemoteAddress4() const {
1368+
#if LWIP_IPV4 && LWIP_IPV6
13461369
if (_pcb && _pcb->remote_ip.type == IPADDR_TYPE_V4) {
13471370
return _pcb->remote_ip.u_addr.ip4;
1348-
} else {
1371+
}
1372+
#else
1373+
if (_pcb) {
1374+
return _pcb->remote_ip;
1375+
}
1376+
#endif
1377+
else {
13491378
ip4_addr_t nulladdr;
13501379
ip4_addr_set_zero(&nulladdr);
13511380
return nulladdr;
13521381
}
13531382
}
13541383

13551384
ip4_addr_t AsyncClient::getLocalAddress4() const {
1385+
#if LWIP_IPV4 && LWIP_IPV6
13561386
if (_pcb && _pcb->local_ip.type == IPADDR_TYPE_V4) {
13571387
return _pcb->local_ip.u_addr.ip4;
1358-
} else {
1388+
}
1389+
#else
1390+
if (_pcb) {
1391+
return _pcb->local_ip;
1392+
}
1393+
#endif
1394+
else {
13591395
ip4_addr_t nulladdr;
13601396
ip4_addr_set_zero(&nulladdr);
13611397
return nulladdr;
@@ -1486,24 +1522,34 @@ AsyncServer::AsyncServer(ip_addr_t addr, uint16_t port)
14861522
#ifdef ARDUINO
14871523
AsyncServer::AsyncServer(IPAddress addr, uint16_t port) : _port(port), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
14881524
#if ESP_IDF_VERSION_MAJOR < 5
1525+
#if LWIP_IPV4 && LWIP_IPV6
14891526
_addr.type = IPADDR_TYPE_V4;
14901527
_addr.u_addr.ip4.addr = addr;
1528+
#else
1529+
_addr.addr = addr;
1530+
#endif
14911531
#else
14921532
addr.to_ip_addr_t(&_addr);
14931533
#endif
14941534
}
1495-
#if ESP_IDF_VERSION_MAJOR < 5
1535+
#if ESP_IDF_VERSION_MAJOR < 5 && __has_include(<IPv6Address.h>) && LWIP_IPV6
14961536
AsyncServer::AsyncServer(IPv6Address addr, uint16_t port) : _port(port), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
1537+
#if LWIP_IPV4 && LWIP_IPV6
14971538
_addr.type = IPADDR_TYPE_V6;
1539+
#endif
14981540
auto ipaddr = static_cast<const uint32_t *>(addr);
14991541
_addr = IPADDR6_INIT(ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
15001542
}
15011543
#endif
15021544
#endif
15031545

15041546
AsyncServer::AsyncServer(uint16_t port) : _port(port), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
1547+
#if LWIP_IPV4 && LWIP_IPV6
15051548
_addr.type = IPADDR_TYPE_ANY;
15061549
_addr.u_addr.ip4.addr = INADDR_ANY;
1550+
#else
1551+
_addr.addr = INADDR_ANY;
1552+
#endif
15071553
}
15081554

15091555
AsyncServer::~AsyncServer() {
@@ -1527,7 +1573,11 @@ void AsyncServer::begin() {
15271573
int8_t err;
15281574
{
15291575
tcp_core_guard tcg;
1576+
#if LWIP_IPV4 && LWIP_IPV6
15301577
_pcb = tcp_new_ip_type(_addr.type);
1578+
#else
1579+
_pcb = tcp_new_ip_type(IPADDR_TYPE_ANY);
1580+
#endif
15311581
}
15321582
if (!_pcb) {
15331583
log_e("_pcb == NULL");

src/AsyncTCP.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include "AsyncTCPVersion.h"
88
#define ASYNCTCP_FORK_ESP32Async
99

10+
#ifndef LIBRETINY
1011
#include <esp_idf_version.h>
12+
#endif
1113

1214
#ifdef ARDUINO
1315
#include "IPAddress.h"
@@ -29,9 +31,9 @@ extern "C" {
2931
#else
3032
extern "C" {
3133
#include <lwip/pbuf.h>
34+
#include <FreeRTOS.h>
3235
#include <semphr.h>
3336
}
34-
#define CONFIG_ASYNC_TCP_RUNNING_CORE -1 // any available core
3537
#endif
3638

3739
// If core is not defined, then we are running in Arduino or PIO

0 commit comments

Comments
 (0)