Skip to content

Commit

Permalink
spi: helper macro for constructing CS gpio_dt_spec
Browse files Browse the repository at this point in the history
Adds a helper macro, `DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET`, that constructs
a `struct gpio_dt_spec` corresponding with the CS gpio of an spi device.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Co-authored-by: Jordan Yates <jordan.yates@data61.csiro.au>
Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
Co-authored-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
  • Loading branch information
2 people authored and cfriedt committed Oct 5, 2021
1 parent e706967 commit 4d1c90e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions include/devicetree/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,46 @@ extern "C" {
*/
#define DT_SPI_DEV_HAS_CS_GPIOS(spi_dev) DT_SPI_HAS_CS_GPIOS(DT_BUS(spi_dev))

/**
* @brief Get a SPI device's chip select devicetree specification
*
* Example devicetree fragment:
*
* @code{.devicetree}
* gpio1: gpio@... { ... };
*
* gpio2: gpio@... { ... };
*
* spi@... {
* compatible = "vnd,spi";
* cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
* <&gpio2 20 GPIO_ACTIVE_LOW>;
*
* a: spi-dev-a@0 {
* reg = <0>;
* };
*
* b: spi-dev-b@1 {
* reg = <1>;
* };
* };
* @endcode
*
* Example usage:
*
* @code{.c}
* DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(a)) \
* // { DEVICE_DT_GET(DT_NODELABEL(gpio1)), 10, GPIO_ACTIVE_LOW }
* DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(b)) \
* // { DEVICE_DT_GET(DT_NODELABEL(gpio2)), 20, GPIO_ACTIVE_LOW }
* @endcode
*
* @param spi_dev a SPI device node identifier
* @return #gpio_dt_spec struct corresponding with spi_dev's chip select
*/
#define DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET(spi_dev) \
GPIO_DT_SPEC_GET_BY_IDX(DT_BUS(spi_dev), cs_gpios, DT_REG_ADDR(spi_dev))

/**
* @brief Get a SPI device's chip select GPIO controller's node identifier
*
Expand Down

0 comments on commit 4d1c90e

Please sign in to comment.