pac_common.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. /* We calculate the autogain at the end of the transfer of a frame, at this
  26. moment a frame with the old settings is being captured and transmitted. So
  27. if we adjust the gain or exposure we must ignore atleast the next frame for
  28. the new settings to come into effect before doing any other adjustments. */
  29. #define PAC_AUTOGAIN_IGNORE_FRAMES 2
  30. static const unsigned char pac_sof_marker[5] =
  31. { 0xff, 0xff, 0x00, 0xff, 0x96 };
  32. /*
  33. The following state machine finds the SOF marker sequence
  34. 0xff, 0xff, 0x00, 0xff, 0x96 in a byte stream.
  35. +----------+
  36. | 0: START |<---------------\
  37. +----------+<-\ |
  38. | \---/otherwise |
  39. v 0xff |
  40. +----------+ otherwise |
  41. | 1 |--------------->*
  42. | | ^
  43. +----------+ |
  44. | |
  45. v 0xff |
  46. +----------+<-\0xff |
  47. /->| |--/ |
  48. | | 2 |--------------->*
  49. | | | otherwise ^
  50. | +----------+ |
  51. | | |
  52. | v 0x00 |
  53. | +----------+ |
  54. | | 3 | |
  55. | | |--------------->*
  56. | +----------+ otherwise ^
  57. | | |
  58. 0xff | v 0xff |
  59. | +----------+ |
  60. \--| 4 | |
  61. | |----------------/
  62. +----------+ otherwise
  63. |
  64. v 0x96
  65. +----------+
  66. | FOUND |
  67. +----------+
  68. */
  69. static unsigned char *pac_find_sof(struct gspca_dev *gspca_dev, u8 *sof_read,
  70. unsigned char *m, int len)
  71. {
  72. int i;
  73. /* Search for the SOF marker (fixed part) in the header */
  74. for (i = 0; i < len; i++) {
  75. switch (*sof_read) {
  76. case 0:
  77. if (m[i] == 0xff)
  78. *sof_read = 1;
  79. break;
  80. case 1:
  81. if (m[i] == 0xff)
  82. *sof_read = 2;
  83. else
  84. *sof_read = 0;
  85. break;
  86. case 2:
  87. switch (m[i]) {
  88. case 0x00:
  89. *sof_read = 3;
  90. break;
  91. case 0xff:
  92. /* stay in this state */
  93. break;
  94. default:
  95. *sof_read = 0;
  96. }
  97. break;
  98. case 3:
  99. if (m[i] == 0xff)
  100. *sof_read = 4;
  101. else
  102. *sof_read = 0;
  103. break;
  104. case 4:
  105. switch (m[i]) {
  106. case 0x96:
  107. /* Pattern found */
  108. PDEBUG(D_FRAM,
  109. "SOF found, bytes to analyze: %u."
  110. " Frame starts at byte #%u",
  111. len, i + 1);
  112. *sof_read = 0;
  113. return m + i + 1;
  114. break;
  115. case 0xff:
  116. *sof_read = 2;
  117. break;
  118. default:
  119. *sof_read = 0;
  120. }
  121. break;
  122. default:
  123. *sof_read = 0;
  124. }
  125. }
  126. return NULL;
  127. }