Skip to content

Commit 3d1c095

Browse files
author
IcingTomato
committed
Add: Add Camera_Display demo
1 parent 4958007 commit 3d1c095

File tree

6 files changed

+2475
-0
lines changed

6 files changed

+2475
-0
lines changed
+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2023 by M5Stack
4+
* Equipped with M5CoreS3 sample source code
5+
* 配套 M5CoreS3 示例源代码
6+
* Visit for more information: https://docs.m5stack.com/en/core/CoreS3
7+
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/CoreS3
8+
*
9+
* Describe: Camera example.
10+
* Date: 2023/6/17
11+
*******************************************************************************
12+
*/
13+
#include <M5CoreS3.h>
14+
#include "esp_camera.h"
15+
#include <WiFi.h>
16+
#include <M5Unified.h>
17+
#include "CoreS3_GC0308.hpp"
18+
19+
// Configure the name and password of the connected wifi.
20+
// 配置所连接wifi的名称、密码
21+
const char* ssid = "**********";
22+
const char* password = "**********";
23+
24+
uint16_t img [76800]PROGMEM = {};
25+
26+
#define PWDN_GPIO_NUM -1
27+
#define RESET_GPIO_NUM -1
28+
#define XCLK_GPIO_NUM -1
29+
#define SIOD_GPIO_NUM -1
30+
#define SIOC_GPIO_NUM -1
31+
32+
#define Y2_GPIO_NUM 39
33+
#define Y3_GPIO_NUM 40
34+
#define Y4_GPIO_NUM 41
35+
#define Y5_GPIO_NUM 42
36+
#define Y6_GPIO_NUM 15
37+
#define Y7_GPIO_NUM 16
38+
#define Y8_GPIO_NUM 48
39+
#define Y9_GPIO_NUM 47
40+
41+
#define VSYNC_GPIO_NUM 46
42+
#define HREF_GPIO_NUM 38
43+
#define PCLK_GPIO_NUM 45
44+
45+
void startCameraServer();
46+
void swap16Array(uint16_t *arr, size_t len);
47+
void showingImage(void);
48+
49+
void setup() {
50+
M5.begin();
51+
M5.Log.setEnableColor(m5::log_target_serial, false);
52+
Serial.begin(115200);
53+
Serial.println();
54+
55+
camera_config_t config;
56+
config.ledc_channel = LEDC_CHANNEL_0;
57+
config.ledc_timer = LEDC_TIMER_0;
58+
config.pin_d0 = Y2_GPIO_NUM;
59+
config.pin_d1 = Y3_GPIO_NUM;
60+
config.pin_d2 = Y4_GPIO_NUM;
61+
config.pin_d3 = Y5_GPIO_NUM;
62+
config.pin_d4 = Y6_GPIO_NUM;
63+
config.pin_d5 = Y7_GPIO_NUM;
64+
config.pin_d6 = Y8_GPIO_NUM;
65+
config.pin_d7 = Y9_GPIO_NUM;
66+
config.pin_xclk = XCLK_GPIO_NUM;
67+
config.pin_pclk = PCLK_GPIO_NUM;
68+
config.pin_vsync = VSYNC_GPIO_NUM;
69+
config.pin_href = HREF_GPIO_NUM;
70+
config.pin_sccb_sda = SIOD_GPIO_NUM;
71+
config.pin_sccb_scl = SIOC_GPIO_NUM;
72+
config.pin_pwdn = PWDN_GPIO_NUM;
73+
config.pin_reset = RESET_GPIO_NUM;
74+
config.xclk_freq_hz = 20000000;
75+
config.frame_size = FRAMESIZE_QVGA;
76+
config.pixel_format = PIXFORMAT_RGB565;
77+
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
78+
config.fb_location = CAMERA_FB_IN_PSRAM;
79+
config.jpeg_quality = 0;
80+
config.fb_count = 2;
81+
config.sccb_i2c_port = M5.In_I2C.getPort();
82+
83+
// camera init
84+
esp_err_t err = esp_camera_init(&config);
85+
if (err != ESP_OK) {
86+
Serial.printf("Camera init failed with error 0x%x", err);
87+
return;
88+
}
89+
if (!cam::GC0308::complementDriver()) {
90+
M5_LOGE("Failed to complement GC0308");
91+
}
92+
93+
WiFi.begin(ssid, password);
94+
WiFi.setSleep(false);
95+
96+
while (WiFi.status() != WL_CONNECTED) {
97+
delay(500);
98+
Serial.print(".");
99+
}
100+
Serial.println("");
101+
Serial.println("WiFi connected");
102+
103+
startCameraServer();
104+
105+
showingImage();
106+
107+
Serial.print("Camera Ready! Use 'http://");
108+
Serial.print(WiFi.localIP());
109+
Serial.println("' to connect");
110+
}
111+
112+
void loop() {
113+
// Do nothing. Everything is done in another task by the web server
114+
delay(1000);
115+
}
116+
117+
void swap16Array(uint16_t *arr, size_t len)
118+
{
119+
for (size_t i = 0; i < len; i++)
120+
{
121+
arr[i] = ((arr[i] >> 8) & 0xFF) | ((arr[i] << 8) & 0xFF00);
122+
}
123+
}
124+
125+
void showingImage(void)
126+
{
127+
camera_fb_t *fb = NULL;
128+
fb = esp_camera_fb_get();
129+
if (!fb)
130+
{
131+
Serial.println("Camera Capture Failed!");
132+
M5.Lcd.setCursor(0, 0);
133+
M5.Lcd.print("Camera Capture Failed!");
134+
}
135+
else
136+
{
137+
memcpy(img, fb->buf, fb->len);
138+
delay(0);
139+
//M5.Lcd.drawBitmap(0, 0, 320, 240, fb->buf);
140+
141+
swap16Array(img,76800);
142+
143+
M5.Lcd.drawBitmap(0, 0, 320, 240, img);
144+
}
145+
esp_camera_fb_return(fb);
146+
}

0 commit comments

Comments
 (0)