pac_common.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Pixart PAC207BCA / PAC73xx common functions
  4. *
  5. * Copyright (C) 2008 Hans de Goede <[email protected]>
  6. * Copyright (C) 2005 Thomas Kaiser [email protected]
  7. * Copyleft (C) 2005 Michel Xhaard [email protected]
  8. *
  9. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  10. */
  11. /* We calculate the autogain at the end of the transfer of a frame, at this
  12. moment a frame with the old settings is being captured and transmitted. So
  13. if we adjust the gain or exposure we must ignore at least the next frame for
  14. the new settings to come into effect before doing any other adjustments. */
  15. #define PAC_AUTOGAIN_IGNORE_FRAMES 2
  16. static const unsigned char pac_sof_marker[5] =
  17. { 0xff, 0xff, 0x00, 0xff, 0x96 };
  18. /*
  19. The following state machine finds the SOF marker sequence
  20. 0xff, 0xff, 0x00, 0xff, 0x96 in a byte stream.
  21. +----------+
  22. | 0: START |<---------------\
  23. +----------+<-\ |
  24. | \---/otherwise |
  25. v 0xff |
  26. +----------+ otherwise |
  27. | 1 |--------------->*
  28. | | ^
  29. +----------+ |
  30. | |
  31. v 0xff |
  32. +----------+<-\0xff |
  33. /->| |--/ |
  34. | | 2 |--------------->*
  35. | | | otherwise ^
  36. | +----------+ |
  37. | | |
  38. | v 0x00 |
  39. | +----------+ |
  40. | | 3 | |
  41. | | |--------------->*
  42. | +----------+ otherwise ^
  43. | | |
  44. 0xff | v 0xff |
  45. | +----------+ |
  46. \--| 4 | |
  47. | |----------------/
  48. +----------+ otherwise
  49. |
  50. v 0x96
  51. +----------+
  52. | FOUND |
  53. +----------+
  54. */
  55. static unsigned char *pac_find_sof(struct gspca_dev *gspca_dev, u8 *sof_read,
  56. unsigned char *m, int len)
  57. {
  58. int i;
  59. /* Search for the SOF marker (fixed part) in the header */
  60. for (i = 0; i < len; i++) {
  61. switch (*sof_read) {
  62. case 0:
  63. if (m[i] == 0xff)
  64. *sof_read = 1;
  65. break;
  66. case 1:
  67. if (m[i] == 0xff)
  68. *sof_read = 2;
  69. else
  70. *sof_read = 0;
  71. break;
  72. case 2:
  73. switch (m[i]) {
  74. case 0x00:
  75. *sof_read = 3;
  76. break;
  77. case 0xff:
  78. /* stay in this state */
  79. break;
  80. default:
  81. *sof_read = 0;
  82. }
  83. break;
  84. case 3:
  85. if (m[i] == 0xff)
  86. *sof_read = 4;
  87. else
  88. *sof_read = 0;
  89. break;
  90. case 4:
  91. switch (m[i]) {
  92. case 0x96:
  93. /* Pattern found */
  94. gspca_dbg(gspca_dev, D_FRAM,
  95. "SOF found, bytes to analyze: %u - Frame starts at byte #%u\n",
  96. len, i + 1);
  97. *sof_read = 0;
  98. return m + i + 1;
  99. break;
  100. case 0xff:
  101. *sof_read = 2;
  102. break;
  103. default:
  104. *sof_read = 0;
  105. }
  106. break;
  107. default:
  108. *sof_read = 0;
  109. }
  110. }
  111. return NULL;
  112. }