ov2640_sharpness.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include <stdint.h>
  2. #include "esp_camera.h"
  3. #include "ov2640_sharpness.h"
  4. const static uint8_t OV2640_SHARPNESS_AUTO[]=
  5. {
  6. //reg, val, mask
  7. 0xFF, 0x00, 0xFF,
  8. 0x92, 0x01, 0xFF,
  9. 0x93, 0x20, 0x20,
  10. 0x00, 0x00, 0x00
  11. };
  12. const static uint8_t OV2640_SHARPNESS_MANUAL[]=
  13. {
  14. //reg, val, mask
  15. 0xFF, 0x00, 0xFF,
  16. 0x92, 0x01, 0xFF,
  17. 0x93, 0x00, 0x20,
  18. 0x00, 0x00, 0x00
  19. };
  20. const static uint8_t OV2640_SHARPNESS_LEVEL0[]=
  21. {
  22. //reg, val, mask
  23. 0xFF, 0x00, 0xFF,
  24. 0x92, 0x01, 0xFF,
  25. 0x93, 0xC0, 0x1F,
  26. 0x00, 0x00, 0x00
  27. };
  28. const static uint8_t OV2640_SHARPNESS_LEVEL1[]=
  29. {
  30. //reg, val, mask
  31. 0xFF, 0x00, 0xFF,
  32. 0x92, 0x01, 0xFF,
  33. 0x93, 0xC1, 0x1F,
  34. 0x00, 0x00, 0x00
  35. };
  36. const static uint8_t OV2640_SHARPNESS_LEVEL2[]=
  37. {
  38. //reg, val, mask
  39. 0xFF, 0x00, 0xFF,
  40. 0x92, 0x01, 0xFF,
  41. 0x93, 0xC2, 0x1F,
  42. 0x00, 0x00, 0x00
  43. };
  44. const static uint8_t OV2640_SHARPNESS_LEVEL3[]=
  45. {
  46. //reg, val, mask
  47. 0xFF, 0x00, 0xFF,
  48. 0x92, 0x01, 0xFF,
  49. 0x93, 0xC4, 0x1F,
  50. 0x00, 0x00, 0x00
  51. };
  52. const static uint8_t OV2640_SHARPNESS_LEVEL4[]=
  53. {
  54. //reg, val, mask
  55. 0xFF, 0x00, 0xFF,
  56. 0x92, 0x01, 0xFF,
  57. 0x93, 0xC8, 0x1F,
  58. 0x00, 0x00, 0x00
  59. };
  60. const static uint8_t OV2640_SHARPNESS_LEVEL5[]=
  61. {
  62. //reg, val, mask
  63. 0xFF, 0x00, 0xFF,
  64. 0x92, 0x01, 0xFF,
  65. 0x93, 0xD0, 0x1F,
  66. 0x00, 0x00, 0x00
  67. };
  68. const static uint8_t OV2640_SHARPNESS_LEVEL6[]=
  69. {
  70. //reg, val, mask
  71. 0xFF, 0x00, 0xFF,
  72. 0x92, 0x01, 0xFF,
  73. 0x93, 0xDF, 0x1F,
  74. 0x00, 0x00, 0x00
  75. };
  76. const static uint8_t *OV2640_SETTING_SHARPNESS[]=
  77. {
  78. OV2640_SHARPNESS_LEVEL0, // -3 sharpness
  79. OV2640_SHARPNESS_LEVEL1,
  80. OV2640_SHARPNESS_LEVEL2,
  81. OV2640_SHARPNESS_LEVEL3,
  82. OV2640_SHARPNESS_LEVEL4,
  83. OV2640_SHARPNESS_LEVEL5,
  84. OV2640_SHARPNESS_LEVEL6 // +3 sharpness
  85. };
  86. #define OV2640_MAXLEVEL_SHARPNESS 6
  87. static int table_mask_write(sensor_t *sensor, const uint8_t* ptab)
  88. {
  89. uint8_t address;
  90. uint8_t value;
  91. uint8_t orgval;
  92. uint8_t mask;
  93. const uint8_t *pdata = ptab;
  94. if (pdata == NULL)
  95. {
  96. return -1;
  97. }
  98. while (1)
  99. {
  100. address = *pdata++;
  101. value = *pdata++;
  102. mask = *pdata++;
  103. if ((address == 0) && (value == 0) && (mask == 0))
  104. {
  105. break;
  106. }
  107. sensor->set_reg(sensor, address, mask, value);
  108. }
  109. return 0;
  110. }
  111. int ov2640_enable_auto_sharpness(sensor_t *sensor)
  112. {
  113. table_mask_write(sensor, OV2640_SHARPNESS_AUTO);
  114. return 0;
  115. }
  116. int ov2640_set_sharpness(sensor_t *sensor, int sharpness)
  117. {
  118. int sharpness_temp = 0;
  119. if (sharpness < -3)
  120. {
  121. sharpness_temp = -3;
  122. }
  123. if (sharpness > OV2640_MAXLEVEL_SHARPNESS - 3)
  124. {
  125. sharpness_temp = OV2640_MAXLEVEL_SHARPNESS - 3;
  126. }
  127. table_mask_write(sensor, OV2640_SHARPNESS_MANUAL);
  128. table_mask_write(sensor, OV2640_SETTING_SHARPNESS[sharpness_temp + 3]);
  129. return 0;
  130. }