xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkisp_demo/demo/sample/sample_agic_module.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (c) 2022 Rockchip Eletronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "sample_agic_module.h"
17 
18 #include "sample_comm.h"
19 #include "uAPI2/rk_aiq_user_api2_agic.h"
20 
sample_agic_usage()21 static void sample_agic_usage() {
22     printf("Usage : \n");
23     printf("  Module API: \n");
24     printf("\t a) GIC:         Set gic Attr & Sync .\n");
25     printf("\t b) GIC:         Set gic Attr & Async .\n");
26     printf("\n");
27     printf("\t h) GIC:         help.\n");
28     printf("\t q) GIC:         return to main sample screen.\n");
29 
30     printf("\n");
31     printf("\t please press the key: ");
32 
33     return;
34 }
35 
sample_print_agic_info(const void * arg)36 void sample_print_agic_info(const void* arg) { printf("enter GIC modult test!\n"); }
37 
38 /*
39 ******************************
40 *
41 * Module level API Sample Func
42 *
43 ******************************
44 */
45 
sample_gic_setgicAttr(const rk_aiq_sys_ctx_t * ctx,rk_aiq_uapi_mode_sync_e sync)46 static int sample_gic_setgicAttr(const rk_aiq_sys_ctx_t* ctx, rk_aiq_uapi_mode_sync_e sync) {
47     XCamReturn ret = XCAM_RETURN_NO_ERROR;
48     rkaiq_gic_v2_api_attr_t attr;
49 
50     memset(&attr, 0, sizeof(rkaiq_gic_v2_api_attr_t));
51     ret = rk_aiq_user_api2_agic_v2_GetAttrib(ctx, &attr);
52     RKAIQ_SAMPLE_CHECK_RET(ret, "setgicAttr failed in getting agic attrib!");
53 
54     memcpy(&attr.manual_param, &attr.auto_params[0], sizeof(rkaiq_gic_v2_param_selected_t));
55     attr.sync.sync_mode = sync;
56     attr.op_mode        = RKAIQ_GIC_API_OPMODE_MANUAL;
57     attr.gic_en         = 0;
58     attr.manual_param.globalStrength = 0.5;
59 
60     ret = rk_aiq_user_api2_agic_v2_SetAttrib(ctx, &attr);
61     RKAIQ_SAMPLE_CHECK_RET(ret, "set GIC Attr failed!");
62     printf("set GIC Attr\n\n");
63 
64     return 0;
65 }
66 
sample_gic_getgicAttr(const rk_aiq_sys_ctx_t * ctx)67 static int sample_gic_getgicAttr(const rk_aiq_sys_ctx_t* ctx) {
68     XCamReturn ret = XCAM_RETURN_NO_ERROR;
69     rkaiq_gic_v2_api_attr_t attr;
70 
71     memset(&attr, 0, sizeof(rkaiq_gic_v2_api_attr_t));
72     ret = rk_aiq_user_api2_agic_v2_GetAttrib(ctx, &attr);
73     RKAIQ_SAMPLE_CHECK_RET(ret, "get gic Attr failed!");
74     printf("get GIC Attr:\n\n");
75     printf("\t sync = %d, done = %d\n", attr.sync.sync_mode, attr.sync.done);
76     printf("\t Mode = %s\n",
77            (attr.op_mode == RKAIQ_GIC_API_OPMODE_AUTO
78                 ? "auto"
79                 : ((attr.op_mode == RKAIQ_GIC_API_OPMODE_MANUAL) ? "manual" : "off")));
80     printf("\t globalStrength = %f\n", attr.manual_param.globalStrength);
81 
82     return 0;
83 }
84 
sample_agic_module(const void * arg)85 XCamReturn sample_agic_module(const void* arg) {
86     int key = -1;
87     CLEAR();
88 
89     const demo_context_t* demo_ctx = (demo_context_t*)arg;
90     const rk_aiq_sys_ctx_t* ctx;
91     if (demo_ctx->camGroup) {
92         ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->camgroup_ctx);
93     } else {
94         ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->aiq_ctx);
95     }
96 
97     if (ctx == NULL) {
98         ERR("%s, ctx is nullptr\n", __FUNCTION__);
99         return XCAM_RETURN_ERROR_PARAM;
100     }
101 
102     sample_agic_usage();
103 
104     do {
105         key = getchar();
106         while (key == '\n' || key == '\r') key = getchar();
107         printf("\n");
108 
109         switch (key) {
110             case 'h':
111                 sample_agic_usage();
112                 CLEAR();
113                 break;
114             case 'a':
115                 sample_gic_setgicAttr(ctx, RK_AIQ_UAPI_MODE_DEFAULT);
116                 sample_gic_getgicAttr(ctx);
117                 break;
118             case 'b':
119                 sample_gic_setgicAttr(ctx, RK_AIQ_UAPI_MODE_ASYNC);
120                 sample_gic_getgicAttr(ctx);
121                 usleep(40 * 1000);
122                 sample_gic_getgicAttr(ctx);
123                 break;
124             default:
125                 CLEAR();
126                 sample_agic_usage();
127                 break;
128         }
129     } while (key != 'q' && key != 'Q');
130 
131     return XCAM_RETURN_NO_ERROR;
132 }
133