Commit | Line | Data |
---|---|---|
327c4abf HG |
1 | /* |
2 | * Pixart PAC207BCA / PAC73xx common functions | |
3 | * | |
4 | * Copyright (C) 2008 Hans de Goede <j.w.r.degoede@hhs.nl> | |
5 | * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li | |
6 | * Copyleft (C) 2005 Michel Xhaard mxhaard@magic.fr | |
7 | * | |
8 | * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 | * | |
24 | */ | |
25 | ||
8a5b2e90 HG |
26 | /* We calculate the autogain at the end of the transfer of a frame, at this |
27 | moment a frame with the old settings is being transmitted, and a frame is | |
28 | being captured with the old settings. So if we adjust the autogain we must | |
29 | ignore atleast the 2 next frames for the new settings to come into effect | |
30 | before doing any other adjustments */ | |
31 | #define PAC_AUTOGAIN_IGNORE_FRAMES 3 | |
32 | ||
327c4abf HG |
33 | static const unsigned char pac_sof_marker[5] = |
34 | { 0xff, 0xff, 0x00, 0xff, 0x96 }; | |
35 | ||
e0d49e2d MN |
36 | /* |
37 | The following state machine finds the SOF marker sequence | |
38 | 0xff, 0xff, 0x00, 0xff, 0x96 in a byte stream. | |
39 | ||
40 | +----------+ | |
41 | | 0: START |<---------------\ | |
42 | +----------+<-\ | | |
43 | | \---/otherwise | | |
44 | v 0xff | | |
45 | +----------+ otherwise | | |
46 | | 1 |--------------->* | |
47 | | | ^ | |
48 | +----------+ | | |
49 | | | | |
50 | v 0xff | | |
51 | +----------+<-\0xff | | |
52 | /->| |--/ | | |
53 | | | 2 |--------------->* | |
54 | | | | otherwise ^ | |
55 | | +----------+ | | |
56 | | | | | |
57 | | v 0x00 | | |
58 | | +----------+ | | |
59 | | | 3 | | | |
60 | | | |--------------->* | |
61 | | +----------+ otherwise ^ | |
62 | | | | | |
63 | 0xff | v 0xff | | |
64 | | +----------+ | | |
65 | \--| 4 | | | |
66 | | |----------------/ | |
67 | +----------+ otherwise | |
68 | | | |
69 | v 0x96 | |
70 | +----------+ | |
71 | | FOUND | | |
72 | +----------+ | |
73 | */ | |
74 | ||
a6b69e40 | 75 | static unsigned char *pac_find_sof(u8 *sof_read, |
327c4abf HG |
76 | unsigned char *m, int len) |
77 | { | |
327c4abf HG |
78 | int i; |
79 | ||
80 | /* Search for the SOF marker (fixed part) in the header */ | |
81 | for (i = 0; i < len; i++) { | |
a6b69e40 | 82 | switch (*sof_read) { |
e0d49e2d MN |
83 | case 0: |
84 | if (m[i] == 0xff) | |
a6b69e40 | 85 | *sof_read = 1; |
e0d49e2d MN |
86 | break; |
87 | case 1: | |
88 | if (m[i] == 0xff) | |
a6b69e40 | 89 | *sof_read = 2; |
e0d49e2d | 90 | else |
a6b69e40 | 91 | *sof_read = 0; |
e0d49e2d MN |
92 | break; |
93 | case 2: | |
94 | switch (m[i]) { | |
95 | case 0x00: | |
a6b69e40 | 96 | *sof_read = 3; |
e0d49e2d MN |
97 | break; |
98 | case 0xff: | |
99 | /* stay in this state */ | |
100 | break; | |
101 | default: | |
a6b69e40 | 102 | *sof_read = 0; |
e0d49e2d MN |
103 | } |
104 | break; | |
105 | case 3: | |
106 | if (m[i] == 0xff) | |
a6b69e40 | 107 | *sof_read = 4; |
e0d49e2d | 108 | else |
a6b69e40 | 109 | *sof_read = 0; |
e0d49e2d MN |
110 | break; |
111 | case 4: | |
112 | switch (m[i]) { | |
113 | case 0x96: | |
114 | /* Pattern found */ | |
8a5b2e90 | 115 | PDEBUG(D_FRAM, |
327c4abf HG |
116 | "SOF found, bytes to analyze: %u." |
117 | " Frame starts at byte #%u", | |
118 | len, i + 1); | |
a6b69e40 | 119 | *sof_read = 0; |
327c4abf | 120 | return m + i + 1; |
e0d49e2d MN |
121 | break; |
122 | case 0xff: | |
a6b69e40 | 123 | *sof_read = 2; |
e0d49e2d MN |
124 | break; |
125 | default: | |
a6b69e40 | 126 | *sof_read = 0; |
327c4abf | 127 | } |
e0d49e2d MN |
128 | break; |
129 | default: | |
a6b69e40 | 130 | *sof_read = 0; |
327c4abf HG |
131 | } |
132 | } | |
133 | ||
134 | return NULL; | |
135 | } |