• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 /*******************************************************************************
21 * Function Declarations
22 *******************************************************************************/
23 UINT32 usb_open (UINT32 op_flag);
24 UINT32 usb_close (void);
25 #if (CONFIG_SOC_BK7271) || (CONFIG_SOC_BK7256XX)
26 UINT32 usb_read (UINT32 pos, const void *buffer, UINT32 size);
27 UINT32 usb_write (UINT32 pos, const void *buffer, UINT32 size);
28 #else
29 UINT32 usb_read (char *user_buf, UINT32 count, UINT32 op_flag);
30 UINT32 usb_write (char *user_buf, UINT32 count, UINT32 op_flag);
31 #endif
32 
33 UINT32 usb_ctrl(UINT32 cmd, void *param);
34 void usb_event_post(void);
35 void usb_isr(void);
36 void usb_check_int_handler(void);
37 
38 /**
39  * @brief     open the USB
40  *
41  * This API configure the resoure common to USB:
42  *   - Select the identity as host or slave
43  *  parameter: usb_mode
44  *            USB_HOST_MODE   = 0
45  *            USB_DEVICE_MODE = 1
46  *
47  *   - Configure USB common clock
48  *   - Configure USB common registers
49  *
50  * This API should be called before any other USB APIs.
51  *
52  * @return
53  *    - BK_OK: succeed
54  *    - others: other errors.
55  */
56 bk_err_t bk_usb_open (uint32_t usb_mode);
57 
58 /**
59  * @brief     close the USB
60  *
61  * This API release USB resources:
62  *   - Restore register
63  *   - Turn off the power and clock
64  *
65  * This API should be called after any other USB APIs.
66  *
67  * @return
68  *    - BK_OK: succeed
69  *    - others: other errors.
70  */
71 bk_err_t bk_usb_close (void);
72 
73 /**
74  * @brief     Start UVC stream transmission
75  *
76  * USB video camera data transfer starts:
77  *   - configure the required configuration parameters
78  *   - Send video stream data transfer instructions
79  *
80  * This API means that the data starts to transfer and needs to
81  * transfer and needs to be copied.
82  *
83  * @return
84  *    - BK_OK: succeed
85  *    - others: other errors.
86  */
87 bk_err_t bk_uvc_start(void);
88 
89 /**
90  * @brief     Stop UVC stream transmission
91  *
92  * USB video camera data transfer stops:
93  *   - Send the video stream data stop transmission command
94  *
95  *
96  * There will be no more data flow after execution.
97  *
98  * @return
99  *    - BK_OK: succeed
100  *    - others: other errors.
101  */
102 bk_err_t bk_uvc_stop(void);
103 
104 /**
105  * @brief     Set required Parameters
106  *
107  *  This API sets resolution and frame rate:
108  *   - The resolution parameters:
109  *       UVC_FRAME_160_120
110  *       UVC_FRAME_176_144
111  *       UVC_FRAME_352_288
112  *       UVC_FRAME_320_240
113  *       UVC_FRAME_640_360
114  *       UVC_FRAME_640_480
115  *
116  *   - These frame rate parameters:
117  *      FPS_60
118  *      FPS_30
119  *      FPS_25
120  *      FPS_20
121  *      FPS_15
122  *      FPS_10
123  *      FPS_5
124  *
125  *  Set parameters based on camera parameters.
126  *
127  * @return
128  *    - BK_OK: succeed
129  *    - others: other errors.
130  */
131 bk_err_t bk_uvc_set_parameter(uint32_t resolution_id, uint32_t fps);
132 
133 /**
134  * @brief     Configure the address of the data buffer
135  *
136  * This API configure the resoure common to UVC:
137  *   - The buffer adderss is the address of the temporary data copy.
138  *   - Can be a global variable address or a storage address.
139  *
140  *
141  * A buffer should be larger than a packet fo data.
142  *
143  * @return
144  *    - BK_OK: succeed
145  *    - others: other errors.
146  */
147 bk_err_t bk_uvc_register_rx_vstream_buffptr(void *param);
148 
149 /**
150  * @brief     Configure the Length of the data buffer
151  *
152  * This API configure the resoure common to UVC:
153  *   - Work with bk_uvc_register_rx_vstream_buffptr().
154  *   - The buffer size is calculated to see if it matches.
155  *
156  *
157  * A buffer should be larger than a packet fo data.
158  *
159  * @return
160  *    - BK_OK: succeed
161  *    - others: other errors.
162  */
163 bk_err_t bk_uvc_register_rx_vstream_bufflen(uint32_t param);
164 
165 /**
166  * @brief     start accepting data
167  *
168  * This API copies data received by USB to buffer:
169  *   - This function is executed after bk_uvc_start().
170  *   - The buffer size is calculated to see if it matches.
171  *
172  *
173  * This API takes the same parameters as the bk_uvc_register_rx_vstream_buffptr()
174  * and bk_uvc_register_rx_vstream_bufflen().
175  *
176  * @return
177  *    - BK_OK: succeed
178  *    - others: other errors.
179  */
180 bk_err_t bk_uvc_receive_video_stream();
181 
182 /**
183  * @brief     Configure the callback function registration function registration
184  *
185  * This API configure the callback:
186  *   - parameter is the registered callback function.
187  *   - The callback function needs to be defined.
188  *
189  *
190  *  Notifies a device connection that a callback function needs to be configured.
191  *
192  * @return
193  *    - BK_OK: succeed
194  *    - others: other errors.
195  */
196 bk_err_t bk_uvc_register_config_callback(void *param);
197 
198 /**
199  * @brief     A transaction transfer completes the callback function registration
200  *
201  * This API configure the callback:
202  *   - parameter is the registered callback function.
203  *   - The callback function needs to be defined.
204  *
205  *
206  *  The callback function must be registered.
207  *
208  * @return
209  *    - BK_OK: succeed
210  *    - others: other errors.
211  *
212  */
213 bk_err_t bk_uvc_register_VSrxed_callback(void *param);
214 
215 /**
216  * @brief     A packet of data transfer completes the callback function registration
217  *
218  * This API configure the callback:
219  *   - parameter is the registered callback function.
220  *   - The callback function needs to be defined.
221  *
222  *
223  *  The callback function must be registered.
224  *
225  * @return
226  *    - BK_OK: succeed
227  *    - others: other errors.
228  *
229  */
230 bk_err_t bk_uvc_register_VSrxed_packet_callback(void *param);
231 
232 /**
233  * @brief     Select the data transmission mode
234  *
235  * This API can select the data transfer mode:
236  *   - Parameters can be passed directly to parameters.
237  *     1 :udp send packet;
238  *     0 :tcp send packet;
239  *
240  *  Choose to call this API.
241  *
242  * @return
243  *    - BK_OK: succeed
244  *    - others: other errors.
245  *
246  */
247 bk_err_t bk_uvc_register_link(uint32_t param);
248 
249 /**
250  * @brief     Set camera attributes values
251  *
252  * This API set camera attributes values:
253  *   - Two parameters attributes and values.
254  *   - attributes:
255  *        UVC_PU_CONTROL_UNDEFINED                                              0x00
256  *        UVC_PU_BACKLIGHT_COMPENSATION_CONTROL                      0x01
257  *        UVC_PU_BRIGHTNESS_CONTRO                                              0x02
258  *        UVC_PU_CONTRAST_CONTROL                                               0x03
259  *        UVC_PU_GAIN_CONTROL                                                       0x04
260  *        UVC_PU_POWER_LINE_FREQUENCY_CONTROL                          0x05
261  *        UVC_PU_HUE_CONTROL                                                         0x06
262  *        UVC_PU_SATURATION_CONTROL                                             0x07
263  *        UVC_PU_SHARPNESS_CONTROL                                              0x08
264  *        UVC_PU_GAMMA_CONTROL                                                     0x09
265  *        UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL                  0x0a
266  *        UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL         0x0b
267  *        UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL                    0x0c
268  *        UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL           0x0d
269  *        UVC_PU_DIGITAL_MULTIPLIER_CONTROL                                 0x0e
270  *        UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL                        0x0f
271  *        UVC_PU_HUE_AUTO_CONTROL                                                0x10
272  *        UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL                        0x11
273  *        UVC_PU_ANALOG_LOCK_STATUS_CONTROL                              0x12
274  *
275  *   - Valid values needs to be viewed in camera.
276  *
277  *  Choose to call this API.
278  *
279  * @return
280  *    - BK_OK: succeed
281  *    - others: other errors.
282  *
283  */
284 bk_err_t bk_uvc_set_cur(uint32_t attribute, uint32_t param);
285 
286 /**
287  * @brief     Get camera attributes values
288  *
289  * This API Get camera attributes values:
290  *   - Two parameters attributes and values.
291  *   - attributes:
292  *        UVC_PU_CONTROL_UNDEFINED                                              0x00
293  *        UVC_PU_BACKLIGHT_COMPENSATION_CONTROL                      0x01
294  *        UVC_PU_BRIGHTNESS_CONTRO                                              0x02
295  *        UVC_PU_CONTRAST_CONTROL                                               0x03
296  *        UVC_PU_GAIN_CONTROL                                                       0x04
297  *        UVC_PU_POWER_LINE_FREQUENCY_CONTROL                          0x05
298  *        UVC_PU_HUE_CONTROL                                                         0x06
299  *        UVC_PU_SATURATION_CONTROL                                             0x07
300  *        UVC_PU_SHARPNESS_CONTROL                                              0x08
301  *        UVC_PU_GAMMA_CONTROL                                                     0x09
302  *        UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL                  0x0a
303  *        UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL         0x0b
304  *        UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL                    0x0c
305  *        UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL           0x0d
306  *        UVC_PU_DIGITAL_MULTIPLIER_CONTROL                                 0x0e
307  *        UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL                        0x0f
308  *        UVC_PU_HUE_AUTO_CONTROL                                                0x10
309  *        UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL                        0x11
310  *        UVC_PU_ANALOG_LOCK_STATUS_CONTROL                              0x12
311  *
312  *   - Valid values needs to be viewed in camera.
313  *
314  *  Choose to call this API.
315  *
316  * @return
317  *    - Values
318  *
319  */
320 uint32_t bk_uvc_get_cur(uint32_t attribute);
321 
322 /**
323  * @brief     Get camera attributes MIN values
324  *
325  * This API Get camera attributes MIN values:
326  *   - Two parameters attributes and values.
327  *   - attributes
328  *
329  *   - Valid values needs to be viewed in camera.
330  *
331  *  Choose to call this API.
332  *
333  * @return
334  *    - values
335  *
336  */
337 uint32_t bk_uvc_get_min(uint32_t attribute);
338 
339 /**
340  * @brief     Get camera attributes MAX values
341  *
342  * This API Get camera attributes MAX values:
343  *   - Two parameters attributes and values.
344  *   - attributes
345  *
346  *   - Valid values needs to be viewed in camera.
347  *
348  *  Choose to call this API.
349  *
350  * @return
351  *    - values
352  *
353  */
354 uint32_t bk_uvc_get_max(uint32_t attribute);
355 
356 /**
357  * @brief     Get camera attributes RES values
358  *
359  * This API Get camera attributes RES values:
360  *   - Two parameters attributes and values.
361  *   - attributes
362  *
363  *   - Valid values needs to be viewed in camera.
364  *
365  *  Choose to call this API.
366  *
367  * @return
368  *    - values
369  *
370  */
371 uint32_t bk_uvc_get_res(uint32_t attribute);
372 
373 /**
374  * @brief     Get camera attributes LEN values
375  *
376  * This API Get camera attributes LEN values:
377  *   - Two parameters attributes and values.
378  *   - attributes
379  *
380  *   - Valid values needs to be viewed in camera.
381  *
382  *  Choose to call this API.
383  *
384  * @return
385  *    - values
386  *
387  */
388 uint32_t bk_uvc_get_len(uint32_t attribute);
389 
390 /**
391  * @brief     Get camera attributes INFO values
392  *
393  * This API Get camera attributes INFO values:
394  *   - Two parameters attributes and values.
395  *   - attributes
396  *
397  *   - Valid values needs to be viewed in camera.
398  *
399  *  Choose to call this API.
400  *
401  * @return
402  *    - values
403  *
404  */
405 uint32_t bk_uvc_get_info(uint32_t attribute);
406 
407 /**
408  * @brief     Get camera attributes DEF values
409  *
410  * This API Get camera attributes DEF values:
411  *   - Two parameters attributes and values.
412  *   - attributes
413  *
414  *   - Valid values needs to be viewed in camera.
415  *
416  *  Choose to call this API.
417  *
418  * @return
419  *    - values
420  *
421  */
422 uint32_t bk_uvc_get_def(uint32_t attribute);
423 #ifdef __cplusplus
424 }
425 #endif