2019-05-27 09:55:06 +03:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
2008-09-04 00:12:14 +04:00
/*
* Pixart PAC207BCA / PAC73xx common functions
*
* Copyright ( C ) 2008 Hans de Goede < j . w . r . degoede @ hhs . nl >
* Copyright ( C ) 2005 Thomas Kaiser thomas @ kaiser - linux . li
* Copyleft ( C ) 2005 Michel Xhaard mxhaard @ magic . fr
*
* V4L2 by Jean - Francois Moine < http : //moinejf.free.fr>
*/
2008-09-04 00:12:17 +04:00
/* We calculate the autogain at the end of the transfer of a frame, at this
2010-02-17 17:59:19 +03:00
moment a frame with the old settings is being captured and transmitted . So
2019-02-18 22:29:03 +03:00
if we adjust the gain or exposure we must ignore at least the next frame for
2010-02-17 17:59:19 +03:00
the new settings to come into effect before doing any other adjustments . */
# define PAC_AUTOGAIN_IGNORE_FRAMES 2
2008-09-04 00:12:17 +04:00
2008-09-04 00:12:14 +04:00
static const unsigned char pac_sof_marker [ 5 ] =
{ 0xff , 0xff , 0x00 , 0xff , 0x96 } ;
2009-10-05 12:41:30 +04:00
/*
The following state machine finds the SOF marker sequence
0xff , 0xff , 0x00 , 0xff , 0x96 in a byte stream .
+ - - - - - - - - - - +
| 0 : START | < - - - - - - - - - - - - - - - \
+ - - - - - - - - - - + < - \ |
| \ - - - / otherwise |
v 0xff |
+ - - - - - - - - - - + otherwise |
| 1 | - - - - - - - - - - - - - - - > *
| | ^
+ - - - - - - - - - - + |
| |
v 0xff |
+ - - - - - - - - - - + < - \ 0xff |
/ - > | | - - / |
| | 2 | - - - - - - - - - - - - - - - > *
| | | otherwise ^
| + - - - - - - - - - - + |
| | |
| v 0x00 |
| + - - - - - - - - - - + |
| | 3 | |
| | | - - - - - - - - - - - - - - - > *
| + - - - - - - - - - - + otherwise ^
| | |
0xff | v 0xff |
| + - - - - - - - - - - + |
\ - - | 4 | |
| | - - - - - - - - - - - - - - - - /
+ - - - - - - - - - - + otherwise
|
v 0x96
+ - - - - - - - - - - +
| FOUND |
+ - - - - - - - - - - +
*/
2013-02-04 20:17:55 +04:00
static unsigned char * pac_find_sof ( struct gspca_dev * gspca_dev , u8 * sof_read ,
2008-09-04 00:12:14 +04:00
unsigned char * m , int len )
{
int i ;
/* Search for the SOF marker (fixed part) in the header */
for ( i = 0 ; i < len ; i + + ) {
2009-11-02 14:05:51 +03:00
switch ( * sof_read ) {
2009-10-05 12:41:30 +04:00
case 0 :
if ( m [ i ] = = 0xff )
2009-11-02 14:05:51 +03:00
* sof_read = 1 ;
2009-10-05 12:41:30 +04:00
break ;
case 1 :
if ( m [ i ] = = 0xff )
2009-11-02 14:05:51 +03:00
* sof_read = 2 ;
2009-10-05 12:41:30 +04:00
else
2009-11-02 14:05:51 +03:00
* sof_read = 0 ;
2009-10-05 12:41:30 +04:00
break ;
case 2 :
switch ( m [ i ] ) {
case 0x00 :
2009-11-02 14:05:51 +03:00
* sof_read = 3 ;
2009-10-05 12:41:30 +04:00
break ;
case 0xff :
/* stay in this state */
break ;
default :
2009-11-02 14:05:51 +03:00
* sof_read = 0 ;
2009-10-05 12:41:30 +04:00
}
break ;
case 3 :
if ( m [ i ] = = 0xff )
2009-11-02 14:05:51 +03:00
* sof_read = 4 ;
2009-10-05 12:41:30 +04:00
else
2009-11-02 14:05:51 +03:00
* sof_read = 0 ;
2009-10-05 12:41:30 +04:00
break ;
case 4 :
switch ( m [ i ] ) {
case 0x96 :
/* Pattern found */
2017-09-22 22:20:33 +03:00
gspca_dbg ( gspca_dev , D_FRAM ,
" SOF found, bytes to analyze: %u - Frame starts at byte #%u \n " ,
len , i + 1 ) ;
2009-11-02 14:05:51 +03:00
* sof_read = 0 ;
2008-09-04 00:12:14 +04:00
return m + i + 1 ;
2009-10-05 12:41:30 +04:00
break ;
case 0xff :
2009-11-02 14:05:51 +03:00
* sof_read = 2 ;
2009-10-05 12:41:30 +04:00
break ;
default :
2009-11-02 14:05:51 +03:00
* sof_read = 0 ;
2008-09-04 00:12:14 +04:00
}
2009-10-05 12:41:30 +04:00
break ;
default :
2009-11-02 14:05:51 +03:00
* sof_read = 0 ;
2008-09-04 00:12:14 +04:00
}
}
return NULL ;
}