@@ -64,7 +64,7 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
64
64
for (int i = 0 ; i < pin_count ; ++ i )
65
65
{
66
66
bus -> pins [i ] = rt_pin_get_named_pin (& bus -> parent , "cs" , i ,
67
- RT_NULL , RT_NULL );
67
+ RT_NULL , RT_NULL );
68
68
}
69
69
}
70
70
else if (pin_count == 0 )
@@ -103,12 +103,15 @@ rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device,
103
103
{
104
104
device -> bus = (struct rt_spi_bus * )bus ;
105
105
106
+ if (device -> bus -> owner == RT_NULL )
107
+ device -> bus -> owner = device ;
108
+
106
109
/* initialize spidev device */
107
110
result = rt_spidev_device_init (device , name );
108
111
if (result != RT_EOK )
109
112
return result ;
110
113
111
- if (cs_pin != PIN_NONE )
114
+ if (cs_pin != PIN_NONE )
112
115
{
113
116
rt_pin_mode (cs_pin , PIN_MODE_OUTPUT );
114
117
}
@@ -140,7 +143,7 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
140
143
result = rt_mutex_take (& (device -> bus -> lock ), RT_WAITING_FOREVER );
141
144
if (result == RT_EOK )
142
145
{
143
- if (device -> bus -> owner == RT_NULL || device -> bus -> owner == device )
146
+ if (device -> bus -> owner == device )
144
147
{
145
148
/* current device is using, re-configure SPI bus */
146
149
result = device -> bus -> ops -> configure (device , & device -> config );
@@ -157,7 +160,6 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
157
160
*/
158
161
result = - RT_EBUSY ;
159
162
}
160
-
161
163
/* release lock */
162
164
rt_mutex_release (& (device -> bus -> lock ));
163
165
}
@@ -451,7 +453,7 @@ rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device,
451
453
}
452
454
453
455
len = rt_spi_transfer (device , & senddata , recvdata , 2 );
454
- if (len < 0 )
456
+ if (len < 0 )
455
457
{
456
458
return (rt_err_t )len ;
457
459
}
@@ -578,7 +580,7 @@ rt_err_t rt_spi_take(struct rt_spi_device *device)
578
580
message .cs_take = 1 ;
579
581
580
582
result = device -> bus -> ops -> xfer (device , & message );
581
- if (result < 0 )
583
+ if (result < 0 )
582
584
{
583
585
return (rt_err_t )result ;
584
586
}
@@ -598,7 +600,7 @@ rt_err_t rt_spi_release(struct rt_spi_device *device)
598
600
message .cs_release = 1 ;
599
601
600
602
result = device -> bus -> ops -> xfer (device , & message );
601
- if (result < 0 )
603
+ if (result < 0 )
602
604
{
603
605
return (rt_err_t )result ;
604
606
}
0 commit comments