@@ -49,6 +49,7 @@ int bmp581_encode(const struct device *dev,
49
49
50
50
if (trigger_status ) {
51
51
edata -> header .channels |= bmp581_encode_channel (SENSOR_CHAN_ALL );
52
+ edata -> header .fifo_count = data -> stream .fifo_thres ;
52
53
} else {
53
54
const struct sensor_chan_spec * const channels = read_config -> channels ;
54
55
size_t num_channels = read_config -> count ;
@@ -63,7 +64,7 @@ int bmp581_encode(const struct device *dev,
63
64
return err ;
64
65
}
65
66
66
- edata -> header .events = trigger_status ? BIT ( 0 ) : 0 ;
67
+ edata -> header .events = trigger_status ;
67
68
edata -> header .timestamp = sensor_clock_cycles_to_ns (cycles );
68
69
69
70
return 0 ;
@@ -86,7 +87,11 @@ static int bmp581_decoder_get_frame_count(const uint8_t *buffer,
86
87
return - ENODATA ;
87
88
}
88
89
89
- * frame_count = 1 ;
90
+ if (edata -> header .events & BMP581_EVENT_FIFO_WM ) {
91
+ * frame_count = edata -> header .fifo_count ;
92
+ } else {
93
+ * frame_count = 1 ;
94
+ }
90
95
return 0 ;
91
96
}
92
97
@@ -105,53 +110,37 @@ static int bmp581_decoder_get_size_info(struct sensor_chan_spec chan_spec,
105
110
}
106
111
}
107
112
108
- static int bmp581_decoder_decode (const uint8_t * buffer ,
109
- struct sensor_chan_spec chan_spec ,
110
- uint32_t * fit ,
111
- uint16_t max_count ,
112
- void * data_out )
113
+ static int bmp581_convert_raw_to_q31_value (const struct bmp581_encoded_header * header ,
114
+ struct sensor_chan_spec * chan_spec ,
115
+ const struct bmp581_frame * frame ,
116
+ uint32_t * fit ,
117
+ struct sensor_q31_data * out )
113
118
{
114
- const struct bmp581_encoded_data * edata = (const struct bmp581_encoded_data * )buffer ;
115
- uint8_t channel_request ;
116
-
117
- if (* fit != 0 ) {
118
- return 0 ;
119
- }
120
-
121
- if (max_count == 0 || chan_spec .chan_idx != 0 ) {
122
- return - EINVAL ;
123
- }
124
-
125
- channel_request = bmp581_encode_channel (chan_spec .chan_type );
126
- if ((channel_request & edata -> header .channels ) != channel_request ) {
119
+ if (((header -> events & BMP581_EVENT_FIFO_WM ) != 0 && * fit >= header -> fifo_count ) ||
120
+ ((header -> events & BMP581_EVENT_FIFO_WM ) == 0 && * fit != 0 )) {
127
121
return - ENODATA ;
128
122
}
129
123
130
- struct sensor_q31_data * out = data_out ;
131
-
132
- out -> header .base_timestamp_ns = edata -> header .timestamp ;
133
- out -> header .reading_count = 1 ;
134
-
135
- switch (chan_spec .chan_type ) {
124
+ switch (chan_spec -> chan_type ) {
136
125
case SENSOR_CHAN_AMBIENT_TEMP : {
137
126
/* Temperature is in data[2:0], data[2] is integer part */
138
- uint32_t raw_temp = ((uint32_t )edata -> payload [2 ] << 16 ) |
139
- ((uint16_t )edata -> payload [1 ] << 8 ) |
140
- edata -> payload [0 ];
127
+ uint32_t raw_temp = ((uint32_t )frame [ * fit ]. payload [2 ] << 16 ) |
128
+ ((uint16_t )frame [ * fit ]. payload [1 ] << 8 ) |
129
+ frame [ * fit ]. payload [0 ];
141
130
int32_t raw_temp_signed = sign_extend (raw_temp , 23 );
142
131
143
132
out -> shift = (31 - 16 ); /* 16 left shifts gives us the value in celsius */
144
- out -> readings [0 ].value = raw_temp_signed ;
133
+ out -> readings [* fit ].value = raw_temp_signed ;
145
134
break ;
146
135
}
147
- case SENSOR_CHAN_PRESS :
148
- if (!edata -> header . press_en ) {
136
+ case SENSOR_CHAN_PRESS : {
137
+ if (!header -> press_en ) {
149
138
return - ENODATA ;
150
139
}
151
140
/* Shift by 10 bits because we'll divide by 1000 to make it kPa */
152
- uint64_t raw_press = (((uint32_t )edata -> payload [5 ] << 16 ) |
153
- ((uint16_t )edata -> payload [4 ] << 8 ) |
154
- edata -> payload [3 ]);
141
+ uint64_t raw_press = (((uint32_t )frame [ * fit ]. payload [5 ] << 16 ) |
142
+ ((uint16_t )frame [ * fit ]. payload [4 ] << 8 ) |
143
+ frame [ * fit ]. payload [3 ]);
155
144
156
145
int64_t raw_press_signed = sign_extend_64 (raw_press , 23 );
157
146
@@ -163,21 +152,63 @@ static int bmp581_decoder_decode(const uint8_t *buffer,
163
152
* converting to kPa. Hence, left-shift 16 spaces.
164
153
*/
165
154
out -> shift = (31 - 6 - 10 );
166
- out -> readings [0 ].value = (int32_t )raw_press_signed ;
155
+ out -> readings [* fit ].value = (int32_t )raw_press_signed ;
167
156
break ;
157
+ }
168
158
default :
169
159
return - EINVAL ;
170
160
}
171
161
172
- * fit = 1 ;
173
- return 1 ;
162
+ * fit = (* fit ) + 1 ;
163
+ return 0 ;
164
+ }
165
+
166
+ static int bmp581_decoder_decode (const uint8_t * buffer ,
167
+ struct sensor_chan_spec chan_spec ,
168
+ uint32_t * fit ,
169
+ uint16_t max_count ,
170
+ void * data_out )
171
+ {
172
+ const struct bmp581_encoded_data * edata = (const struct bmp581_encoded_data * )buffer ;
173
+ uint8_t channel_request ;
174
+
175
+ if (max_count == 0 || chan_spec .chan_idx != 0 ) {
176
+ return - EINVAL ;
177
+ }
178
+
179
+ channel_request = bmp581_encode_channel (chan_spec .chan_type );
180
+ if ((channel_request & edata -> header .channels ) != channel_request ) {
181
+ return - ENODATA ;
182
+ }
183
+
184
+ struct sensor_q31_data * out = data_out ;
185
+
186
+ out -> header .base_timestamp_ns = edata -> header .timestamp ;
187
+
188
+ int err ;
189
+ uint32_t fit_0 = * fit ;
190
+
191
+ do {
192
+ err = bmp581_convert_raw_to_q31_value (& edata -> header , & chan_spec ,
193
+ edata -> frame , fit , out );
194
+ } while ((err == 0 ) && (* fit < max_count ));
195
+
196
+ if (* fit == fit_0 || err != 0 ) {
197
+ return err ;
198
+ }
199
+
200
+ out -> header .reading_count = * fit ;
201
+ return * fit - fit_0 ;
174
202
}
175
203
176
204
static bool bmp581_decoder_has_trigger (const uint8_t * buffer , enum sensor_trigger_type trigger )
177
205
{
178
206
const struct bmp581_encoded_data * edata = (const struct bmp581_encoded_data * )buffer ;
179
207
180
- if ((trigger == SENSOR_TRIG_DATA_READY ) && (edata -> header .events != 0 )) {
208
+ if (((trigger == SENSOR_TRIG_DATA_READY ) &&
209
+ (edata -> header .events & BMP581_EVENT_DRDY )) ||
210
+ ((trigger == SENSOR_TRIG_FIFO_WATERMARK ) &&
211
+ (edata -> header .events & BMP581_EVENT_FIFO_WM ))) {
181
212
return true;
182
213
}
183
214
0 commit comments