MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / spi_bit_xfer

Function spi_bit_xfer

components/drivers/spi/dev_spi_bit_ops.c:468–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

466}
467
468rt_ssize_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *message)
469{
470 struct rt_spi_bit_obj *obj = rt_container_of(device->bus, struct rt_spi_bit_obj, bus);
471 struct rt_spi_bit_ops *ops = obj->ops;
472 struct rt_spi_configuration *config = &obj->config;
473 rt_base_t cs_pin = device->cs_pin;
474 rt_ssize_t length = 0;
475
476 RT_ASSERT(device != NULL);
477 RT_ASSERT(message != NULL);
478
479#ifdef RT_SPI_BITOPS_DEBUG
480 if (!ops->tog_sclk || !ops->set_sclk || !ops->get_sclk)
481 {
482 LOG_E("SPI bus error, SCLK line not defined");
483 }
484 if (!ops->set_mosi || !ops->get_mosi)
485 {
486 LOG_E("SPI bus error, MOSI line not defined");
487 }
488 if (!ops->set_miso || !ops->get_miso)
489 {
490 LOG_E("SPI bus error, MISO line not defined");
491 }
492#endif
493
494 /* take CS */
495 if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS) && (cs_pin != PIN_NONE))
496 {
497 LOG_I("spi take cs\n");
498 if (device->config.mode & RT_SPI_CS_HIGH)
499 {
500 rt_pin_write(cs_pin, PIN_HIGH);
501 }
502 else
503 {
504 rt_pin_write(cs_pin, PIN_LOW);
505 }
506 spi_delay(ops);
507 }
508
509 /* spi phase */
510 if ((config->mode & RT_SPI_CPHA))
511 {
512 spi_delay(ops);
513 TOG_SCLK(ops);
514 }
515 if (config->mode & RT_SPI_3WIRE)
516 {
517 if (config->data_width <= 8)
518 {
519 length = spi_xfer_3line_data8(ops, config, message->send_buf, message->recv_buf, message->length);
520 }
521 else if (config->data_width <= 16)
522 {
523 length = spi_xfer_3line_data16(ops, config, message->send_buf, message->recv_buf, message->length);
524 }
525 }

Callers

nothing calls this directly

Calls 6

spi_xfer_3line_data8Function · 0.85
spi_xfer_3line_data16Function · 0.85
spi_xfer_4line_data8Function · 0.85
spi_xfer_4line_data16Function · 0.85
spi_delayFunction · 0.70
rt_pin_writeFunction · 0.50

Tested by

no test coverage detected