/* * Copyright (c) 2010 by WIZnet * * This file is free software; you can redistribute it and/or modify * it under the terms of either the GNU General Public License version 2 * or the GNU Lesser General Public License version 2.1, both as * published by the Free Software Foundation. */ #include #include #include #include "w5100.h" #if defined(W5500_ETHERNET_SHIELD) // W5500 controller instance W5500Class W5100; void W5500Class::init(void) { initSS(); delay(300); SPI.begin(); for (int i=0; i> 8); SPI.transfer(_addr & 0xFF); SPI.transfer(_cb); SPI.transfer(_data); resetSS(); return 1; } uint16_t W5500Class::write(uint16_t _addr, uint8_t _cb, const uint8_t *_buf, uint16_t _len) { setSS(); SPI.transfer(_addr >> 8); SPI.transfer(_addr & 0xFF); SPI.transfer(_cb); for (uint16_t i=0; i<_len; i++){ SPI.transfer(_buf[i]); } resetSS(); return _len; } uint8_t W5500Class::read(uint16_t _addr, uint8_t _cb) { setSS(); SPI.transfer(_addr >> 8); SPI.transfer(_addr & 0xFF); SPI.transfer(_cb); uint8_t _data = SPI.transfer(0); resetSS(); return _data; } uint16_t W5500Class::read(uint16_t _addr, uint8_t _cb, uint8_t *_buf, uint16_t _len) { setSS(); SPI.transfer(_addr >> 8); SPI.transfer(_addr & 0xFF); SPI.transfer(_cb); for (uint16_t i=0; i<_len; i++){ _buf[i] = SPI.transfer(0); } resetSS(); return _len; } void W5500Class::execCmdSn(SOCKET s, SockCMD _cmd) { // Send command to socket writeSnCR(s, _cmd); // Wait for command to complete while (readSnCR(s)) ; } #endif