- /* Check if we have contraints on allowed sampling rates */
-
- sprintf(avail_sysfs_path, DEVICE_AVAIL_FREQ_PATH, dev_num);
-
- if (sysfs_read_str(avail_sysfs_path, freqs_buf, sizeof(freqs_buf)) > 0) {
- cursor = freqs_buf;
-
- /* Decode allowed sampling rates string, ex: "10 20 50 100" */
-
- /* While we're not at the end of the string */
- while (*cursor && cursor[0]) {
-
- /* Decode a single value */
- sr = strtod(cursor, NULL);
-
- /* If this matches the selected rate, we're happy. Have some tolerance for rounding errors and avoid needless jumps to higher rates */
- if (fabs(arb_sampling_rate - sr) <= 0.001) {
- arb_sampling_rate = sr;
- break;
- }
-
- /*
- * If we reached a higher value than the desired rate, adjust selected rate so it matches the first higher available one and
- * stop parsing - this makes the assumption that rates are sorted by increasing value in the allowed frequencies string.
- */
- if (sr > arb_sampling_rate) {
- arb_sampling_rate = sr;
- break;
- }
-
- /* Skip digits */
- while (cursor[0] && !isspace(cursor[0]))
- cursor++;
-
- /* Skip spaces */
- while (cursor[0] && isspace(cursor[0]))
- cursor++;
- }
- }
-
- if (sensor[s].max_supported_rate &&
- arb_sampling_rate > sensor[s].max_supported_rate) {
- arb_sampling_rate = sensor[s].max_supported_rate;
+ if (sensor[s].hrtimer_trigger_name[0] != '\0') {
+ snprintf(trigger_path, PATH_MAX, "%s%s%d/", IIO_DEVICES, "trigger", sensor[s].trigger_nr);
+ snprintf(hrtimer_sampling_path, PATH_MAX, "%s%s", trigger_path, "sampling_frequency");
+ /* Enforce frequency update when software trigger
+ * frequency and current sampling rate are different */
+ if (sysfs_read_float(hrtimer_sampling_path, &sr) != -1 && sr != cur_sampling_rate)
+ cur_sampling_rate = -1;
+ } else {
+ arb_sampling_rate = select_closest_available_rate(s, arb_sampling_rate);