用户级应用程序不能与硬件交互。它们可以通过系统调用(ioctl、open、读写等)和Sysfs(sysfs是一个虚拟文件系统)进行通信。
1 :- 您的设备是 hwmom 设备。您的驱动程序是“tmp102”。驱动程序为用户级应用程序公开这三个 temp1_input、temp1_max_hyst 和 temp1_max sysfs 条目。
SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, tmp102_show_temp, NULL , 0);
SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, tmp102_show_temp, tmp102_set_temp, 1);
SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, tmp102_show_temp,
tmp102_set_temp, 2);
您可以读取 /sys/class/hwmom/tmp102/temp1_input sysfs 文件。
你可以读写这两个sysfs文件/sys/class/hwmom/tmp102/temp1_max_hyst和sys/class/hwmom/tmp102/temp1_max。
2 :- /dev 中的文件是 UDEV 在运行时创建的实际设备文件。设备文件是出现在文件系统中的设备驱动程序的接口,就好像它是一个普通文件一样。您的驱动程序公开了一些其他设备文件。 thermo_zone_of_sensor_register(hwmon_dev, 0,hwmon_dev, &tmp102_of_thermal_ops)。你有 /dev/hwmom_dev 节点。
用户级应用程序不能直接与任何 i2c 设备或硬件通信。 Linux内核有限制。应用程序需要驱动程序作为接口来控制任何设备。