diff --git a/include/drivers/spi.h b/include/drivers/spi.h index 6e8c65578d1..279e6a16e59 100644 --- a/include/drivers/spi.h +++ b/include/drivers/spi.h @@ -473,6 +473,28 @@ static inline int z_impl_spi_transceive(const struct device *dev, return api->transceive(dev, config, tx_bufs, rx_bufs); } +/** + * @brief Read/write data from an SPI bus specified in @p spi_dt_spec. + * + * This is equivalent to: + * + * spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs); + * + * @param spec SPI specification from devicetree + * @param tx_bufs Buffer array where data to be sent originates from, + * or NULL if none. + * @param rx_bufs Buffer array where data to be read will be written to, + * or NULL if none. + * + * @retval a value from spi_transceive() + */ +static inline int spi_transceive_dt(const struct spi_dt_spec *spec, + const struct spi_buf_set *tx_bufs, + const struct spi_buf_set *rx_bufs) +{ + return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs); +} + /** * @brief Read the specified amount of data from the SPI driver. * @@ -495,6 +517,24 @@ static inline int spi_read(const struct device *dev, return spi_transceive(dev, config, NULL, rx_bufs); } +/** + * @brief Read data from a SPI bus specified in @p spi_dt_spec. + * + * This is equivalent to: + * + * spi_read(spec->bus, &spec->config, rx_bufs); + * + * @param spec SPI specification from devicetree + * @param rx_bufs Buffer array where data to be read will be written to. + * + * @retval a value from spi_read() + */ +static inline int spi_read_dt(const struct spi_dt_spec *spec, + const struct spi_buf_set *rx_bufs) +{ + return spi_read(spec->bus, &spec->config, rx_bufs); +} + /** * @brief Write the specified amount of data from the SPI driver. * @@ -517,6 +557,24 @@ static inline int spi_write(const struct device *dev, return spi_transceive(dev, config, tx_bufs, NULL); } +/** + * @brief Write data to a SPI bus specified in @p spi_dt_spec. + * + * This is equivalent to: + * + * spi_write(spec->bus, &spec->config, tx_bufs); + * + * @param spec SPI specification from devicetree + * @param tx_bufs Buffer array where data to be sent originates from. + * + * @retval a value from spi_write() + */ +static inline int spi_write_dt(const struct spi_dt_spec *spec, + const struct spi_buf_set *tx_bufs) +{ + return spi_write(spec->bus, &spec->config, tx_bufs); +} + /* Doxygen defines this so documentation is generated. */ #ifdef CONFIG_SPI_ASYNC