Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit 3543df5

Browse files
mbolivar-nordiccarlescufi
authored andcommitted
api: move a devicetree.h layering violation to drivers/spi.h
The DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET macro belongs in drivers/spi.h, not devicetree.h. It is creating a struct gpio_dt_spec, but the devicetree.h API does not (other than in this case) and should not depend on structures that are defined in the GPIO API. This is because the GPIO API already depends on the devicetree.h API, so making a dependency in the reverse direction creates a needless circular dependency. This macro should have been added to the drivers/spi.h API from the beginning. Move it there under a new name, SPI_CS_GPIOS_DT_SPEC_GET. We haven't created a Zephyr release with DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET in it, so there is no need to go through the stable API change process for devicetree.h to deprecate and eventually remove it. We can just remove it directly. Fixes: zephyrproject-rtos#42149 Signed-off-by: Martí Bolívar <[email protected]>
1 parent ac24576 commit 3543df5

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

include/devicetree/spi.h

-40
Original file line numberDiff line numberDiff line change
@@ -116,46 +116,6 @@ extern "C" {
116116
*/
117117
#define DT_SPI_DEV_HAS_CS_GPIOS(spi_dev) DT_SPI_HAS_CS_GPIOS(DT_BUS(spi_dev))
118118

119-
/**
120-
* @brief Get a SPI device's chip select devicetree specification
121-
*
122-
* Example devicetree fragment:
123-
*
124-
* @code{.devicetree}
125-
* gpio1: gpio@... { ... };
126-
*
127-
* gpio2: gpio@... { ... };
128-
*
129-
* spi@... {
130-
* compatible = "vnd,spi";
131-
* cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
132-
* <&gpio2 20 GPIO_ACTIVE_LOW>;
133-
*
134-
* a: spi-dev-a@0 {
135-
* reg = <0>;
136-
* };
137-
*
138-
* b: spi-dev-b@1 {
139-
* reg = <1>;
140-
* };
141-
* };
142-
* @endcode
143-
*
144-
* Example usage:
145-
*
146-
* @code{.c}
147-
* DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(a)) \
148-
* // { DEVICE_DT_GET(DT_NODELABEL(gpio1)), 10, GPIO_ACTIVE_LOW }
149-
* DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(b)) \
150-
* // { DEVICE_DT_GET(DT_NODELABEL(gpio2)), 20, GPIO_ACTIVE_LOW }
151-
* @endcode
152-
*
153-
* @param spi_dev a SPI device node identifier
154-
* @return #gpio_dt_spec struct corresponding with spi_dev's chip select
155-
*/
156-
#define DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET(spi_dev) \
157-
GPIO_DT_SPEC_GET_BY_IDX(DT_BUS(spi_dev), cs_gpios, DT_REG_ADDR(spi_dev))
158-
159119
/**
160120
* @brief Get a SPI device's chip select GPIO controller's node identifier
161121
*

include/drivers/spi.h

+41-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,46 @@ struct spi_cs_control {
164164
uint32_t delay;
165165
};
166166

167+
/**
168+
* @brief Get a <tt>struct gpio_dt_spec</tt> for a SPI device's chip select pin
169+
*
170+
* Example devicetree fragment:
171+
*
172+
* @code{.devicetree}
173+
* gpio1: gpio@... { ... };
174+
*
175+
* gpio2: gpio@... { ... };
176+
*
177+
* spi@... {
178+
* compatible = "vnd,spi";
179+
* cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
180+
* <&gpio2 20 GPIO_ACTIVE_LOW>;
181+
*
182+
* a: spi-dev-a@0 {
183+
* reg = <0>;
184+
* };
185+
*
186+
* b: spi-dev-b@1 {
187+
* reg = <1>;
188+
* };
189+
* };
190+
* @endcode
191+
*
192+
* Example usage:
193+
*
194+
* @code{.c}
195+
* SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(a)) \
196+
* // { DEVICE_DT_GET(DT_NODELABEL(gpio1)), 10, GPIO_ACTIVE_LOW }
197+
* SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(b)) \
198+
* // { DEVICE_DT_GET(DT_NODELABEL(gpio2)), 20, GPIO_ACTIVE_LOW }
199+
* @endcode
200+
*
201+
* @param spi_dev a SPI device node identifier
202+
* @return #gpio_dt_spec struct corresponding with spi_dev's chip select
203+
*/
204+
#define SPI_CS_GPIOS_DT_SPEC_GET(spi_dev) \
205+
GPIO_DT_SPEC_GET_BY_IDX(DT_BUS(spi_dev), cs_gpios, DT_REG_ADDR(spi_dev))
206+
167207
#ifndef __cplusplus
168208
/**
169209
* @brief Initialize and get a pointer to a @p spi_cs_control from a
@@ -211,7 +251,7 @@ struct spi_cs_control {
211251
*/
212252
#define SPI_CS_CONTROL_PTR_DT(node_id, delay_) \
213253
(&(struct spi_cs_control) { \
214-
.gpio = DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET(node_id), \
254+
.gpio = SPI_CS_GPIOS_DT_SPEC_GET(node_id), \
215255
.delay = (delay_), \
216256
})
217257

0 commit comments

Comments
 (0)