drivers/soft_spi: update API to match periph_spi
This commit is contained in:
parent
9e5f7b6797
commit
7aab478678
@ -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
|
* @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)
|
* valid (they are checked in soft_spi_init and soft_spi_init_cs before)
|
||||||
*
|
*
|
||||||
* @param[in] bus SPI device to access
|
* @param[in] bus SPI device to access
|
||||||
* @param[in] cs chip select pin/line to use
|
* @param[in] cs chip select pin/line to use
|
||||||
* @param[in] mode mode to use for the new transaction
|
* @param[in] mode mode to use for the new transaction
|
||||||
* @param[in] clk bus clock speed to use for the 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
|
|
||||||
*/
|
*/
|
||||||
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
|
* @brief Finish an ongoing SPI transaction by releasing the given SPI bus
|
||||||
|
|||||||
@ -101,18 +101,24 @@ int soft_spi_init_cs(soft_spi_t bus, soft_spi_cs_t cs)
|
|||||||
return SOFT_SPI_OK;
|
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_bus_is_valid(bus));
|
||||||
|
assert(soft_spi_mode_is_valid(mode));
|
||||||
|
|
||||||
/* lock bus */
|
/* lock bus */
|
||||||
mutex_lock(&locks[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;
|
soft_spi_config[bus].soft_spi_mode = mode;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case SOFT_SPI_MODE_0:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
soft_spi_config[bus].soft_spi_clk = clk;
|
soft_spi_config[bus].soft_spi_clk = clk;
|
||||||
return SOFT_SPI_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void soft_spi_release(soft_spi_t bus)
|
void soft_spi_release(soft_spi_t bus)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user