@@ -18,13 +18,9 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
18
18
#define NODE_ID DT_INST(0, DT_DRV_COMPAT)
19
19
20
20
/* SPI device */
21
- static const struct device * spi_ft8xx_dev ;
22
- static struct spi_cs_control cs_ctrl ;
23
- static const struct spi_config spi_cfg = {
24
- .frequency = 8000000UL ,
25
- .operation = SPI_WORD_SET (8 ) | SPI_OP_MODE_MASTER ,
26
- .cs = & cs_ctrl ,
27
- };
21
+ static const struct spi_dt_spec spi = SPI_DT_SPEC_INST_GET (0 ,
22
+ SPI_WORD_SET (8 ) | SPI_OP_MODE_MASTER ,
23
+ 0 );
28
24
29
25
/* GPIO int line */
30
26
#define IRQ_PIN DT_GPIO_PIN(NODE_ID, irq_gpios)
@@ -60,16 +56,8 @@ int ft8xx_drv_init(void)
60
56
{
61
57
int ret ;
62
58
63
- cs_ctrl = (struct spi_cs_control ){
64
- .gpio_dev = device_get_binding (
65
- DT_SPI_DEV_CS_GPIOS_LABEL (NODE_ID )),
66
- .gpio_pin = DT_SPI_DEV_CS_GPIOS_PIN (NODE_ID ),
67
- .gpio_dt_flags = DT_SPI_DEV_CS_GPIOS_FLAGS (NODE_ID ),
68
- .delay = 0 ,
69
- };
70
-
71
- spi_ft8xx_dev = device_get_binding (DT_BUS_LABEL (NODE_ID ));
72
- if (!spi_ft8xx_dev ) {
59
+ if (!spi_is_ready (& spi )) {
60
+ LOG_ERR ("SPI bus %s not ready" , spi .bus -> name );
73
61
return - ENODEV ;
74
62
}
75
63
@@ -124,7 +112,7 @@ int ft8xx_drv_write(uint32_t address, const uint8_t *data, unsigned int length)
124
112
.count = 2 ,
125
113
};
126
114
127
- ret = spi_write ( spi_ft8xx_dev , & spi_cfg , & tx_bufs );
115
+ ret = spi_write_dt ( & spi , & tx_bufs );
128
116
if (ret < 0 ) {
129
117
LOG_ERR ("SPI write error: %d" , ret );
130
118
}
@@ -167,7 +155,7 @@ int ft8xx_drv_read(uint32_t address, uint8_t *data, unsigned int length)
167
155
.count = 2 ,
168
156
};
169
157
170
- ret = spi_transceive ( spi_ft8xx_dev , & spi_cfg , & tx_bufs , & rx_bufs );
158
+ ret = spi_transceive_dt ( & spi , & tx_bufs , & rx_bufs );
171
159
if (ret < 0 ) {
172
160
LOG_ERR ("SPI transceive error: %d" , ret );
173
161
}
@@ -193,7 +181,7 @@ int ft8xx_drv_command(uint8_t command)
193
181
.count = 1 ,
194
182
};
195
183
196
- ret = spi_write ( spi_ft8xx_dev , & spi_cfg , & tx_bufs );
184
+ ret = spi_write_dt ( & spi , & tx_bufs );
197
185
if (ret < 0 ) {
198
186
LOG_ERR ("SPI command error: %d" , ret );
199
187
}
0 commit comments