Skip to content

Commit f820c19

Browse files
authored
[drivers/spi]修复spi configure会执行两次的问题 (#9972)
* [drivers/spi]修复spi configure会执行两次的问题
1 parent 21ea7c6 commit f820c19

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

components/drivers/spi/dev_spi_core.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
6464
for (int i = 0; i < pin_count; ++i)
6565
{
6666
bus->pins[i] = rt_pin_get_named_pin(&bus->parent, "cs", i,
67-
RT_NULL, RT_NULL);
67+
RT_NULL, RT_NULL);
6868
}
6969
}
7070
else if (pin_count == 0)
@@ -103,12 +103,15 @@ rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device,
103103
{
104104
device->bus = (struct rt_spi_bus *)bus;
105105

106+
if (device->bus->owner == RT_NULL)
107+
device->bus->owner = device;
108+
106109
/* initialize spidev device */
107110
result = rt_spidev_device_init(device, name);
108111
if (result != RT_EOK)
109112
return result;
110113

111-
if(cs_pin != PIN_NONE)
114+
if (cs_pin != PIN_NONE)
112115
{
113116
rt_pin_mode(cs_pin, PIN_MODE_OUTPUT);
114117
}
@@ -140,7 +143,7 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
140143
result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
141144
if (result == RT_EOK)
142145
{
143-
if (device->bus->owner == RT_NULL || device->bus->owner == device)
146+
if (device->bus->owner == device)
144147
{
145148
/* current device is using, re-configure SPI bus */
146149
result = device->bus->ops->configure(device, &device->config);
@@ -157,7 +160,6 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
157160
*/
158161
result = -RT_EBUSY;
159162
}
160-
161163
/* release lock */
162164
rt_mutex_release(&(device->bus->lock));
163165
}
@@ -451,7 +453,7 @@ rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device,
451453
}
452454

453455
len = rt_spi_transfer(device, &senddata, recvdata, 2);
454-
if(len < 0)
456+
if (len < 0)
455457
{
456458
return (rt_err_t)len;
457459
}
@@ -578,7 +580,7 @@ rt_err_t rt_spi_take(struct rt_spi_device *device)
578580
message.cs_take = 1;
579581

580582
result = device->bus->ops->xfer(device, &message);
581-
if(result < 0)
583+
if (result < 0)
582584
{
583585
return (rt_err_t)result;
584586
}
@@ -598,7 +600,7 @@ rt_err_t rt_spi_release(struct rt_spi_device *device)
598600
message.cs_release = 1;
599601

600602
result = device->bus->ops->xfer(device, &message);
601-
if(result < 0)
603+
if (result < 0)
602604
{
603605
return (rt_err_t)result;
604606
}

0 commit comments

Comments
 (0)