Here's the fifth patch in the Build-a-Driver series for MCP9808.
(If this post seems out of context, please refer to "Build-a-Driver Introduction" post.)
mcp9808: this version adds support for changing measurement resolution also known as the integration time.
MCP9808 supports 4 resolutions: .5 .25 .125 .0625.
Power-on default resolution is .0625.
This requires the following changes:
- update the channel definition to include IIO_CHAN_INFO_INT_TIME
- set up an attribute group that defines the integration times available and export that to sysfs via the iio_info structure
- export a *write_raw routine to welcome requests to change integration time and funnel them to *set_it_time()
- create a *set_it_time function that indexes into a short array of integration times to find which bits to set in the sensor resolution register. It sets those bits, and upon success, updates the current int_time in our global data. Use a lock to prevent simultaneous integration time changes.
- update *read_raw to handle requests for current integration time which is obtained directly from *data->int_time.
Much of this was verified with debug code that has since been removed. For example, for the writing of the resolution bits, I had dumped the array at probe, dumped the bits before I sent them, and read back the resolution register after I wrote it to be sure those bits were set correctly.
The testing at this point was a simple bash script, some icepacks, hotpack, icewater and some ziploc bags. My sensor has survived, but I have not reached zero. So, more to do on the coldest side. I looped while reading temps and changing integration times checking that they were as expected.
Labels: Build-a-Driver, MCP9808