SPI驱动框架一
spi总线
设备链表 spi_device
控制器spi_master
读写硬件:
spidev_sync_read(struct spidev_data *spidev, size_t len) { struct spi_transfer t = { .rx_buf = spidev->rx_buffer, .len = len, .speed_hz = spidev->speed_hz, }; struct spi_message m; spi_message_init(&m); spi_message_add_tail(&t, &m); return spidev_sync(spidev, &m); } spidev_sync_write(struct spidev_data *spidev, size_t len) { struct spi_transfer t = { .rx_buf = spidev->tx_buffer, .len = len, .speed_hz = spidev->speed_hz, }; struct spi_message m; spi_message_init(&m); spi_message_add_tail(&t, &m); return spidev_sync(spidev, &m); }
spi_sync是同步函数,这个函数返回的时候,要么传输成功了,要么传输失败了
spi_transfer描述一次传输,里面有tx_buf和rx_buf
可以构造多个spi_transfer,然后初始化一个spi_message来进行管理