Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Pixart PAC207BCA / PAC73xx common functions
0004  *
0005  * Copyright (C) 2008 Hans de Goede <j.w.r.degoede@hhs.nl>
0006  * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li
0007  * Copyleft (C) 2005 Michel Xhaard mxhaard@magic.fr
0008  *
0009  * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
0010  */
0011 
0012 /* We calculate the autogain at the end of the transfer of a frame, at this
0013    moment a frame with the old settings is being captured and transmitted. So
0014    if we adjust the gain or exposure we must ignore at least the next frame for
0015    the new settings to come into effect before doing any other adjustments. */
0016 #define PAC_AUTOGAIN_IGNORE_FRAMES  2
0017 
0018 static const unsigned char pac_sof_marker[5] =
0019         { 0xff, 0xff, 0x00, 0xff, 0x96 };
0020 
0021 /*
0022    The following state machine finds the SOF marker sequence
0023    0xff, 0xff, 0x00, 0xff, 0x96 in a byte stream.
0024 
0025        +----------+
0026        | 0: START |<---------------\
0027        +----------+<-\             |
0028          |       \---/otherwise    |
0029          v 0xff                    |
0030        +----------+ otherwise      |
0031        |     1    |--------------->*
0032        |          |                ^
0033        +----------+                |
0034          |                         |
0035          v 0xff                    |
0036        +----------+<-\0xff         |
0037     /->|          |--/             |
0038     |  |     2    |--------------->*
0039     |  |          | otherwise      ^
0040     |  +----------+                |
0041     |    |                         |
0042     |    v 0x00                    |
0043     |  +----------+                |
0044     |  |     3    |                |
0045     |  |          |--------------->*
0046     |  +----------+ otherwise      ^
0047     |    |                         |
0048    0xff |    v 0xff                    |
0049     |  +----------+                |
0050     \--|     4    |                |
0051        |          |----------------/
0052        +----------+ otherwise
0053          |
0054          v 0x96
0055        +----------+
0056        |  FOUND   |
0057        +----------+
0058 */
0059 
0060 static unsigned char *pac_find_sof(struct gspca_dev *gspca_dev, u8 *sof_read,
0061                     unsigned char *m, int len)
0062 {
0063     int i;
0064 
0065     /* Search for the SOF marker (fixed part) in the header */
0066     for (i = 0; i < len; i++) {
0067         switch (*sof_read) {
0068         case 0:
0069             if (m[i] == 0xff)
0070                 *sof_read = 1;
0071             break;
0072         case 1:
0073             if (m[i] == 0xff)
0074                 *sof_read = 2;
0075             else
0076                 *sof_read = 0;
0077             break;
0078         case 2:
0079             switch (m[i]) {
0080             case 0x00:
0081                 *sof_read = 3;
0082                 break;
0083             case 0xff:
0084                 /* stay in this state */
0085                 break;
0086             default:
0087                 *sof_read = 0;
0088             }
0089             break;
0090         case 3:
0091             if (m[i] == 0xff)
0092                 *sof_read = 4;
0093             else
0094                 *sof_read = 0;
0095             break;
0096         case 4:
0097             switch (m[i]) {
0098             case 0x96:
0099                 /* Pattern found */
0100                 gspca_dbg(gspca_dev, D_FRAM,
0101                       "SOF found, bytes to analyze: %u - Frame starts at byte #%u\n",
0102                       len, i + 1);
0103                 *sof_read = 0;
0104                 return m + i + 1;
0105                 break;
0106             case 0xff:
0107                 *sof_read = 2;
0108                 break;
0109             default:
0110                 *sof_read = 0;
0111             }
0112             break;
0113         default:
0114             *sof_read = 0;
0115         }
0116     }
0117 
0118     return NULL;
0119 }