How it works...
In this recipe, we showed how to implement a very simple device driver that is available on a bus such as the I2C (https://learn.sparkfun.com/tutorials/i2c/all). Since the I2C is a comparatively sophisticated bus (which makes implementing drivers simpler), a driver implements a protocol for reading and write operations to assumed registers and encapsulates them in a nice API. In this recipe, we did not actually use an I2C bus crate to provide the struct device, since it would impact OS compatibility.
In step 2, we create the main loop to read from the sensor in a very simplistic way (check the Efficiently reading hardware sensors recipe), using sleep to control reading speed. In a typical fashion, we instantiate the driver ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access