Linux下SPI驅動簡解

2021-08-20 21:27:48 字數 1559 閱讀 7126

基礎知識:

第一點:硬體四線

第二點:重要結構體和函式

struct spi_device 

struct spi_message

struct spi_transfer

int spi_async(struct spi_device *spi, struct spi_message *message)

static inline void spi_message_init(struct spi_message *m)

static inline void spi_message_add_tail(struct spi_transfer *t, struct spi_message *m)

第三點:裝置驅動編寫步驟

/*在mach-***xx中新增這個裝置 , 裝置註冊=核心挖土坑 ,形成新的zimage*/

struct spi_board_info ***xx_spi_board_info

;#ifdef config_***xx

spi_register_board_info(***xx_spi_board_info, array_size(***xx_spi_board_info));

#endif

/*註冊驅動*/

static struct spi_driver ***xx_spi_driver = ,

.probe =

***xx_probe,

.remove = __devexit_p(***xx_remove),

};module_init(my_rc522_init)->spi_register_driver(&***xx_spi_driver)->***xx_probe->

gpio_init->misc_register(&***xx_dev)->fops->read/write->

/*讀寫實現*/

struct spi_device *my_spi; //

/*read*/

int status;

unsigned char rx_buf; //rx_buf存放被讀的東西,前提要先寫入位址

struct spi_transfer

t = ;

struct spi_message

m;spi_message_init(&m);

spi_message_add_tail(&t, &m);

status = spi_async(my_spi,&m);

/*wirte*/

int status;

unsigned char tx_buf; //tx_buf存放想寫的東西,前提是要先寫入位址

struct spi_transfer

t = ;

struct spi_message

m;spi_message_init(&m);

spi_message_add_tail(&t, &m);

status = spi_async(my_spi,&m);

/*解除安裝*/

spi_unregister_driver(&***xx_spi_driver)

linux下spi驅動分析

核心版本 linux 2.6.29 主要的幾個結構platform device platform driver s3c24xx spi spi master spi bitbang spi device spi driver spidev data s3c spi info第一步 註冊platfo...

Linux下SPI驅動分析 2

接上乙個繼續看spi.c。名詞解釋of openfirmware 呼叫層次spi match device of driver match device of match device of match node 用於驅動程式檢查platform device是否在其支援列表裡 80static i...

Linux下Framebuffer驅動簡介

version v0.1 time 09 06 2008 author green waste 163.com 最近接觸了一些關於linux下framebuffer方面的東西和lcd的framebuffer驅動,所以去了解了一些相關基礎知識。為了避免其他人走我走過的彎路,所以就把我的一些很少的心得,...