1.写在前面
spi(Serial Peripheral Interface)即串行外设接口。与i2c一样,spi也常用外设设备通信的总线,从事嵌入式开发必不可少的掌握。根据本人以往的经历,对spi进行总结(主要是MCU范畴,Linux已有成熟的驱动设备),主要目的及实现:
1)spi总线与spi设备分离;
2)快速使用新的硬件spi或者模拟spi;
3)方便移植spi总线设备及spi外设程序到不同mcu平台。
2.spi总线抽象
此部分实现源码为:spi_core.c spi_core.h
2.1 spi总线模型对外接口(API)
/*extern function*/
extern int spi_send_then_recv(struct spi_dev_device *spi_dev,const void *send_buff,
unsigned short send_size,void *recv_buff,unsigned short recv_size);
extern int spi_send_then_send(struct spi