New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: sensor: add ScioSense ENS160 driver #67343
Conversation
96c0724
to
b70cb5c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
9e1616a
to
f63121c
Compare
@MaureenHelm rebase done |
d0bcb39
to
6039cc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good, just a couple of comments
drivers/sensor/ens160/ens160.c
Outdated
return 0; | ||
} | ||
|
||
static int ens160_new_data(const struct device *dev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static int ens160_new_data(const struct device *dev) | |
static bool ens160_new_data(const struct device *dev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
drivers/sensor/ens160/ens160.c
Outdated
if (FIELD_GET(ENS160_STATUS_NEWDAT, status) == 0x01) { | ||
return 1; | ||
} | ||
|
||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (FIELD_GET(ENS160_STATUS_NEWDAT, status) == 0x01) { | |
return 1; | |
} | |
return 0; | |
return FIELD_GET(ENS160_STATUS_NEWDAT, status) != 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
drivers/sensor/ens160/ens160.c
Outdated
chan == (enum sensor_channel)SENSOR_CHAN_ENS160_AQI); | ||
|
||
if (!IS_ENABLED(CONFIG_ENS160_TRIGGER)) { | ||
WAIT_FOR((ens160_new_data(dev) == 1), ENS160_TIMEOUT_US, k_msleep(10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WAIT_FOR((ens160_new_data(dev) == 1), ENS160_TIMEOUT_US, k_msleep(10)); | |
WAIT_FOR(ens160_new_data(dev), ENS160_TIMEOUT_US, k_msleep(10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
drivers/sensor/ens160/ens160_i2c.c
Outdated
{ | ||
const struct ens160_config *config = dev->config; | ||
|
||
return i2c_burst_write_dt(&config->i2c, reg, data, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately i2c_burst_write is problematic, so should be avoided (#20154).
You will need to create a combined write buffer here, something like:
return i2c_burst_write_dt(&config->i2c, reg, data, len); | |
__ASSERT(len == 2, "Only 2 byte write are supported"); | |
uint8_t buff[] = {reg, data[0], data[1]}; | |
return i2c_write_dt(&config->i2c, buff, sizeof(buff)); | |
} |
Alternatively you may wish to have a write 2 registers function instead.
If it is unlikely that there will be need to writes more than 2 bytes, this is a good option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not aware of this problem. Thank you for pointing it out.
The datasheet (version 1.3) mentions in section 16.2.4 a write operation to a set of consecutive registers for configuring threshold interrupt, but some details are absent in the current revision. Therefore, this driver does not implement threshold triggers for the same reason.
However, I imagine that in a future revision the datasheet may become clearer and there will be the need for writing more than two bytes.
Because of this, I opted for your first suggestion.
Add driver for ScioSense ENS160 multi-gas sensor. The driver includes support for I2C and SPI, attributes for setting temperature and humidity compensation and data ready trigger. Also add ScioSense to the list of vendor prefixes. Signed-off-by: Gustavo Silva <gustavograzs@gmail.com>
Add driver for ScioSense ENS160 multi-gas sensor. The driver includes support for I2C and SPI, attributes for setting temperature and humidity compensation and data ready trigger. Also add ScioSense to the list of vendor prefixes.