@@ -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,40 @@ 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
+ return - ENODATA ;
121
+ } else if (((header -> events & BMP581_EVENT_FIFO_WM ) == 0 ) && (* fit != 0 )) {
127
122
return - ENODATA ;
123
+ } else {
124
+ /* Empty for completeness */
128
125
}
129
126
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 ) {
127
+ switch (chan_spec -> chan_type ) {
136
128
case SENSOR_CHAN_AMBIENT_TEMP : {
137
129
/* 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 ];
130
+ uint32_t raw_temp = ((uint32_t )frame [ * fit ]. payload [2 ] << 16 ) |
131
+ ((uint16_t )frame [ * fit ]. payload [1 ] << 8 ) |
132
+ frame [ * fit ]. payload [0 ];
141
133
int32_t raw_temp_signed = sign_extend (raw_temp , 23 );
142
134
143
135
out -> shift = (31 - 16 ); /* 16 left shifts gives us the value in celsius */
144
- out -> readings [0 ].value = raw_temp_signed ;
136
+ out -> readings [* fit ].value = raw_temp_signed ;
145
137
break ;
146
138
}
147
- case SENSOR_CHAN_PRESS :
148
- if (!edata -> header . press_en ) {
139
+ case SENSOR_CHAN_PRESS : {
140
+ if (!header -> press_en ) {
149
141
return - ENODATA ;
150
142
}
151
143
/* 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 ]);
144
+ uint64_t raw_press = (((uint32_t )frame [ * fit ]. payload [5 ] << 16 ) |
145
+ ((uint16_t )frame [ * fit ]. payload [4 ] << 8 ) |
146
+ frame [ * fit ]. payload [3 ]);
155
147
156
148
int64_t raw_press_signed = sign_extend_64 (raw_press , 23 );
157
149
@@ -163,21 +155,65 @@ static int bmp581_decoder_decode(const uint8_t *buffer,
163
155
* converting to kPa. Hence, left-shift 16 spaces.
164
156
*/
165
157
out -> shift = (31 - 6 - 10 );
166
- out -> readings [0 ].value = (int32_t )raw_press_signed ;
158
+ out -> readings [* fit ].value = (int32_t )raw_press_signed ;
167
159
break ;
160
+ }
168
161
default :
169
162
return - EINVAL ;
170
163
}
171
164
172
- * fit = 1 ;
173
- return 1 ;
165
+ * fit = (* fit ) + 1 ;
166
+ return 0 ;
167
+ }
168
+
169
+ static int bmp581_decoder_decode (const uint8_t * buffer ,
170
+ struct sensor_chan_spec chan_spec ,
171
+ uint32_t * fit ,
172
+ uint16_t max_count ,
173
+ void * data_out )
174
+ {
175
+ const struct bmp581_encoded_data * edata = (const struct bmp581_encoded_data * )buffer ;
176
+ uint8_t channel_request ;
177
+
178
+ if (max_count == 0 || chan_spec .chan_idx != 0 ) {
179
+ return - EINVAL ;
180
+ }
181
+
182
+ channel_request = bmp581_encode_channel (chan_spec .chan_type );
183
+ if ((channel_request & edata -> header .channels ) != channel_request ) {
184
+ return - ENODATA ;
185
+ }
186
+
187
+ struct sensor_q31_data * out = data_out ;
188
+
189
+ out -> header .base_timestamp_ns = edata -> header .timestamp ;
190
+ out -> header .reading_count = 1 ;
191
+
192
+ int err ;
193
+ uint32_t fit_0 = * fit ;
194
+
195
+ do {
196
+ err = bmp581_convert_raw_to_q31_value (& edata -> header , & chan_spec ,
197
+ edata -> frame , fit , out );
198
+ } while ((err == 0 ) && (* fit < max_count ));
199
+
200
+ if (* fit == fit_0 || err != 0 ) {
201
+ return err ;
202
+ }
203
+
204
+ out -> header .reading_count = * fit ;
205
+ return * fit - fit_0 ;
174
206
}
175
207
176
208
static bool bmp581_decoder_has_trigger (const uint8_t * buffer , enum sensor_trigger_type trigger )
177
209
{
178
210
const struct bmp581_encoded_data * edata = (const struct bmp581_encoded_data * )buffer ;
179
211
180
- if ((trigger == SENSOR_TRIG_DATA_READY ) && (edata -> header .events != 0 )) {
212
+ if (((trigger == SENSOR_TRIG_DATA_READY ) &&
213
+ (edata -> header .events & BMP581_EVENT_DRDY )) ||
214
+ ((trigger == SENSOR_TRIG_FIFO_WATERMARK ) &&
215
+ (edata -> header .events & BMP581_EVENT_FIFO_WM ))) {
216
+ return true;
181
217
return true;
182
218
}
183
219
0 commit comments