You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.7 KiB

3 years ago
  1. #include "who_camera.h"
  2. #include "esp_log.h"
  3. #include "esp_system.h"
  4. static const char *TAG = "who_camera";
  5. static QueueHandle_t xQueueFrameO = NULL;
  6. static void task_process_handler(void *arg)
  7. {
  8. while (true)
  9. {
  10. camera_fb_t *frame = esp_camera_fb_get();
  11. if (frame)
  12. xQueueSend(xQueueFrameO, &frame, portMAX_DELAY);
  13. }
  14. }
  15. void register_camera(const pixformat_t pixel_fromat,
  16. const framesize_t frame_size,
  17. const uint8_t fb_count,
  18. const QueueHandle_t frame_o)
  19. {
  20. ESP_LOGI(TAG, "Camera module is %s", CAMERA_MODULE_NAME);
  21. #if CONFIG_CAMERA_MODULE_ESP_EYE || CONFIG_CAMERA_MODULE_ESP32_CAM_BOARD
  22. /* IO13, IO14 is designed for JTAG by default,
  23. * to use it as generalized input,
  24. * firstly declair it as pullup input */
  25. gpio_config_t conf;
  26. conf.mode = GPIO_MODE_INPUT;
  27. conf.pull_up_en = GPIO_PULLUP_ENABLE;
  28. conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
  29. conf.intr_type = GPIO_INTR_DISABLE;
  30. conf.pin_bit_mask = 1LL << 13;
  31. gpio_config(&conf);
  32. conf.pin_bit_mask = 1LL << 14;
  33. gpio_config(&conf);
  34. #endif
  35. camera_config_t config;
  36. config.ledc_channel = LEDC_CHANNEL_0;
  37. config.ledc_timer = LEDC_TIMER_0;
  38. config.pin_d0 = CAMERA_PIN_D0;
  39. config.pin_d1 = CAMERA_PIN_D1;
  40. config.pin_d2 = CAMERA_PIN_D2;
  41. config.pin_d3 = CAMERA_PIN_D3;
  42. config.pin_d4 = CAMERA_PIN_D4;
  43. config.pin_d5 = CAMERA_PIN_D5;
  44. config.pin_d6 = CAMERA_PIN_D6;
  45. config.pin_d7 = CAMERA_PIN_D7;
  46. config.pin_xclk = CAMERA_PIN_XCLK;
  47. config.pin_pclk = CAMERA_PIN_PCLK;
  48. config.pin_vsync = CAMERA_PIN_VSYNC;
  49. config.pin_href = CAMERA_PIN_HREF;
  50. config.pin_sscb_sda = CAMERA_PIN_SIOD;
  51. config.pin_sscb_scl = CAMERA_PIN_SIOC;
  52. config.pin_pwdn = CAMERA_PIN_PWDN;
  53. config.pin_reset = CAMERA_PIN_RESET;
  54. config.xclk_freq_hz = XCLK_FREQ_HZ;
  55. config.pixel_format = pixel_fromat;
  56. config.frame_size = frame_size;
  57. config.jpeg_quality = 12;
  58. config.fb_count = fb_count;
  59. config.fb_location = CAMERA_FB_IN_PSRAM;
  60. config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  61. // camera init
  62. esp_err_t err = esp_camera_init(&config);
  63. if (err != ESP_OK)
  64. {
  65. ESP_LOGE(TAG, "Camera init failed with error 0x%x", err);
  66. return;
  67. }
  68. sensor_t *s = esp_camera_sensor_get();
  69. s->set_vflip(s, 1); //flip it back
  70. //initial sensors are flipped vertically and colors are a bit saturated
  71. if (s->id.PID == OV3660_PID)
  72. {
  73. s->set_brightness(s, 1); //up the blightness just a bit
  74. s->set_saturation(s, -2); //lower the saturation
  75. }
  76. xQueueFrameO = frame_o;
  77. xTaskCreatePinnedToCore(task_process_handler, TAG, 2 * 1024, NULL, 5, NULL, 1);
  78. }