feat: support USB Camera (#1519)
Some checks failed
Build Boards / Determine variants to build (push) Has been cancelled
Build Boards / Build ${{ matrix.name }} (push) Has been cancelled

This commit is contained in:
laride 2025-12-11 07:10:12 +08:00 committed by GitHub
parent 1f0d2e993b
commit 4b582f8074
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 113 additions and 5 deletions

View File

@ -6,6 +6,7 @@
#include "button.h" #include "button.h"
#include "config.h" #include "config.h"
#include "backlight.h" #include "backlight.h"
#include "esp32_camera.h"
#include <esp_log.h> #include <esp_log.h>
@ -379,7 +380,7 @@ private:
SemaphoreHandle_t touch_isr_mux_; SemaphoreHandle_t touch_isr_mux_;
}; };
class EspS3Cat : public WifiBoard { class EchoEar : public WifiBoard {
private: private:
i2c_master_bus_handle_t i2c_bus_; i2c_master_bus_handle_t i2c_bus_;
Cst816s* cst816s_; Cst816s* cst816s_;
@ -389,6 +390,7 @@ private:
PwmBacklight* backlight_ = nullptr; PwmBacklight* backlight_ = nullptr;
esp_timer_handle_t touchpad_timer_; esp_timer_handle_t touchpad_timer_;
esp_lcd_touch_handle_t tp; // LCD touch handle esp_lcd_touch_handle_t tp; // LCD touch handle
Esp32Camera* camera_ = nullptr;
void InitializeI2c() void InitializeI2c()
{ {
@ -467,7 +469,7 @@ private:
while (true) { while (true) {
if (touchpad->WaitForTouchEvent()) { if (touchpad->WaitForTouchEvent()) {
auto &app = Application::GetInstance(); auto &app = Application::GetInstance();
auto &board = (EspS3Cat &)Board::GetInstance(); auto &board = (EchoEar &)Board::GetInstance();
ESP_LOGI(TAG, "Touch event, TP_PIN_NUM_INT: %d", gpio_get_level(TP_PIN_NUM_INT)); ESP_LOGI(TAG, "Touch event, TP_PIN_NUM_INT: %d", gpio_get_level(TP_PIN_NUM_INT));
touchpad->UpdateTouchPoint(); touchpad->UpdateTouchPoint();
@ -505,7 +507,7 @@ private:
gpio_config(&int_gpio_config); gpio_config(&int_gpio_config);
gpio_install_isr_service(0); gpio_install_isr_service(0);
gpio_intr_enable(TP_PIN_NUM_INT); gpio_intr_enable(TP_PIN_NUM_INT);
gpio_isr_handler_add(TP_PIN_NUM_INT, EspS3Cat::touch_isr_callback, cst816s_); gpio_isr_handler_add(TP_PIN_NUM_INT, EchoEar::touch_isr_callback, cst816s_);
} }
void InitializeSpi() void InitializeSpi()
@ -582,8 +584,33 @@ private:
gpio_set_level(POWER_CTRL, 0); gpio_set_level(POWER_CTRL, 0);
} }
#ifdef CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
void InitializeCamera() {
esp_video_init_usb_uvc_config_t usb_uvc_config = {
.uvc = {
.uvc_dev_num = 1,
.task_stack = 4096,
.task_priority = 5,
.task_affinity = -1,
},
.usb = {
.init_usb_host_lib = true,
.task_stack = 4096,
.task_priority = 5,
.task_affinity = -1,
},
};
esp_video_init_config_t video_config = {
.usb_uvc = &usb_uvc_config,
};
camera_ = new Esp32Camera(video_config);
}
#endif // CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
public: public:
EspS3Cat() : boot_button_(BOOT_BUTTON_GPIO) EchoEar() : boot_button_(BOOT_BUTTON_GPIO)
{ {
InitializeI2c(); InitializeI2c();
uint8_t pcb_verison = DetectPcbVersion(); uint8_t pcb_verison = DetectPcbVersion();
@ -593,6 +620,9 @@ public:
InitializeSpi(); InitializeSpi();
Initializest77916Display(pcb_verison); Initializest77916Display(pcb_verison);
InitializeButtons(); InitializeButtons();
#ifdef CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
InitializeCamera();
#endif // CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
} }
virtual AudioCodec* GetAudioCodec() override virtual AudioCodec* GetAudioCodec() override
@ -627,6 +657,10 @@ public:
{ {
return backlight_; return backlight_;
} }
virtual Camera* GetCamera() override {
return camera_;
}
}; };
DECLARE_BOARD(EspS3Cat); DECLARE_BOARD(EchoEar);

View File

@ -5,6 +5,7 @@
#include "button.h" #include "button.h"
#include "led/single_led.h" #include "led/single_led.h"
#include "pin_config.h" #include "pin_config.h"
#include "esp32_camera.h"
#include "config.h" #include "config.h"
@ -26,6 +27,8 @@ private:
i2c_master_bus_handle_t i2c_bus_; i2c_master_bus_handle_t i2c_bus_;
Button boot_button_; Button boot_button_;
LcdDisplay* display_; LcdDisplay* display_;
Esp32Camera* camera_;
//add support ev board lcd //add support ev board lcd
esp_io_expander_handle_t expander = NULL; esp_io_expander_handle_t expander = NULL;
@ -195,12 +198,39 @@ private:
lvgl_port_add_touch(&touch_cfg); lvgl_port_add_touch(&touch_cfg);
} }
#ifdef CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
void InitializeCamera() {
esp_video_init_usb_uvc_config_t usb_uvc_config = {
.uvc = {
.uvc_dev_num = 1,
.task_stack = 4096,
.task_priority = 5,
.task_affinity = -1,
},
.usb = {
.init_usb_host_lib = true,
.task_stack = 4096,
.task_priority = 5,
.task_affinity = -1,
},
};
}
esp_video_init_config_t video_config = {
.usb_uvc = &usb_uvc_config,
};
camera_ = new Esp32Camera(video_config);
}
#endif // CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
public: public:
ESP_S3_LCD_EV_Board_2() : boot_button_(BOOT_BUTTON_GPIO) { ESP_S3_LCD_EV_Board_2() : boot_button_(BOOT_BUTTON_GPIO) {
InitializeCodecI2c(); InitializeCodecI2c();
InitializeButtons(); InitializeButtons();
InitializeRGB_GC9503V_Display(); InitializeRGB_GC9503V_Display();
InitializeTouch(); InitializeTouch();
#ifdef CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
InitializeCamera();
#endif // CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
} }
virtual AudioCodec* GetAudioCodec() override { virtual AudioCodec* GetAudioCodec() override {
@ -230,6 +260,12 @@ public:
return &led; return &led;
} }
#ifdef CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
virtual Camera* GetCamera() override {
return camera_;
}
#endif // CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
}; };
DECLARE_BOARD(ESP_S3_LCD_EV_Board_2); DECLARE_BOARD(ESP_S3_LCD_EV_Board_2);

View File

@ -5,6 +5,7 @@
#include "button.h" #include "button.h"
#include "led/single_led.h" #include "led/single_led.h"
#include "pin_config.h" #include "pin_config.h"
#include "esp32_camera.h"
#include "config.h" #include "config.h"
@ -24,6 +25,7 @@ private:
i2c_master_bus_handle_t codec_i2c_bus_; i2c_master_bus_handle_t codec_i2c_bus_;
Button boot_button_; Button boot_button_;
LcdDisplay* display_; LcdDisplay* display_;
Esp32Camera* camera_;
//add support ev board lcd //add support ev board lcd
esp_io_expander_handle_t expander = NULL; esp_io_expander_handle_t expander = NULL;
@ -165,11 +167,39 @@ private:
}); });
} }
#ifdef CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
void InitializeCamera() {
esp_video_init_usb_uvc_config_t usb_uvc_config = {
.uvc = {
.uvc_dev_num = 1,
.task_stack = 4096,
.task_priority = 5,
.task_affinity = -1,
},
.usb = {
.init_usb_host_lib = true,
.task_stack = 4096,
.task_priority = 5,
.task_affinity = -1,
},
};
esp_video_init_config_t video_config = {
.usb_uvc = &usb_uvc_config,
};
camera_ = new Esp32Camera(video_config);
}
#endif // CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
public: public:
ESP_S3_LCD_EV_Board() : boot_button_(BOOT_BUTTON_GPIO) { ESP_S3_LCD_EV_Board() : boot_button_(BOOT_BUTTON_GPIO) {
InitializeCodecI2c(); InitializeCodecI2c();
InitializeButtons(); InitializeButtons();
InitializeRGB_GC9503V_Display(); InitializeRGB_GC9503V_Display();
#ifdef CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
InitializeCamera();
#endif // CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
} }
virtual AudioCodec* GetAudioCodec() override { virtual AudioCodec* GetAudioCodec() override {
@ -199,6 +229,12 @@ public:
return &led; return &led;
} }
#ifdef CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
virtual Camera* GetCamera() override {
return camera_;
}
#endif // CONFIG_ESP_VIDEO_ENABLE_USB_UVC_VIDEO_DEVICE
}; };
DECLARE_BOARD(ESP_S3_LCD_EV_Board); DECLARE_BOARD(ESP_S3_LCD_EV_Board);

View File

@ -25,5 +25,7 @@ CONFIG_SR_WN_WN9_NIHAOXIAOZHI_TTS=y
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096 CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096
CONFIG_USB_HOST_CONTROL_TRANSFER_MAX_SIZE=1536
# LVGL Graphics # LVGL Graphics
CONFIG_LV_USE_SNAPSHOT=y CONFIG_LV_USE_SNAPSHOT=y