From 4b15cc635e950ede413d71eee84cd6d1f96a3b15 Mon Sep 17 00:00:00 2001
From: Kaspar Schleiser <kaspar@schleiser.de>
Date: Thu, 13 Aug 2015 15:20:39 +0200
Subject: [PATCH] cpu: stm32f4: use periph_common SPI functions

---
 cpu/stm32f4/Makefile.include     |  3 ++
 cpu/stm32f4/include/periph_cpu.h |  8 +++++
 cpu/stm32f4/periph/spi.c         | 60 --------------------------------
 3 files changed, 11 insertions(+), 60 deletions(-)

diff --git a/cpu/stm32f4/Makefile.include b/cpu/stm32f4/Makefile.include
index ed4584a485..329c4fe9e5 100644
--- a/cpu/stm32f4/Makefile.include
+++ b/cpu/stm32f4/Makefile.include
@@ -3,4 +3,7 @@ export CPU_ARCH = cortex-m4f
 # use hwtimer compatibility module
 USEMODULE += hwtimer_compat
 
+# use common periph functions
+USEMODULE += periph_common
+
 include $(RIOTCPU)/Makefile.include.cortexm_common
diff --git a/cpu/stm32f4/include/periph_cpu.h b/cpu/stm32f4/include/periph_cpu.h
index 609fc51f18..aead4e9a08 100644
--- a/cpu/stm32f4/include/periph_cpu.h
+++ b/cpu/stm32f4/include/periph_cpu.h
@@ -90,6 +90,14 @@ typedef enum {
  */
 void gpio_init_af(gpio_t pin, gpio_af_t af);
 
+/**
+ * @brief declare needed generic SPI functions
+ * @{
+ */
+#define PERIPH_SPI_NEEDS_TRANSFER_BYTES
+#define PERIPH_SPI_NEEDS_TRANSFER_REG
+#define PERIPH_SPI_NEEDS_TRANSFER_REGS
+/** @} */
 
 #ifdef __cplusplus
 }
diff --git a/cpu/stm32f4/periph/spi.c b/cpu/stm32f4/periph/spi.c
index 1d59d630b7..2f7eb49267 100644
--- a/cpu/stm32f4/periph/spi.c
+++ b/cpu/stm32f4/periph/spi.c
@@ -350,66 +350,6 @@ int spi_transfer_byte(spi_t dev, char out, char *in)
     return 1;
 }
 
-int spi_transfer_bytes(spi_t dev, char *out, char *in, unsigned int length)
-{
-    int trans_bytes = 0;
-
-    for (unsigned int i = 0; i < length; i++) {
-        char in_temp;
-        int trans_ret;
-
-        if (out) {
-            trans_ret = spi_transfer_byte(dev, out[i], &in_temp);
-        }
-        else {
-            trans_ret = spi_transfer_byte(dev, 0, &in_temp);
-        }
-
-        if (trans_ret < 0) {
-            return -1;
-        }
-
-        if (in != NULL) {
-            in[i] = in_temp;
-        }
-        trans_bytes++;
-    }
-
-    return trans_bytes++;
-}
-
-int spi_transfer_reg(spi_t dev, uint8_t reg, char out, char *in)
-{
-    int trans_ret;
-
-    trans_ret = spi_transfer_byte(dev, reg, in);
-    if (trans_ret < 0) {
-        return -1;
-    }
-    trans_ret = spi_transfer_byte(dev, out, in);
-    if (trans_ret < 0) {
-        return -1;
-    }
-
-    return 1;
-}
-
-int spi_transfer_regs(spi_t dev, uint8_t reg, char *out, char *in, unsigned int length)
-{
-    int trans_ret;
-
-    trans_ret = spi_transfer_byte(dev, reg, in);
-    if (trans_ret < 0) {
-        return -1;
-    }
-    trans_ret = spi_transfer_bytes(dev, out, in, length);
-    if (trans_ret < 0) {
-        return -1;
-    }
-
-    return trans_ret;
-}
-
 void spi_transmission_begin(spi_t dev, char reset_val)
 {
 
-- 
GitLab