SPI驅動框架一

lethe1203發表於2024-03-31
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來進行管理

相關文章