Skip to content

Ensure arduino-style compatibility of library. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
**************************************************************************************/

auto const tc6_io = new TC6::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);
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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
**************************************************************************************/

auto const tc6_io = new TC6::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);
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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
**************************************************************************************/

auto const tc6_io = new TC6::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);
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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
**************************************************************************************/

auto const tc6_io = new TC6::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);
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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
**************************************************************************************/

auto const tc6_io = new TC6::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);
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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);
6 changes: 3 additions & 3 deletions src/T1SMacSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class T1SMacSettings : public arduino::Printable

virtual size_t printTo(Print & p) const override;

uint8_t mac_promiscuous_mode() const { return _mac_promiscuous_mode; }
uint8_t mac_tx_cut_through() const { return _mac_tx_cut_through; }
uint8_t mac_rx_cut_through() const { return _mac_rx_cut_through; }
bool isMacPromiscuousModeEnabled() const { return _mac_promiscuous_mode; }
bool isMacTxCutThroughEnabled() const { return _mac_tx_cut_through; }
bool isMacRxCutThroughEnabled() const { return _mac_rx_cut_through; }
};
8 changes: 4 additions & 4 deletions src/T1SPlcaSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class T1SPlcaSettings : public arduino::Printable
virtual size_t printTo(Print & p) const override;


uint8_t node_id() const { return _node_id; }
uint8_t node_count() const { return _node_count; }
uint8_t burst_count() const { return _burst_count; }
uint8_t burst_timer() const { return _burst_timer; }
uint8_t nodeId() const { return _node_id; }
uint8_t nodeCount() const { return _node_count; }
uint8_t burstCount() const { return _burst_count; }
uint8_t burstTimer() const { return _burst_timer; }
};
Loading