123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #include "camera.h"
- static void ov_camera_pw_gpio_init(void);
- static void ov_camera_pw_on(void);
- static void ov_camera_pw_off(void);
- static const char *TAG = "camera";
- camera_fb_t *pic;
- static camera_config_t camera_config = {
- .pin_pwdn = -1,
- .pin_reset = CAM_RST_PIN,
- .pin_xclk = CAM_XCLK_PIN,
- .pin_sscb_sda = CAM_SDA_PIN,
- .pin_sscb_scl = CAM_SCL_PIN,
- .pin_d7 = CAM_D7_PIN,
- .pin_d6 = CAM_D6_PIN,
- .pin_d5 = CAM_D5_PIN,
- .pin_d4 = CAM_D4_PIN,
- .pin_d3 = CAM_D3_PIN,
- .pin_d2 = CAM_D2_PIN,
- .pin_d1 = CAM_D1_PIN,
- .pin_d0 = CAM_D0_PIN,
- .pin_vsync = CAM_VSYNC_PIN,
- .pin_href = CAM_HREF_PIN,
- .pin_pclk = CAM_PCLK_PIN,
- //XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
- .xclk_freq_hz = CONFIG_CAM_XCLK_FREQ,
- .pixel_format = PIXFORMAT_JPEG, //YUV422,GRAYSCALE,RGB565,JPEG
- .frame_size = FRAMESIZE_SVGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG
- .jpeg_quality = JPG_QUALITY, //0-63 lower number means higher quality
- .fb_count = 1, //if more than one, i2s runs in continuous mode. Use only with JPEG
- .grab_mode = CAMERA_GRAB_WHEN_EMPTY,
- };
- static void camera_task(void)
- {
- while (1)
- {
- ESP_LOGI(TAG, "Taking picture...");
- camera_fb_t *pic = esp_camera_fb_get();
- // use pic->buf to access the image
- ESP_LOGI(TAG, "Picture taken! Its size was: %zu bytes", pic->len);
- esp_camera_fb_return(pic);
- vTaskDelay(5000 / portTICK_RATE_MS);
- }
- }
- esp_err_t camera_run(void)
- {
- ESP_LOGD(TAG, "Taking picture...");
- pic = esp_camera_fb_get();
- if(pic == NULL)
- {
- return ESP_FAIL;
- }
- // use pic->buf to access the image
- ESP_LOGD(TAG, "Picture taken! Its size was: %zu bytes", pic->len);
- return ESP_OK;
- }
- void camera_stop(void)
- {
- esp_camera_fb_return(pic);
- }
- uint8_t * camera_get_fb(void)
- {
- return pic->buf;
- }
- size_t camera_get_data_size(void)
- {
- return pic->len;
- }
- esp_err_t init_camera(void)
- {
- ov_camera_pw_gpio_init();
- ov_camera_pw_on();
- //initialize the camera
- esp_err_t err = esp_camera_init(&camera_config);
- if (err != ESP_OK)
- {
- ESP_LOGE(TAG, "Camera Init Failed");
- return err;
- }
- return ESP_OK;
- }
- static void ov_camera_pw_gpio_init(void)
- {
- #ifdef CONFIG_OV2640_SUPPORT
- uint64_t ov2640_output_gpio = ((1ULL<<CONFIG_CAM_PW_GPIO));
- //zero-initialize the config structure.
- gpio_config_t io_conf;
- //disable interrupt
- io_conf.intr_type = GPIO_INTR_DISABLE;
- //set as output mode
- io_conf.mode = GPIO_MODE_OUTPUT;
- //bit mask of the pins that you want to set
- io_conf.pin_bit_mask = ov2640_output_gpio;
- //disable pull-down mode
- io_conf.pull_down_en = 0;
- //disable pull-up mode
- io_conf.pull_up_en = 0;
- //configure GPIO with the given settings
- gpio_config(&io_conf);
- #endif
- }
- static void ov_camera_pw_on(void)
- {
- #ifdef CONFIG_OV2640_SUPPORT
- gpio_set_level(CONFIG_CAM_PW_GPIO, CONFIG_CAM_PW_ON_LEVEL?1:0);
- #endif
- vTaskDelay(100 / portTICK_PERIOD_MS);
- }
- static void ov_camera_pw_off(void)
- {
- #ifdef CONFIG_OV2640_SUPPORT
- gpio_set_level(CONFIG_CAM_PW_GPIO, CONFIG_CAM_PW_ON_LEVEL?0:1);
- #endif
- }
|