Skip to content

Commit 56e8fc1

Browse files
authored
Merge pull request #21 from arduino-libraries/arduino-style
Ensure arduino-style compatibility of library.
2 parents cb58fdb + 9bc3d51 commit 56e8fc1

File tree

12 files changed

+75
-92
lines changed

12 files changed

+75
-92
lines changed

examples/UDP_Client/UDP_Client.ino

+8-13
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,11 @@ static uint16_t const UDP_SERVER_PORT = 8888;
3434
* GLOBAL VARIABLES
3535
**************************************************************************************/
3636

37-
auto const tc6_io = new TC6::TC6_Io(
3837
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
39-
SPI1
38+
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
4039
#else
41-
SPI
40+
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
4241
#endif
43-
, CS_PIN
44-
, RESET_PIN
45-
, IRQ_PIN);
46-
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
4742
Arduino_10BASE_T1S_UDP udp_client;
4843

4944
/**************************************************************************************
@@ -61,19 +56,19 @@ void setup()
6156
*/
6257
pinMode(IRQ_PIN, INPUT_PULLUP);
6358
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
64-
[]() { tc6_io->onInterrupt(); },
59+
[]() { t1s_io.onInterrupt(); },
6560
FALLING);
6661

6762
/* Initialize IO module. */
68-
if (!tc6_io->begin())
63+
if (!t1s_io.begin())
6964
{
7065
Serial.println("'TC6_Io::begin(...)' failed.");
7166
for (;;) { }
7267
}
7368

7469
MacAddress const mac_addr = MacAddress::create_from_uid();
7570

76-
if (!tc6_inst->begin(ip_addr
71+
if (!t1s_phy.begin(ip_addr
7772
, network_mask
7873
, gateway
7974
, mac_addr
@@ -104,7 +99,7 @@ void loop()
10499
/* Services the hardware and the protocol stack.
105100
* Must be called cyclic. The faster the better.
106101
*/
107-
tc6_inst->service();
102+
t1s_phy.service();
108103

109104
static unsigned long prev_beacon_check = 0;
110105
static unsigned long prev_udp_packet_sent = 0;
@@ -114,7 +109,7 @@ void loop()
114109
if ((now - prev_beacon_check) > 1000)
115110
{
116111
prev_beacon_check = now;
117-
if (!tc6_inst->getPlcaStatus(OnPlcaStatus))
112+
if (!t1s_phy.getPlcaStatus(OnPlcaStatus))
118113
Serial.println("getPlcaStatus(...) failed");
119114
}
120115

@@ -189,6 +184,6 @@ static void OnPlcaStatus(bool success, bool plcaStatus)
189184
Serial.println("PLCA Mode active");
190185
else {
191186
Serial.println("CSMA/CD fallback");
192-
tc6_inst->enablePlca();
187+
t1s_phy.enablePlca();
193188
}
194189
}

examples/UDP_Server/UDP_Server.ino

+8-13
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,11 @@ static uint16_t const UDP_SERVER_LOCAL_PORT = 8888;
3838
* GLOBAL VARIABLES
3939
**************************************************************************************/
4040

41-
auto const tc6_io = new TC6::TC6_Io(
4241
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
43-
SPI1
42+
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
4443
#else
45-
SPI
44+
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
4645
#endif
47-
, CS_PIN
48-
, RESET_PIN
49-
, IRQ_PIN);
50-
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
5146
Arduino_10BASE_T1S_UDP udp_server;
5247

5348
/**************************************************************************************
@@ -65,19 +60,19 @@ void setup()
6560
*/
6661
pinMode(IRQ_PIN, INPUT_PULLUP);
6762
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
68-
[]() { tc6_io->onInterrupt(); },
63+
[]() { t1s_io.onInterrupt(); },
6964
FALLING);
7065

7166
/* Initialize IO module. */
72-
if (!tc6_io->begin())
67+
if (!t1s_io.begin())
7368
{
7469
Serial.println("'TC6_Io::begin(...)' failed.");
7570
for (;;) { }
7671
}
7772

7873
MacAddress const mac_addr = MacAddress::create_from_uid();
7974

80-
if (!tc6_inst->begin(ip_addr
75+
if (!t1s_phy.begin(ip_addr
8176
, network_mask
8277
, gateway
8378
, mac_addr
@@ -108,7 +103,7 @@ void loop()
108103
/* Services the hardware and the protocol stack.
109104
* Must be called cyclic. The faster the better.
110105
*/
111-
tc6_inst->service();
106+
t1s_phy.service();
112107

113108
static unsigned long prev_beacon_check = 0;
114109

@@ -117,7 +112,7 @@ void loop()
117112
if ((now - prev_beacon_check) > 1000)
118113
{
119114
prev_beacon_check = now;
120-
if (!tc6_inst->getPlcaStatus(OnPlcaStatus))
115+
if (!t1s_phy.getPlcaStatus(OnPlcaStatus))
121116
Serial.println("getPlcaStatus(...) failed");
122117
}
123118

@@ -180,6 +175,6 @@ static void OnPlcaStatus(bool success, bool plcaStatus)
180175
Serial.println("PLCA Mode active");
181176
else {
182177
Serial.println("CSMA/CD fallback");
183-
tc6_inst->enablePlca();
178+
t1s_phy.enablePlca();
184179
}
185180
}

examples/tools/Control-DIOx/Control-DIOx.ino

+7-12
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,11 @@ static auto const DIO_PIN = TC6::DIO::A0;
3535
* GLOBAL VARIABLES
3636
**************************************************************************************/
3737

38-
auto const tc6_io = new TC6::TC6_Io(
3938
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
40-
SPI1
39+
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
4140
#else
42-
SPI
41+
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
4342
#endif
44-
, CS_PIN
45-
, RESET_PIN
46-
, IRQ_PIN);
47-
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
4843

4944
/**************************************************************************************
5045
* SETUP/LOOP
@@ -61,19 +56,19 @@ void setup()
6156
*/
6257
pinMode(IRQ_PIN, INPUT_PULLUP);
6358
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
64-
[]() { tc6_io->onInterrupt(); },
59+
[]() { t1s_io.onInterrupt(); },
6560
FALLING);
6661

6762
/* Initialize IO module. */
68-
if (!tc6_io->begin())
63+
if (!t1s_io.begin())
6964
{
7065
Serial.println("'TC6_Io::begin(...)' failed.");
7166
for (;;) { }
7267
}
7368

7469
MacAddress const mac_addr = MacAddress::create_from_uid();
7570

76-
if (!tc6_inst->begin(ip_addr
71+
if (!t1s_phy.begin(ip_addr
7772
, network_mask
7873
, gateway
7974
, mac_addr
@@ -96,7 +91,7 @@ void loop()
9691
/* Services the hardware and the protocol stack.
9792
* Must be called cyclic. The faster the better.
9893
*/
99-
tc6_inst->service();
94+
t1s_phy.service();
10095

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

115-
tc6_inst->digitalWrite(DIO_PIN, dio_val);
110+
t1s_phy.digitalWrite(DIO_PIN, dio_val);
116111
dio_val = !dio_val;
117112
}
118113
}

examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino

+8-13
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,11 @@ static T1SMacSettings const t1s_default_mac_settings;
3232
* GLOBAL VARIABLES
3333
**************************************************************************************/
3434

35-
auto const tc6_io = new TC6::TC6_Io(
3635
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
37-
SPI1
36+
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
3837
#else
39-
SPI
38+
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
4039
#endif
41-
, CS_PIN
42-
, RESET_PIN
43-
, IRQ_PIN);
44-
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
4540

4641
/**************************************************************************************
4742
* SETUP/LOOP
@@ -58,19 +53,19 @@ void setup()
5853
*/
5954
pinMode(IRQ_PIN, INPUT_PULLUP);
6055
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
61-
[]() { tc6_io->onInterrupt(); },
56+
[]() { t1s_io.onInterrupt(); },
6257
FALLING);
6358

6459
/* Initialize IO module. */
65-
if (!tc6_io->begin())
60+
if (!t1s_io.begin())
6661
{
6762
Serial.println("'TC6_Io::begin(...)' failed.");
6863
for (;;) { }
6964
}
7065

7166
MacAddress const mac_addr = MacAddress::create_from_uid();
7267

73-
if (!tc6_inst->begin(ip_addr
68+
if (!t1s_phy.begin(ip_addr
7469
, network_mask
7570
, gateway
7671
, mac_addr
@@ -88,9 +83,9 @@ void setup()
8883
Serial.println(t1s_default_mac_settings);
8984

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

9590
Serial.println("PoDL-Sink-Auto-TurnOff");
9691
}
@@ -100,5 +95,5 @@ void loop()
10095
/* Services the hardware and the protocol stack.
10196
* Must be called cyclic. The faster the better.
10297
*/
103-
tc6_inst->service();
98+
t1s_phy.service();
10499
}

examples/tools/PoDL-Source/PoDL-Source.ino

+8-13
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,11 @@ static T1SMacSettings const t1s_default_mac_settings;
3232
* GLOBAL VARIABLES
3333
**************************************************************************************/
3434

35-
auto const tc6_io = new TC6::TC6_Io(
3635
#if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33)
37-
SPI1
36+
Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN);
3837
#else
39-
SPI
38+
Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
4039
#endif
41-
, CS_PIN
42-
, RESET_PIN
43-
, IRQ_PIN);
44-
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
4540

4641
/**************************************************************************************
4742
* SETUP/LOOP
@@ -58,19 +53,19 @@ void setup()
5853
*/
5954
pinMode(IRQ_PIN, INPUT_PULLUP);
6055
attachInterrupt(digitalPinToInterrupt(IRQ_PIN),
61-
[]() { tc6_io->onInterrupt(); },
56+
[]() { t1s_io.onInterrupt(); },
6257
FALLING);
6358

6459
/* Initialize IO module. */
65-
if (!tc6_io->begin())
60+
if (!t1s_io.begin())
6661
{
6762
Serial.println("'TC6_Io::begin(...)' failed.");
6863
for (;;) { }
6964
}
7065

7166
MacAddress const mac_addr = MacAddress::create_from_uid();
7267

73-
if (!tc6_inst->begin(ip_addr
68+
if (!t1s_phy.begin(ip_addr
7469
, network_mask
7570
, gateway
7671
, mac_addr
@@ -88,9 +83,9 @@ void setup()
8883
Serial.println(t1s_default_mac_settings);
8984

9085
/* A0 -> LOCAL_ENABLE -> feed power from board to network. */
91-
tc6_inst->digitalWrite(TC6::DIO::A0, true);
86+
t1s_phy.digitalWrite(TC6::DIO::A0, true);
9287
/* A1 -> T1S_DISABLE -> close the switch connecting network to board. */
93-
tc6_inst->digitalWrite(TC6::DIO::A1, true);
88+
t1s_phy.digitalWrite(TC6::DIO::A1, true);
9489

9590
Serial.println("PoDL-Source");
9691
}
@@ -100,5 +95,5 @@ void loop()
10095
/* Services the hardware and the protocol stack.
10196
* Must be called cyclic. The faster the better.
10297
*/
103-
tc6_inst->service();
98+
t1s_phy.service();
10499
}

src/Arduino_10BASE_T1S.h

+8
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ static int const RESET_PIN = -1;
5353
static int const IRQ_PIN = -1;
5454
# warning "No pins defined for your board"
5555
#endif
56+
57+
/**************************************************************************************
58+
* MACROS
59+
**************************************************************************************/
60+
61+
#define Arduino_10BASE_T1S_PHY_TC6(__SPI, __CS_PIN, __RESET_PIN, __IRQ_PIN) \
62+
TC6::TC6_Io t1s_io(__SPI, __CS_PIN, __RESET_PIN, __IRQ_PIN); \
63+
TC6::TC6_Arduino_10BASE_T1S t1s_phy(t1s_io);

src/T1SMacSettings.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class T1SMacSettings : public arduino::Printable
4343

4444
virtual size_t printTo(Print & p) const override;
4545

46-
uint8_t mac_promiscuous_mode() const { return _mac_promiscuous_mode; }
47-
uint8_t mac_tx_cut_through() const { return _mac_tx_cut_through; }
48-
uint8_t mac_rx_cut_through() const { return _mac_rx_cut_through; }
46+
bool isMacPromiscuousModeEnabled() const { return _mac_promiscuous_mode; }
47+
bool isMacTxCutThroughEnabled() const { return _mac_tx_cut_through; }
48+
bool isMacRxCutThroughEnabled() const { return _mac_rx_cut_through; }
4949
};

src/T1SPlcaSettings.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class T1SPlcaSettings : public arduino::Printable
4949
virtual size_t printTo(Print & p) const override;
5050

5151

52-
uint8_t node_id() const { return _node_id; }
53-
uint8_t node_count() const { return _node_count; }
54-
uint8_t burst_count() const { return _burst_count; }
55-
uint8_t burst_timer() const { return _burst_timer; }
52+
uint8_t nodeId() const { return _node_id; }
53+
uint8_t nodeCount() const { return _node_count; }
54+
uint8_t burstCount() const { return _burst_count; }
55+
uint8_t burstTimer() const { return _burst_timer; }
5656
};

0 commit comments

Comments
 (0)