1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-20 10:24:18 +03:00

modified Ethernet (w5100) library to run on the ESP8266

see #962
This commit is contained in:
Markus Sattler
2015-11-05 20:59:17 +01:00
parent 6735cad17a
commit 2a01c2ad53
4 changed files with 22 additions and 8 deletions

View File

@ -5,6 +5,8 @@ With the Arduino Ethernet Shield, this library allows an Arduino board to connec
For more information about this library please visit us at For more information about this library please visit us at
http://www.arduino.cc/en/Reference/Ethernet http://www.arduino.cc/en/Reference/Ethernet
modified to run on the ESP8266
== License == == License ==
Copyright (c) 2010 Arduino LLC. All right reserved. Copyright (c) 2010 Arduino LLC. All right reserved.

View File

@ -8,9 +8,15 @@ uint8_t EthernetClass::_state[MAX_SOCK_NUM] = {
uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
0, 0, 0, 0 }; 0, 0, 0, 0 };
#ifdef ESP8266
static DhcpClass s_dhcp;
#endif
int EthernetClass::begin(uint8_t *mac_address) int EthernetClass::begin(uint8_t *mac_address)
{ {
#ifndef ESP8266
static DhcpClass s_dhcp; static DhcpClass s_dhcp;
#endif
_dhcp = &s_dhcp; _dhcp = &s_dhcp;
@ -133,4 +139,4 @@ IPAddress EthernetClass::dnsServerIP()
return _dnsServerAddress; return _dnsServerAddress;
} }
EthernetClass Ethernet; EthernetClass Ethernet;

View File

@ -26,7 +26,7 @@ void W5100Class::init(void)
{ {
delay(300); delay(300);
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR) || defined(ESP8266)
SPI.begin(); SPI.begin();
initSS(); initSS();
#else #else
@ -136,7 +136,7 @@ void W5100Class::read_data(SOCKET s, volatile uint16_t src, volatile uint8_t *ds
uint8_t W5100Class::write(uint16_t _addr, uint8_t _data) uint8_t W5100Class::write(uint16_t _addr, uint8_t _data)
{ {
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR) || defined(ESP8266)
setSS(); setSS();
SPI.transfer(0xF0); SPI.transfer(0xF0);
SPI.transfer(_addr >> 8); SPI.transfer(_addr >> 8);
@ -156,7 +156,7 @@ uint16_t W5100Class::write(uint16_t _addr, const uint8_t *_buf, uint16_t _len)
{ {
for (uint16_t i=0; i<_len; i++) for (uint16_t i=0; i<_len; i++)
{ {
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR) || defined(ESP8266)
setSS(); setSS();
SPI.transfer(0xF0); SPI.transfer(0xF0);
SPI.transfer(_addr >> 8); SPI.transfer(_addr >> 8);
@ -177,7 +177,7 @@ uint16_t W5100Class::write(uint16_t _addr, const uint8_t *_buf, uint16_t _len)
uint8_t W5100Class::read(uint16_t _addr) uint8_t W5100Class::read(uint16_t _addr)
{ {
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR) || defined(ESP8266)
setSS(); setSS();
SPI.transfer(0x0F); SPI.transfer(0x0F);
SPI.transfer(_addr >> 8); SPI.transfer(_addr >> 8);
@ -197,7 +197,7 @@ uint16_t W5100Class::read(uint16_t _addr, uint8_t *_buf, uint16_t _len)
{ {
for (uint16_t i=0; i<_len; i++) for (uint16_t i=0; i<_len; i++)
{ {
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR) || defined(ESP8266)
setSS(); setSS();
SPI.transfer(0x0F); SPI.transfer(0x0F);
SPI.transfer(_addr >> 8); SPI.transfer(_addr >> 8);
@ -222,4 +222,4 @@ void W5100Class::execCmdSn(SOCKET s, SockCMD _cmd) {
// Wait for command to complete // Wait for command to complete
while (readSnCR(s)) while (readSnCR(s))
; ;
} }

View File

@ -16,6 +16,8 @@
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR)
#define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0) #define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
#elif defined(ESP8266)
#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0)
#else #else
#define SPI_ETHERNET_SETTINGS SPI_CS,SPISettings(4000000, MSBFIRST, SPI_MODE0) #define SPI_ETHERNET_SETTINGS SPI_CS,SPISettings(4000000, MSBFIRST, SPI_MODE0)
#endif #endif
@ -348,6 +350,10 @@ private:
inline static void setSS() { PORTB &= ~_BV(2); }; inline static void setSS() { PORTB &= ~_BV(2); };
inline static void resetSS() { PORTB |= _BV(2); }; inline static void resetSS() { PORTB |= _BV(2); };
#endif #endif
#elif defined(ESP8266)
inline static void initSS() { pinMode(SS, OUTPUT); };
inline static void setSS() { GPOC = digitalPinToBitMask(SS); };
inline static void resetSS() { GPOS = digitalPinToBitMask(SS); };
#endif // ARDUINO_ARCH_AVR #endif // ARDUINO_ARCH_AVR
}; };
@ -409,4 +415,4 @@ void W5100Class::setRetransmissionCount(uint8_t _retry) {
writeRCR(_retry); writeRCR(_retry);
} }
#endif #endif