From 35544e81ee4b88188a5dfac93b296afd4fa55cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Tue, 14 Jul 2015 18:27:06 +0200 Subject: [PATCH] enc28j60: Reuse read/writedata() for read/writedatabyte() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The read/writedatabyte() functions are just a special case of read/writedata() with a simpler API, so reuse these instead of duplicating code. Signed-off-by: Benoît Thébaudeau --- dev/enc28j60/enc28j60.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/dev/enc28j60/enc28j60.c b/dev/enc28j60/enc28j60.c index dd00dddeb..1ee77ad9f 100644 --- a/dev/enc28j60/enc28j60.c +++ b/dev/enc28j60/enc28j60.c @@ -160,16 +160,6 @@ setregbank(uint8_t bank) } /*---------------------------------------------------------------------------*/ static void -writedatabyte(uint8_t byte) -{ - enc28j60_arch_spi_select(); - /* The Write Buffer Memory (WBM) command is 0 1 1 1 1 0 1 0 */ - enc28j60_arch_spi_write(0x7a); - enc28j60_arch_spi_write(byte); - enc28j60_arch_spi_deselect(); -} -/*---------------------------------------------------------------------------*/ -static void writedata(uint8_t *data, int datalen) { int i; @@ -182,16 +172,10 @@ writedata(uint8_t *data, int datalen) enc28j60_arch_spi_deselect(); } /*---------------------------------------------------------------------------*/ -static uint8_t -readdatabyte(void) +static void +writedatabyte(uint8_t byte) { - uint8_t r; - enc28j60_arch_spi_select(); - /* THe Read Buffer Memory (RBM) command is 0 0 1 1 1 0 1 0 */ - enc28j60_arch_spi_write(0x3a); - r = enc28j60_arch_spi_read(); - enc28j60_arch_spi_deselect(); - return r; + writedata(&byte, 1); } /*---------------------------------------------------------------------------*/ static int @@ -208,6 +192,14 @@ readdata(uint8_t *buf, int len) return i; } /*---------------------------------------------------------------------------*/ +static uint8_t +readdatabyte(void) +{ + uint8_t r; + readdata(&r, 1); + return r; +} +/*---------------------------------------------------------------------------*/ static void softreset(void) {