Skip to content

Commit b5eeb6c

Browse files
committed
SPI挂载设备时,如果总线设备为空则赋值
1 parent d17fafb commit b5eeb6c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

components/drivers/spi/dev_spi_core.c

Lines changed: 15 additions & 13 deletions
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
}
@@ -150,17 +153,16 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
150153
LOG_E("SPI device %s configuration failed", device->parent.parent.name);
151154
}
152155
}
153-
156+
else
157+
{
158+
/* RT_EBUSY is not an error condition and
159+
* the configuration will take effect once the device has the bus
160+
*/
161+
result = -RT_EBUSY;
162+
}
154163
/* release lock */
155164
rt_mutex_release(&(device->bus->lock));
156165
}
157-
else
158-
{
159-
/* RT_EBUSY is not an error condition and
160-
* the configuration will take effect once the device has the bus
161-
*/
162-
result = -RT_EBUSY;
163-
}
164166
}
165167
else
166168
{
@@ -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)