1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

drivers/soft_spi: update API to match periph_spi

This commit is contained in:
Marian Buschsieweke 2021-02-01 14:23:28 +01:00
parent 9e5f7b6797
commit 7aab478678
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
2 changed files with 17 additions and 16 deletions

View File

@ -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

View File

@ -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)