]>
Commit | Line | Data |
---|---|---|
c942fddf | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
327c4abf HG |
2 | /* |
3 | * Pixart PAC207BCA / PAC73xx common functions | |
4 | * | |
5 | * Copyright (C) 2008 Hans de Goede <j.w.r.degoede@hhs.nl> | |
6 | * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li | |
7 | * Copyleft (C) 2005 Michel Xhaard mxhaard@magic.fr | |
8 | * | |
9 | * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> | |
327c4abf HG |
10 | */ |
11 | ||
8a5b2e90 | 12 | /* We calculate the autogain at the end of the transfer of a frame, at this |
5fb2dde2 | 13 | moment a frame with the old settings is being captured and transmitted. So |
3e4d8f48 | 14 | if we adjust the gain or exposure we must ignore at least the next frame for |
5fb2dde2 HG |
15 | the new settings to come into effect before doing any other adjustments. */ |
16 | #define PAC_AUTOGAIN_IGNORE_FRAMES 2 | |
8a5b2e90 | 17 | |
327c4abf HG |
18 | static const unsigned char pac_sof_marker[5] = |
19 | { 0xff, 0xff, 0x00, 0xff, 0x96 }; | |
20 | ||
e0d49e2d MN |
21 | /* |
22 | The following state machine finds the SOF marker sequence | |
23 | 0xff, 0xff, 0x00, 0xff, 0x96 in a byte stream. | |
24 | ||
25 | +----------+ | |
26 | | 0: START |<---------------\ | |
27 | +----------+<-\ | | |
28 | | \---/otherwise | | |
29 | v 0xff | | |
30 | +----------+ otherwise | | |
31 | | 1 |--------------->* | |
32 | | | ^ | |
33 | +----------+ | | |
34 | | | | |
35 | v 0xff | | |
36 | +----------+<-\0xff | | |
37 | /->| |--/ | | |
38 | | | 2 |--------------->* | |
39 | | | | otherwise ^ | |
40 | | +----------+ | | |
41 | | | | | |
42 | | v 0x00 | | |
43 | | +----------+ | | |
44 | | | 3 | | | |
45 | | | |--------------->* | |
46 | | +----------+ otherwise ^ | |
47 | | | | | |
48 | 0xff | v 0xff | | |
49 | | +----------+ | | |
50 | \--| 4 | | | |
51 | | |----------------/ | |
52 | +----------+ otherwise | |
53 | | | |
54 | v 0x96 | |
55 | +----------+ | |
56 | | FOUND | | |
57 | +----------+ | |
58 | */ | |
59 | ||
c93396e1 | 60 | static unsigned char *pac_find_sof(struct gspca_dev *gspca_dev, u8 *sof_read, |
327c4abf HG |
61 | unsigned char *m, int len) |
62 | { | |
327c4abf HG |
63 | int i; |
64 | ||
65 | /* Search for the SOF marker (fixed part) in the header */ | |
66 | for (i = 0; i < len; i++) { | |
a6b69e40 | 67 | switch (*sof_read) { |
e0d49e2d MN |
68 | case 0: |
69 | if (m[i] == 0xff) | |
a6b69e40 | 70 | *sof_read = 1; |
e0d49e2d MN |
71 | break; |
72 | case 1: | |
73 | if (m[i] == 0xff) | |
a6b69e40 | 74 | *sof_read = 2; |
e0d49e2d | 75 | else |
a6b69e40 | 76 | *sof_read = 0; |
e0d49e2d MN |
77 | break; |
78 | case 2: | |
79 | switch (m[i]) { | |
80 | case 0x00: | |
a6b69e40 | 81 | *sof_read = 3; |
e0d49e2d MN |
82 | break; |
83 | case 0xff: | |
84 | /* stay in this state */ | |
85 | break; | |
86 | default: | |
a6b69e40 | 87 | *sof_read = 0; |
e0d49e2d MN |
88 | } |
89 | break; | |
90 | case 3: | |
91 | if (m[i] == 0xff) | |
a6b69e40 | 92 | *sof_read = 4; |
e0d49e2d | 93 | else |
a6b69e40 | 94 | *sof_read = 0; |
e0d49e2d MN |
95 | break; |
96 | case 4: | |
97 | switch (m[i]) { | |
98 | case 0x96: | |
99 | /* Pattern found */ | |
37d5efb0 JP |
100 | gspca_dbg(gspca_dev, D_FRAM, |
101 | "SOF found, bytes to analyze: %u - Frame starts at byte #%u\n", | |
102 | len, i + 1); | |
a6b69e40 | 103 | *sof_read = 0; |
327c4abf | 104 | return m + i + 1; |
e0d49e2d MN |
105 | break; |
106 | case 0xff: | |
a6b69e40 | 107 | *sof_read = 2; |
e0d49e2d MN |
108 | break; |
109 | default: | |
a6b69e40 | 110 | *sof_read = 0; |
327c4abf | 111 | } |
e0d49e2d MN |
112 | break; |
113 | default: | |
a6b69e40 | 114 | *sof_read = 0; |
327c4abf HG |
115 | } |
116 | } | |
117 | ||
118 | return NULL; | |
119 | } |