@@ -443,10 +443,17 @@ rt_ssize_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *mes
443
443
#endif
444
444
445
445
/* take CS */
446
- if (message -> cs_take && (cs_pin != PIN_NONE ))
446
+ if (message -> cs_take && !( device -> config . mode & RT_SPI_NO_CS ) && (cs_pin != PIN_NONE ))
447
447
{
448
448
LOG_I ("spi take cs\n" );
449
- rt_pin_write (cs_pin , PIN_LOW );
449
+ if (device -> config .mode & RT_SPI_CS_HIGH )
450
+ {
451
+ rt_pin_write (cs_pin , PIN_HIGH );
452
+ }
453
+ else
454
+ {
455
+ rt_pin_write (cs_pin , PIN_LOW );
456
+ }
450
457
spi_delay (ops );
451
458
452
459
/* spi phase */
@@ -497,10 +504,17 @@ rt_ssize_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *mes
497
504
}
498
505
499
506
/* release CS */
500
- if (message -> cs_release && (cs_pin != PIN_NONE ))
507
+ if (message -> cs_take && !( device -> config . mode & RT_SPI_NO_CS ) && (cs_pin != PIN_NONE ))
501
508
{
502
509
spi_delay (ops );
503
- rt_pin_write (cs_pin , PIN_HIGH );
510
+ if (device -> config .mode & RT_SPI_CS_HIGH )
511
+ {
512
+ rt_pin_write (cs_pin , PIN_LOW );
513
+ }
514
+ else
515
+ {
516
+ rt_pin_write (cs_pin , PIN_HIGH );
517
+ }
504
518
LOG_I ("spi release cs\n" );
505
519
}
506
520
@@ -522,9 +536,5 @@ rt_err_t rt_spi_bit_add_bus(struct rt_spi_bit_obj *obj,
522
536
obj -> config .max_hz = 1 * 1000 * 1000 ;
523
537
obj -> config .mode = RT_SPI_MASTER | RT_SPI_MSB | RT_SPI_MODE_0 ;
524
538
525
- /* idle status */
526
- if (obj -> config .mode & RT_SPI_CPOL ) SCLK_H (ops );
527
- else SCLK_L (ops );
528
-
529
539
return rt_spi_bus_register (& obj -> bus , bus_name , & spi_bit_bus_ops );
530
540
}
0 commit comments