The sps30 driver for the Sensirion SPS30 is based on the IIO subsystem.
The driver contained here was originally submitted to the Linux kernel mailing list: https://lkml.org/lkml/2018/12/14/1066
Sensirion then backported it to older kernel versions.
Kernel with the following config options set, either as module or compiled in.
The config options must be listed in .config (e.g. selected with
make menuconfig)
Minimal driver requirements:
CONFIG_CRC8CONFIG_IIO
/: The root directory contains the Makefile needed for out-of-tree module builds.
/sps30: The sps30 directory contains the driver source and Kconfig as needed for upstream merging with the Linux sources.
Compiling for your local machine is useful to test if the driver compiles correctly. Prerequisites are the kernel headers and build tools.
# Install dependencies
sudo apt install build-essential linux-headers-$(uname -r)
# configure
export KERNELDIR=/lib/modules/$(uname -r)/build
# build
make -jTo check for style issues we can use the check target
make checkTo cross compile, one needs to install a cross compilation tool chain and set
the ARCH and CROSS_COMPILE environment variables accordingly:
# Example to cross compile for raspbian
export ARCH=arm
export CROSS_COMPILE=~/opt/toolchain/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-The driver is meant for direct use with sysfs or libiio. Errors are printed to the kernel log (dmesg)
Load the dependencies of the sps30.ko kernel module:
sudo modprobe industrialio
sudo modprobe crc8Load the kernel module with the appropriate command:
-
Out-of-tree build
sudo insmod sps30.ko
-
In-kernel build
sudo modprobe sps30
Instantiate the driver on the correct i2c bus with
echo sps30 0x69 | sudo tee /sys/class/i2c-adapter/i2c-1/new_deviceOnly sps30 is a permissible name.
Query device files by reading from the iio subsytem's device:
cat /sys/bus/iio/devices/iio\:device0/in_concentration_pm2p5_inputor alternatively on the i2c bus: /sys/bus/i2c/devices/1-0069/iio:device0/
Unload the driver by removing the device instance and then unloading the module.
echo 0x69 | sudo tee /sys/class/i2c-adapter/i2c-1/delete_device
sudo rmmod sps30