Skip to content

Commit

Permalink
Using macros for T1S class object instantiation.
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger committed Dec 2, 2024
1 parent e0c1bfc commit 9bc3d51
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 64 deletions.
21 changes: 8 additions & 13 deletions examples/UDP_Client/UDP_Client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,11 @@ static uint16_t const UDP_SERVER_PORT = 8888;
* GLOBAL VARIABLES
**************************************************************************************/

TC6::TC6_Io tc6_io(
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
SPI1
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
#else
SPI
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
#endif
, CS_PIN
, RESET_PIN
, IRQ_PIN);
TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io);
Arduino_10BASE_T1S_UDP udp_client;

/**************************************************************************************
Expand All @@ -61,19 +56,19 @@ void setup()
*/
pinMode(IRQ_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
[]() { tc6_io.onInterrupt(); },
[]() { t1s_io.onInterrupt(); },
FALLING);

/* Initialize IO module. */
if (!tc6_io.begin())
if (!t1s_io.begin())
{
Serial.println("'TC6_Io::begin(...)' failed.");
for (;;) { }
}

MacAddress const mac_addr = MacAddress::create_from_uid();

if (!tc6_inst.begin(ip_addr
if (!t1s_phy.begin(ip_addr
, network_mask
, gateway
, mac_addr
Expand Down Expand Up @@ -104,7 +99,7 @@ void loop()
/* Services the hardware and the protocol stack.
* Must be called cyclic. The faster the better.
*/
tc6_inst.service();
t1s_phy.service();

static unsigned long prev_beacon_check = 0;
static unsigned long prev_udp_packet_sent = 0;
Expand All @@ -114,7 +109,7 @@ void loop()
if ((now - prev_beacon_check) > 1000)
{
prev_beacon_check = now;
if (!tc6_inst.getPlcaStatus(OnPlcaStatus))
if (!t1s_phy.getPlcaStatus(OnPlcaStatus))
Serial.println("getPlcaStatus(...) failed");
}

Expand Down Expand Up @@ -189,6 +184,6 @@ static void OnPlcaStatus(bool success, bool plcaStatus)
Serial.println("PLCA Mode active");
else {
Serial.println("CSMA/CD fallback");
tc6_inst.enablePlca();
t1s_phy.enablePlca();
}
}
21 changes: 8 additions & 13 deletions examples/UDP_Server/UDP_Server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ static uint16_t const UDP_SERVER_LOCAL_PORT = 8888;
* GLOBAL VARIABLES
**************************************************************************************/

TC6::TC6_Io tc6_io(
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
SPI1
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
#else
SPI
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
#endif
, CS_PIN
, RESET_PIN
, IRQ_PIN);
TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io);
Arduino_10BASE_T1S_UDP udp_server;

/**************************************************************************************
Expand All @@ -65,19 +60,19 @@ void setup()
*/
pinMode(IRQ_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
[]() { tc6_io.onInterrupt(); },
[]() { t1s_io.onInterrupt(); },
FALLING);

/* Initialize IO module. */
if (!tc6_io.begin())
if (!t1s_io.begin())
{
Serial.println("'TC6_Io::begin(...)' failed.");
for (;;) { }
}

MacAddress const mac_addr = MacAddress::create_from_uid();

if (!tc6_inst.begin(ip_addr
if (!t1s_phy.begin(ip_addr
, network_mask
, gateway
, mac_addr
Expand Down Expand Up @@ -108,7 +103,7 @@ void loop()
/* Services the hardware and the protocol stack.
* Must be called cyclic. The faster the better.
*/
tc6_inst.service();
t1s_phy.service();

static unsigned long prev_beacon_check = 0;

Expand All @@ -117,7 +112,7 @@ void loop()
if ((now - prev_beacon_check) > 1000)
{
prev_beacon_check = now;
if (!tc6_inst.getPlcaStatus(OnPlcaStatus))
if (!t1s_phy.getPlcaStatus(OnPlcaStatus))
Serial.println("getPlcaStatus(...) failed");
}

Expand Down Expand Up @@ -180,6 +175,6 @@ static void OnPlcaStatus(bool success, bool plcaStatus)
Serial.println("PLCA Mode active");
else {
Serial.println("CSMA/CD fallback");
tc6_inst.enablePlca();
t1s_phy.enablePlca();
}
}
19 changes: 7 additions & 12 deletions examples/tools/Control-DIOx/Control-DIOx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,11 @@ static auto const DIO_PIN = TC6::DIO::A0;
* GLOBAL VARIABLES
**************************************************************************************/

TC6::TC6_Io tc6_io(
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
SPI1
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
#else
SPI
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
#endif
, CS_PIN
, RESET_PIN
, IRQ_PIN);
TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io);

/**************************************************************************************
* SETUP/LOOP
Expand All @@ -61,19 +56,19 @@ void setup()
*/
pinMode(IRQ_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
[]() { tc6_io.onInterrupt(); },
[]() { t1s_io.onInterrupt(); },
FALLING);

/* Initialize IO module. */
if (!tc6_io.begin())
if (!t1s_io.begin())
{
Serial.println("'TC6_Io::begin(...)' failed.");
for (;;) { }
}

MacAddress const mac_addr = MacAddress::create_from_uid();

if (!tc6_inst.begin(ip_addr
if (!t1s_phy.begin(ip_addr
, network_mask
, gateway
, mac_addr
Expand All @@ -96,7 +91,7 @@ void loop()
/* Services the hardware and the protocol stack.
* Must be called cyclic. The faster the better.
*/
tc6_inst.service();
t1s_phy.service();

static unsigned long prev_dio_toogle = 0;
auto const now = millis();
Expand All @@ -112,7 +107,7 @@ void loop()
Serial.print(" = ");
Serial.println(dio_val);

tc6_inst.digitalWrite(DIO_PIN, dio_val);
t1s_phy.digitalWrite(DIO_PIN, dio_val);
dio_val = !dio_val;
}
}
Expand Down
21 changes: 8 additions & 13 deletions examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,11 @@ static T1SMacSettings const t1s_default_mac_settings;
* GLOBAL VARIABLES
**************************************************************************************/

TC6::TC6_Io tc6_io(
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
SPI1
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
#else
SPI
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
#endif
, CS_PIN
, RESET_PIN
, IRQ_PIN);
TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io);

/**************************************************************************************
* SETUP/LOOP
Expand All @@ -58,19 +53,19 @@ void setup()
*/
pinMode(IRQ_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
[]() { tc6_io.onInterrupt(); },
[]() { t1s_io.onInterrupt(); },
FALLING);

/* Initialize IO module. */
if (!tc6_io.begin())
if (!t1s_io.begin())
{
Serial.println("'TC6_Io::begin(...)' failed.");
for (;;) { }
}

MacAddress const mac_addr = MacAddress::create_from_uid();

if (!tc6_inst.begin(ip_addr
if (!t1s_phy.begin(ip_addr
, network_mask
, gateway
, mac_addr
Expand All @@ -88,9 +83,9 @@ void setup()
Serial.println(t1s_default_mac_settings);

/* A0 -> LOCAL_ENABLE -> DO NOT feed power from board to network. */
tc6_inst.digitalWrite(TC6::DIO::A0, false);
t1s_phy.digitalWrite(TC6::DIO::A0, false);
/* A1 -> T1S_DISABLE -> Open the switch connecting network to board by pulling EN LOW. */
tc6_inst.digitalWrite(TC6::DIO::A1, true);
t1s_phy.digitalWrite(TC6::DIO::A1, true);

Serial.println("PoDL-Sink-Auto-TurnOff");
}
Expand All @@ -100,5 +95,5 @@ void loop()
/* Services the hardware and the protocol stack.
* Must be called cyclic. The faster the better.
*/
tc6_inst.service();
t1s_phy.service();
}
21 changes: 8 additions & 13 deletions examples/tools/PoDL-Source/PoDL-Source.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,11 @@ static T1SMacSettings const t1s_default_mac_settings;
* GLOBAL VARIABLES
**************************************************************************************/

TC6::TC6_Io tc6_io(
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
SPI1
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
#else
SPI
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
#endif
, CS_PIN
, RESET_PIN
, IRQ_PIN);
TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io);

/**************************************************************************************
* SETUP/LOOP
Expand All @@ -58,19 +53,19 @@ void setup()
*/
pinMode(IRQ_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
[]() { tc6_io.onInterrupt(); },
[]() { t1s_io.onInterrupt(); },
FALLING);

/* Initialize IO module. */
if (!tc6_io.begin())
if (!t1s_io.begin())
{
Serial.println("'TC6_Io::begin(...)' failed.");
for (;;) { }
}

MacAddress const mac_addr = MacAddress::create_from_uid();

if (!tc6_inst.begin(ip_addr
if (!t1s_phy.begin(ip_addr
, network_mask
, gateway
, mac_addr
Expand All @@ -88,9 +83,9 @@ void setup()
Serial.println(t1s_default_mac_settings);

/* A0 -> LOCAL_ENABLE -> feed power from board to network. */
tc6_inst.digitalWrite(TC6::DIO::A0, true);
t1s_phy.digitalWrite(TC6::DIO::A0, true);
/* A1 -> T1S_DISABLE -> close the switch connecting network to board. */
tc6_inst.digitalWrite(TC6::DIO::A1, true);
t1s_phy.digitalWrite(TC6::DIO::A1, true);

Serial.println("PoDL-Source");
}
Expand All @@ -100,5 +95,5 @@ void loop()
/* Services the hardware and the protocol stack.
* Must be called cyclic. The faster the better.
*/
tc6_inst.service();
t1s_phy.service();
}
8 changes: 8 additions & 0 deletions src/Arduino_10BASE_T1S.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ static int const RESET_PIN = -1;
static int const IRQ_PIN = -1;
# warning "No pins defined for your board"
#endif

/**************************************************************************************
* MACROS
**************************************************************************************/

#define Arduino_10BASE_T1S_PHY_TC6(__SPI, __CS_PIN, __RESET_PIN, __IRQ_PIN) \
TC6::TC6_Io t1s_io(__SPI, __CS_PIN, __RESET_PIN, __IRQ_PIN); \
TC6::TC6_Arduino_10BASE_T1S t1s_phy(t1s_io);

0 comments on commit 9bc3d51

Please sign in to comment.