First we need to enable iio_dummy
make -C "$IIO_TREE" menuconfig
device drivers -> industrial i/o support
Then we inspect .config file to check configurations
We also need to compile, load de module and check it:
cd "$IIO_TREE"
kw build --clean
cd "$IIO_TREE"
kw build
mkdir "${VM_DIR}/arm64_rootfs"
# mount the VM `rootfs` to the given mount point in read and write mode (this could take a while)
sudo guestmount --rw --add "${VM_DIR}/arm64_img.qcow2" --mount /dev/vda2 "${VM_DIR}/arm64_rootfs"
# install modules to inside the VM
sudo --preserve-env make -C "${IIO_TREE}" INSTALL_MOD_PATH="${VM_DIR}/arm64_rootfs" modules_install
# unmount the VM `rootfs`
sudo guestunmount "${VM_DIR}/arm64_rootfs"
# vm
sudo modprobe iio_dummy
modinfo iio_dummy
lsmod | grep iio_dummy
ls -l /sys/bus/iio/devices
ls -l /sys/bus/iio/devices/iio_evgen/
# to unload
sudo modprobe -r iio_dummy
obs: the module needs to be loaded
After that, we create a new device
sudo mkdir /mnt/iio_experiments/iio/devices/dummy/my_glorious_dummy_device
obs: if we want to unload the module after thar we need to remove this device
sudo rmdir /mnt/iio_experiments/iio/devices/dummy/my_glorious_dummy_device/
sudo modprobe -r iio_dummy
Adding Channels For a 3-axis Compass
Now we are going to extend the driver’s functionality by defining a 3-axis compass using the IIO framework’s standard attributes. Specifically, you need to configure the iio_chan_spec structure to create three distinct channels (X, Y, and Z) that allow users to read raw digital values, while providing a shared scale factor to convert those numbers into meaningful physical units. Furthermore, you must implement buffer support to handle continuous data streams, ensuring the data is formatted as 16-bit unsigned integers, all while omitting complex event-handling since this specific sensor doesn’t require interrupt-driven alerts.
we start editing the file drivers/iio/dummy/iio_simple_dummy.h
In this step, we are preparing the driver’s internal data structures to support a new sensor type by modifying the header file. First, a constant DUMMY_AXIS_XYZ is defined to represent the three dimensions of the compass. Next, the iio_dummy_state structure is expanded with a u16 buffer_compass array to provide a dedicated memory space for storing the magnetic field data from each axis. Finally, the iio_simple_dummy_scan_elements enumeration is updated to include unique indices for the X, Y, and Z axes, as well as a software timestamp; these indices are crucial for the IIO subsystem to correctly identify and order the data within the scan buffer.
We also add Channels to iio_chan_spec in lk_dev/iio/drivers/iio/dummy/iio_simple_dummy.c file
Then, we can compile and install the modules again assim foi possível testar as alterações After restarting the vm we need to run the following command again:
sudo mount -t configfs none /mnt/iio_experiments/