Skip to content

Commit cd465ff

Browse files
Emil ObalskiMaureenHelm
Emil Obalski
authored andcommitted
drivers: sensors: Support XYZ accel get for adxl362.
Add a possibility to get values of accelerometer measurement for all 3 axis of accelerometer with one channel_get(). Signed-off-by: Emil Obalski <[email protected]>
1 parent ecac194 commit cd465ff

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

drivers/sensor/adxl362/adxl362.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,11 @@ static int adxl362_channel_get(const struct device *dev,
614614
case SENSOR_CHAN_ACCEL_Z: /* Acceleration on the Z axis, in m/s^2. */
615615
adxl362_accel_convert(val, data->acc_z, data->selected_range);
616616
break;
617+
case SENSOR_CHAN_ACCEL_XYZ: /* Acceleration on the XYZ axis, in m/s^2. */
618+
for (size_t i = 0; i < 3; i++) {
619+
adxl362_accel_convert(&val[i], data->acc_xyz[i], data->selected_range);
620+
}
621+
break;
617622
case SENSOR_CHAN_DIE_TEMP: /* Temperature in degrees Celsius. */
618623
adxl362_temp_convert(val, data->temp);
619624
break;

drivers/sensor/adxl362/adxl362.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,14 @@ struct adxl362_data {
194194
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
195195
struct spi_cs_control adxl362_cs_ctrl;
196196
#endif
197-
int16_t acc_x;
198-
int16_t acc_y;
199-
int16_t acc_z;
197+
union {
198+
int16_t acc_xyz[3];
199+
struct {
200+
int16_t acc_x;
201+
int16_t acc_y;
202+
int16_t acc_z;
203+
};
204+
} __packed;
200205
int16_t temp;
201206
uint8_t selected_range;
202207

0 commit comments

Comments
 (0)