@@ -18,13 +18,9 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
1818#define NODE_ID DT_INST(0, DT_DRV_COMPAT)
1919
2020/* 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 );
2824
2925/* GPIO int line */
3026#define IRQ_PIN DT_GPIO_PIN(NODE_ID, irq_gpios)
@@ -60,16 +56,8 @@ int ft8xx_drv_init(void)
6056{
6157 int ret ;
6258
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 );
7361 return - ENODEV ;
7462 }
7563
@@ -124,7 +112,7 @@ int ft8xx_drv_write(uint32_t address, const uint8_t *data, unsigned int length)
124112 .count = 2 ,
125113 };
126114
127- ret = spi_write ( spi_ft8xx_dev , & spi_cfg , & tx_bufs );
115+ ret = spi_write_dt ( & spi , & tx_bufs );
128116 if (ret < 0 ) {
129117 LOG_ERR ("SPI write error: %d" , ret );
130118 }
@@ -167,7 +155,7 @@ int ft8xx_drv_read(uint32_t address, uint8_t *data, unsigned int length)
167155 .count = 2 ,
168156 };
169157
170- ret = spi_transceive ( spi_ft8xx_dev , & spi_cfg , & tx_bufs , & rx_bufs );
158+ ret = spi_transceive_dt ( & spi , & tx_bufs , & rx_bufs );
171159 if (ret < 0 ) {
172160 LOG_ERR ("SPI transceive error: %d" , ret );
173161 }
@@ -193,7 +181,7 @@ int ft8xx_drv_command(uint8_t command)
193181 .count = 1 ,
194182 };
195183
196- ret = spi_write ( spi_ft8xx_dev , & spi_cfg , & tx_bufs );
184+ ret = spi_write_dt ( & spi , & tx_bufs );
197185 if (ret < 0 ) {
198186 LOG_ERR ("SPI command error: %d" , ret );
199187 }
0 commit comments