mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-07 01:44:41 +08:00
[drivers/spi]修复spi configure会执行两次的问题 (#9972)
* [drivers/spi]修复spi configure会执行两次的问题
This commit is contained in:
@@ -64,7 +64,7 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
|
||||
for (int i = 0; i < pin_count; ++i)
|
||||
{
|
||||
bus->pins[i] = rt_pin_get_named_pin(&bus->parent, "cs", i,
|
||||
RT_NULL, RT_NULL);
|
||||
RT_NULL, RT_NULL);
|
||||
}
|
||||
}
|
||||
else if (pin_count == 0)
|
||||
@@ -103,12 +103,15 @@ rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device,
|
||||
{
|
||||
device->bus = (struct rt_spi_bus *)bus;
|
||||
|
||||
if (device->bus->owner == RT_NULL)
|
||||
device->bus->owner = device;
|
||||
|
||||
/* initialize spidev device */
|
||||
result = rt_spidev_device_init(device, name);
|
||||
if (result != RT_EOK)
|
||||
return result;
|
||||
|
||||
if(cs_pin != PIN_NONE)
|
||||
if (cs_pin != PIN_NONE)
|
||||
{
|
||||
rt_pin_mode(cs_pin, PIN_MODE_OUTPUT);
|
||||
}
|
||||
@@ -140,7 +143,7 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
|
||||
result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
if (device->bus->owner == RT_NULL || device->bus->owner == device)
|
||||
if (device->bus->owner == device)
|
||||
{
|
||||
/* current device is using, re-configure SPI bus */
|
||||
result = device->bus->ops->configure(device, &device->config);
|
||||
@@ -157,7 +160,6 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
|
||||
*/
|
||||
result = -RT_EBUSY;
|
||||
}
|
||||
|
||||
/* release lock */
|
||||
rt_mutex_release(&(device->bus->lock));
|
||||
}
|
||||
@@ -451,7 +453,7 @@ rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device,
|
||||
}
|
||||
|
||||
len = rt_spi_transfer(device, &senddata, recvdata, 2);
|
||||
if(len < 0)
|
||||
if (len < 0)
|
||||
{
|
||||
return (rt_err_t)len;
|
||||
}
|
||||
@@ -578,7 +580,7 @@ rt_err_t rt_spi_take(struct rt_spi_device *device)
|
||||
message.cs_take = 1;
|
||||
|
||||
result = device->bus->ops->xfer(device, &message);
|
||||
if(result < 0)
|
||||
if (result < 0)
|
||||
{
|
||||
return (rt_err_t)result;
|
||||
}
|
||||
@@ -598,7 +600,7 @@ rt_err_t rt_spi_release(struct rt_spi_device *device)
|
||||
message.cs_release = 1;
|
||||
|
||||
result = device->bus->ops->xfer(device, &message);
|
||||
if(result < 0)
|
||||
if (result < 0)
|
||||
{
|
||||
return (rt_err_t)result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user