Lines Matching +full:in +full:- +full:min
3 * SPDX-License-Identifier: Apache-2.0
23 * The linear range API maps values in a linear range to a range index. A linear
26 * - Minimum value
27 * - Step value
28 * - Minimum index value
29 * - Maximum index value
31 * For example, in a voltage regulator, supported voltages typically map to a
34 * - 1000uV: 0x00
35 * - 1250uV: 0x01
36 * - 1500uV: 0x02
37 * - ...
38 * - 3000uV: 0x08
40 * In this case, we have:
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,
63 int32_t min; member
75 * @param _min Minimum value in range.
82 .min = (_min), \
89 * @brief Obtain the number of values representable in a linear range.
91 * @param[in] r Linear range instance.
97 return r->max_idx - r->min_idx + 1U; in linear_range_values_count()
103 * @param[in] r Array of linear range instances.
123 * @param[in] r Linear range instance.
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.
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()
155 * @brief Obtain value in a group given a linear range index.
157 * @param[in] r Array of linear range instances.
163 * @retval -EINVAL If index is out of range.
169 int ret = -EINVAL; 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.
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()
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()
217 * @brief Obtain index in a group given a value.
220 * all ranges in the group.
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).
237 (i < (r_cnt - 1U))) { 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
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()
299 * @brief Obtain index in a group given a value that must be within a window of
303 * considering all ranges in the group.
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
332 return -EINVAL; in linear_range_group_get_win_index()