Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Devicetree SPI API

Macros

#define DT_SPI_HAS_CS_GPIOS(spi)
 Does a SPI controller node have chip select GPIOs configured?
 
#define DT_SPI_NUM_CS_GPIOS(spi)
 Number of chip select GPIOs in a SPI controller's cs-gpios property.
 
#define DT_SPI_DEV_HAS_CS_GPIOS(spi_dev)
 Does a SPI device have a chip select line configured? Example devicetree fragment:
 
#define DT_SPI_DEV_CS_GPIOS_CTLR(spi_dev)
 Get a SPI device's chip select GPIO controller's node identifier.
 
#define DT_SPI_DEV_CS_GPIOS_PIN(spi_dev)
 Get a SPI device's chip select GPIO pin number.
 
#define DT_SPI_DEV_CS_GPIOS_FLAGS(spi_dev)
 Get a SPI device's chip select GPIO flags.
 
#define DT_INST_SPI_DEV_HAS_CS_GPIOS(inst)
 Equivalent to DT_SPI_DEV_HAS_CS_GPIOS(DT_DRV_INST(inst)).
 
#define DT_INST_SPI_DEV_CS_GPIOS_CTLR(inst)
 Get GPIO controller node identifier for a SPI device instance This is equivalent to DT_SPI_DEV_CS_GPIOS_CTLR(DT_DRV_INST(inst)).
 
#define DT_INST_SPI_DEV_CS_GPIOS_PIN(inst)
 Equivalent to DT_SPI_DEV_CS_GPIOS_PIN(DT_DRV_INST(inst)).
 
#define DT_INST_SPI_DEV_CS_GPIOS_FLAGS(inst)
 DT_SPI_DEV_CS_GPIOS_FLAGS(DT_DRV_INST(inst)).
 

Detailed Description

Macro Definition Documentation

◆ DT_INST_SPI_DEV_CS_GPIOS_CTLR

#define DT_INST_SPI_DEV_CS_GPIOS_CTLR ( inst)

#include <zephyr/devicetree/spi.h>

Value:
#define DT_DRV_INST(inst)
Node identifier for an instance of a DT_DRV_COMPAT compatible.
Definition devicetree.h:3869
#define DT_SPI_DEV_CS_GPIOS_CTLR(spi_dev)
Get a SPI device's chip select GPIO controller's node identifier.
Definition spi.h:150

Get GPIO controller node identifier for a SPI device instance This is equivalent to DT_SPI_DEV_CS_GPIOS_CTLR(DT_DRV_INST(inst)).

Parameters
instDT_DRV_COMPAT instance number
Returns
node identifier for instance's chip select GPIO controller
See also
DT_SPI_DEV_CS_GPIOS_CTLR()

◆ DT_INST_SPI_DEV_CS_GPIOS_FLAGS

#define DT_INST_SPI_DEV_CS_GPIOS_FLAGS ( inst)

#include <zephyr/devicetree/spi.h>

Value:
#define DT_SPI_DEV_CS_GPIOS_FLAGS(spi_dev)
Get a SPI device's chip select GPIO flags.
Definition spi.h:211

DT_SPI_DEV_CS_GPIOS_FLAGS(DT_DRV_INST(inst)).

Parameters
instDT_DRV_COMPAT instance number
Returns
flags value of the instance's chip select GPIO specifier, or zero if there is none
See also
DT_SPI_DEV_CS_GPIOS_FLAGS()

◆ DT_INST_SPI_DEV_CS_GPIOS_PIN

#define DT_INST_SPI_DEV_CS_GPIOS_PIN ( inst)

#include <zephyr/devicetree/spi.h>

Value:
#define DT_SPI_DEV_CS_GPIOS_PIN(spi_dev)
Get a SPI device's chip select GPIO pin number.
Definition spi.h:183

Equivalent to DT_SPI_DEV_CS_GPIOS_PIN(DT_DRV_INST(inst)).

Parameters
instDT_DRV_COMPAT instance number
Returns
pin number of the instance's chip select GPIO
See also
DT_SPI_DEV_CS_GPIOS_PIN()

◆ DT_INST_SPI_DEV_HAS_CS_GPIOS

#define DT_INST_SPI_DEV_HAS_CS_GPIOS ( inst)

#include <zephyr/devicetree/spi.h>

Value:
#define DT_SPI_DEV_HAS_CS_GPIOS(spi_dev)
Does a SPI device have a chip select line configured? Example devicetree fragment:
Definition spi.h:117

Equivalent to DT_SPI_DEV_HAS_CS_GPIOS(DT_DRV_INST(inst)).

Parameters
instDT_DRV_COMPAT instance number
Returns
1 if the instance's bus has a CS pin at index DT_INST_REG_ADDR(inst), 0 otherwise
See also
DT_SPI_DEV_HAS_CS_GPIOS()

◆ DT_SPI_DEV_CS_GPIOS_CTLR

#define DT_SPI_DEV_CS_GPIOS_CTLR ( spi_dev)

#include <zephyr/devicetree/spi.h>

Value:
DT_GPIO_CTLR_BY_IDX(DT_BUS(spi_dev), cs_gpios, DT_REG_ADDR_RAW(spi_dev))
#define DT_BUS(node_id)
Node's bus controller.
Definition devicetree.h:3821
#define DT_GPIO_CTLR_BY_IDX(node_id, gpio_pha, idx)
Get the node identifier for the controller phandle from a gpio phandle-array property at an index.
Definition gpio.h:53
#define DT_REG_ADDR_RAW(node_id)
Get a node's (only) register block raw address.
Definition devicetree.h:2418

Get a SPI device's chip select GPIO controller's node identifier.

Example devicetree fragment:

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>;
        };
};

Example usage:

DT_SPI_DEV_CS_GPIOS_CTLR(DT_NODELABEL(a)) // DT_NODELABEL(gpio1)
DT_SPI_DEV_CS_GPIOS_CTLR(DT_NODELABEL(b)) // DT_NODELABEL(gpio2)
Parameters
spi_deva SPI device node identifier
Returns
node identifier for spi_dev's chip select GPIO controller

◆ DT_SPI_DEV_CS_GPIOS_FLAGS

#define DT_SPI_DEV_CS_GPIOS_FLAGS ( spi_dev)

#include <zephyr/devicetree/spi.h>

Value:
DT_GPIO_FLAGS_BY_IDX(DT_BUS(spi_dev), cs_gpios, DT_REG_ADDR_RAW(spi_dev))
#define DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, idx)
Get a GPIO specifier's flags cell at an index.
Definition gpio.h:165

Get a SPI device's chip select GPIO flags.

Example devicetree fragment:

spi1: spi@... {
        compatible = "vnd,spi";
        cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>;

        a: spi-dev-a@0 {
                reg = <0>;
        };
};

Example usage:

DT_SPI_DEV_CS_GPIOS_FLAGS(DT_NODELABEL(a)) // GPIO_ACTIVE_LOW

If the GPIO specifier for spi_dev's entry in its bus node's cs-gpios property has no flags cell, this expands to zero.

Parameters
spi_deva SPI device node identifier
Returns
flags value of spi_dev's chip select GPIO specifier, or zero if there is none

◆ DT_SPI_DEV_CS_GPIOS_PIN

#define DT_SPI_DEV_CS_GPIOS_PIN ( spi_dev)

#include <zephyr/devicetree/spi.h>

Value:
DT_GPIO_PIN_BY_IDX(DT_BUS(spi_dev), cs_gpios, DT_REG_ADDR_RAW(spi_dev))
#define DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, idx)
Get a GPIO specifier's pin cell at an index.
Definition gpio.h:109

Get a SPI device's chip select GPIO pin number.

It's an error if the GPIO specifier for spi_dev's entry in its bus node's cs-gpios property has no pin cell.

Example devicetree fragment:

spi1: 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>;
        };
};

Example usage:

DT_SPI_DEV_CS_GPIOS_PIN(DT_NODELABEL(a)) // 10
DT_SPI_DEV_CS_GPIOS_PIN(DT_NODELABEL(b)) // 20
Parameters
spi_deva SPI device node identifier
Returns
pin number of spi_dev's chip select GPIO

◆ DT_SPI_DEV_HAS_CS_GPIOS

#define DT_SPI_DEV_HAS_CS_GPIOS ( spi_dev)

#include <zephyr/devicetree/spi.h>

Value:
#define DT_SPI_HAS_CS_GPIOS(spi)
Does a SPI controller node have chip select GPIOs configured?
Definition spi.h:52

Does a SPI device have a chip select line configured? Example devicetree fragment:

spi1: 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>;
        };
};

spi2: spi@... {
        compatible = "vnd,spi";
        c: spi-dev-c@0 {
                reg = <0>;
        };
};

Example usage:

DT_SPI_DEV_HAS_CS_GPIOS(DT_NODELABEL(a)) // 1
DT_SPI_DEV_HAS_CS_GPIOS(DT_NODELABEL(b)) // 1
DT_SPI_DEV_HAS_CS_GPIOS(DT_NODELABEL(c)) // 0
Parameters
spi_deva SPI device node identifier
Returns
1 if spi_dev's bus node DT_BUS(spi_dev) has a chip select pin at index DT_REG_ADDR(spi_dev), 0 otherwise

◆ DT_SPI_HAS_CS_GPIOS

#define DT_SPI_HAS_CS_GPIOS ( spi)

#include <zephyr/devicetree/spi.h>

Value:
DT_NODE_HAS_PROP(spi, cs_gpios)
#define DT_NODE_HAS_PROP(node_id, prop)
Does a devicetree node have a property?
Definition devicetree.h:3744

Does a SPI controller node have chip select GPIOs configured?

SPI bus controllers use the "cs-gpios" property for configuring chip select GPIOs. Its value is a phandle-array which specifies the chip select lines.

Example devicetree fragment:

spi1: spi@... {
        compatible = "vnd,spi";
        cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
                   <&gpio2 20 GPIO_ACTIVE_LOW>;
};

spi2: spi@... {
        compatible = "vnd,spi";
};

Example usage:

DT_SPI_HAS_CS_GPIOS(DT_NODELABEL(spi1)) // 1
DT_SPI_HAS_CS_GPIOS(DT_NODELABEL(spi2)) // 0
Parameters
spia SPI bus controller node identifier
Returns
1 if "spi" has a cs-gpios property, 0 otherwise

◆ DT_SPI_NUM_CS_GPIOS

#define DT_SPI_NUM_CS_GPIOS ( spi)

#include <zephyr/devicetree/spi.h>

Value:
(DT_PROP_LEN(spi, cs_gpios)), (0))
#define DT_PROP_LEN(node_id, prop)
Get a property's logical length.
Definition devicetree.h:786
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:195

Number of chip select GPIOs in a SPI controller's cs-gpios property.

Example devicetree fragment:

spi1: spi@... {
        compatible = "vnd,spi";
        cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
                   <&gpio2 20 GPIO_ACTIVE_LOW>;
};

spi2: spi@... {
        compatible = "vnd,spi";
};

Example usage:

DT_SPI_NUM_CS_GPIOS(DT_NODELABEL(spi1)) // 2
DT_SPI_NUM_CS_GPIOS(DT_NODELABEL(spi2)) // 0
Parameters
spia SPI bus controller node identifier
Returns
Logical length of spi's cs-gpios property, or 0 if "spi" doesn't have a cs-gpios property