devicetree.h: add accessor API for nodes and properties
This is joint work with Kumar Gala (see signed-off-by). Add helper macros which abstract the "true names" of each of the four types of node identifier we intend to support (e.g. DT_ALIAS(), DT_INST()). These can be passed to a new DT_PROP() macro which can be used to read the value of a devicetree property given a node identifier from one of these four other macros, and the as-a-c-token name of the property. Add other accessor macros and tests as well. Add some convenience APIs for writing device drivers based on instance numbers as well. Drivers can "#define DT_DRV_COMPAT driver_compatible" at the top of the file, then utilize these DT_INST_* macros to access various property defines. For example, the uart_sifive driver can do: #define DT_DRV_COMPAT sifive_uart0 Then use DT_INST macros like: .port = DT_INST_REG_ADDR(0), .sys_clk_freq = DT_INST_PROP(0, clock_frequency), For convenience working with specific hardware, also add: <devicetree/gpio.h> <devicetree/adc.h> <devicetree/spi.h> Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no> Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
dc85edd2e9
commit
c3ec5db6d2
28 changed files with 3697 additions and 0 deletions
1370
include/devicetree.h
1370
include/devicetree.h
File diff suppressed because it is too large
Load diff
198
include/devicetree/adc.h
Normal file
198
include/devicetree/adc.h
Normal file
|
@ -0,0 +1,198 @@
|
|||
/**
|
||||
* @file
|
||||
* @brief ADC Devicetree macro public API header file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020, Linaro Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DEVICETREE_ADC_H_
|
||||
#define ZEPHYR_INCLUDE_DEVICETREE_ADC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup devicetree-adc Devicetree ADC API
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get IO channels controller "name" (label property) at an index
|
||||
*
|
||||
* It's an error if the IO channels controller referenced by the phandle
|
||||
* in property "io_channels" at index "idx" has no label property.
|
||||
*
|
||||
* Example devicetree fragment:
|
||||
*
|
||||
* adc1: adc@... {
|
||||
* label = "ADC_1";
|
||||
* };
|
||||
*
|
||||
* adc2: adc@... {
|
||||
* label = "ADC_2";
|
||||
* };
|
||||
*
|
||||
* n: node {
|
||||
* io-channels = <&adc1 10>, <&adc2 20>;
|
||||
* };
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* DT_IO_CHANNELS_LABEL_BY_IDX(DT_NODELABEL(n), 1) // "ADC_2"
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param idx logical index into the property
|
||||
* @return the label property for the referenced node at index idx
|
||||
* @see DT_PHANDLE_BY_IDX()
|
||||
*/
|
||||
#define DT_IO_CHANNELS_LABEL_BY_IDX(node_id, idx) \
|
||||
DT_PROP_BY_PHANDLE_IDX(node_id, io_channels, idx, label)
|
||||
|
||||
/**
|
||||
* @brief Get IO channels controller "name" (label property) by name
|
||||
*
|
||||
* It's an error if the IO channels controller referenced by the phandle
|
||||
* in property "io_channels" at index "idx" has no label property.
|
||||
*
|
||||
* Example devicetree fragment:
|
||||
*
|
||||
* adc1: adc@... {
|
||||
* label = "ADC_1";
|
||||
* };
|
||||
*
|
||||
* adc2: adc@... {
|
||||
* label = "ADC_2";
|
||||
* };
|
||||
*
|
||||
* n: node {
|
||||
* io-channels = <&adc1 10>, <&adc2 20>;
|
||||
* io-channel-names = "SENSOR", "BANDGAP";
|
||||
* };
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* DT_IO_CHANNELS_LABEL_BY_NAME(DT_NODELABEL(n), bandgap) // "ADC_2"
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param name lowercase-and-underscores "io_channel" name
|
||||
* @return the label property for the referenced node by name
|
||||
* @see DT_PHANDLE_BY_NAME()
|
||||
*/
|
||||
#define DT_IO_CHANNELS_LABEL_BY_NAME(node_id, name) \
|
||||
DT_PROP(DT_PHANDLE_BY_NAME(node_id, io_channels, name), label)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_IO_CHANNELS_LABEL_BY_IDX(node_id, 0)
|
||||
* @param node_id node identifier
|
||||
* @return the label property for the named specifier at index 0
|
||||
* @see DT_IO_CHANNELS_LABEL_BY_IDX()
|
||||
*/
|
||||
#define DT_IO_CHANNELS_LABEL(node_id) DT_IO_CHANNELS_LABEL_BY_IDX(node_id, 0)
|
||||
|
||||
/**
|
||||
* @brief Get IO channel's controller "name" at an index
|
||||
* (see @ref DT_IO_CHANNELS_LABEL_BY_IDX)
|
||||
* @param inst instance number
|
||||
* @param idx logical index into the property
|
||||
* @return the label property for the named specifier at index idx
|
||||
*/
|
||||
#define DT_INST_IO_CHANNELS_LABEL_BY_IDX(inst, idx) \
|
||||
DT_IO_CHANNELS_LABEL_BY_IDX(DT_DRV_INST(inst), idx)
|
||||
|
||||
/**
|
||||
* @brief Get IO channel's controller "name" by name
|
||||
* (see @ref DT_IO_CHANNELS_LABEL_BY_NAME)
|
||||
* @param inst instance number
|
||||
* @param name lowercase-and-underscores "io_channel" name
|
||||
* @return the label property for the named specifier by name
|
||||
*/
|
||||
#define DT_INST_IO_CHANNELS_LABEL_BY_NAME(inst, name) \
|
||||
DT_IO_CHANNELS_LABEL_BY_NAME(DT_DRV_INST(inst), name)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_INST_IO_CHANNELS_LABEL_BY_IDX(inst, 0)
|
||||
* @param inst instance number
|
||||
* @return the label property for the named specifier at index 0
|
||||
*/
|
||||
#define DT_INST_IO_CHANNELS_LABEL(inst) DT_INST_IO_CHANNELS_LABEL_BY_IDX(inst, 0)
|
||||
|
||||
/**
|
||||
* @brief Get IO channels controller 'input' at an index
|
||||
*
|
||||
* This macro only works for IO channels controllers that specify a 'input'
|
||||
* field in the phandle-array specifier. Refer to the specific IO channels
|
||||
* controller binding if needed.
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param idx logical index into the property
|
||||
* @return the input value for the named specifier at index idx
|
||||
* @see DT_PHA_BY_IDX()
|
||||
* @see DT_PHA()
|
||||
*/
|
||||
#define DT_IO_CHANNELS_INPUT_BY_IDX(node_id, idx) \
|
||||
DT_PHA_BY_IDX(node_id, io_channels, idx, input)
|
||||
|
||||
/**
|
||||
* @brief Get IO channels controller 'input' by name
|
||||
*
|
||||
* This macro only works for IO channels controllers that specify a 'input'
|
||||
* field in the phandle-array specifier. Refer to the specific IO channels
|
||||
* controller binding if needed.
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param name lowercase-and-underscores "io_channel" name
|
||||
* @return the input value for the named specifier by name
|
||||
* @see DT_PHA_BY_NAME()
|
||||
*/
|
||||
#define DT_IO_CHANNELS_INPUT_BY_NAME(node_id, name) \
|
||||
DT_PHA_BY_NAME(node_id, io_channels, name, input)
|
||||
/**
|
||||
* @brief Equivalent to DT_IO_CHANNELS_INPUT_BY_IDX(node_id, 0)
|
||||
* @param node_id node identifier
|
||||
* @return the label property for the named specifier at index 0
|
||||
* @see DT_IO_CHANNELS_INPUT_BY_IDX()
|
||||
*/
|
||||
#define DT_IO_CHANNELS_INPUT(node_id) DT_IO_CHANNELS_INPUT_BY_IDX(node_id, 0)
|
||||
|
||||
/**
|
||||
* @brief Get IO channel's controller "input" at an index
|
||||
* (see @ref DT_IO_CHANNELS_INPUT_BY_IDX)
|
||||
* @param inst instance number
|
||||
* @param idx logical index into the property
|
||||
* @return the input value for the named specifier at index idx
|
||||
*/
|
||||
#define DT_INST_IO_CHANNELS_INPUT_BY_IDX(inst, idx) \
|
||||
DT_IO_CHANNELS_INPUT_BY_IDX(DT_DRV_INST(inst), idx)
|
||||
|
||||
/**
|
||||
* @brief Get IO channel's controller "input" by name
|
||||
* (see @ref DT_IO_CHANNELS_INPUT_BY_NAME)
|
||||
* @param inst instance number
|
||||
* @param name lowercase-and-underscores "io_channel" name
|
||||
* @return the input value for the named specifier at index idx
|
||||
*/
|
||||
#define DT_INST_IO_CHANNELS_INPUT_BY_NAME(inst, name) \
|
||||
DT_IO_CHANNELS_INPUT_BY_NAME(DT_DRV_INST(inst), name)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_INST_IO_CHANNELS_INPUT(inst, 0)
|
||||
* @param inst instance number
|
||||
* @return the input property for the named specifier at index 0
|
||||
*/
|
||||
#define DT_INST_IO_CHANNELS_INPUT(inst) DT_INST_IO_CHANNELS_INPUT_BY_IDX(inst, 0)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DEVICETREE_ADC_H_ */
|
153
include/devicetree/clocks.h
Normal file
153
include/devicetree/clocks.h
Normal file
|
@ -0,0 +1,153 @@
|
|||
/**
|
||||
* @file
|
||||
* @brief Clocks Devicetree macro public API header file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020, Linaro Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DEVICETREE_CLOCKS_H_
|
||||
#define ZEPHYR_INCLUDE_DEVICETREE_CLOCKS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup devicetree-clocks Devicetree Clocks API
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get clock controller "name" (label property) at an index
|
||||
*
|
||||
* It's an error if the clock controller referenced by the phandle
|
||||
* in property "clocks" at index "idx" has no label property.
|
||||
*
|
||||
* Example devicetree fragment:
|
||||
*
|
||||
* clk1: clkctrl@... {
|
||||
* label = "CLK_1";
|
||||
* };
|
||||
*
|
||||
* clk2: clkctrl@... {
|
||||
* label = "CLK_2";
|
||||
* };
|
||||
*
|
||||
* n: node {
|
||||
* clocks = <&clk1 10 20>, <&clk2 30 40>;
|
||||
* };
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* DT_CLOCKS_LABEL_BY_IDX(DT_NODELABEL(n), 1) // "CLK_2"
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param idx logical index into the property
|
||||
* @return the label property for the referenced node at index idx
|
||||
* @see DT_PROP_BY_PHANDLE_IDX()
|
||||
*/
|
||||
#define DT_CLOCKS_LABEL_BY_IDX(node_id, idx) \
|
||||
DT_PROP_BY_PHANDLE_IDX(node_id, clocks, idx, label)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_CLOCKS_LABEL_BY_IDX(node_id, 0)
|
||||
* @param node_id node identifier
|
||||
* @return the label property for the named specifier at index 0
|
||||
* @see DT_CLOCKS_LABEL_BY_IDX()
|
||||
*/
|
||||
#define DT_CLOCKS_LABEL(node_id) DT_CLOCKS_LABEL_BY_IDX(node_id, 0)
|
||||
|
||||
/**
|
||||
* @brief Get Clock controller "cell" value at an index
|
||||
*
|
||||
* Example devicetree fragment:
|
||||
*
|
||||
* clk1: clkctrl@... {
|
||||
* label = "CLK_1";
|
||||
* #clock-cells = < 2 >;
|
||||
* };
|
||||
*
|
||||
* n: node {
|
||||
* clocks = < &clk1 10 20 >, < &clk1 30 40 >;
|
||||
* };
|
||||
*
|
||||
* Bindings fragment for the gpio0 node:
|
||||
*
|
||||
* clock-cells:
|
||||
* - bus
|
||||
* - bits
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(n), bus, 0) // 10
|
||||
* DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(n), bits, 1) // 40
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param cell binding's cell name within the specifier at index "idx"
|
||||
* @param idx logical index into the property
|
||||
* @return the value of the cell inside the specifier at index "idx"
|
||||
* @see DT_PHA_PHANDLE_IDX()
|
||||
*/
|
||||
#define DT_CLOCKS_CELL_BY_IDX(node_id, cell, idx) \
|
||||
DT_PHA_BY_IDX(node_id, clocks, idx, cell)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_CLOCKS_CELL_BY_IDX(node_id, cell, 0)
|
||||
* @param node_id node identifier
|
||||
* @param cell binding's cell name within the specifier at index 0
|
||||
* @return the value of the cell inside the specifier at index 0
|
||||
* @see DT_CLOCKS_CELL_BY_IDX()
|
||||
*/
|
||||
#define DT_CLOCKS_CELL(node_id, cell) DT_CLOCKS_CELL_BY_IDX(node_id, cell, 0)
|
||||
|
||||
/**
|
||||
* @brief Get a DT_DRV_COMPAT clock controller "name" at an index
|
||||
* (see @ref DT_CLOCKS_LABEL_BY_IDX)
|
||||
* @param inst instance number
|
||||
* @param idx logical index into the property
|
||||
* @return the label property for the named specifier at index idx
|
||||
*/
|
||||
#define DT_INST_CLOCKS_LABEL_BY_IDX(inst, idx) \
|
||||
DT_CLOCKS_LABEL_BY_IDX(DT_DRV_INST(inst), idx)
|
||||
|
||||
/**
|
||||
* @brief Get a DT_DRV_COMPAT clock controller "name"
|
||||
* (see @ref DT_CLOCKS_LABEL_BY_IDX)
|
||||
* @param inst instance number
|
||||
* @return the label property for the named specifier at index 0
|
||||
*/
|
||||
#define DT_INST_CLOCKS_LABEL(inst) DT_INST_CLOCKS_LABEL_BY_IDX(inst, 0)
|
||||
|
||||
/**
|
||||
* @brief Get a DT_DRV_COMPAT clock controller "cell" value at an index
|
||||
* @param inst instance number
|
||||
* @param cell binding's cell name within the specifier at index "idx"
|
||||
* @param idx logical index into the property
|
||||
* @return the value of the cell inside the specifier at index "idx"
|
||||
*/
|
||||
#define DT_INST_CLOCKS_CELL_BY_IDX(inst, cell, idx) \
|
||||
DT_CLOCKS_CELL_BY_IDX(DT_DRV_INST(inst), cell, idx)
|
||||
|
||||
/**
|
||||
* @brief Get a DT_DRV_COMPAT clock controller "cell" value at an index 0
|
||||
* @param inst instance number
|
||||
* @param cell binding's cell name within the specifier at index 0
|
||||
* @return the value of the cell inside the specifier at index 0
|
||||
*/
|
||||
#define DT_INST_CLOCKS_CELL(inst, cell) \
|
||||
DT_INST_CLOCKS_CELL_BY_IDX(inst, cell, 0)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DEVICETREE_CLOCKS_H_ */
|
202
include/devicetree/gpio.h
Normal file
202
include/devicetree/gpio.h
Normal file
|
@ -0,0 +1,202 @@
|
|||
/**
|
||||
* @file
|
||||
* @brief GPIO Devicetree macro public API header file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020, Linaro Ltd.
|
||||
* Copyright (c) 2020 Nordic Semiconductor
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DEVICETREE_GPIO_H_
|
||||
#define ZEPHYR_INCLUDE_DEVICETREE_GPIO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup devicetree-gpio Devicetree GPIO API
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get gpio controller "name" (label property) at an index
|
||||
*
|
||||
* It's an error if the GPIO controller referenced by the phandle
|
||||
* in property "gpio_pha" at index "idx" has no label property.
|
||||
*
|
||||
* Example devicetree fragment:
|
||||
*
|
||||
* gpio1: gpio@... {
|
||||
* label = "GPIO_1";
|
||||
* };
|
||||
*
|
||||
* gpio2: gpio@... {
|
||||
* label = "GPIO_2";
|
||||
* };
|
||||
*
|
||||
* n: node {
|
||||
* gpios = <&gpio1 10 20>, <&gpio2 30 40>;
|
||||
* };
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* DT_GPIO_LABEL_BY_IDX(DT_NODELABEL(n), gpios, 1) // "GPIO_2"
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @param idx logical index into the property
|
||||
* @return the label property for the referenced node at index idx
|
||||
* @see DT_PHANDLE_BY_IDX()
|
||||
*/
|
||||
#define DT_GPIO_LABEL_BY_IDX(node_id, gpio_pha, idx) \
|
||||
DT_PROP_BY_PHANDLE_IDX(node_id, gpio_pha, idx, label)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_GPIO_LABEL_BY_IDX(node_id, gpio_pha, 0)
|
||||
* @param node_id node identifier
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @return the label property for the named specifier at index 0
|
||||
* @see DT_GPIO_LABEL_BY_IDX()
|
||||
*/
|
||||
#define DT_GPIO_LABEL(node_id, gpio_pha) \
|
||||
DT_GPIO_LABEL_BY_IDX(node_id, gpio_pha, 0)
|
||||
|
||||
/**
|
||||
* @brief Get gpio controller 'pin' at an index
|
||||
*
|
||||
* This macro only works for GPIO controllers that specify a 'pin'
|
||||
* field in the phandle-array specifier. Refer to the specific GPIO
|
||||
* controller binding if needed.
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @param idx logical index into the property
|
||||
* @return the pin value for the named specifier at index idx
|
||||
* @see DT_PHA_BY_IDX()
|
||||
* @see DT_PHA()
|
||||
*/
|
||||
#define DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, idx) \
|
||||
DT_PHA_BY_IDX(node_id, gpio_pha, idx, pin)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, 0)
|
||||
* @param node_id node identifier
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @return the pin value for the named specifier at index idx
|
||||
* @see DT_GPIO_PIN_BY_IDX()
|
||||
*/
|
||||
#define DT_GPIO_PIN(node_id, gpio_pha) \
|
||||
DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, 0)
|
||||
|
||||
/**
|
||||
* @brief Get gpio controller 'flags' at an index
|
||||
*
|
||||
* This macro only works for GPIO controllers that specify a 'flags'
|
||||
* field in the phandle-array specifier. Refer to the specific GPIO
|
||||
* controller binding if needed.
|
||||
*
|
||||
* @param node_id node identifier
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @param idx logical index into the property
|
||||
* @return the flags value for the named specifier at index idx
|
||||
* @see DT_PHA_BY_IDX()
|
||||
* @see DT_PHA()
|
||||
*/
|
||||
#define DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, idx) \
|
||||
DT_PHA_BY_IDX(node_id, gpio_pha, idx, flags)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, 0)
|
||||
* @param node_id node identifier
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @return the flags value for the named specifier at index idx
|
||||
* @see DT_GPIO_FLAGS_BY_IDX()
|
||||
*/
|
||||
#define DT_GPIO_FLAGS(node_id, gpio_pha) \
|
||||
DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, 0)
|
||||
|
||||
/**
|
||||
* @brief Get gpio controller "name" at an index (see @ref DT_GPIO_LABEL_BY_IDX)
|
||||
* @param inst instance number
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @param idx logical index into the property
|
||||
* @return the label property for the named specifier at index idx
|
||||
*/
|
||||
#define DT_INST_GPIO_LABEL_BY_IDX(inst, gpio_pha, idx) \
|
||||
DT_GPIO_LABEL_BY_IDX(DT_DRV_INST(inst), gpio_pha, idx)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_INST_GPIO_LABEL_BY_IDX(inst, gpio_pha, 0)
|
||||
* @param inst instance number
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @return the label property for the named specifier at index 0
|
||||
*/
|
||||
#define DT_INST_GPIO_LABEL(inst, gpio_pha) \
|
||||
DT_INST_GPIO_LABEL_BY_IDX(inst, gpio_pha, 0)
|
||||
|
||||
/**
|
||||
* @brief Get gpio controller "pin" at an index (see @ref DT_GPIO_PIN_BY_IDX)
|
||||
* @param inst instance number
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @param idx logical index into the property
|
||||
* @return the pin value for the named specifier at index idx
|
||||
*/
|
||||
#define DT_INST_GPIO_PIN_BY_IDX(inst, gpio_pha, idx) \
|
||||
DT_GPIO_PIN_BY_IDX(DT_DRV_INST(inst), gpio_pha, idx)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_INST_GPIO_PIN_BY_IDX(inst, gpio_pha, 0)
|
||||
* @param inst instance number
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @return the pin value for the named specifier at index 0
|
||||
* @see DT_INST_GPIO_PIN_BY_IDX()
|
||||
*/
|
||||
#define DT_INST_GPIO_PIN(inst, gpio_pha) \
|
||||
DT_INST_GPIO_PIN_BY_IDX(inst, gpio_pha, 0)
|
||||
|
||||
/**
|
||||
* @brief Get a devicetree property value (see @ref DT_GPIO_FLAGS_BY_IDX)
|
||||
* @param inst instance number
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @param idx logical index into the property
|
||||
* @return a representation of the property's value
|
||||
*/
|
||||
#define DT_INST_GPIO_FLAGS_BY_IDX(inst, gpio_pha, idx) \
|
||||
DT_GPIO_FLAGS_BY_IDX(DT_DRV_INST(inst), gpio_pha, idx)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_INST_GPIO_FLAGS_BY_IDX(inst, gpio_pha, 0)
|
||||
* @param inst instance number
|
||||
* @param gpio_pha lowercase-and-underscores GPIO property with
|
||||
* type "phandle-array"
|
||||
* @return the flags value for the named specifier at index 0
|
||||
* @see DT_INST_GPIO_FLAGS_BY_IDX()
|
||||
*/
|
||||
#define DT_INST_GPIO_FLAGS(inst, gpio_pha) \
|
||||
DT_INST_GPIO_FLAGS_BY_IDX(inst, gpio_pha, 0)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DEVICETREE_GPIO_H_ */
|
121
include/devicetree/spi.h
Normal file
121
include/devicetree/spi.h
Normal file
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* @file
|
||||
* @brief SPI Devicetree macro public API header file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020 Nordic Semiconductor
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DEVICETREE_SPI_H_
|
||||
#define ZEPHYR_INCLUDE_DEVICETREE_SPI_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup devicetree-spi Devicetree SPI API
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Does a SPI controller have chip select GPIOs configured?
|
||||
* The commonly used "cs-gpios" property is used for this test.
|
||||
* @param spi node identifier for a SPI bus controller
|
||||
* @return 1 if it has a cs-gpios property, 0 otherwise
|
||||
*/
|
||||
#define DT_SPI_HAS_CS(spi) DT_NODE_HAS_PROP(spi, cs_gpios)
|
||||
|
||||
/**
|
||||
* @brief The number of chip select GPIOs in a SPI controller
|
||||
* @param spi node identifier for a SPI bus controller
|
||||
* @return The length of its cs-gpios, or 0 if it doesn't have one
|
||||
*/
|
||||
#define DT_SPI_NUM_CS(spi) \
|
||||
COND_CODE_1(DT_SPI_HAS_CS(spi), \
|
||||
(DT_PROP_LEN(spi, cs_gpios)), (0))
|
||||
|
||||
/**
|
||||
* @brief Does a SPI device have a chip select line in DT?
|
||||
* @param spi_dev node identifier for a SPI device
|
||||
* @return 1 if the SPI device's bus DT_BUS(spi_dev) has a CS
|
||||
* pin at index DT_REG_ADDR(spi_dev), 0 otherwise
|
||||
*/
|
||||
#define DT_SPI_DEV_HAS_CS(spi_dev) DT_SPI_HAS_CS(DT_BUS(spi_dev))
|
||||
|
||||
/**
|
||||
* @brief Get GPIO controller name for a SPI device's chip select
|
||||
* DT_SPI_DEV_HAS_CS(spi_dev) must expand to 1.
|
||||
* @brief spi_dev a SPI device node identifier
|
||||
* @return label property of spi_dev's chip select GPIO controller
|
||||
*/
|
||||
#define DT_SPI_DEV_CS_GPIO_LABEL(spi_dev) \
|
||||
DT_GPIO_LABEL_BY_IDX(DT_BUS(spi_dev), cs_gpios, DT_REG_ADDR(spi_dev))
|
||||
|
||||
/**
|
||||
* @brief Get GPIO specifier 'pin' value for a SPI device's chip select
|
||||
* It's an error if the GPIO specifier for spi_dev's entry in its
|
||||
* bus node's cs-gpios property has no 'pin' value.
|
||||
* @brief spi_dev a SPI device node identifier
|
||||
* @return pin number of spi_dev's chip select GPIO
|
||||
*/
|
||||
#define DT_SPI_DEV_CS_GPIO_PIN(spi_dev) \
|
||||
DT_GPIO_PIN_BY_IDX(DT_BUS(spi_dev), cs_gpios, DT_REG_ADDR(spi_dev))
|
||||
|
||||
/**
|
||||
* @brief Get GPIO specifier 'flags' value for a SPI device's chip select
|
||||
* It's an error if the GPIO specifier for spi_dev's entry in its
|
||||
* bus node's cs-gpios property has no 'flags' value.
|
||||
* @brief spi_dev a SPI device node identifier
|
||||
* @return flags value of spi_dev's chip select GPIO specifier
|
||||
*/
|
||||
#define DT_SPI_DEV_CS_GPIO_FLAGS(spi_dev) \
|
||||
DT_GPIO_FLAGS_BY_IDX(DT_BUS(spi_dev), cs_gpios, DT_REG_ADDR(spi_dev))
|
||||
|
||||
/**
|
||||
* @brief Equivalent to DT_SPI_DEV_HAS_CS(DT_DRV_INST(inst))
|
||||
* @param inst instance number
|
||||
* @return 1 if the instance's bus has a CS pin at index
|
||||
* DT_INST_REG_ADDR(inst), 0 otherwise
|
||||
*/
|
||||
#define DT_INST_SPI_DEV_HAS_CS(inst) DT_SPI_DEV_HAS_CS(DT_DRV_INST(inst))
|
||||
|
||||
/**
|
||||
* @brief Get GPIO controller name for a SPI device instance
|
||||
* This is equivalent to DT_SPI_DEV_CS_GPIO_LABEL(DT_DRV_INST(inst)).
|
||||
* @brief inst instance number
|
||||
* @return label property of the instance's chip select GPIO controller
|
||||
*/
|
||||
#define DT_INST_SPI_DEV_CS_GPIO_LABEL(inst) \
|
||||
DT_SPI_DEV_CS_GPIO_LABEL(DT_DRV_INST(inst))
|
||||
|
||||
/**
|
||||
* @brief Get GPIO specifier "pin" value for a SPI device instance
|
||||
* This is equivalent to DT_SPI_DEV_CS_GPIO_PIN(DT_DRV_INST(inst)).
|
||||
* @brief inst a SPI device instance number
|
||||
* @return pin number of the instance's chip select GPIO
|
||||
*/
|
||||
#define DT_INST_SPI_DEV_CS_GPIO_PIN(inst) \
|
||||
DT_SPI_DEV_CS_GPIO_PIN(DT_DRV_INST(inst))
|
||||
|
||||
/**
|
||||
* @brief Get GPIO specifier "flags" value for a SPI device instance
|
||||
* This is equivalent to DT_SPI_DEV_CS_GPIO_FLAGS(DT_DRV_INST(inst)).
|
||||
* @brief inst a SPI device instance number
|
||||
* @return flags value of the instance's chip select GPIO specifier
|
||||
*/
|
||||
#define DT_INST_SPI_DEV_CS_GPIO_FLAGS(inst) \
|
||||
DT_SPI_DEV_CS_GPIO_FLAGS(DT_DRV_INST(inst))
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DEVICETREE_SPI_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue