-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
sensor: drivers: Panasonic sngcja5 particle matter sensor #55765
sensor: drivers: Panasonic sngcja5 particle matter sensor #55765
Conversation
457efe5
to
7d1f0e5
Compare
6a81df6
to
371b209
Compare
f48dfc2
to
63a5936
Compare
drivers/sensor/sngcja5/sngcja5.c
Outdated
return -EIO; | ||
} | ||
|
||
*value = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[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.
sys_be32_to_cpu
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.
See comment below
drivers/sensor/sngcja5/sngcja5.c
Outdated
return -EIO; | ||
} | ||
|
||
*value = (buf[1] << 8) | buf[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.
sys_be16_to_cpu
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.
When using sys_be16_to_cpu
like in following snippet:
static int read_register_2(const struct i2c_dt_spec *dev, uint8_t addr, uint16_t *value)
{
if (i2c_burst_read_dt(dev, addr, (uint8_t *)value, sizeof(*value)) < 0) {
LOG_ERR("i2c_burst_read_dt() @ i2c failed");
return -EIO;
}
*value = sys_be16_to_cpu(*value);
return 0;
}
Like it's done for example in drivers/sensor/tmp112/tmp112.c
, i would get the wrong byte order for my read data. Should be:
new sample: pc0_5.1: 0x0003
But is:
new sample: pc0_5.1: 0x0300
So i guess i have to stick to the previous solution.
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.
These are actually little-endian, not big-endian, so using *_le*.
versions of the conversion macros should work as expected
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Hello @MaureenHelm |
cd1d396
to
cb41cc2
Compare
cb41cc2
to
30f227d
Compare
015b3d9
to
bf62427
Compare
4c0324a
to
36359a4
Compare
Hi @teburd and @avisconti |
Hi @MaureenHelm, @avisconti, |
Hi to all listed reviewers, |
Hello to the reviewers in the list @avisconti, @nashif, @galak, @yperess, @kartben, @tristan-google, |
drivers/sensor/sngcja5/sngcja5.c
Outdated
return -EIO; | ||
} | ||
|
||
*value = (buf[1] << 8) | buf[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.
These are actually little-endian, not big-endian, so using *_le*.
versions of the conversion macros should work as expected
/** | ||
* Particle count array | ||
* value1[(0.3-0.5µm)], | ||
* value2[(0.5-1.0µm)], | ||
* value3[(1.0-2.5µm)], | ||
* value4[(2.5-5.0µm)], | ||
* value5[(5.0-7.5µm)], | ||
* value6[(7.5-10.0µm)] | ||
*/ | ||
SENSOR_CHAN_PARTICLE_COUNT, |
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.
At a minimum this should be a different commit, yes.
But I am -1 on adding this new "array" channel as both your linked datasheets actually show that different sensors will likely use different "classes" of particle counts in this array i.e PM 0.5/1.0/2.5/4.0/10.0 for SPS30, and PM 0.3/0.5/1.0/2.5/5.0/10.0, none of which correspond to the ranges proposed here. HM3300/3600 sensors have yet another range (https://files.seeedstudio.com/wiki/Grove-Laser_PM2.5_Sensor-HM3301/res/HM-3300%263600_V2.1.pdf) and so on.
What would probably work though is adding SENSOR_CHAN_PC_{X_Y}
channels.
…nnel Particle matter sensors like the SNGCJA5 are able to detect particle counts. This sensor channel array needs to be added. Signed-off-by: Steffen Jahnke <[email protected]>
Added driver for Panasonic's "particulate matters (PM) sensor" laser type. PM sensor is able to detect smoke, environmental dust and other unwanted dangerous pollutant in the air that surrounds us. Signed-off-by: Steffen Jahnke <[email protected]>
Added sample for Panasonic's "particulate matters (PM) sensor" laser type. The sample detects values for PM1, PM2.5, PM10 and the particle counts periodically and prints them once a second to the console. Signed-off-by: Steffen Jahnke <[email protected]>
36359a4
to
31b0606
Compare
@MaureenHelm and other core contributors to the sensor API, |
Ack, will review today |
if (read_register_4(&device_config->i2c, SNGCJA5_PM10_LL, &(device_data->pm1_0))) { | ||
return -EIO; | ||
} | ||
if (read_register_4(&device_config->i2c, SNGCJA5_PM25_LL, &(device_data->pm2_5))) { | ||
return -EIO; | ||
} | ||
if (read_register_4(&device_config->i2c, SNGCJA5_PM100_LL, &(device_data->pm10_0))) { | ||
return -EIO; | ||
} | ||
if (read_register_2(&device_config->i2c, SNGCJA5_05_L, &(device_data->pc0_5))) { | ||
return -EIO; | ||
} | ||
if (read_register_2(&device_config->i2c, SNGCJA5_10_L, &(device_data->pc1_0))) { | ||
return -EIO; | ||
} | ||
if (read_register_2(&device_config->i2c, SNGCJA5_25_L, &(device_data->pc2_5))) { | ||
return -EIO; | ||
} | ||
if (read_register_2(&device_config->i2c, SNGCJA5_50_L, &(device_data->pc5_0))) { | ||
return -EIO; | ||
} | ||
if (read_register_2(&device_config->i2c, SNGCJA5_75_L, &(device_data->pc7_5))) { | ||
return -EIO; | ||
} | ||
if (read_register_2(&device_config->i2c, SNGCJA5_100_L, &(device_data->pc10_0))) { | ||
return -EIO; | ||
} |
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.
These all seem to be sequential registers, can we just do 1 burst i2c read and then convert to CPU endianess one by one?
/** | ||
* Particle count array | ||
* value1[(0.3-0.5µm)], | ||
* value2[(0.5-1.0µm)], | ||
* value3[(1.0-2.5µm)], | ||
* value4[(2.5-5.0µm)], | ||
* value5[(5.0-7.5µm)], | ||
* value6[(7.5-10.0µm)] | ||
*/ | ||
SENSOR_CHAN_PARTICLE_COUNT, |
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'm not really seeing the need for this to be a part of sensor.h, why can't this highly specific 6 value channel be added in sngcja5.h? I would also like to add that with the new async API you're able to have an index along with a channel which would service this model much better. SENSOR_CHAN_PARTICLE_COUNT would be used along with an index to provide any number of dimensions to the measurement. We would still need a way to describe what each index means.
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'm going to let @MaureenHelm decide the path on this, but I'm not seeing a strong benefit to adding yet another sensor specific sample to sensors. The sensor shell sample can do this just fine.
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.
@yperess, thanks for reviewing.
Okay, so I will wait for decision of @MaureenHelm, before I change this in the driver.
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Support for Panasonic's SN-GCJA5 Particle Matter Sensor.
Added sensor drivers and sensor sample for example usage.