Skip to content

Commit 2ef30e5

Browse files
pabigotnashif
authored andcommitted
drivers: spi: update to conform to API guidelines
When the async API is not enabled produce a build-time error rather than a runtime error. Also document the dependence on the option. Signed-off-by: Peter Bigot <[email protected]>
1 parent 2b7a27e commit 2ef30e5

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

include/drivers/spi.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,16 @@ static inline int spi_write(const struct device *dev,
320320
return spi_transceive(dev, config, tx_bufs, NULL);
321321
}
322322

323+
/* Doxygen defines this so documentation is generated. */
324+
#ifdef CONFIG_SPI_ASYNC
325+
323326
/**
324327
* @brief Read/write the specified amount of data from the SPI driver.
325328
*
326-
* Note: This function is asynchronous.
329+
* @note This function is asynchronous.
330+
*
331+
* @note This function is available only if @option{CONFIG_SPI_ASYNC}
332+
* is selected.
327333
*
328334
* @param dev Pointer to the device structure for the driver instance
329335
* @param config Pointer to a valid spi_config structure instance.
@@ -348,26 +354,19 @@ static inline int spi_transceive_async(const struct device *dev,
348354
const struct spi_buf_set *rx_bufs,
349355
struct k_poll_signal *async)
350356
{
351-
#ifdef CONFIG_SPI_ASYNC
352357
const struct spi_driver_api *api =
353358
(const struct spi_driver_api *)dev->api;
354359

355360
return api->transceive_async(dev, config, tx_bufs, rx_bufs, async);
356-
#else
357-
ARG_UNUSED(dev);
358-
ARG_UNUSED(config);
359-
ARG_UNUSED(tx_bufs);
360-
ARG_UNUSED(rx_bufs);
361-
ARG_UNUSED(async);
362-
363-
return -ENOTSUP;
364-
#endif /* CONFIG_SPI_ASYNC */
365361
}
366362

367363
/**
368364
* @brief Read the specified amount of data from the SPI driver.
369365
*
370-
* Note: This function is asynchronous.
366+
* @note This function is asynchronous.
367+
*
368+
* @note This function is available only if @option{CONFIG_SPI_ASYNC}
369+
* is selected.
371370
*
372371
* @param dev Pointer to the device structure for the driver instance
373372
* @param config Pointer to a valid spi_config structure instance.
@@ -394,7 +393,10 @@ static inline int spi_read_async(const struct device *dev,
394393
/**
395394
* @brief Write the specified amount of data from the SPI driver.
396395
*
397-
* Note: This function is asynchronous.
396+
* @note This function is asynchronous.
397+
*
398+
* @note This function is available only if @option{CONFIG_SPI_ASYNC}
399+
* is selected.
398400
*
399401
* @param dev Pointer to the device structure for the driver instance
400402
* @param config Pointer to a valid spi_config structure instance.
@@ -417,6 +419,7 @@ static inline int spi_write_async(const struct device *dev,
417419
{
418420
return spi_transceive_async(dev, config, tx_bufs, NULL, async);
419421
}
422+
#endif /* CONFIG_SPI_ASYNC */
420423

421424
/**
422425
* @brief Release the SPI device locked on by the current config

0 commit comments

Comments
 (0)