11/*
2- * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
2+ * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
33 *
44 * SPDX-License-Identifier: MIT
55 */
66
77/* *
8- * @file camera.ino
9- * @brief M5AtomS3R Cam Web Server
10- * @version 1.0
11- * @date 2024-09-27
12- *
13- *
14- * @Hardwares: M5AtomS3R Cam
15- * @Platform Version: Arduino M5Stack Board Manager v2.1.2
16- * @Notes: Remember to turn on PSRAM, otherwise the camera can't be initialized normally.
8+ * @Hardwares: AtomS3R-CAM / AtomS3R-M12
9+ * @Platform Version: Arduino M5Stack Board Manager v2.1.4
1710 */
1811
1912#include " camera_pins.h"
2013#include < WiFi.h>
2114#include " esp_camera.h"
2215
16+ #define USE_ATOMS3R_CAM
17+ // #define USE_ATOMS3R_M12
18+
2319#define STA_MODE
2420// #define AP_MODE
2521
@@ -56,16 +52,25 @@ static camera_config_t camera_config = {
5652 .ledc_timer = LEDC_TIMER_0,
5753 .ledc_channel = LEDC_CHANNEL_0,
5854
59- .pixel_format = PIXFORMAT_RGB565,
60- .frame_size = FRAMESIZE_QVGA,
61- .jpeg_quality = 0 ,
55+ #ifdef USE_ATOMS3R_CAM
56+ .pixel_format = PIXFORMAT_RGB565,
57+ .frame_size = FRAMESIZE_QVGA,
58+ #endif
59+
60+ #ifdef USE_ATOMS3R_M12
61+ .pixel_format = PIXFORMAT_JPEG,
62+ .frame_size = FRAMESIZE_UXGA,
63+ #endif
64+
65+ .jpeg_quality = 12 ,
6266 .fb_count = 2 ,
6367 .fb_location = CAMERA_FB_IN_PSRAM,
6468 .grab_mode = CAMERA_GRAB_LATEST,
6569 .sccb_i2c_port = 0 ,
6670};
6771
68- void setup () {
72+ void setup ()
73+ {
6974 Serial.begin (115200 );
7075 pinMode (POWER_GPIO_NUM, OUTPUT);
7176 digitalWrite (POWER_GPIO_NUM, LOW);
@@ -106,8 +111,7 @@ void setup() {
106111#ifdef AP_MODE
107112 if (!WiFi.softAP (ssid, password)) {
108113 log_e (" Soft AP creation failed." );
109- while (1 )
110- ;
114+ while (1 );
111115 }
112116
113117 Serial.println (" AP SSID:" );
@@ -123,7 +127,8 @@ void setup() {
123127 server.begin ();
124128}
125129
126- void loop () {
130+ void loop ()
131+ {
127132 WiFiClient client = server.available (); // listen for incoming clients
128133 if (client) { // if you get a client,
129134 while (client.connected ()) { // loop while the client's connected
@@ -143,7 +148,8 @@ static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary="
143148static const char * _STREAM_BOUNDARY = " \r\n --" PART_BOUNDARY " \r\n " ;
144149static const char * _STREAM_PART = " Content-Type: image/jpeg\r\n Content-Length: %u\r\n\r\n " ;
145150
146- static void jpegStream (WiFiClient* client) {
151+ static void jpegStream (WiFiClient* client)
152+ {
147153 Serial.println (" Image stream satrt" );
148154 client->println (" HTTP/1.1 200 OK" );
149155 client->printf (" Content-Type: %s\r\n " , _STREAM_CONTENT_TYPE);
@@ -158,7 +164,14 @@ static void jpegStream(WiFiClient* client) {
158164 for (;;) {
159165 fb = esp_camera_fb_get ();
160166 if (fb) {
167+ #ifdef USE_ATOMS3R_CAM
161168 frame2jpg (fb, 255 , &out_jpg, &out_jpg_len);
169+ #endif
170+
171+ #ifdef USE_ATOMS3R_M12
172+ out_jpg = fb->buf ;
173+ out_jpg_len = fb->len ;
174+ #endif
162175
163176 Serial.printf (" pic size: %d\n " , out_jpg_len);
164177 client->print (_STREAM_BOUNDARY);
@@ -187,11 +200,13 @@ static void jpegStream(WiFiClient* client) {
187200 esp_camera_fb_return (fb);
188201 fb = NULL ;
189202 }
203+ #ifdef USE_ATOMS3R_CAM
190204 if (out_jpg) {
191205 free (out_jpg);
192206 out_jpg = NULL ;
193207 out_jpg_len = 0 ;
194208 }
209+ #endif
195210 } else {
196211 Serial.println (" Camera capture failed" );
197212 }
@@ -202,6 +217,13 @@ client_exit:
202217 esp_camera_fb_return (fb);
203218 fb = NULL ;
204219 }
220+ #ifdef USE_ATOMS3R_CAM
221+ if (out_jpg) {
222+ free (out_jpg);
223+ out_jpg = NULL ;
224+ out_jpg_len = 0 ;
225+ }
226+ #endif
205227 client->stop ();
206228 Serial.printf (" Image stream end\r\n " );
207- }
229+ }
0 commit comments