xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/algos/aeis/imu_service.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * imu_service.h - interfaces for EIS algorithm to access imu sensor
3  *
4  *  Copyright (c) 2021 Rockchip Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Author: Cody Xie <cody.xie@rock-chips.com>
19  */
20 #ifndef ALGOS_AEIS_IMU_SERVICE_H
21 #define ALGOS_AEIS_IMU_SERVICE_H
22 
23 #include <memory>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 #include "rk_aiq_mems_sensor.h"
29 #include "task_service.h"
30 #include "xcam_common.h"
31 
32 using namespace XCam;
33 
34 namespace RkCam {
35 
36 class EisImuAdaptor;
37 
38 class EisImuData {
39  public:
40     EisImuData() = delete;
41     explicit EisImuData(std::shared_ptr<EisImuAdaptor> imu, mems_sensor_type_t type,
42                         mems_sensor_event_t* data, size_t count);
43     EisImuData(const EisImuData&) = delete;
44     const EisImuData& operator=(const EisImuData&) = delete;
45     ~EisImuData();
46 
47     mems_sensor_type_t GetType() const;
48     mems_sensor_event_t* GetData() const;
49     size_t GetCount() const;
50 
51  private:
52     const std::shared_ptr<EisImuAdaptor> imu_;
53     const mems_sensor_type_t type_;
54     mems_sensor_event_t* data_;
55     const size_t count_;
56 };
57 
58 class EisImuAdaptor : std::enable_shared_from_this<EisImuAdaptor> {
59  public:
60     EisImuAdaptor() = delete;
61     explicit EisImuAdaptor(const rk_aiq_mems_sensor_intf_t intf,
62                            const mems_sensor_type_t type = SENSOR_ALL_TYPE);
63     EisImuAdaptor(const EisImuAdaptor&) = delete;
64     const EisImuAdaptor& operator=(const EisImuAdaptor&) = delete;
65     ~EisImuAdaptor();
66 
GetType()67     mems_sensor_type_t GetType() const { return type_; };
GetPtr()68     std::shared_ptr<EisImuAdaptor> GetPtr() { return shared_from_this(); }
69 
70     mems_sensor_event_t* GetData(size_t* num_sample);
71     void FreeData(mems_sensor_event_t* data);
72 
73     XCamReturn Init(float sample_rate);
74 
75  private:
76     XCamReturn DeInit();
77 
78     const rk_aiq_mems_sensor_intf_t intf_;
79     const mems_sensor_type_t type_;
80     std::string key_;
81     mems_sensor_ctx_t ctx_;
82     mems_sensor_handle_t handle_;
83     std::vector<std::pair<size_t, mems_sensor_event_t*>> datas_;
84 };
85 
86 struct imu_param {
87     uint32_t frame_id;
88     TaskTimePoint time_point;
89     std::unique_ptr<EisImuData> data;
90 };
91 
92 class ImuTask final : public ServiceTask<imu_param> {
93  public:
94     ImuTask() = delete;
ImuTask(std::shared_ptr<EisImuAdaptor> imu)95     explicit ImuTask(std::shared_ptr<EisImuAdaptor> imu) : imu_(imu) {}
96     ImuTask(const ImuTask&) = delete;
97     const ImuTask& operator=(const ImuTask&) = delete;
98     ~ImuTask()                               = default;
99 
100     TaskResult operator()(ServiceParam<imu_param>& p);
101 
102  private:
103     std::shared_ptr<EisImuAdaptor> imu_;
104 };
105 
106 using ImuService = TaskService<imu_param>;
107 
108 }  // namespace RkCam
109 
110 #endif  // ALGOS_AEIS_IMU_SERVICE_H
111