当前位置:网站首页>Two ideas of I2C driver implementation (I2C dev.c and I2C core.c)

Two ideas of I2C driver implementation (I2C dev.c and I2C core.c)

2022-06-21 06:56:00 Snail taking off

1、 take I2C How the controller is exposed to the application (i2c-dev.c)

(1)i2c-dev.c The idea of mode is to provide and I2C The way in which the devices on the bus send and receive data , But not responsible for specific timing or business , The specific timing and business are realized by the upper business ;
(2) The embodiment of this way : Register at I2C After driving , Will see "/dev/i2c-n(n=0,1,2······)" Device node , Used to open the device node , And then through read、write、ioctl Wait for the interface to connect with I2C Interface device communication ;
(3) This way is not often used , Because it is necessary to put the timing of operating specific hardware into the application , Application developers are required to understand the specific hardware operation sequence , Also understand I2C bus protocol . The general timing is to be implemented in the driver , Try to shield the difference of hardware for the application ;
(4) Such as reading data : Application first open Open the device node , then ioctl Set the device to be operated in I2C Address on the bus , Finally, according to I2C Read between bus protocol and device / Writing data ;
a key : This method is directly provided to the application I2C Operation method of the controller , every last "/dev/i2c-n(n=0、1、2、······)", Each device node represents Soc One of them I2C controller , The application can operate the device node, that is, operate I2C controller , Go and mount in I2C Slave devices on the bus communicate ;

2、 take I2C The controller is abstracted as a common driver ( i2c-core.c)

(1) take I2C The communication sequence is abstracted into a simple read-write interface , for I2C Interface device driver calls , This method is generally used with other driver frameworks ;
(2) In this way I2C The driver is equivalent to the kernel I2C Communication is abstracted , Because of all the I2C The interface equipment adopts I2C Bus protocol for communication , Then we will I2C Communication is abstracted into one for others I2C Basic function driver of interface device driver call ;
(3) Is equivalent to I2C The driver is implemented as a common driver , Be similar to platform Bus , It may not involve specific hardware differences , all I2C Interface devices can be shared I2C Drive to read and write data ;
(4) for example I2C Interface touch screen : The application operates the touch screen through input Subsystem operation , adopt open"/dev/eventn" Device node , The application only needs to accept the reported input events , I don't care how the touch screen reports , I don't even know if the touch screen is used I2C The bus interacts with the host ;

3、 Compare the two ways

(1)i2c-dev.c The way to put I2C The operating method of the equipment is exposed to the application , The timing of the specific operating hardware is controlled by the application , Can do some non-standard I2C Functions of the protocol , But it increases the difficulty and workload of application development , Is not commonly used ;
(2) take I2C The controller is abstracted into a common driver for other drivers to call , Masked the application I2C Content of communication , It simplifies the difficulty of application development ;
(3) take I2C The controller is abstracted into a common driver for other drivers to call ,I2C The framework that drives itself is complex , Increase the learning difficulty of those responsible for driving development ;
(4)i2c-dev.c In the end, it is also called i2c-core.c File interface , It's just encapsulated ;

原网站

版权声明
本文为[Snail taking off]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210640291341.html