spi: helper macro for constructing CS gpio_dt_spec
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>
This commit is contained in:
parent
e706967d34
commit
4d1c90ee53
1 changed files with 40 additions and 0 deletions
|
@ -116,6 +116,46 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
#define DT_SPI_DEV_HAS_CS_GPIOS(spi_dev) DT_SPI_HAS_CS_GPIOS(DT_BUS(spi_dev))
|
#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
|
* @brief Get a SPI device's chip select GPIO controller's node identifier
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue