Skip to content

Commit 6e0c70b

Browse files
author
IcingTomato
committed
Add: Add PlatformIO demo
1 parent 69c7e0a commit 6e0c70b

File tree

11 files changed

+2567
-0
lines changed

11 files changed

+2567
-0
lines changed

examples/PlatformIO/Camera/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch
6+
.vscode
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

examples/PlatformIO/Camera/lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:esp32-s3-devkitc-1]
12+
platform = espressif32@ ^5.3.0
13+
board = esp32-s3-devkitc-1
14+
platform_packages =
15+
platformio/tool-esptoolpy@^1.40400.0
16+
framework = arduino
17+
board_build.f_cpu = 240000000L
18+
board_build.f_flash = 80000000L
19+
board_build.flash_mode = qio
20+
board_build.flash_size = 16MB
21+
board_build.partitions = ./src/partitions.csv
22+
upload_speed = 921600
23+
; upload_protocol = espota
24+
upload_protocol = esptool
25+
monitor_speed = 115200
26+
lib_deps = m5stack/M5Unified@^0.1.6
27+
build_flags =
28+
-DESP32S3
29+
-DBOARD_HAS_PSRAM
30+
-mfix-esp32-psram-cache-issue
31+
-DCORE_DEBUG_LEVEL=5
32+
-DARDUINO_USB_CDC_ON_BOOT=1
33+
-DARDUINO_USB_MODE=1
34+
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#include "esp_camera.h"
2+
#include <WiFi.h>
3+
#include <M5Unified.h>
4+
#include "CoreS3_GC0308.hpp"
5+
6+
#define CWS_ENABLE_FACE
7+
8+
#define PWDN_GPIO_NUM -1
9+
#define RESET_GPIO_NUM -1
10+
#define XCLK_GPIO_NUM -1
11+
#define SIOD_GPIO_NUM -1
12+
#define SIOC_GPIO_NUM -1
13+
14+
#define Y2_GPIO_NUM 39
15+
#define Y3_GPIO_NUM 40
16+
#define Y4_GPIO_NUM 41
17+
#define Y5_GPIO_NUM 42
18+
#define Y6_GPIO_NUM 15
19+
#define Y7_GPIO_NUM 16
20+
#define Y8_GPIO_NUM 48
21+
#define Y9_GPIO_NUM 47
22+
23+
#define VSYNC_GPIO_NUM 46
24+
#define HREF_GPIO_NUM 38
25+
#define PCLK_GPIO_NUM 45
26+
27+
// ===========================
28+
// Enter your WiFi credentials
29+
// ===========================
30+
const char* ssid = "@PHICOMM_2E5950";
31+
const char* password = "myfamily";
32+
33+
void startCameraServer();
34+
35+
void setup() {
36+
M5.begin();
37+
M5.Log.setEnableColor(m5::log_target_serial, false);
38+
Serial.begin(115200);
39+
Serial.println();
40+
41+
camera_config_t config;
42+
config.ledc_channel = LEDC_CHANNEL_0;
43+
config.ledc_timer = LEDC_TIMER_0;
44+
config.pin_d0 = Y2_GPIO_NUM;
45+
config.pin_d1 = Y3_GPIO_NUM;
46+
config.pin_d2 = Y4_GPIO_NUM;
47+
config.pin_d3 = Y5_GPIO_NUM;
48+
config.pin_d4 = Y6_GPIO_NUM;
49+
config.pin_d5 = Y7_GPIO_NUM;
50+
config.pin_d6 = Y8_GPIO_NUM;
51+
config.pin_d7 = Y9_GPIO_NUM;
52+
config.pin_xclk = XCLK_GPIO_NUM;
53+
config.pin_pclk = PCLK_GPIO_NUM;
54+
config.pin_vsync = VSYNC_GPIO_NUM;
55+
config.pin_href = HREF_GPIO_NUM;
56+
config.pin_sccb_sda = SIOD_GPIO_NUM;
57+
config.pin_sccb_scl = SIOC_GPIO_NUM;
58+
config.pin_pwdn = PWDN_GPIO_NUM;
59+
config.pin_reset = RESET_GPIO_NUM;
60+
config.xclk_freq_hz = 20000000;
61+
config.frame_size = FRAMESIZE_QVGA;
62+
config.pixel_format = PIXFORMAT_RGB565;
63+
// config.pixel_format = PIXFORMAT_YUV422;
64+
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
65+
config.fb_location = CAMERA_FB_IN_PSRAM;
66+
config.jpeg_quality = 0;
67+
config.fb_count = 2;
68+
config.sccb_i2c_port = M5.In_I2C.getPort();
69+
70+
71+
// camera init
72+
esp_err_t err = esp_camera_init(&config);
73+
if (err != ESP_OK) {
74+
Serial.printf("Camera init failed with error 0x%x", err);
75+
return;
76+
}
77+
if(!cam::GC0308::complementDriver())
78+
{
79+
M5_LOGE("Failed to complement GC0308");
80+
}
81+
82+
WiFi.begin(ssid, password);
83+
WiFi.setSleep(false);
84+
85+
while (WiFi.status() != WL_CONNECTED) {
86+
delay(500);
87+
Serial.print(".");
88+
}
89+
Serial.println("");
90+
Serial.println("WiFi connected");
91+
92+
startCameraServer();
93+
94+
Serial.print("Camera Ready! Use 'http://");
95+
Serial.print(WiFi.localIP());
96+
Serial.println("' to connect");
97+
}
98+
99+
void loop() {
100+
// Do nothing. Everything is done in another task by the web server
101+
delay(1000);
102+
}

0 commit comments

Comments
 (0)