ov2640_sharpness.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <stdint.h>
  2. #include "esp_camera.h"
  3. #include "ov2640_sharpness.h"
  4. #define OV2640_MAXLEVEL_SHARPNESS 6
  5. const static uint8_t OV2640_SHARPNESS_AUTO[]=
  6. {
  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. 0xFF, 0x00, 0xff,
  15. 0x92, 0x01, 0xff,
  16. 0x93, 0x00, 0x20,
  17. 0x00, 0x00, 0x00
  18. };
  19. const static uint8_t OV2640_SHARPNESS_LEVEL0[]=
  20. {
  21. 0xFF, 0x00, 0xff,
  22. 0x92, 0x01, 0xff,
  23. 0x93, 0xc0, 0x1f,
  24. 0x00, 0x00, 0x00
  25. };
  26. const static uint8_t OV2640_SHARPNESS_LEVEL1[]=
  27. {
  28. 0xFF, 0x00, 0xff,
  29. 0x92, 0x01, 0xff,
  30. 0x93, 0xc1, 0x1f,
  31. 0x00, 0x00, 0x00
  32. };
  33. const static uint8_t OV2640_SHARPNESS_LEVEL2[]=
  34. {
  35. 0xFF, 0x00, 0xff,
  36. 0x92, 0x01, 0xff,
  37. 0x93, 0xc2, 0x1f,
  38. 0x00, 0x00, 0x00
  39. };
  40. const static uint8_t OV2640_SHARPNESS_LEVEL3[]=
  41. {
  42. 0xFF, 0x00, 0xff,
  43. 0x92, 0x01, 0xff,
  44. 0x93, 0xc4, 0x1f,
  45. 0x00, 0x00, 0x00
  46. };
  47. const static uint8_t OV2640_SHARPNESS_LEVEL4[]=
  48. {
  49. 0xFF, 0x00, 0xff,
  50. 0x92, 0x01, 0xff,
  51. 0x93, 0xc8, 0x1f,
  52. 0x00, 0x00, 0x00
  53. };
  54. const static uint8_t OV2640_SHARPNESS_LEVEL5[]=
  55. {
  56. 0xFF, 0x00, 0xff,
  57. 0x92, 0x01, 0xff,
  58. 0x93, 0xd0, 0x1f,
  59. 0x00, 0x00, 0x00
  60. };
  61. const static uint8_t OV2640_SHARPNESS_LEVEL6[]=
  62. {
  63. 0xFF, 0x00, 0xff,
  64. 0x92, 0x01, 0xff,
  65. 0x93, 0xdf, 0x1f,
  66. 0x00, 0x00, 0x00
  67. };
  68. const static uint8_t *OV2640_SETTING_SHARPNESS[]=
  69. {
  70. OV2640_SHARPNESS_LEVEL0, // -3 sharpness
  71. OV2640_SHARPNESS_LEVEL1,
  72. OV2640_SHARPNESS_LEVEL2,
  73. OV2640_SHARPNESS_LEVEL3,
  74. OV2640_SHARPNESS_LEVEL4,
  75. OV2640_SHARPNESS_LEVEL5,
  76. OV2640_SHARPNESS_LEVEL6 // +3 sharpness
  77. };
  78. static int table_mask_write(sensor_t *sensor, const uint8_t* ptab)
  79. {
  80. uint8_t address;
  81. uint8_t value;
  82. uint8_t orgval;
  83. uint8_t mask;
  84. const uint8_t *pdata = ptab;
  85. if (pdata == NULL)
  86. return -1;
  87. while (1)
  88. {
  89. address = *pdata++;
  90. value = *pdata++;
  91. mask = *pdata++;
  92. if ((address == 0) && (value == 0) && (mask == 0))
  93. break;
  94. sensor->set_reg(sensor, address, mask, value);
  95. }
  96. return 0;
  97. }
  98. int ov2640_enable_auto_sharpness(sensor_t *sensor)
  99. {
  100. table_mask_write(sensor, OV2640_SHARPNESS_AUTO);
  101. return 0;
  102. }
  103. int ov2640_set_sharpness(sensor_t *sensor, int sharpness)
  104. {
  105. if ((sharpness < -3) || (sharpness > OV2640_MAXLEVEL_SHARPNESS - 3))
  106. return -1;
  107. table_mask_write(sensor, OV2640_SHARPNESS_MANUAL);
  108. table_mask_write(sensor, OV2640_SETTING_SHARPNESS[sharpness + 3]);
  109. return 0;
  110. }