1beacf11bSopenharmony_ci/* ----------------------------------------------------------------------------
2beacf11bSopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
3beacf11bSopenharmony_ci * Description: LiteOS USB Driver Hicamera Control
4beacf11bSopenharmony_ci * Author: huangjieliang
5beacf11bSopenharmony_ci * Create: 2017-11-25
6beacf11bSopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
7beacf11bSopenharmony_ci * are permitted provided that the following conditions are met:
8beacf11bSopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
9beacf11bSopenharmony_ci * conditions and the following disclaimer.
10beacf11bSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11beacf11bSopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials
12beacf11bSopenharmony_ci * provided with the distribution.
13beacf11bSopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14beacf11bSopenharmony_ci * to endorse or promote products derived from this software without specific prior written
15beacf11bSopenharmony_ci * permission.
16beacf11bSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17beacf11bSopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18beacf11bSopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19beacf11bSopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20beacf11bSopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21beacf11bSopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22beacf11bSopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23beacf11bSopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24beacf11bSopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25beacf11bSopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26beacf11bSopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27beacf11bSopenharmony_ci * --------------------------------------------------------------------------- */
28beacf11bSopenharmony_ci/* ----------------------------------------------------------------------------
29beacf11bSopenharmony_ci * Notice of Export Control Law
30beacf11bSopenharmony_ci * ===============================================
31beacf11bSopenharmony_ci * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
32beacf11bSopenharmony_ci * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
33beacf11bSopenharmony_ci * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
34beacf11bSopenharmony_ci * applicable export control laws and regulations.
35beacf11bSopenharmony_ci * --------------------------------------------------------------------------- */
36beacf11bSopenharmony_ci
37beacf11bSopenharmony_ci#include "implementation/global_implementation.h"
38beacf11bSopenharmony_ci#include "hicamera_control.h"
39beacf11bSopenharmony_ci#include "gadget/f_uvc.h"
40beacf11bSopenharmony_ci
41beacf11bSopenharmony_ci#ifdef __cplusplus
42beacf11bSopenharmony_ci#if __cplusplus
43beacf11bSopenharmony_ciextern "C" {
44beacf11bSopenharmony_ci#endif /* __cplusplus */
45beacf11bSopenharmony_ci#endif /* __cplusplus */
46beacf11bSopenharmony_ci
47beacf11bSopenharmony_ci#define UVC_UNIT_MAP_SIZE 4
48beacf11bSopenharmony_cistatic struct uvc_camera_cmd g_cmd_map[CMD_MAX_NUM] = {0};
49beacf11bSopenharmony_cistatic bool g_uvc_unit_is_register = false;
50beacf11bSopenharmony_cistatic struct uvc_camera_cmd g_uvc_unit_mappings[UVC_UNIT_MAP_SIZE];
51beacf11bSopenharmony_ciDEFINE_SPINLOCK(g_cmd_spinlock);
52beacf11bSopenharmony_ci
53beacf11bSopenharmony_cistatic int cmd_check(struct uvc_camera_cmd *cmd)
54beacf11bSopenharmony_ci{
55beacf11bSopenharmony_ci  if (cmd->id >= CMD_MAX_NUM)
56beacf11bSopenharmony_ci    {
57beacf11bSopenharmony_ci      usb_err("the cmd id is too big, make sure it less than %d\n", CMD_MAX_NUM);
58beacf11bSopenharmony_ci      return -1;
59beacf11bSopenharmony_ci    }
60beacf11bSopenharmony_ci
61beacf11bSopenharmony_ci  return 0;
62beacf11bSopenharmony_ci}
63beacf11bSopenharmony_ci
64beacf11bSopenharmony_civoid uvc_unit_control_register(void)
65beacf11bSopenharmony_ci{
66beacf11bSopenharmony_ci  int ret;
67beacf11bSopenharmony_ci  uint32_t i;
68beacf11bSopenharmony_ci
69beacf11bSopenharmony_ci  if (g_uvc_unit_is_register == false)
70beacf11bSopenharmony_ci    {
71beacf11bSopenharmony_ci      hi_camera_cmd_init();
72beacf11bSopenharmony_ci
73beacf11bSopenharmony_ci      for (i = 0; i < sizeof(g_uvc_unit_mappings) / sizeof(g_uvc_unit_mappings[0]); i++)
74beacf11bSopenharmony_ci        {
75beacf11bSopenharmony_ci          ret = hi_camera_register_cmd(&g_uvc_unit_mappings[i]);
76beacf11bSopenharmony_ci          if (ret < 0)
77beacf11bSopenharmony_ci            {
78beacf11bSopenharmony_ci              usb_err("register cmd failed\n");
79beacf11bSopenharmony_ci            }
80beacf11bSopenharmony_ci        }
81beacf11bSopenharmony_ci    }
82beacf11bSopenharmony_ci}
83beacf11bSopenharmony_ci
84beacf11bSopenharmony_ciint run_cmd_func(void *buf, uint32_t len, uint32_t event_id, uint32_t cmdtype, uint32_t cmd_id)
85beacf11bSopenharmony_ci{
86beacf11bSopenharmony_ci  struct uvc_camera_cmd *cmd_cb;
87beacf11bSopenharmony_ci  uint32_t flags;
88beacf11bSopenharmony_ci  int ret;
89beacf11bSopenharmony_ci
90beacf11bSopenharmony_ci  if (cmd_id >= CMD_MAX_NUM)
91beacf11bSopenharmony_ci    {
92beacf11bSopenharmony_ci      return -1;
93beacf11bSopenharmony_ci    }
94beacf11bSopenharmony_ci
95beacf11bSopenharmony_ci  spin_lock_irqsave(&g_cmd_spinlock, flags);
96beacf11bSopenharmony_ci  cmd_cb = &g_cmd_map[cmd_id];
97beacf11bSopenharmony_ci
98beacf11bSopenharmony_ci  ret = cmd_check(cmd_cb);
99beacf11bSopenharmony_ci  if (ret < 0)
100beacf11bSopenharmony_ci    {
101beacf11bSopenharmony_ci      spin_unlock_irqrestore(&g_cmd_spinlock, flags);
102beacf11bSopenharmony_ci      usb_err("cmd check is invalid\n");
103beacf11bSopenharmony_ci      return -1;
104beacf11bSopenharmony_ci    }
105beacf11bSopenharmony_ci
106beacf11bSopenharmony_ci  if (cmd_cb->uvc_control_func != NULL)
107beacf11bSopenharmony_ci    {
108beacf11bSopenharmony_ci      ret = (int)cmd_cb->uvc_control_func(buf, len, event_id, cmdtype);
109beacf11bSopenharmony_ci    }
110beacf11bSopenharmony_ci  spin_unlock_irqrestore(&g_cmd_spinlock, flags);
111beacf11bSopenharmony_ci
112beacf11bSopenharmony_ci  return ret;
113beacf11bSopenharmony_ci}
114beacf11bSopenharmony_ci
115beacf11bSopenharmony_civoid hi_camera_cmd_init(void)
116beacf11bSopenharmony_ci{
117beacf11bSopenharmony_ci  uint32_t flags;
118beacf11bSopenharmony_ci
119beacf11bSopenharmony_ci  spin_lock_irqsave(&g_cmd_spinlock, flags);
120beacf11bSopenharmony_ci  (void)memset_s(g_cmd_map, (CMD_MAX_NUM * sizeof(struct uvc_camera_cmd)),
121beacf11bSopenharmony_ci                 0, (CMD_MAX_NUM * sizeof(struct uvc_camera_cmd)));
122beacf11bSopenharmony_ci  g_uvc_unit_is_register = false;
123beacf11bSopenharmony_ci  spin_unlock_irqrestore(&g_cmd_spinlock, flags);
124beacf11bSopenharmony_ci}
125beacf11bSopenharmony_ci
126beacf11bSopenharmony_cistatic void new_cmd_add(struct uvc_camera_cmd *cmd)
127beacf11bSopenharmony_ci{
128beacf11bSopenharmony_ci  uint32_t cmd_id = cmd->id;
129beacf11bSopenharmony_ci  struct uvc_camera_cmd *cmd_cb = &g_cmd_map[cmd_id];
130beacf11bSopenharmony_ci
131beacf11bSopenharmony_ci  cmd_cb->id = cmd_id;
132beacf11bSopenharmony_ci  (void)memcpy_s(cmd_cb->name, sizeof(cmd_cb->name), cmd->name, sizeof(cmd->name));
133beacf11bSopenharmony_ci  cmd_cb->uvc_control_func = cmd->uvc_control_func;
134beacf11bSopenharmony_ci}
135beacf11bSopenharmony_ci
136beacf11bSopenharmony_ciint hi_camera_register_cmd(struct uvc_camera_cmd *cmd)
137beacf11bSopenharmony_ci{
138beacf11bSopenharmony_ci  uint32_t flags;
139beacf11bSopenharmony_ci  int ret;
140beacf11bSopenharmony_ci
141beacf11bSopenharmony_ci  if (cmd == NULL)
142beacf11bSopenharmony_ci    {
143beacf11bSopenharmony_ci      usb_err("the arg is NULL\n");
144beacf11bSopenharmony_ci      return -1;
145beacf11bSopenharmony_ci    }
146beacf11bSopenharmony_ci
147beacf11bSopenharmony_ci  ret = cmd_check(cmd);
148beacf11bSopenharmony_ci  if (ret == -1)
149beacf11bSopenharmony_ci    {
150beacf11bSopenharmony_ci      usb_err("cmd check is invalid\n");
151beacf11bSopenharmony_ci      return -1;
152beacf11bSopenharmony_ci    }
153beacf11bSopenharmony_ci
154beacf11bSopenharmony_ci  spin_lock_irqsave(&g_cmd_spinlock, flags);
155beacf11bSopenharmony_ci  new_cmd_add(cmd);
156beacf11bSopenharmony_ci  g_uvc_unit_is_register = true;
157beacf11bSopenharmony_ci  spin_unlock_irqrestore(&g_cmd_spinlock, flags);
158beacf11bSopenharmony_ci
159beacf11bSopenharmony_ci  return 0;
160beacf11bSopenharmony_ci}
161beacf11bSopenharmony_ci
162beacf11bSopenharmony_civoid hi_camera_cmd_info_print(void)
163beacf11bSopenharmony_ci{
164beacf11bSopenharmony_ci  int i;
165beacf11bSopenharmony_ci
166beacf11bSopenharmony_ci  for (i = 0; i < CMD_MAX_NUM; i++)
167beacf11bSopenharmony_ci    {
168beacf11bSopenharmony_ci      dprintf("cmd_id=%u, name:%s, func:%x\n", g_cmd_map[i].id, g_cmd_map[i].name, g_cmd_map[i].uvc_control_func);
169beacf11bSopenharmony_ci    }
170beacf11bSopenharmony_ci}
171beacf11bSopenharmony_ci
172beacf11bSopenharmony_cistatic uint32_t camera_unit_control_sample(void *buf, uint32_t len, uint32_t cmdtype)
173beacf11bSopenharmony_ci{
174beacf11bSopenharmony_ci  uint8_t *data = (uint8_t *)buf;
175beacf11bSopenharmony_ci  uint32_t ret  = 0;
176beacf11bSopenharmony_ci
177beacf11bSopenharmony_ci  (void)len;
178beacf11bSopenharmony_ci
179beacf11bSopenharmony_ci  switch (cmdtype)
180beacf11bSopenharmony_ci    {
181beacf11bSopenharmony_ci    case UVC_RC_SETCUR:
182beacf11bSopenharmony_ci    case UVC_RC_GETCUR:
183beacf11bSopenharmony_ci    case UVC_RC_GETMIN:
184beacf11bSopenharmony_ci      ret = 4;
185beacf11bSopenharmony_ci      break;
186beacf11bSopenharmony_ci
187beacf11bSopenharmony_ci    case UVC_RC_GETLEN:
188beacf11bSopenharmony_ci      data[0] = 0x40;
189beacf11bSopenharmony_ci      data[1] = 0x00;
190beacf11bSopenharmony_ci      ret     = 2;
191beacf11bSopenharmony_ci      break;
192beacf11bSopenharmony_ci
193beacf11bSopenharmony_ci    case UVC_RC_GETINFO:
194beacf11bSopenharmony_ci      data[0] = 0x03;
195beacf11bSopenharmony_ci      ret     = 1;
196beacf11bSopenharmony_ci      break;
197beacf11bSopenharmony_ci
198beacf11bSopenharmony_ci    default:
199beacf11bSopenharmony_ci      break;
200beacf11bSopenharmony_ci    }
201beacf11bSopenharmony_ci
202beacf11bSopenharmony_ci  return ret;
203beacf11bSopenharmony_ci}
204beacf11bSopenharmony_ci
205beacf11bSopenharmony_cistatic uint32_t hicamera_unit_control(void *buf, uint32_t len, uint32_t event_id, uint32_t cmdtype)
206beacf11bSopenharmony_ci{
207beacf11bSopenharmony_ci  uint32_t ret;
208beacf11bSopenharmony_ci
209beacf11bSopenharmony_ci  PRINT_INFO("%s %d, event_id=%u, len=%u, cmdtype=%02x\n", __FUNCTION__, __LINE__, event_id, len, cmdtype);
210beacf11bSopenharmony_ci
211beacf11bSopenharmony_ci  switch(event_id)
212beacf11bSopenharmony_ci    {
213beacf11bSopenharmony_ci    case HICAMERA_GET_VERSION_CONTROL:
214beacf11bSopenharmony_ci    case HICAMERA_START_UPDATE_CONTROL:
215beacf11bSopenharmony_ci    case HICAMERA_TRUN_ON_CONTROL:
216beacf11bSopenharmony_ci    case HICAMERA_RESET_CONTROL:
217beacf11bSopenharmony_ci    case HICAMERA_TRUN_OFF_CONTROL:
218beacf11bSopenharmony_ci    case HICAMERA_VIBRATOR_UP_CONTROL:
219beacf11bSopenharmony_ci    case HICAMERA_VIBRATOR_DOWN_CONTROL:
220beacf11bSopenharmony_ci    case HICAMERA_VIBRATOR_LEFT_CONTROL:
221beacf11bSopenharmony_ci    case HICAMERA_VIBRATOR_RIGHT_CONTROL:
222beacf11bSopenharmony_ci    default:
223beacf11bSopenharmony_ci      ret = camera_unit_control_sample(buf, len, cmdtype);
224beacf11bSopenharmony_ci      break;
225beacf11bSopenharmony_ci    }
226beacf11bSopenharmony_ci
227beacf11bSopenharmony_ci  return ret;
228beacf11bSopenharmony_ci}
229beacf11bSopenharmony_ci
230beacf11bSopenharmony_cistatic uint32_t h264_unit_control(void *buf, uint32_t len, uint32_t event_id, uint32_t cmdtype)
231beacf11bSopenharmony_ci{
232beacf11bSopenharmony_ci  uint32_t ret  = 0;
233beacf11bSopenharmony_ci  uint8_t *data = (uint8_t *)buf;
234beacf11bSopenharmony_ci
235beacf11bSopenharmony_ci  PRINT_INFO("%s %d, event_id=%u, len=%u, cmdtype=%02x\n", __FUNCTION__, __LINE__, event_id, len, cmdtype);
236beacf11bSopenharmony_ci
237beacf11bSopenharmony_ci  switch (cmdtype)
238beacf11bSopenharmony_ci    {
239beacf11bSopenharmony_ci    case UVC_RC_SETCUR:
240beacf11bSopenharmony_ci      ret = 4;
241beacf11bSopenharmony_ci      break;
242beacf11bSopenharmony_ci
243beacf11bSopenharmony_ci    case UVC_RC_GETLEN:
244beacf11bSopenharmony_ci      data[0] = 0x40;
245beacf11bSopenharmony_ci      data[1] = 0x00;
246beacf11bSopenharmony_ci      ret     = 0x2;
247beacf11bSopenharmony_ci      break;
248beacf11bSopenharmony_ci
249beacf11bSopenharmony_ci    case UVC_RC_GETINFO:
250beacf11bSopenharmony_ci      data[0] = 0x3;
251beacf11bSopenharmony_ci      ret     = 0x1;
252beacf11bSopenharmony_ci      break;
253beacf11bSopenharmony_ci
254beacf11bSopenharmony_ci    case UVC_RC_GETMIN:
255beacf11bSopenharmony_ci    case UVC_RC_GETMAX:
256beacf11bSopenharmony_ci    case UVC_RC_GETRES:
257beacf11bSopenharmony_ci    case UVC_RC_GETDEF:
258beacf11bSopenharmony_ci      ret = 4;
259beacf11bSopenharmony_ci      break;
260beacf11bSopenharmony_ci
261beacf11bSopenharmony_ci    default:
262beacf11bSopenharmony_ci      usb_err("Yet to be supported cmdtype: %#x\n", cmdtype);
263beacf11bSopenharmony_ci      break;
264beacf11bSopenharmony_ci    }
265beacf11bSopenharmony_ci
266beacf11bSopenharmony_ci  return ret;
267beacf11bSopenharmony_ci}
268beacf11bSopenharmony_ci
269beacf11bSopenharmony_cistatic void histream_pu_set_brightness(uint16_t val)
270beacf11bSopenharmony_ci{
271beacf11bSopenharmony_ci  PRINT_INFO("set brightness val = %u\n", val);
272beacf11bSopenharmony_ci}
273beacf11bSopenharmony_ci
274beacf11bSopenharmony_cistatic uint16_t histream_pu_get_brightness(void)
275beacf11bSopenharmony_ci{
276beacf11bSopenharmony_ci  const uint16_t cur_val = 30;
277beacf11bSopenharmony_ci
278beacf11bSopenharmony_ci  PRINT_INFO("get brightness val = %u\n", cur_val);
279beacf11bSopenharmony_ci
280beacf11bSopenharmony_ci  return cur_val;
281beacf11bSopenharmony_ci}
282beacf11bSopenharmony_ci
283beacf11bSopenharmony_cistatic uint32_t sample_uvc_pu_brightness_ctrl(void *buf, uint32_t len, uint32_t cmdtype)
284beacf11bSopenharmony_ci{
285beacf11bSopenharmony_ci  uint32_t ret  = 0;
286beacf11bSopenharmony_ci  uint8_t *data = (uint8_t *)buf;
287beacf11bSopenharmony_ci  uint16_t val;
288beacf11bSopenharmony_ci
289beacf11bSopenharmony_ci  (void)len;
290beacf11bSopenharmony_ci
291beacf11bSopenharmony_ci  switch (cmdtype)
292beacf11bSopenharmony_ci    {
293beacf11bSopenharmony_ci    case UVC_RC_SETCUR:
294beacf11bSopenharmony_ci      val = data[0] + (data[1] << 8);
295beacf11bSopenharmony_ci      histream_pu_set_brightness(val);
296beacf11bSopenharmony_ci      ret = 2;
297beacf11bSopenharmony_ci      break;
298beacf11bSopenharmony_ci
299beacf11bSopenharmony_ci    case UVC_RC_GETCUR:
300beacf11bSopenharmony_ci      val = histream_pu_get_brightness();
301beacf11bSopenharmony_ci      data[0] = val & 0xff;
302beacf11bSopenharmony_ci      data[1] = (val >> 8) & 0xff;
303beacf11bSopenharmony_ci      ret     = 2;
304beacf11bSopenharmony_ci      break;
305beacf11bSopenharmony_ci
306beacf11bSopenharmony_ci    case UVC_RC_GETRES:
307beacf11bSopenharmony_ci      data[0] = 0x1;
308beacf11bSopenharmony_ci      ret     = 2;
309beacf11bSopenharmony_ci      break;
310beacf11bSopenharmony_ci
311beacf11bSopenharmony_ci    case UVC_RC_GETINFO:
312beacf11bSopenharmony_ci      data[0] = 0x3;
313beacf11bSopenharmony_ci      ret     = 1;
314beacf11bSopenharmony_ci      break;
315beacf11bSopenharmony_ci
316beacf11bSopenharmony_ci    case UVC_RC_GETMIN:
317beacf11bSopenharmony_ci      val = 0;
318beacf11bSopenharmony_ci      data[0] = val & 0xff;
319beacf11bSopenharmony_ci      data[1] = (val >> 8) & 0xff;
320beacf11bSopenharmony_ci      ret     = 2;
321beacf11bSopenharmony_ci      break;
322beacf11bSopenharmony_ci
323beacf11bSopenharmony_ci    case UVC_RC_GETMAX:
324beacf11bSopenharmony_ci      val = 0x64;
325beacf11bSopenharmony_ci      data[0] = val & 0xff;
326beacf11bSopenharmony_ci      data[1] = (val >> 8) & 0xff;
327beacf11bSopenharmony_ci      ret     = 2;
328beacf11bSopenharmony_ci      break;
329beacf11bSopenharmony_ci
330beacf11bSopenharmony_ci    case UVC_RC_GETDEF:
331beacf11bSopenharmony_ci      val = 0x32;
332beacf11bSopenharmony_ci      data[0] = val & 0xff;
333beacf11bSopenharmony_ci      data[1] = (val >> 8) & 0xff;
334beacf11bSopenharmony_ci      ret     = 2;
335beacf11bSopenharmony_ci      break;
336beacf11bSopenharmony_ci
337beacf11bSopenharmony_ci    default:
338beacf11bSopenharmony_ci      break;
339beacf11bSopenharmony_ci    }
340beacf11bSopenharmony_ci
341beacf11bSopenharmony_ci  return ret;
342beacf11bSopenharmony_ci}
343beacf11bSopenharmony_ci
344beacf11bSopenharmony_cistatic void histream_pu_set_contrast(uint16_t val)
345beacf11bSopenharmony_ci{
346beacf11bSopenharmony_ci  PRINT_INFO("set contrast val = %u\n", val);
347beacf11bSopenharmony_ci}
348beacf11bSopenharmony_ci
349beacf11bSopenharmony_cistatic uint16_t histream_pu_get_contrast(void)
350beacf11bSopenharmony_ci{
351beacf11bSopenharmony_ci  const uint16_t cur_cal = 30;
352beacf11bSopenharmony_ci
353beacf11bSopenharmony_ci  PRINT_INFO("get contrast val = %u\n", __FUNCTION__, __LINE__);
354beacf11bSopenharmony_ci
355beacf11bSopenharmony_ci  return cur_cal;
356beacf11bSopenharmony_ci}
357beacf11bSopenharmony_ci
358beacf11bSopenharmony_cistatic uint32_t sample_uvc_pu_contrast_ctrl(void *buf, uint32_t len, uint32_t cmdtype)
359beacf11bSopenharmony_ci{
360beacf11bSopenharmony_ci  uint32_t ret  = 0;
361beacf11bSopenharmony_ci  uint8_t *data = (uint8_t *)buf;
362beacf11bSopenharmony_ci  uint16_t val;
363beacf11bSopenharmony_ci
364beacf11bSopenharmony_ci  (void)len;
365beacf11bSopenharmony_ci
366beacf11bSopenharmony_ci  switch (cmdtype)
367beacf11bSopenharmony_ci    {
368beacf11bSopenharmony_ci    case UVC_RC_SETCUR:
369beacf11bSopenharmony_ci      val = data[0] + (data[1] << 8);
370beacf11bSopenharmony_ci      histream_pu_set_contrast(val);
371beacf11bSopenharmony_ci      ret = 2;
372beacf11bSopenharmony_ci      break;
373beacf11bSopenharmony_ci
374beacf11bSopenharmony_ci    case UVC_RC_GETCUR:
375beacf11bSopenharmony_ci      val = histream_pu_get_contrast();
376beacf11bSopenharmony_ci      data[0] = val & 0xff;
377beacf11bSopenharmony_ci      data[1] = (val >> 8) & 0xff;
378beacf11bSopenharmony_ci      ret     = 2;
379beacf11bSopenharmony_ci      break;
380beacf11bSopenharmony_ci
381beacf11bSopenharmony_ci    case UVC_RC_GETRES:
382beacf11bSopenharmony_ci      data[0] = 0x1;
383beacf11bSopenharmony_ci      ret     = 2;
384beacf11bSopenharmony_ci      break;
385beacf11bSopenharmony_ci
386beacf11bSopenharmony_ci    case UVC_RC_GETINFO:
387beacf11bSopenharmony_ci      data[0] = 0x3;
388beacf11bSopenharmony_ci      ret     = 1;
389beacf11bSopenharmony_ci      break;
390beacf11bSopenharmony_ci
391beacf11bSopenharmony_ci    case UVC_RC_GETMIN:
392beacf11bSopenharmony_ci      val = 0;
393beacf11bSopenharmony_ci      data[0] = val & 0xff;
394beacf11bSopenharmony_ci      data[1] = (val >> 8) & 0xff;
395beacf11bSopenharmony_ci      ret     = 2;
396beacf11bSopenharmony_ci      break;
397beacf11bSopenharmony_ci
398beacf11bSopenharmony_ci    case UVC_RC_GETMAX:
399beacf11bSopenharmony_ci      val = 0x64;
400beacf11bSopenharmony_ci      data[0] = val & 0xff;
401beacf11bSopenharmony_ci      data[1] = (val >> 8) & 0xff;
402beacf11bSopenharmony_ci      ret     = 2;
403beacf11bSopenharmony_ci      break;
404beacf11bSopenharmony_ci
405beacf11bSopenharmony_ci    case UVC_RC_GETDEF:
406beacf11bSopenharmony_ci      val = 0x32;
407beacf11bSopenharmony_ci      data[0] = val & 0xff;
408beacf11bSopenharmony_ci      data[1] = (val >> 8) & 0xff;
409beacf11bSopenharmony_ci      ret     = 2;
410beacf11bSopenharmony_ci      break;
411beacf11bSopenharmony_ci
412beacf11bSopenharmony_ci    default:
413beacf11bSopenharmony_ci      break;
414beacf11bSopenharmony_ci    }
415beacf11bSopenharmony_ci
416beacf11bSopenharmony_ci  return ret;
417beacf11bSopenharmony_ci}
418beacf11bSopenharmony_ci
419beacf11bSopenharmony_cistatic uint32_t uvc_process_unit_contorl(void *buf, uint32_t len, uint32_t event_id, uint32_t cmdtype)
420beacf11bSopenharmony_ci{
421beacf11bSopenharmony_ci  uint32_t ret = 0;
422beacf11bSopenharmony_ci
423beacf11bSopenharmony_ci  PRINT_INFO("%s %d, event_id=%u, len=%u, cmdtype=%02x\n", __FUNCTION__, __LINE__, event_id, len, cmdtype);
424beacf11bSopenharmony_ci
425beacf11bSopenharmony_ci  switch (event_id)
426beacf11bSopenharmony_ci    {
427beacf11bSopenharmony_ci    case USBD_UVC_PU_CONTROL_UNDEFINED:
428beacf11bSopenharmony_ci      break;
429beacf11bSopenharmony_ci
430beacf11bSopenharmony_ci    case USBD_UVC_PU_BACKLIGHT_COMPENSATION_CONTROL:
431beacf11bSopenharmony_ci      break;
432beacf11bSopenharmony_ci
433beacf11bSopenharmony_ci    case USBD_UVC_PU_BRIGHTNESS_CONTROL:
434beacf11bSopenharmony_ci      ret = sample_uvc_pu_brightness_ctrl(buf, len, cmdtype);
435beacf11bSopenharmony_ci      break;
436beacf11bSopenharmony_ci
437beacf11bSopenharmony_ci    case USBD_UVC_PU_CONTRAST_CONTROL:
438beacf11bSopenharmony_ci      ret = sample_uvc_pu_contrast_ctrl(buf, len, cmdtype);
439beacf11bSopenharmony_ci      break;
440beacf11bSopenharmony_ci
441beacf11bSopenharmony_ci    case USBD_UVC_PU_GAIN_CONTROL:
442beacf11bSopenharmony_ci      break;
443beacf11bSopenharmony_ci
444beacf11bSopenharmony_ci    case USBD_UVC_PU_POWER_LINE_FREQUENCY_CONTROL:
445beacf11bSopenharmony_ci      break;
446beacf11bSopenharmony_ci
447beacf11bSopenharmony_ci    case USBD_UVC_PU_HUE_CONTROL:
448beacf11bSopenharmony_ci      break;
449beacf11bSopenharmony_ci
450beacf11bSopenharmony_ci    case USBD_UVC_PU_SATURATION_CONTROL:
451beacf11bSopenharmony_ci      break;
452beacf11bSopenharmony_ci
453beacf11bSopenharmony_ci    case USBD_UVC_PU_SHARPNESS_CONTROL:
454beacf11bSopenharmony_ci      break;
455beacf11bSopenharmony_ci
456beacf11bSopenharmony_ci    case USBD_UVC_PU_GAMMA_CONTROL:
457beacf11bSopenharmony_ci      break;
458beacf11bSopenharmony_ci
459beacf11bSopenharmony_ci    case USBD_UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL:
460beacf11bSopenharmony_ci      break;
461beacf11bSopenharmony_ci
462beacf11bSopenharmony_ci    case USBD_UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTORL:
463beacf11bSopenharmony_ci      break;
464beacf11bSopenharmony_ci
465beacf11bSopenharmony_ci    case USBD_UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL:
466beacf11bSopenharmony_ci      break;
467beacf11bSopenharmony_ci
468beacf11bSopenharmony_ci    case USBD_UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL:
469beacf11bSopenharmony_ci      break;
470beacf11bSopenharmony_ci
471beacf11bSopenharmony_ci    case USBD_UVC_PU_DIGITAL_MULTIPLIER_CONTROL:
472beacf11bSopenharmony_ci      break;
473beacf11bSopenharmony_ci
474beacf11bSopenharmony_ci    case USBD_UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL:
475beacf11bSopenharmony_ci      break;
476beacf11bSopenharmony_ci
477beacf11bSopenharmony_ci    case USBD_UVC_PU_HUE_AUTO_CONTROL:
478beacf11bSopenharmony_ci      break;
479beacf11bSopenharmony_ci
480beacf11bSopenharmony_ci    case USBD_UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL:
481beacf11bSopenharmony_ci      break;
482beacf11bSopenharmony_ci
483beacf11bSopenharmony_ci    case USBD_UVC_PU_ANALOG_LOCK_STATUS_CONTROL:
484beacf11bSopenharmony_ci      break;
485beacf11bSopenharmony_ci
486beacf11bSopenharmony_ci    case USBD_UVC_PU_CONTRAST_AUTO_CONTROL:
487beacf11bSopenharmony_ci      break;
488beacf11bSopenharmony_ci
489beacf11bSopenharmony_ci    default:
490beacf11bSopenharmony_ci      break;
491beacf11bSopenharmony_ci    }
492beacf11bSopenharmony_ci
493beacf11bSopenharmony_ci  return ret;
494beacf11bSopenharmony_ci}
495beacf11bSopenharmony_ci
496beacf11bSopenharmony_cistatic uint32_t camera_terminal_unit_contorl(void *buf, uint32_t len, uint32_t event_id, uint32_t cmdtype)
497beacf11bSopenharmony_ci{
498beacf11bSopenharmony_ci  (void)buf;
499beacf11bSopenharmony_ci
500beacf11bSopenharmony_ci  PRINT_INFO("%s %d, event_id=%u, len=%u, cmdtype=%02x\n", __FUNCTION__, __LINE__, event_id, len, cmdtype);
501beacf11bSopenharmony_ci
502beacf11bSopenharmony_ci  switch (event_id)
503beacf11bSopenharmony_ci    {
504beacf11bSopenharmony_ci    case USBD_UVC_CT_CONTROL_UNDEFINED:
505beacf11bSopenharmony_ci      break;
506beacf11bSopenharmony_ci
507beacf11bSopenharmony_ci    case USBD_UVC_CT_SCANNING_MODE_CONTROL:
508beacf11bSopenharmony_ci      break;
509beacf11bSopenharmony_ci
510beacf11bSopenharmony_ci    case USBD_UVC_CT_AE_MODE_CONTROL:
511beacf11bSopenharmony_ci      break;
512beacf11bSopenharmony_ci
513beacf11bSopenharmony_ci    case USBD_UVC_CT_AE_PRIORITY_CONTROL:
514beacf11bSopenharmony_ci      break;
515beacf11bSopenharmony_ci
516beacf11bSopenharmony_ci    case USBD_UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL:
517beacf11bSopenharmony_ci      break;
518beacf11bSopenharmony_ci
519beacf11bSopenharmony_ci    case USBD_UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL:
520beacf11bSopenharmony_ci      break;
521beacf11bSopenharmony_ci
522beacf11bSopenharmony_ci    case USBD_UVC_CT_FOCUS_ABSOLUTE_CONTROL:
523beacf11bSopenharmony_ci      break;
524beacf11bSopenharmony_ci
525beacf11bSopenharmony_ci    case USBD_UVC_CT_FOCUS_RELATIVE_CONTROL:
526beacf11bSopenharmony_ci      break;
527beacf11bSopenharmony_ci
528beacf11bSopenharmony_ci    case USBD_UVC_CT_FOCUS_AUTO_CONTROL:
529beacf11bSopenharmony_ci      break;
530beacf11bSopenharmony_ci
531beacf11bSopenharmony_ci    case USBD_UVC_CT_IRIS_ABSOLUTE_CONTROL:
532beacf11bSopenharmony_ci      break;
533beacf11bSopenharmony_ci
534beacf11bSopenharmony_ci    case USBD_UVC_CT_IRIS_RELATIVE_CONTROL:
535beacf11bSopenharmony_ci      break;
536beacf11bSopenharmony_ci
537beacf11bSopenharmony_ci    case USBD_UVC_CT_ZOOM_ABSOLUTE_CONTROL:
538beacf11bSopenharmony_ci      break;
539beacf11bSopenharmony_ci
540beacf11bSopenharmony_ci    case USBD_UVC_CT_ZOOM_RELATIVE_CONTROL:
541beacf11bSopenharmony_ci      break;
542beacf11bSopenharmony_ci
543beacf11bSopenharmony_ci    case USBD_UVC_CT_PANTILT_ABSOLUTE_CONTROL:
544beacf11bSopenharmony_ci      break;
545beacf11bSopenharmony_ci
546beacf11bSopenharmony_ci    case USBD_UVC_CT_PANTILT_RELATIVE_CONTROL:
547beacf11bSopenharmony_ci      break;
548beacf11bSopenharmony_ci
549beacf11bSopenharmony_ci    case USBD_UVC_CT_ROLL_ABSOLUTE_CONTROL:
550beacf11bSopenharmony_ci      break;
551beacf11bSopenharmony_ci
552beacf11bSopenharmony_ci    case USBD_UVC_CT_ROLL_RELATIVE_CONTROL:
553beacf11bSopenharmony_ci      break;
554beacf11bSopenharmony_ci
555beacf11bSopenharmony_ci    case USBD_UVC_CT_PRIVACY_CONTROL:
556beacf11bSopenharmony_ci      break;
557beacf11bSopenharmony_ci
558beacf11bSopenharmony_ci    case USBD_UVC_CT_FOCUS_SIMPLE_CONTROL:
559beacf11bSopenharmony_ci      break;
560beacf11bSopenharmony_ci
561beacf11bSopenharmony_ci    case USBD_UVC_CT_WINDOW_CONTROL:
562beacf11bSopenharmony_ci      break;
563beacf11bSopenharmony_ci
564beacf11bSopenharmony_ci    case USBD_UVC_CT_REGION_OF_INTEREST_CONTROL:
565beacf11bSopenharmony_ci      break;
566beacf11bSopenharmony_ci
567beacf11bSopenharmony_ci    default:
568beacf11bSopenharmony_ci      break;
569beacf11bSopenharmony_ci    }
570beacf11bSopenharmony_ci
571beacf11bSopenharmony_ci  return 0;
572beacf11bSopenharmony_ci}
573beacf11bSopenharmony_ci
574beacf11bSopenharmony_cistatic struct uvc_camera_cmd g_uvc_unit_mappings[UVC_UNIT_MAP_SIZE] =
575beacf11bSopenharmony_ci{
576beacf11bSopenharmony_ci  {
577beacf11bSopenharmony_ci    .id = CMD_HICAMERA_UNIT_CONTROL,
578beacf11bSopenharmony_ci    .name = "hicamera_unit_control",
579beacf11bSopenharmony_ci    .uvc_control_func = hicamera_unit_control,
580beacf11bSopenharmony_ci  },
581beacf11bSopenharmony_ci  {
582beacf11bSopenharmony_ci    .id = CMD_H264_UNIT_CONTROL,
583beacf11bSopenharmony_ci    .name = "h264_unit_control",
584beacf11bSopenharmony_ci    .uvc_control_func = h264_unit_control,
585beacf11bSopenharmony_ci  },
586beacf11bSopenharmony_ci  {
587beacf11bSopenharmony_ci    .id = CMD_CAMERA_UNIT_CONTROL,
588beacf11bSopenharmony_ci    .name = "camera_terminal_unit_contorl",
589beacf11bSopenharmony_ci    .uvc_control_func = camera_terminal_unit_contorl,
590beacf11bSopenharmony_ci  },
591beacf11bSopenharmony_ci  {
592beacf11bSopenharmony_ci    .id = CMD_PROCESS_UNIT_CONTROL,
593beacf11bSopenharmony_ci    .name = "uvc_process_unit_contorl",
594beacf11bSopenharmony_ci    .uvc_control_func = uvc_process_unit_contorl,
595beacf11bSopenharmony_ci  },
596beacf11bSopenharmony_ci};
597beacf11bSopenharmony_ci
598beacf11bSopenharmony_ci#ifdef __cplusplus
599beacf11bSopenharmony_ci#if __cplusplus
600beacf11bSopenharmony_ci}
601beacf11bSopenharmony_ci#endif /* __cplusplus */
602beacf11bSopenharmony_ci#endif /* __cplusplus */
603