From 7aab4786781250e2abc53fa743fde96c43d7925d Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Mon, 1 Feb 2021 14:23:28 +0100 Subject: [PATCH] drivers/soft_spi: update API to match periph_spi --- drivers/include/soft_spi.h | 14 +++++--------- drivers/soft_spi/soft_spi.c | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/include/soft_spi.h b/drivers/include/soft_spi.h index 4ba55d87e8..777552ee48 100644 --- a/drivers/include/soft_spi.h +++ b/drivers/include/soft_spi.h @@ -185,16 +185,12 @@ int soft_spi_init_cs(soft_spi_t bus, soft_spi_cs_t cs); * @note This function expects the @p bus and the @p cs parameters to be * valid (they are checked in soft_spi_init and soft_spi_init_cs before) * - * @param[in] bus SPI device to access - * @param[in] cs chip select pin/line to use - * @param[in] mode mode to use for the new transaction - * @param[in] clk bus clock speed to use for the transaction - * - * @return SOFT_SPI_OK on success - * @return SOFT_SPI_NOMODE if given mode is not supported - * @return SOFT_SPI_NOCLK if given clock speed is not supported + * @param[in] bus SPI device to access + * @param[in] cs chip select pin/line to use + * @param[in] mode mode to use for the new transaction + * @param[in] clk bus clock speed to use for the transaction */ -int soft_spi_acquire(soft_spi_t bus, soft_spi_cs_t cs, soft_spi_mode_t mode, soft_spi_clk_t clk); +void soft_spi_acquire(soft_spi_t bus, soft_spi_cs_t cs, soft_spi_mode_t mode, soft_spi_clk_t clk); /** * @brief Finish an ongoing SPI transaction by releasing the given SPI bus diff --git a/drivers/soft_spi/soft_spi.c b/drivers/soft_spi/soft_spi.c index 77c55c890e..9e31e24b53 100644 --- a/drivers/soft_spi/soft_spi.c +++ b/drivers/soft_spi/soft_spi.c @@ -101,18 +101,24 @@ int soft_spi_init_cs(soft_spi_t bus, soft_spi_cs_t cs) return SOFT_SPI_OK; } -int soft_spi_acquire(soft_spi_t bus, soft_spi_cs_t cs, soft_spi_mode_t mode, soft_spi_clk_t clk) +static inline int soft_spi_mode_is_valid(soft_spi_mode_t mode) { - (void) cs; + if ((mode != SOFT_SPI_MODE_0) && (mode != SOFT_SPI_MODE_1) && + (mode != SOFT_SPI_MODE_2) && (mode != SOFT_SPI_MODE_3)) { + return 0; + } + return 1; +} + +void soft_spi_acquire(soft_spi_t bus, soft_spi_cs_t cs, soft_spi_mode_t mode, soft_spi_clk_t clk) +{ + (void)cs; assert(soft_spi_bus_is_valid(bus)); + assert(soft_spi_mode_is_valid(mode)); /* lock bus */ mutex_lock(&locks[bus]); - if ((mode != SOFT_SPI_MODE_0) && (mode != SOFT_SPI_MODE_1) && - (mode != SOFT_SPI_MODE_2) && (mode != SOFT_SPI_MODE_3)) { - return SOFT_SPI_NOMODE; - } soft_spi_config[bus].soft_spi_mode = mode; switch (mode) { case SOFT_SPI_MODE_0: @@ -127,7 +133,6 @@ int soft_spi_acquire(soft_spi_t bus, soft_spi_cs_t cs, soft_spi_mode_t mode, sof break; } soft_spi_config[bus].soft_spi_clk = clk; - return SOFT_SPI_OK; } void soft_spi_release(soft_spi_t bus)