Lines Matching +full:- +full:r
3 * SPDX-License-Identifier: Apache-2.0
26 * - Minimum value
27 * - Step value
28 * - Minimum index value
29 * - Maximum index value
34 * - 1000uV: 0x00
35 * - 1250uV: 0x01
36 * - 1500uV: 0x02
37 * - ...
38 * - 3000uV: 0x08
42 * - Minimum value: 1000uV
43 * - Step value: 250uV
44 * - Minimum index value: 0x00
45 * - Maximum index value: 0x08
53 * Implementation uses fixed-width integers. Range is limited to [INT32_MIN,
91 * @param[in] r Linear range instance.
93 * @return Number of ranges representable by @p r.
95 static inline uint32_t linear_range_values_count(const struct linear_range *r) in linear_range_values_count() argument
97 return r->max_idx - r->min_idx + 1U; in linear_range_values_count()
103 * @param[in] r Array of linear range instances.
106 * @return Number of ranges representable by the @p r group.
109 const struct linear_range *r, size_t r_cnt) in linear_range_group_values_count() argument
114 values += linear_range_values_count(&r[i]); in linear_range_group_values_count()
123 * @param[in] r Linear range instance.
125 * @return Maximum value representable by @p r.
127 static inline int32_t linear_range_get_max_value(const struct linear_range *r) in linear_range_get_max_value() argument
129 return r->min + (int32_t)(r->step * (r->max_idx - r->min_idx)); in linear_range_get_max_value()
135 * @param[in] r Linear range instance.
140 * @retval -EINVAL If index is out of range.
142 static inline int linear_range_get_value(const struct linear_range *r, in linear_range_get_value() argument
145 if ((idx < r->min_idx) || (idx > r->max_idx)) { in linear_range_get_value()
146 return -EINVAL; in linear_range_get_value()
149 *val = r->min + (int32_t)(r->step * (idx - r->min_idx)); in linear_range_get_value()
157 * @param[in] r Array of linear range instances.
163 * @retval -EINVAL If index is out of range.
165 static inline int linear_range_group_get_value(const struct linear_range *r, in linear_range_group_get_value() argument
169 int ret = -EINVAL; in linear_range_group_get_value()
172 ret = linear_range_get_value(&r[i], idx, val); in linear_range_group_get_value()
182 * -ERANGE returned. That is, if the value falls below or above the range, the
186 * @param[in] r Linear range instance.
191 * @retval -ERANGE If the value falls out of the range.
193 static inline int linear_range_get_index(const struct linear_range *r, in linear_range_get_index() argument
196 if (val < r->min) { in linear_range_get_index()
197 *idx = r->min_idx; in linear_range_get_index()
198 return -ERANGE; in linear_range_get_index()
201 if (val > linear_range_get_max_value(r)) { in linear_range_get_index()
202 *idx = r->max_idx; in linear_range_get_index()
203 return -ERANGE; in linear_range_get_index()
206 if (r->step == 0U) { in linear_range_get_index()
207 *idx = r->min_idx; in linear_range_get_index()
209 *idx = r->min_idx + DIV_ROUND_UP((uint32_t)(val - r->min), in linear_range_get_index()
210 r->step); in linear_range_get_index()
222 * @param[in] r Linear range instances.
228 * @retval -ERANGE If the value falls out of the range group.
229 * @retval -EINVAL If input is not valid (i.e. zero groups).
231 static inline int linear_range_group_get_index(const struct linear_range *r, in linear_range_group_get_index() argument
236 if ((val > linear_range_get_max_value(&r[i])) && in linear_range_group_get_index()
237 (i < (r_cnt - 1U))) { in linear_range_group_get_index()
241 return linear_range_get_index(&r[i], val, idx); in linear_range_group_get_index()
244 return -EINVAL; in linear_range_group_get_index()
250 * If the window of values does not intersect with the range, -EINVAL will be
252 * intersect), the nearest index will be stored and -ERANGE returned.
254 * @param[in] r Linear range instance.
260 * @retval -ERANGE If the given window of values falls partially out of the
262 * @retval -EINVAL If the given window of values does not intersect with the
265 static inline int linear_range_get_win_index(const struct linear_range *r, in linear_range_get_win_index() argument
269 int32_t r_max = linear_range_get_max_value(r); in linear_range_get_win_index()
271 if ((val_max < r->min) || (val_min > r_max)) { in linear_range_get_win_index()
272 return -EINVAL; in linear_range_get_win_index()
275 if (val_min < r->min) { in linear_range_get_win_index()
276 *idx = r->min_idx; in linear_range_get_win_index()
277 return -ERANGE; in linear_range_get_win_index()
281 *idx = r->max_idx; in linear_range_get_win_index()
282 return -ERANGE; in linear_range_get_win_index()
285 if (r->step == 0U) { in linear_range_get_win_index()
286 *idx = r->min_idx; in linear_range_get_win_index()
290 *idx = r->min_idx + DIV_ROUND_UP((uint32_t)(val_min - r->min), r->step); in linear_range_get_win_index()
291 if ((r->min + r->step * (*idx - r->min_idx)) > val_max) { in linear_range_get_win_index()
292 return -EINVAL; in linear_range_get_win_index()
305 * @param[in] r Linear range instances.
312 * @retval -ERANGE If the given window of values falls partially out of the
314 * @retval -EINVAL If the given window of values does not intersect with the
318 static inline int linear_range_group_get_win_index(const struct linear_range *r, in linear_range_group_get_win_index() argument
325 if (val_min > linear_range_get_max_value(&r[i])) { in linear_range_group_get_win_index()
329 return linear_range_get_win_index(&r[i], val_min, val_max, idx); in linear_range_group_get_win_index()
332 return -EINVAL; in linear_range_group_get_win_index()