-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft of high-level API for controlling various DIOs.
This works, but needs refinement and extension.
- Loading branch information
Showing
5 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* This example has been tested with the Arduino 10BASE-T1S (T1TOS) shield and | ||
* can be used to control the value of various DIO output pins. | ||
* | ||
* Author: | ||
* Alexander Entinger | ||
*/ | ||
|
||
/************************************************************************************** | ||
* INCLUDE | ||
**************************************************************************************/ | ||
|
||
#include <Arduino_10BASE_T1S.h> | ||
|
||
#include <SPI.h> | ||
|
||
/************************************************************************************** | ||
* CONSTANTS | ||
**************************************************************************************/ | ||
|
||
static uint8_t const T1S_PLCA_NODE_ID = 0; /* Doubles as PLCA coordinator. */ | ||
|
||
static IPAddress const ip_addr {192, 168, 42, 100 + T1S_PLCA_NODE_ID}; | ||
static IPAddress const network_mask{255, 255, 255, 0}; | ||
static IPAddress const gateway {192, 168, 42, 100}; | ||
|
||
static T1SPlcaSettings const t1s_plca_settings{T1S_PLCA_NODE_ID}; | ||
static T1SMacSettings const t1s_default_mac_settings; | ||
|
||
/************************************************************************************** | ||
* GLOBAL VARIABLES | ||
**************************************************************************************/ | ||
|
||
auto const tc6_io = new TC6::TC6_Io | ||
( SPI | ||
, CS_PIN | ||
, RESET_PIN | ||
, IRQ_PIN); | ||
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io); | ||
|
||
/************************************************************************************** | ||
* SETUP/LOOP | ||
**************************************************************************************/ | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
while (!Serial) { } | ||
delay(1000); | ||
|
||
/* Initialize digital IO interface for interfacing | ||
* with the LAN8651. | ||
*/ | ||
pinMode(IRQ_PIN, INPUT_PULLUP); | ||
attachInterrupt(digitalPinToInterrupt(IRQ_PIN), | ||
[]() { tc6_io->onInterrupt(); }, | ||
FALLING); | ||
|
||
/* Initialize IO module. */ | ||
if (!tc6_io->begin()) | ||
{ | ||
Serial.println("'TC6_Io::begin(...)' failed."); | ||
for (;;) { } | ||
} | ||
|
||
MacAddress const mac_addr = MacAddress::create_from_uid(); | ||
|
||
if (!tc6_inst->begin(ip_addr | ||
, network_mask | ||
, gateway | ||
, mac_addr | ||
, t1s_plca_settings | ||
, t1s_default_mac_settings)) | ||
{ | ||
Serial.println("'TC6::begin(...)' failed."); | ||
for (;;) { } | ||
} | ||
|
||
Serial.print("IP\t"); | ||
Serial.println(ip_addr); | ||
Serial.println(mac_addr); | ||
Serial.println(t1s_plca_settings); | ||
Serial.println(t1s_default_mac_settings); | ||
|
||
// If Power Provider, turn on LOCAL_ENABLE and turn on T1S_DISABLE | ||
//tc6_inst->digitalWrite(1,1,1); | ||
//tc6_inst->digitalWrite(0,0,0); | ||
} | ||
|
||
void loop() | ||
{ | ||
/* Services the hardware and the protocol stack. | ||
* Must be called cyclic. The faster the better. | ||
*/ | ||
tc6_inst->service(); | ||
|
||
static unsigned long prev_dio_toogle = 0; | ||
auto const now = millis(); | ||
|
||
if ((now - prev_dio_toogle) > 5000) | ||
{ | ||
prev_dio_toogle = now; | ||
|
||
static bool dio_val = true; | ||
|
||
Serial.print("DIO A0 = "); | ||
Serial.println(dio_val); | ||
|
||
/* Modify this function call parameter if you want | ||
* to test a different LAN8651 DIO. | ||
*/ | ||
tc6_inst->digitalWrite(TC6::DIO::A0, dio_val); | ||
dio_val = !dio_val; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters