简体   繁体   English

I2C符号链接

[英]I2C Symbolic Link

In linux you are able to use the ln command to link files/folders together to create symbolic files/folders. 在Linux中,您可以使用ln命令将文件/文件夹链接在一起以创建符号文件/文件夹。 Is there a way to do the same thing but with i2c master addresses. 除了i2c主地址外,是否有办法做同样的事情。

Ex: i2c-this -> i2c-06 例如:i2c-this-> i2c-06

So that when my code calls on "i2c-this", the address "i2c-06" is the one actually being called. 这样,当我的代码调用“ i2c-this”时,地址“ i2c-06”就是实际被调用的地址。

Yes, this is possible. 是的,这是可能的。 See https://www.kernel.org/doc/Documentation/i2c/dev-interface . 请参阅https://www.kernel.org/doc/Documentation/i2c/dev-interface

  int file;
  int adapter_nr = 2; /* probably dynamically determined */
  char filename[20];

  snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
  file = open(filename, O_RDWR);
  if (file < 0) {
    /* ERROR HANDLING; you can check errno to see what went wrong */
    exit(1);
  }

To instantiate a user space driver, follow method 4 from Yes. 若要实例化用户空间驱动程序,请按照“是”中的方法4进行操作。 https://www.kernel.org/doc/Documentation/i2c/instantiating-devices . https://www.kernel.org/doc/Documentation/i2c/instantiating-devices Specifically, your script will have to create the device in the /dev/ tree after adding the I2C device to the device tree since /dev is handled dynamically. 具体来说,由于/ dev是动态处理的,因此在将I2C设备添加到设备树后,脚本将必须在/ dev /树中创建设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM