1515// Pin settings
1616#define CAM_PIN_PWDN -1
1717#define CAM_PIN_RESET -1
18- #define CAM_PIN_XCLK - 1
19- #define CAM_PIN_SIOD - 1
20- #define CAM_PIN_SIOC - 1
18+ #define CAM_PIN_XCLK 2
19+ #define CAM_PIN_SIOD 12
20+ #define CAM_PIN_SIOC 11
2121#define CAM_PIN_D7 47
2222#define CAM_PIN_D6 48
2323#define CAM_PIN_D5 16
2424#define CAM_PIN_D4 15
2525#define CAM_PIN_D3 42
26- #define CAM_PIN_D4 15
2726#define CAM_PIN_D2 41
2827#define CAM_PIN_D1 40
2928#define CAM_PIN_D0 39
3029#define CAM_PIN_VSYNC 46
3130#define CAM_PIN_HREF 38
3231#define CAM_PIN_PCLK 45
3332
34- extern void startCameraServer (); // server.cpp
33+ extern void startCameraServer (); // app_httpd.cpp
34+
35+ // #define USING_EXISTING_I2C
36+
37+ #if defined(USING_EXISTING_I2C)
38+ static camera_config_t camera_config =
39+ {
40+ .pin_pwdn = CAM_PIN_PWDN;
41+ .pin_reset = CAM_PIN_RESET;
42+ .pin_xclk = CAM_PIN_XCLK;
43+ // .pin_xclk = -1;
44+ // .pin_sccb_sda = CAM_PIN_SIOD;
45+ .pin_sccb_sda = -1 ;
46+ // .pin_sccb_scl = CAM_PIN_SIOC;
47+ .pin_sccb_scl = -1 ;
48+
49+ .pin_d7 = CAM_PIN_D7;
50+ .pin_d6 = CAM_PIN_D6;
51+ .pin_d5 = CAM_PIN_D5;
52+ .pin_d4 = CAM_PIN_D4;
53+ .pin_d3 = CAM_PIN_D3;
54+ .pin_d2 = CAM_PIN_D2;
55+ .pin_d1 = CAM_PIN_D1;
56+ .pin_d0 = CAM_PIN_D0;
57+ .pin_vsync = CAM_PIN_VSYNC;
58+ .pin_href = CAM_PIN_HREF;
59+ .pin_pclk = CAM_PIN_PCLK;
60+
61+ .xclk_freq_hz = 20000000 ;
62+ .ledc_timer = LEDC_TIMER_0;
63+ .ledc_channel = LEDC_CHANNEL_0;
64+ .fb_location = CAMERA_FB_IN_PSRAM,
65+ .pixel_format = PIXFORMAT_RGB565;
66+ // .pixel_format = PIXFORMAT_YUV422;
67+ // .frame_size = FRAMESIZE_VGA; // 640x480
68+ // .frame_size = FRAMESIZE_QVGA; // 320x240
69+ // .frame_size = FRAMESIZE_240X240, // 240x240
70+ // .frame_size = FRAMESIZE_QQVGA; // 160x120
71+ .jpeg_quality = 0 ,
72+ // .fb_count = 1;
73+ .fb_count = 2 ; // CPU Loads too much but faster
74+ .grab_mode = CAMERA_GRAB_WHEN_EMPTY;
75+ .sccb_i2c_port = M5.In_I2C .getPort ()
76+ };
77+ #else
78+ static camera_config_t camera_config =
79+ {
80+ .pin_pwdn = -1 ,
81+ .pin_reset = -1 ,
82+ .pin_xclk = 2 ,
83+ .pin_sscb_sda = 12 ,
84+ .pin_sscb_scl = 11 ,
85+ .pin_d7 = 47 ,
86+ .pin_d6 = 48 ,
87+ .pin_d5 = 16 ,
88+ .pin_d4 = 15 ,
89+ .pin_d3 = 42 ,
90+ .pin_d2 = 41 ,
91+ .pin_d1 = 40 ,
92+ .pin_d0 = 39 ,
93+ .pin_vsync = 46 ,
94+ .pin_href = 38 ,
95+ .pin_pclk = 45 ,
96+ .xclk_freq_hz = 20000000 ,
97+ .ledc_timer = LEDC_TIMER_0,
98+ .ledc_channel = LEDC_CHANNEL_0,
99+ .pixel_format = PIXFORMAT_RGB565,
100+ // .frame_size = FRAMESIZE_QQVGA,
101+ .frame_size = FRAMESIZE_QVGA,
102+ .jpeg_quality = 0 ,
103+ .fb_count = 2 ,
104+ .fb_location = CAMERA_FB_IN_PSRAM,
105+ .grab_mode = CAMERA_GRAB_WHEN_EMPTY,
106+ .sccb_i2c_port = -1 ,
107+ };
108+ #endif
35109
36110void setup ()
37111{
38112 // M5
39113 M5.begin ();
40114 M5.Log .setEnableColor (m5::log_target_serial, false );
41115
42- // Camera
43- camera_config_t ccfg{};
44- ccfg.pin_pwdn = CAM_PIN_PWDN;
45- ccfg.pin_reset = CAM_PIN_RESET;
46- ccfg.pin_xclk = CAM_PIN_XCLK;
47- ccfg.pin_sccb_sda = CAM_PIN_SIOD;
48- ccfg.pin_sccb_scl = CAM_PIN_SIOC;
49- ccfg.pin_d7 = CAM_PIN_D7;
50- ccfg.pin_d6 = CAM_PIN_D6;
51- ccfg.pin_d5 = CAM_PIN_D5;
52- ccfg.pin_d4 = CAM_PIN_D4;
53- ccfg.pin_d3 = CAM_PIN_D3;
54- ccfg.pin_d2 = CAM_PIN_D2;
55- ccfg.pin_d1 = CAM_PIN_D1;
56- ccfg.pin_d0 = CAM_PIN_D0;
57- ccfg.pin_vsync = CAM_PIN_VSYNC;
58- ccfg.pin_href = CAM_PIN_HREF;
59- ccfg.pin_pclk = CAM_PIN_PCLK;
60- ccfg.xclk_freq_hz = 20000000 ;
61- ccfg.ledc_timer = LEDC_TIMER_0;
62- ccfg.ledc_channel = LEDC_CHANNEL_0;
63-
64- ccfg.pixel_format = PIXFORMAT_RGB565;
65- // ccfg.pixel_format = PIXFORMAT_YUV422;
66-
67- // //ccfg.frame_size = FRAMESIZE_VGA; // 640x480
68- ccfg.frame_size = FRAMESIZE_QVGA; // 320x240
69- // ccfg.frame_size = FRAMESIZE_240X240, // 240x240
70- // ccfg.frame_size = FRAMESIZE_QQVGA; // 160x120
71-
72- ccfg.fb_count = 1 ;
73- // ccfg.fb_count = 2; // CPU Loads too much but faster
74-
75- ccfg.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
76- ccfg.sccb_i2c_port = M5.In_I2C .getPort (); // Using initialized I2C
77-
116+ M5.Display .clear (TFT_ORANGE);
117+ #if defined(USING_EXISTING_I2C)
118+ camera_config.sccb_i2c_port = M5.In_I2C .getPort ();
78119 esp_err_t err = esp_camera_init (&ccfg);
120+ #else
121+ M5.In_I2C .release ();
122+ esp_err_t err = esp_camera_init (&camera_config);
123+ #endif
79124 if (err != ESP_OK)
80125 {
81- M5.Display .clear (TFT_RED);
82- M5.Display .setCursor (0 ,0 );
126+ M5.Display .clear (TFT_BLUE);
83127 M5_LOGE (" Failed to init camera:%d" , err);
84- delay (1000 );
128+ delay (1000 * 10 );
85129 abort ();
86130 }
87131 if (!goblib::camera::GC0308::complementDriver ())
88132 {
89133 M5_LOGE (" Failed to complement GC0308" );
90134 }
91135
92- M5.Display .clear (TFT_DARKGREEN);
93136 // WiFi
94137 WiFi.begin (); // // Connects to credential stored in the hardware.
95138 // WiFi.begin("Your SSID", "Your password"); // or use it.
@@ -113,10 +156,9 @@ void setup()
113156
114157 // Server
115158 startCameraServer ();
116- M5.Display .clear (0 );
117159 M5_LOGI (" Camera ready use: http;//%s to connect" , WiFi.localIP ().toString ().c_str ());
118-
119- M5.Log . setLogLevel (m5::log_target_display, ESP_LOG_NONE); // Disable output to display
160+
161+ M5.Display . clear (TFT_DARKGREEN);
120162}
121163
122164void loop ()
0 commit comments