Skip to content

Commit

Permalink
SPI挂载设备时,如果总线设备为空则赋值
Browse files Browse the repository at this point in the history
  • Loading branch information
Rbb666 committed Feb 11, 2025
1 parent d17fafb commit b5eeb6c
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions components/drivers/spi/dev_spi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -150,17 +153,16 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
LOG_E("SPI device %s configuration failed", device->parent.parent.name);
}
}

else
{
/* RT_EBUSY is not an error condition and
* the configuration will take effect once the device has the bus
*/
result = -RT_EBUSY;
}
/* release lock */
rt_mutex_release(&(device->bus->lock));
}
else
{
/* RT_EBUSY is not an error condition and
* the configuration will take effect once the device has the bus
*/
result = -RT_EBUSY;
}
}
else
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit b5eeb6c

Please sign in to comment.