sensor: adxl3xx: Move run-time modification of ODR from cfg to data

Config struct is constant and attempting to modify it triggers a fault.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
This commit is contained in:
Luis Ubieda 2025-01-11 13:29:14 -05:00 committed by Benjamin Cabé
commit 5a9ff03c21
6 changed files with 8 additions and 6 deletions

View file

@ -229,7 +229,7 @@ static int adxl345_attr_set_odr(const struct device *dev,
const struct sensor_value *val) const struct sensor_value *val)
{ {
enum adxl345_odr odr; enum adxl345_odr odr;
struct adxl345_dev_config *cfg = (struct adxl345_dev_config *)dev->config; struct adxl345_dev_data *data = dev->data;
switch (val->val1) { switch (val->val1) {
case 12: case 12:
@ -257,7 +257,7 @@ static int adxl345_attr_set_odr(const struct device *dev,
int ret = adxl345_set_odr(dev, odr); int ret = adxl345_set_odr(dev, odr);
if (ret == 0) { if (ret == 0) {
cfg->odr = odr; data->odr = odr;
} }
return ret; return ret;

View file

@ -156,6 +156,7 @@ struct adxl345_dev_data {
struct adxl345_fifo_config fifo_config; struct adxl345_fifo_config fifo_config;
uint8_t is_full_res; uint8_t is_full_res;
uint8_t selected_range; uint8_t selected_range;
enum adxl345_odr odr;
#ifdef CONFIG_ADXL345_TRIGGER #ifdef CONFIG_ADXL345_TRIGGER
struct gpio_callback gpio_cb; struct gpio_callback gpio_cb;

View file

@ -159,7 +159,7 @@ static void adxl345_process_fifo_samples_cb(struct rtio *r, const struct rtio_sq
hdr->int_status = data->status1; hdr->int_status = data->status1;
hdr->is_full_res = data->is_full_res; hdr->is_full_res = data->is_full_res;
hdr->selected_range = data->selected_range; hdr->selected_range = data->selected_range;
hdr->accel_odr = cfg->odr; hdr->accel_odr = data->odr;
hdr->sample_set_size = sample_set_size; hdr->sample_set_size = sample_set_size;
uint32_t buf_avail = buf_len; uint32_t buf_avail = buf_len;

View file

@ -550,7 +550,7 @@ static int adxl372_attr_set_odr(const struct device *dev,
const struct sensor_value *val) const struct sensor_value *val)
{ {
enum adxl372_odr odr; enum adxl372_odr odr;
struct adxl372_dev_config *cfg = (struct adxl372_dev_config *)dev->config; struct adxl372_data *data = dev->data;
switch (val->val1) { switch (val->val1) {
case 400: case 400:
@ -575,7 +575,7 @@ static int adxl372_attr_set_odr(const struct device *dev,
int ret = adxl372_set_odr(dev, odr); int ret = adxl372_set_odr(dev, odr);
if (ret == 0) { if (ret == 0) {
cfg->odr = odr; data->odr = odr;
} }
return ret; return ret;

View file

@ -312,6 +312,7 @@ struct adxl372_data {
const struct adxl372_transfer_function *hw_tf; const struct adxl372_transfer_function *hw_tf;
struct adxl372_fifo_config fifo_config; struct adxl372_fifo_config fifo_config;
enum adxl372_act_proc_mode act_proc_mode; enum adxl372_act_proc_mode act_proc_mode;
enum adxl372_odr odr;
#ifdef CONFIG_ADXL372_TRIGGER #ifdef CONFIG_ADXL372_TRIGGER
struct gpio_callback gpio_cb; struct gpio_callback gpio_cb;

View file

@ -214,7 +214,7 @@ static void adxl372_process_fifo_samples_cb(struct rtio *r, const struct rtio_sq
hdr->is_fifo = 1; hdr->is_fifo = 1;
hdr->timestamp = data->timestamp; hdr->timestamp = data->timestamp;
hdr->int_status = data->status1; hdr->int_status = data->status1;
hdr->accel_odr = cfg->odr; hdr->accel_odr = data->odr;
hdr->sample_set_size = sample_set_size; hdr->sample_set_size = sample_set_size;
if ((cfg->fifo_config.fifo_format == ADXL372_X_FIFO) || if ((cfg->fifo_config.fifo_format == ADXL372_X_FIFO) ||