diff --git a/src/EtherCard.cpp b/src/EtherCard.cpp index f752a9bf..60b02b70 100644 --- a/src/EtherCard.cpp +++ b/src/EtherCard.cpp @@ -31,11 +31,23 @@ uint16_t EtherCard::delaycnt = 0; //request gateway ARP lookup uint8_t EtherCard::begin (const uint16_t size, const uint8_t* macaddr, uint8_t csPin) { + copyMac(mymac, macaddr); + return begin(size, csPin); +} + +uint8_t EtherCard::begin (const uint16_t size, + const __FlashStringHelper *macaddr, + uint8_t csPin) { + copyMac(mymac, macaddr); + return begin(size, csPin); +} + +/// helper for EtherCard::begin(3) +inline uint8_t EtherCard::begin (const uint16_t size, uint8_t csPin) { using_dhcp = false; #if ETHERCARD_STASH Stash::initMap(); #endif - copyMac(mymac, macaddr); return initialize(size, mymac, csPin); } diff --git a/src/EtherCard.h b/src/EtherCard.h index 703b5990..8b23051a 100644 --- a/src/EtherCard.h +++ b/src/EtherCard.h @@ -129,6 +129,14 @@ class EtherCard : public Ethernet { */ static uint8_t begin (const uint16_t size, const uint8_t* macaddr, uint8_t csPin = SS); + /** @brief Initialise the network interface using a MAC in PROGMEM + * @param size Size of data buffer + * @param macaddr Hardware address to assign to the network interface (6 bytes), read from program space + * @param csPin Arduino pin number connected to chip select. Default = 8 + * @return uint8_t Firmware version or zero on failure. + */ + static uint8_t begin (const uint16_t size, const __FlashStringHelper * macaddr, + uint8_t csPin = SS); /** @brief Configure network interface with static IP * @param my_ip IP address (4 bytes). 0 for no change. @@ -394,6 +402,13 @@ class EtherCard : public Ethernet { */ static void copyMac (uint8_t *dst, const uint8_t *src); + /** @brief Copies a hardware address from PROGMEM + * @param dst Pointer to the 6 byte destination + * @param src Pointer to the 6 byte destination in program space + * @note There is no check of source or destination size. Ensure both are 6 bytes + */ + static void copyMac (uint8_t *dst, const __FlashStringHelper *src); + /** @brief Output to serial port in dotted decimal IP format * @param buf Pointer to 4 byte IP address * @note There is no check of source or destination size. Ensure both are 4 bytes @@ -469,6 +484,14 @@ class EtherCard : public Ethernet { /** @brief Return the payload length of the current Tcp package */ static uint16_t getTcpPayloadLength(); +private: + /** @brief Initialise the network interface + * @param size Size of data buffer + * @param csPin Arduino pin number connected to chip select. Default = 8 + * @return uint8_t Firmware version or zero on failure. + * @note assumes the MAC address has already been set + */ + inline static uint8_t begin (const uint16_t size, uint8_t csPin = SS); }; extern EtherCard ether; //!< Global presentation of EtherCard class diff --git a/src/webutil.cpp b/src/webutil.cpp index 4eb9ba50..ce62752a 100644 --- a/src/webutil.cpp +++ b/src/webutil.cpp @@ -14,6 +14,10 @@ void EtherCard::copyMac (uint8_t *dst, const uint8_t *src) { memcpy(dst, src, ETH_LEN); } +void EtherCard::copyMac (uint8_t *dst, const __FlashStringHelper *src) { + memcpy_P(dst, src, ETH_LEN); +} + void EtherCard::printIp (const char* msg, const uint8_t *buf) { Serial.print(msg); EtherCard::printIp(buf);