xclk.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "driver/gpio.h"
  2. #include "driver/ledc.h"
  3. #include "esp_err.h"
  4. #include "esp_log.h"
  5. #include "xclk.h"
  6. #if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
  7. #include "esp32-hal-log.h"
  8. #else
  9. #include "esp_log.h"
  10. static const char* TAG = "camera_xclk";
  11. #endif
  12. esp_err_t camera_enable_out_clock(camera_config_t* config)
  13. {
  14. periph_module_enable(PERIPH_LEDC_MODULE);
  15. ledc_timer_config_t timer_conf;
  16. timer_conf.duty_resolution = 2;
  17. timer_conf.freq_hz = config->xclk_freq_hz;
  18. timer_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
  19. timer_conf.timer_num = config->ledc_timer;
  20. timer_conf.clk_cfg = LEDC_USE_APB_CLK;
  21. esp_err_t err = ledc_timer_config(&timer_conf);
  22. if (err != ESP_OK) {
  23. ESP_LOGE(TAG, "ledc_timer_config failed, rc=%x", err);
  24. return err;
  25. }
  26. ledc_channel_config_t ch_conf;
  27. ch_conf.gpio_num = config->pin_xclk;
  28. ch_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
  29. ch_conf.channel = config->ledc_channel;
  30. ch_conf.intr_type = LEDC_INTR_DISABLE;
  31. ch_conf.timer_sel = config->ledc_timer;
  32. ch_conf.duty = 2;
  33. ch_conf.hpoint = 0;
  34. err = ledc_channel_config(&ch_conf);
  35. if (err != ESP_OK) {
  36. ESP_LOGE(TAG, "ledc_channel_config failed, rc=%x", err);
  37. return err;
  38. }
  39. return ESP_OK;
  40. }
  41. void camera_disable_out_clock()
  42. {
  43. periph_module_disable(PERIPH_LEDC_MODULE);
  44. }