Skip to content

Commit 5a9ff03

Browse files
ubiedakartben
authored andcommitted
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 <[email protected]>
1 parent 0a71e95 commit 5a9ff03

File tree

6 files changed

+8
-6
lines changed

6 files changed

+8
-6
lines changed

drivers/sensor/adi/adxl345/adxl345.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static int adxl345_attr_set_odr(const struct device *dev,
229229
const struct sensor_value *val)
230230
{
231231
enum adxl345_odr odr;
232-
struct adxl345_dev_config *cfg = (struct adxl345_dev_config *)dev->config;
232+
struct adxl345_dev_data *data = dev->data;
233233

234234
switch (val->val1) {
235235
case 12:
@@ -257,7 +257,7 @@ static int adxl345_attr_set_odr(const struct device *dev,
257257
int ret = adxl345_set_odr(dev, odr);
258258

259259
if (ret == 0) {
260-
cfg->odr = odr;
260+
data->odr = odr;
261261
}
262262

263263
return ret;

drivers/sensor/adi/adxl345/adxl345.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ struct adxl345_dev_data {
156156
struct adxl345_fifo_config fifo_config;
157157
uint8_t is_full_res;
158158
uint8_t selected_range;
159+
enum adxl345_odr odr;
159160
#ifdef CONFIG_ADXL345_TRIGGER
160161
struct gpio_callback gpio_cb;
161162

drivers/sensor/adi/adxl345/adxl345_stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static void adxl345_process_fifo_samples_cb(struct rtio *r, const struct rtio_sq
159159
hdr->int_status = data->status1;
160160
hdr->is_full_res = data->is_full_res;
161161
hdr->selected_range = data->selected_range;
162-
hdr->accel_odr = cfg->odr;
162+
hdr->accel_odr = data->odr;
163163
hdr->sample_set_size = sample_set_size;
164164

165165
uint32_t buf_avail = buf_len;

drivers/sensor/adi/adxl372/adxl372.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ static int adxl372_attr_set_odr(const struct device *dev,
550550
const struct sensor_value *val)
551551
{
552552
enum adxl372_odr odr;
553-
struct adxl372_dev_config *cfg = (struct adxl372_dev_config *)dev->config;
553+
struct adxl372_data *data = dev->data;
554554

555555
switch (val->val1) {
556556
case 400:
@@ -575,7 +575,7 @@ static int adxl372_attr_set_odr(const struct device *dev,
575575
int ret = adxl372_set_odr(dev, odr);
576576

577577
if (ret == 0) {
578-
cfg->odr = odr;
578+
data->odr = odr;
579579
}
580580

581581
return ret;

drivers/sensor/adi/adxl372/adxl372.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ struct adxl372_data {
312312
const struct adxl372_transfer_function *hw_tf;
313313
struct adxl372_fifo_config fifo_config;
314314
enum adxl372_act_proc_mode act_proc_mode;
315+
enum adxl372_odr odr;
315316
#ifdef CONFIG_ADXL372_TRIGGER
316317
struct gpio_callback gpio_cb;
317318

drivers/sensor/adi/adxl372/adxl372_stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static void adxl372_process_fifo_samples_cb(struct rtio *r, const struct rtio_sq
214214
hdr->is_fifo = 1;
215215
hdr->timestamp = data->timestamp;
216216
hdr->int_status = data->status1;
217-
hdr->accel_odr = cfg->odr;
217+
hdr->accel_odr = data->odr;
218218
hdr->sample_set_size = sample_set_size;
219219

220220
if ((cfg->fifo_config.fifo_format == ADXL372_X_FIFO) ||

0 commit comments

Comments
 (0)