if (period_gyro <= period_accel)
period = period_gyro; else
period = period_accel;
st->fifo.period = period;
}
int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st, unsignedint fifo_en)
{ unsignedint mask, val; int ret;
/* update only FIFO EN bits */
mask = INV_ICM42600_FIFO_CONFIG1_TMST_FSYNC_EN |
INV_ICM42600_FIFO_CONFIG1_TEMP_EN |
INV_ICM42600_FIFO_CONFIG1_GYRO_EN |
INV_ICM42600_FIFO_CONFIG1_ACCEL_EN;
val = 0; if (fifo_en & INV_ICM42600_SENSOR_GYRO)
val |= INV_ICM42600_FIFO_CONFIG1_GYRO_EN; if (fifo_en & INV_ICM42600_SENSOR_ACCEL)
val |= INV_ICM42600_FIFO_CONFIG1_ACCEL_EN; if (fifo_en & INV_ICM42600_SENSOR_TEMP)
val |= INV_ICM42600_FIFO_CONFIG1_TEMP_EN;
ret = regmap_update_bits(st->map, INV_ICM42600_REG_FIFO_CONFIG1, mask, val); if (ret) return ret;
/* exit if FIFO is already on */ if (st->fifo.on) {
ret = 0; goto out_on;
}
/* set FIFO threshold interrupt */
ret = regmap_set_bits(st->map, INV_ICM42600_REG_INT_SOURCE0,
INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN); if (ret) goto out_unlock;
/* flush FIFO data */
ret = regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET,
INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH); if (ret) goto out_unlock;
/* set FIFO in streaming mode */
ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG,
INV_ICM42600_FIFO_CONFIG_STREAM); if (ret) goto out_unlock;
/* workaround: first read of FIFO count after reset is always 0 */
ret = regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, st->buffer, 2); if (ret) goto out_unlock;
/* exit if there are several sensors using the FIFO */ if (st->fifo.on > 1) {
ret = 0; goto out_off;
}
/* set FIFO in bypass mode */
ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG,
INV_ICM42600_FIFO_CONFIG_BYPASS); if (ret) goto out_unlock;
/* flush FIFO data */
ret = regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET,
INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH); if (ret) goto out_unlock;
/* disable FIFO threshold interrupt */
ret = regmap_clear_bits(st->map, INV_ICM42600_REG_INT_SOURCE0,
INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN); if (ret) goto out_unlock;
/* compute maximum FIFO read size */ if (max == 0)
max_count = sizeof(st->fifo.data); else
max_count = max * inv_icm42600_get_packet_size(st->fifo.en);
/* read FIFO count value */
raw_fifo_count = (__be16 *)st->buffer;
ret = regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT,
raw_fifo_count, sizeof(*raw_fifo_count)); if (ret) return ret;
st->fifo.count = be16_to_cpup(raw_fifo_count);
/* check and clamp FIFO count value */ if (st->fifo.count == 0) return0; if (st->fifo.count > max_count)
st->fifo.count = max_count;
/* read all FIFO data in internal buffer */
ret = regmap_noinc_read(st->map, INV_ICM42600_REG_FIFO_DATA,
st->fifo.data, st->fifo.count); if (ret) return ret;
/* compute number of samples for each sensor */ for (i = 0; i < st->fifo.count; i += size) {
size = inv_icm42600_fifo_decode_packet(&st->fifo.data[i],
&accel, &gyro, &temp, ×tamp, &odr); if (size <= 0) break; if (gyro != NULL && inv_icm42600_fifo_is_data_valid(gyro))
st->fifo.nb.gyro++; if (accel != NULL && inv_icm42600_fifo_is_data_valid(accel))
st->fifo.nb.accel++;
st->fifo.nb.total++;
}
return0;
}
int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st)
{ struct inv_icm42600_sensor_state *gyro_st = iio_priv(st->indio_gyro); struct inv_icm42600_sensor_state *accel_st = iio_priv(st->indio_accel); struct inv_sensors_timestamp *ts; int ret;
if (st->fifo.nb.total == 0) return0;
/* handle gyroscope timestamp and FIFO data parsing */ if (st->fifo.nb.gyro > 0) {
ts = &gyro_st->ts;
inv_sensors_timestamp_interrupt(ts, st->fifo.watermark.eff_gyro,
st->timestamp.gyro);
ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro); if (ret) return ret;
}
/* handle accelerometer timestamp and FIFO data parsing */ if (st->fifo.nb.accel > 0) {
ts = &accel_st->ts;
inv_sensors_timestamp_interrupt(ts, st->fifo.watermark.eff_accel,
st->timestamp.accel);
ret = inv_icm42600_accel_parse_fifo(st->indio_accel); if (ret) return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.