Path: blob/master/drivers/media/video/gspca/pac_common.h
17602 views
/*1* Pixart PAC207BCA / PAC73xx common functions2*3* Copyright (C) 2008 Hans de Goede <[email protected]>4* Copyright (C) 2005 Thomas Kaiser [email protected]5* Copyleft (C) 2005 Michel Xhaard [email protected]6*7* V4L2 by Jean-Francois Moine <http://moinejf.free.fr>8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA22*23*/2425/* We calculate the autogain at the end of the transfer of a frame, at this26moment a frame with the old settings is being captured and transmitted. So27if we adjust the gain or exposure we must ignore atleast the next frame for28the new settings to come into effect before doing any other adjustments. */29#define PAC_AUTOGAIN_IGNORE_FRAMES 23031static const unsigned char pac_sof_marker[5] =32{ 0xff, 0xff, 0x00, 0xff, 0x96 };3334/*35The following state machine finds the SOF marker sequence360xff, 0xff, 0x00, 0xff, 0x96 in a byte stream.3738+----------+39| 0: START |<---------------\40+----------+<-\ |41| \---/otherwise |42v 0xff |43+----------+ otherwise |44| 1 |--------------->*45| | ^46+----------+ |47| |48v 0xff |49+----------+<-\0xff |50/->| |--/ |51| | 2 |--------------->*52| | | otherwise ^53| +----------+ |54| | |55| v 0x00 |56| +----------+ |57| | 3 | |58| | |--------------->*59| +----------+ otherwise ^60| | |610xff | v 0xff |62| +----------+ |63\--| 4 | |64| |----------------/65+----------+ otherwise66|67v 0x9668+----------+69| FOUND |70+----------+71*/7273static unsigned char *pac_find_sof(u8 *sof_read,74unsigned char *m, int len)75{76int i;7778/* Search for the SOF marker (fixed part) in the header */79for (i = 0; i < len; i++) {80switch (*sof_read) {81case 0:82if (m[i] == 0xff)83*sof_read = 1;84break;85case 1:86if (m[i] == 0xff)87*sof_read = 2;88else89*sof_read = 0;90break;91case 2:92switch (m[i]) {93case 0x00:94*sof_read = 3;95break;96case 0xff:97/* stay in this state */98break;99default:100*sof_read = 0;101}102break;103case 3:104if (m[i] == 0xff)105*sof_read = 4;106else107*sof_read = 0;108break;109case 4:110switch (m[i]) {111case 0x96:112/* Pattern found */113PDEBUG(D_FRAM,114"SOF found, bytes to analyze: %u."115" Frame starts at byte #%u",116len, i + 1);117*sof_read = 0;118return m + i + 1;119break;120case 0xff:121*sof_read = 2;122break;123default:124*sof_read = 0;125}126break;127default:128*sof_read = 0;129}130}131132return NULL;133}134135136