Skip to content

Commit aef527f

Browse files
authored
LilyGo T-CameraPlus-S3 add camera function (#704)
* add camera function * add camera function
1 parent 245be0e commit aef527f

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

main/boards/lilygo-t-cameraplus-s3/lilygo-t-cameraplus-s3.cc

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "i2c_device.h"
99
#include "iot/thing_manager.h"
1010
#include "sy6970.h"
11+
#include "pin_config.h"
12+
#include "esp32_camera.h"
1113

1214
#include <esp_log.h>
1315
#include <esp_lcd_panel_vendor.h>
@@ -74,6 +76,7 @@ class LilygoTCameraPlusS3Board : public WifiBoard {
7476
LcdDisplay *display_;
7577
Button key1_button_;
7678
PowerSaveTimer* power_save_timer_;
79+
Esp32Camera* camera_;
7780

7881
void InitializePowerSaveTimer() {
7982
power_save_timer_ = new PowerSaveTimer(-1, 60, -1);
@@ -99,7 +102,7 @@ class LilygoTCameraPlusS3Board : public WifiBoard {
99102
void InitI2c(){
100103
// Initialize I2C peripheral
101104
i2c_master_bus_config_t i2c_bus_config = {
102-
.i2c_port = I2C_NUM_0,
105+
.i2c_port = I2C_NUM_1,
103106
.sda_io_num = TOUCH_I2C_SDA_PIN,
104107
.scl_io_num = TOUCH_I2C_SCL_PIN,
105108
.clk_source = I2C_CLK_SRC_DEFAULT,
@@ -159,7 +162,7 @@ class LilygoTCameraPlusS3Board : public WifiBoard {
159162

160163
void InitCst816d() {
161164
ESP_LOGI(TAG, "Init CST816x");
162-
cst816d_ = new Cst816x(i2c_bus_, 0x15);
165+
cst816d_ = new Cst816x(i2c_bus_, CST816_ADDRESS);
163166
xTaskCreate(touchpad_daemon, "tp", 2048, NULL, 5, NULL);
164167
}
165168

@@ -176,7 +179,7 @@ class LilygoTCameraPlusS3Board : public WifiBoard {
176179

177180
void InitSy6970() {
178181
ESP_LOGI(TAG, "Init Sy6970");
179-
pmic_ = new Pmic(i2c_bus_, 0x6A);
182+
pmic_ = new Pmic(i2c_bus_, SY6970_ADDRESS);
180183
}
181184

182185
void InitializeSt7789Display() {
@@ -227,12 +230,37 @@ class LilygoTCameraPlusS3Board : public WifiBoard {
227230
});
228231
}
229232

230-
// 物联网初始化,添加对 AI 可见设备
231-
void InitializeIot() {
232-
auto &thing_manager = iot::ThingManager::GetInstance();
233-
thing_manager.AddThing(iot::CreateThing("Speaker"));
234-
thing_manager.AddThing(iot::CreateThing("Screen"));
235-
thing_manager.AddThing(iot::CreateThing("Battery"));
233+
void InitializeCamera() {
234+
camera_config_t config = {};
235+
config.ledc_channel = LEDC_CHANNEL_2; // LEDC通道选择 用于生成XCLK时钟 但是S3不用
236+
config.ledc_timer = LEDC_TIMER_2; // LEDC timer选择 用于生成XCLK时钟 但是S3不用
237+
config.pin_d0 = Y2_GPIO_NUM;
238+
config.pin_d1 = Y3_GPIO_NUM;
239+
config.pin_d2 = Y4_GPIO_NUM;
240+
config.pin_d3 = Y5_GPIO_NUM;
241+
config.pin_d4 = Y6_GPIO_NUM;
242+
config.pin_d5 = Y7_GPIO_NUM;
243+
config.pin_d6 = Y8_GPIO_NUM;
244+
config.pin_d7 = Y9_GPIO_NUM;
245+
config.pin_xclk = XCLK_GPIO_NUM;
246+
config.pin_pclk = PCLK_GPIO_NUM;
247+
config.pin_vsync = VSYNC_GPIO_NUM;
248+
config.pin_href = HREF_GPIO_NUM;
249+
config.pin_sccb_sda = -1; // 这里如果写-1 表示使用已经初始化的I2C接口
250+
config.pin_sccb_scl = SIOC_GPIO_NUM;
251+
config.sccb_i2c_port = 1; // 这里如果写1 默认使用I2C1
252+
config.pin_pwdn = PWDN_GPIO_NUM;
253+
config.pin_reset = RESET_GPIO_NUM;
254+
config.xclk_freq_hz = XCLK_FREQ_HZ;
255+
config.pixel_format = PIXFORMAT_RGB565;
256+
config.frame_size = FRAMESIZE_240X240;
257+
config.jpeg_quality = 12;
258+
config.fb_count = 1;
259+
config.fb_location = CAMERA_FB_IN_PSRAM;
260+
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
261+
262+
camera_ = new Esp32Camera(config);
263+
camera_->SetVFlip(1); // 解决摄像头倒置问题
236264
}
237265

238266
public:
@@ -245,7 +273,13 @@ class LilygoTCameraPlusS3Board : public WifiBoard {
245273
InitSpi();
246274
InitializeSt7789Display();
247275
InitializeButtons();
248-
InitializeIot();
276+
InitializeCamera();
277+
#if CONFIG_IOT_PROTOCOL_XIAOZHI
278+
auto &thing_manager = iot::ThingManager::GetInstance();
279+
thing_manager.AddThing(iot::CreateThing("Speaker"));
280+
thing_manager.AddThing(iot::CreateThing("Screen"));
281+
thing_manager.AddThing(iot::CreateThing("Battery"));
282+
#endif
249283
GetBacklight()->RestoreBrightness();
250284
}
251285

@@ -296,6 +330,10 @@ class LilygoTCameraPlusS3Board : public WifiBoard {
296330
Cst816x *GetTouchpad() {
297331
return cst816d_;
298332
}
333+
334+
virtual Camera* GetCamera() override {
335+
return camera_;
336+
}
299337
};
300338

301339
DECLARE_BOARD(LilygoTCameraPlusS3Board);

main/boards/lilygo-t-cameraplus-s3/pin_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
#define HREF_GPIO_NUM OV2640_HREF
140140
#define PCLK_GPIO_NUM OV2640_PCLK
141141

142+
#define XCLK_FREQ_HZ 20000000
143+
142144
// CST816
143145
#define CST816_ADDRESS 0x15
144146
#define TP_SDA IIC_SDA

0 commit comments

Comments
 (0)