Skip to content

added ability of setting CS pin inside sketch #129

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 12 additions & 12 deletions UIPEthernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ UIPEthernetClass::UIPEthernetClass()

#if UIP_UDP
int
UIPEthernetClass::begin(const uint8_t* mac)
UIPEthernetClass::begin(const uint8_t* mac, int cs_pin)
{
static DhcpClass s_dhcp;
_dhcp = &s_dhcp;

// Initialise the basic info
init(mac);
init(mac, cs_pin);

// Now try to get our config info from a DHCP server
int ret = _dhcp->beginWithDHCP((uint8_t*)mac);
Expand All @@ -77,32 +77,32 @@ UIPEthernetClass::begin(const uint8_t* mac)
#endif

void
UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip)
UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, int cs_pin)
{
IPAddress dns = ip;
dns[3] = 1;
begin(mac, ip, dns);
begin(mac, ip, dns, cs_pin);
}

void
UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns)
UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, int cs_pin)
{
IPAddress gateway = ip;
gateway[3] = 1;
begin(mac, ip, dns, gateway);
begin(mac, ip, dns, gateway, cs_pin);
}

void
UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway)
UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, int cs_pin)
{
IPAddress subnet(255, 255, 255, 0);
begin(mac, ip, dns, gateway, subnet);
begin(mac, ip, dns, gateway, subnet, cs_pin);
}

void
UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet)
UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, int cs_pin)
{
init(mac);
init(mac, cs_pin);
configure(ip,dns,gateway,subnet);
}

Expand Down Expand Up @@ -314,10 +314,10 @@ boolean UIPEthernetClass::network_send()
return true;
}

void UIPEthernetClass::init(const uint8_t* mac) {
void UIPEthernetClass::init(const uint8_t* mac, int cs_pin) {
periodic_timer = millis() + UIP_PERIODIC_TIMER;

Enc28J60Network::init((uint8_t*)mac);
Enc28J60Network::init((uint8_t*)mac, cs_pin);
uip_seteth_addr(mac);

uip_init();
Expand Down
12 changes: 6 additions & 6 deletions UIPEthernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class UIPEthernetClass
public:
UIPEthernetClass();

int begin(const uint8_t* mac);
void begin(const uint8_t* mac, IPAddress ip);
void begin(const uint8_t* mac, IPAddress ip, IPAddress dns);
void begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway);
void begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);
int begin(const uint8_t* mac, int cs_pin=SS);
void begin(const uint8_t* mac, IPAddress ip, int cs_pin=SS);
void begin(const uint8_t* mac, IPAddress ip, IPAddress dns, int cs_pin=SS);
void begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, int cs_pin=SS);
void begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, int cs_pin=SS);

// maintain() must be called at regular intervals to process the incoming serial
// data and issue IP events to the sketch. It does not return until all IP
Expand All @@ -92,7 +92,7 @@ class UIPEthernetClass

static unsigned long periodic_timer;

static void init(const uint8_t* mac);
static void init(const uint8_t* mac, int cs_pin);
static void configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);

static void tick();
Expand Down
6 changes: 5 additions & 1 deletion utility/Enc28J60Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extern "C" {
#include "HardwareSerial.h"
#endif

int ENC28J60_CS;

// set CS to 0 = active
#define CSACTIVE digitalWrite(ENC28J60_CONTROL_CS, LOW)
// set CS to 1 = passive
Expand All @@ -47,10 +49,12 @@ uint8_t Enc28J60Network::bank=0xff;

struct memblock Enc28J60Network::receivePkt;

void Enc28J60Network::init(uint8_t* macaddr)
void Enc28J60Network::init(uint8_t* macaddr, int cs_pin)
{
MemoryPool::init(); // 1 byte in between RX_STOP_INIT and pool to allow prepending of controlbyte
// initialize I/O
// set CS pin
ENC28J60_CS = cs_pin;
// ss as output:
pinMode(ENC28J60_CONTROL_CS, OUTPUT);
CSPASSIVE; // ss=0
Expand Down
4 changes: 2 additions & 2 deletions utility/Enc28J60Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "mempool.h"

#define ENC28J60_CONTROL_CS SS
#define ENC28J60_CONTROL_CS ENC28J60_CS
#define SPI_MOSI MOSI
#define SPI_MISO MISO
#define SPI_SCK SCK
Expand Down Expand Up @@ -76,7 +76,7 @@ class Enc28J60Network : public MemoryPool
void powerOff();
bool linkStatus();

static void init(uint8_t* macaddr);
static void init(uint8_t* macaddr, int cs_pin);
static memhandle receivePacket();
static void freePacket();
static memaddress blockSize(memhandle handle);
Expand Down