158d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol/*
258d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * Copyright (C) 2016 The Android Open Source Project
358d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol *
458d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * Licensed under the Apache License, Version 2.0 (the "License");
558d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * you may not use this file except in compliance with the License.
658d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * You may obtain a copy of the License at
758d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol *
858d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol *      http://www.apache.org/licenses/LICENSE-2.0
958d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol *
1058d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * Unless required by applicable law or agreed to in writing, software
1158d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * distributed under the License is distributed on an "AS IS" BASIS,
1258d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1358d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * See the License for the specific language governing permissions and
1458d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * limitations under the License.
1558d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol */
1658d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol
170d94eb2fcf599754d9a1087c3292ab6ac6495de6Andrew Rossignol#ifndef CHRE_PLATFORM_SLPI_PLATFORM_SENSOR_UTIL_H_
180d94eb2fcf599754d9a1087c3292ab6ac6495de6Andrew Rossignol#define CHRE_PLATFORM_SLPI_PLATFORM_SENSOR_UTIL_H_
1958d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol
2058d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol#include <cstdint>
2158d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol
2258d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol#include "chre/util/time.h"
2358d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol
2458d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignolnamespace chre {
2558d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol
2658d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol/**
2758d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * Converts an interval in nanoseconds to an SMGR report rate. SMGR overloads
2858d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * the value of a uint16_t to have an inversion point at which the value is no
2958d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * longer a sample rate and becomes an interval for sub-zero sampling rates.
3058d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * This function handles that conversion.
3158d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol *
3258d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * @param interval The sampling interval to convert to a report rate.
3358d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol * @return Returns the SMGR report rate for this interval.
3458d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol */
353e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chunguint16_t intervalToSmgrSamplingRate(Nanoseconds interval);
363e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chung
373e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chung/**
383e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chung * Converts an interval in nanoseconds to an SMGR report rate in Hz and Q16
393e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chung * format.
403e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chung *
413e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chung * @param interval The interval to convert to a report rate.
423e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chung * @return Returns the SMGR uint32_t report rate for this interval.
433e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chung */
443e1892c28b41fd0b76ea86b10d00c6ef669f9354Meng-hsuan Chunguint32_t intervalToSmgrQ16ReportRate(Nanoseconds interval);
4558d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol
4658d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol}  // namespace chre
4758d03812b7cce3a90c39cd30bbff6531cc3e6e30Andrew Rossignol
480d94eb2fcf599754d9a1087c3292ab6ac6495de6Andrew Rossignol#endif  // CHRE_PLATFORM_SLPI_PLATFORM_SENSOR_UTIL_H_
49