int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len) { struct spi_transfer t = { .tx_buf = buf, .len = len, }; struct spi_message m; fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len, "%s(len=%d): ", __func__, len); if (!par->spi) { dev_err(par->info->device, "%s: par->spi is unexpectedly NULL\n", __func__); return -1; } spi_message_init(&m); if (par->txbuf.dma && buf == par->txbuf.buf) { t.tx_dma = par->txbuf.dma; m.is_dma_mapped = 1; } spi_message_add_tail(&t, &m); return spi_sync(par->spi, &m); }逐行注释
时间: 2024-04-02 11:33:02 浏览: 110
mmc_spi.rar_linux mmc_spi
// This function is used to write data to the display using SPI communication
int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len) {
// Create a SPI transfer struct with the buffer and length provided
struct spi_transfer t = {
.tx_buf = buf, // Pointer to the transmit buffer
.len = len, // Length of the transmit buffer in bytes
};
// Create a SPI message struct
struct spi_message m;
// Print the buffer contents in hexadecimal format for debugging purposes
fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
"%s(len=%d): ", __func__, len);
// Check if the SPI device pointer is valid
if (!par->spi) {
dev_err(par->info->device,
"%s: par->spi is unexpectedly NULL\n", __func__);
return -1; // Return an error code if the pointer is NULL
}
// Initialize the SPI message struct
spi_message_init(&m);
// If DMA mode is enabled and the buffer pointer is the same as the transmit buffer
if (par->txbuf.dma && buf == par->txbuf.buf) {
t.tx_dma = par->txbuf.dma; // Set the DMA address of the transmit buffer
m.is_dma_mapped = 1; // Set the DMA flag in the SPI message struct
}
// Add the SPI transfer to the SPI message
spi_message_add_tail(&t, &m);
// Synchronously transfer the SPI message using the SPI device
return spi_sync(par->spi, &m);
}
阅读全文