esp_camera.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /*
  15. * Example Use
  16. *
  17. static camera_config_t camera_example_config = {
  18. .pin_pwdn = PIN_PWDN,
  19. .pin_reset = PIN_RESET,
  20. .pin_xclk = PIN_XCLK,
  21. .pin_sscb_sda = PIN_SIOD,
  22. .pin_sscb_scl = PIN_SIOC,
  23. .pin_d7 = PIN_D7,
  24. .pin_d6 = PIN_D6,
  25. .pin_d5 = PIN_D5,
  26. .pin_d4 = PIN_D4,
  27. .pin_d3 = PIN_D3,
  28. .pin_d2 = PIN_D2,
  29. .pin_d1 = PIN_D1,
  30. .pin_d0 = PIN_D0,
  31. .pin_vsync = PIN_VSYNC,
  32. .pin_href = PIN_HREF,
  33. .pin_pclk = PIN_PCLK,
  34. .xclk_freq_hz = 20000000,
  35. .ledc_timer = LEDC_TIMER_0,
  36. .ledc_channel = LEDC_CHANNEL_0,
  37. .pixel_format = PIXFORMAT_JPEG,
  38. .frame_size = FRAMESIZE_SVGA,
  39. .jpeg_quality = 10,
  40. .fb_count = 2
  41. };
  42. esp_err_t camera_example_init(){
  43. return esp_camera_init(&camera_example_config);
  44. }
  45. esp_err_t camera_example_capture(){
  46. //capture a frame
  47. camera_fb_t * fb = esp_camera_fb_get();
  48. if (!fb) {
  49. ESP_LOGE(TAG, "Frame buffer could not be acquired");
  50. return ESP_FAIL;
  51. }
  52. //replace this with your own function
  53. display_image(fb->width, fb->height, fb->pixformat, fb->buf, fb->len);
  54. //return the frame buffer back to be reused
  55. esp_camera_fb_return(fb);
  56. return ESP_OK;
  57. }
  58. */
  59. #pragma once
  60. #include "esp_err.h"
  61. //在esp_camera.h中定义了CONFIG_OV2640_SUPPORT 用于选择摄像头型号
  62. #define CONFIG_OV2640_SUPPORT 1
  63. #include "driver/ledc.h"
  64. #include "sensor.h"
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. /**
  69. * @brief Configuration structure for camera initialization
  70. */
  71. typedef struct {
  72. int pin_pwdn; /*!< GPIO pin for camera power down line */
  73. int pin_reset; /*!< GPIO pin for camera reset line */
  74. int pin_xclk; /*!< GPIO pin for camera XCLK line */
  75. int pin_sscb_sda; /*!< GPIO pin for camera SDA line */
  76. int pin_sscb_scl; /*!< GPIO pin for camera SCL line */
  77. int pin_d7; /*!< GPIO pin for camera D7 line */
  78. int pin_d6; /*!< GPIO pin for camera D6 line */
  79. int pin_d5; /*!< GPIO pin for camera D5 line */
  80. int pin_d4; /*!< GPIO pin for camera D4 line */
  81. int pin_d3; /*!< GPIO pin for camera D3 line */
  82. int pin_d2; /*!< GPIO pin for camera D2 line */
  83. int pin_d1; /*!< GPIO pin for camera D1 line */
  84. int pin_d0; /*!< GPIO pin for camera D0 line */
  85. int pin_vsync; /*!< GPIO pin for camera VSYNC line */
  86. int pin_href; /*!< GPIO pin for camera HREF line */
  87. int pin_pclk; /*!< GPIO pin for camera PCLK line */
  88. int xclk_freq_hz; /*!< Frequency of XCLK signal, in Hz. Either 20KHz or 10KHz for OV2640 double FPS (Experimental) */
  89. ledc_timer_t ledc_timer; /*!< LEDC timer to be used for generating XCLK */
  90. ledc_channel_t ledc_channel; /*!< LEDC channel to be used for generating XCLK */
  91. pixformat_t pixel_format; /*!< Format of the pixel data: PIXFORMAT_ + YUV422|GRAYSCALE|RGB565|JPEG */
  92. framesize_t frame_size; /*!< Size of the output image: FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA */
  93. int jpeg_quality; /*!< Quality of JPEG output. 0-63 lower means higher quality */
  94. size_t fb_count; /*!< Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed) */
  95. } camera_config_t;
  96. /**
  97. * @brief Data structure of camera frame buffer
  98. */
  99. typedef struct {
  100. uint8_t * buf; /*!< Pointer to the pixel data */
  101. size_t len; /*!< Length of the buffer in bytes */
  102. size_t width; /*!< Width of the buffer in pixels */
  103. size_t height; /*!< Height of the buffer in pixels */
  104. pixformat_t format; /*!< Format of the pixel data */
  105. } camera_fb_t;
  106. #define ESP_ERR_CAMERA_BASE 0x20000
  107. #define ESP_ERR_CAMERA_NOT_DETECTED (ESP_ERR_CAMERA_BASE + 1)
  108. #define ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE (ESP_ERR_CAMERA_BASE + 2)
  109. #define ESP_ERR_CAMERA_FAILED_TO_SET_OUT_FORMAT (ESP_ERR_CAMERA_BASE + 3)
  110. #define ESP_ERR_CAMERA_NOT_SUPPORTED (ESP_ERR_CAMERA_BASE + 4)
  111. /**
  112. * @brief Initialize the camera driver
  113. *
  114. * @note call camera_probe before calling this function
  115. *
  116. * This function detects and configures camera over I2C interface,
  117. * allocates framebuffer and DMA buffers,
  118. * initializes parallel I2S input, and sets up DMA descriptors.
  119. *
  120. * Currently this function can only be called once and there is
  121. * no way to de-initialize this module.
  122. *
  123. * @param config Camera configuration parameters
  124. *
  125. * @return ESP_OK on success
  126. */
  127. esp_err_t esp_camera_init(const camera_config_t* config);
  128. /**
  129. * @brief Deinitialize the camera driver
  130. *
  131. * @return
  132. * - ESP_OK on success
  133. * - ESP_ERR_INVALID_STATE if the driver hasn't been initialized yet
  134. */
  135. esp_err_t esp_camera_deinit();
  136. /**
  137. * @brief Obtain pointer to a frame buffer.
  138. *
  139. * @return pointer to the frame buffer
  140. */
  141. camera_fb_t* esp_camera_fb_get();
  142. /**
  143. * @brief Return the frame buffer to be reused again.
  144. *
  145. * @param fb Pointer to the frame buffer
  146. */
  147. void esp_camera_fb_return(camera_fb_t * fb);
  148. /**
  149. * @brief Get a pointer to the image sensor control structure
  150. *
  151. * @return pointer to the sensor
  152. */
  153. sensor_t * esp_camera_sensor_get();
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #include "img_converters.h"