Skip to content

Commit

Permalink
Support NRF52x
Browse files Browse the repository at this point in the history
  • Loading branch information
TMRh20 authored and 2bndy5 committed May 30, 2023
1 parent 440ddad commit 991fed3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
35 changes: 24 additions & 11 deletions RF24Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,33 @@
#include "RF24Ethernet.h"

IPAddress RF24EthernetClass::_dnsServerAddress;
//DhcpClass* RF24EthernetClass::_dhcp(NULL);
// DhcpClass* RF24EthernetClass::_dhcp(NULL);

/*************************************************************/
#if defined(RF24_TAP)
RF24EthernetClass::RF24EthernetClass(RF24& _radio, RF24Network& _network) : radio(_radio), network(_network) //fn_uip_cb(NULL)
#if !defined NRF52_RADIO_LIBRARY
#if defined(RF24_TAP)
RF24EthernetClass::RF24EthernetClass(RF24& _radio, RF24Network& _network) : radio(_radio), network(_network) // fn_uip_cb(NULL)
{
}

#else // Using RF24Mesh
RF24EthernetClass::RF24EthernetClass(RF24& _radio, RF24Network& _network, RF24Mesh& _mesh) : radio(_radio), network(_network), mesh(_mesh) //fn_uip_cb(NULL)
#else // Using RF24Mesh
RF24EthernetClass::RF24EthernetClass(RF24& _radio, RF24Network& _network, RF24Mesh& _mesh) : radio(_radio), network(_network), mesh(_mesh) // fn_uip_cb(NULL)
{
}
#endif
#endif

#else
#if defined(RF24_TAP)
RF24EthernetClass::RF24EthernetClass(nrf_to_nrf& _radio, RF24Network& _network) : radio(_radio), network(_network) // fn_uip_cb(NULL)
{
}

#else // Using RF24Mesh
RF24EthernetClass::RF24EthernetClass(nrf_to_nrf& _radio, RF24Network& _network, RF24Mesh& _mesh) : radio(_radio), network(_network), mesh(_mesh) // fn_uip_cb(NULL)
{
}
#endif
#endif
/*************************************************************/

void RF24EthernetClass::update()
Expand All @@ -58,14 +71,14 @@ void RF24EthernetClass::setMac(uint16_t address)
}

const uint8_t mac[6] = {0x52, 0x46, 0x32, 0x34, (uint8_t)address, (uint8_t)(address >> 8)};
//printf("MAC: %o %d\n", address, mac[0]);
// printf("MAC: %o %d\n", address, mac[0]);

#if defined(RF24_TAP)
uip_seteth_addr(mac);
network.multicastRelay = 1;
#else
if (mac[0] == 1) {
//Dummy operation to prevent warnings if TAP not defined
// Dummy operation to prevent warnings if TAP not defined
};
#endif
RF24_Channel = RF24_Channel ? RF24_Channel : 97;
Expand Down Expand Up @@ -274,8 +287,8 @@ void RF24EthernetClass::tick()
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if (uip_len > 0) {
//uip_arp_out();
//network_send();
// uip_arp_out();
// network_send();
RF24UDP::_send((uip_udp_userdata_t*)(uip_udp_conns[i].appstate));
}
}
Expand All @@ -288,7 +301,7 @@ void RF24EthernetClass::tick()
uip_arp_timer();
}
}
#endif //RF24_TAP
#endif // RF24_TAP
}

/*******************************************************/
Expand Down
20 changes: 17 additions & 3 deletions RF24Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ extern "C" {
}

#include "RF24Ethernet_config.h"
#if defined ARDUINO_ARCH_NRF52840 || defined ARDUINO_ARCH_NRF52833
#include <nrf_to_nrf.h>
#endif
#include <RF24.h>
#include <RF24Network.h>
#if !defined(RF24_TAP) // Using RF24Mesh
Expand Down Expand Up @@ -76,7 +79,7 @@ extern "C" {
} while (0)
#define uip_ip_addr(addr, ip) memcpy(addr, &ip[0], 4)

#define ip_addr_uip(a) IPAddress(a[0] & 0xFF, a[0] >> 8, a[1] & 0xFF, a[1] >> 8) //TODO this is not IPV6 capable
#define ip_addr_uip(a) IPAddress(a[0] & 0xFF, a[0] >> 8, a[1] & 0xFF, a[1] >> 8) // TODO this is not IPV6 capable

#define uip_seteth_addr(eaddr) \
do { \
Expand Down Expand Up @@ -111,6 +114,13 @@ class RF24EthernetClass
#else
RF24EthernetClass(RF24& _radio, RF24Network& _network);
#endif
#if defined NRF52_RADIO_LIBRARY
#if !defined(RF24_TAP)
RF24EthernetClass(nrf_to_nrf& _radio, RF24Network& _network, RF24Mesh& _mesh);
#else
RF24EthernetClass(nrf_to_nrf& _radio, RF24Network& _network);
#endif
#endif

/** Basic constructor */
RF24EthernetClass();
Expand Down Expand Up @@ -176,10 +186,14 @@ class RF24EthernetClass

/** Keeps the TCP/IP stack running & processing incoming data */
void update();
//uint8_t *key;
// uint8_t *key;

private:
#if defined NRF52_RADIO_LIBRARY
nrf_to_nrf& radio;
#else
RF24& radio;
#endif
RF24Network& network;
#if !defined(RF24_TAP) // Using RF24Mesh
RF24Mesh& mesh;
Expand Down Expand Up @@ -225,7 +239,7 @@ extern RF24EthernetClass RF24Ethernet;
/**
* @example Getting_Started_SimpleClient_Mesh_DNS.ino
*
* This is an example of how to use the RF24Ethernet class to connect out to a web server and retrieve data via HTTP,
* This is an example of how to use the RF24Ethernet class to connect out to a web server and retrieve data via HTTP,
* using DNS lookups instead of IP address.
*/

Expand Down

0 comments on commit 991fed3

Please sign in to comment.