Skip to content

Commit 108a330

Browse files
authored
Merge pull request #452 from WangYuxin-esp/feature/add_sc031gs_camera_sensor_driver
feat: add SC031GS camera sensor support
2 parents de025b8 + 9d9e7d6 commit 108a330

File tree

12 files changed

+602
-3
lines changed

12 files changed

+602
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
4141
sensors/bf20a6.c
4242
sensors/sc101iot.c
4343
sensors/sc030iot.c
44+
sensors/sc031gs.c
4445
)
4546

4647
list(APPEND COMPONENT_PRIV_INCLUDEDIRS

Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ menu "Camera configuration"
108108
help
109109
Enable this option if you want to use the SC030IOT.
110110
Disable this option to save memory.
111+
112+
config SC031GS_SUPPORT
113+
bool "Support SC031GS VGA"
114+
default n
115+
help
116+
SC031GS is a global shutter CMOS sensor with high frame rate and single-frame HDR.
117+
Enable this option if you want to use the SC031GS.
118+
Disable this option to save memory.
111119

112120
choice SCCB_HARDWARE_I2C_PORT
113121
bool "I2C peripheral to use for SCCB"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This repository hosts ESP32 series Soc compatible driver for image sensors. Addi
2828
| BF20A6 | 640 x 480 | color | YUV/YCbCr422<br/>RAW Bayer | 1/10" |
2929
| SC101IOT| 1280 x 720 | color | YUV/YCbCr422<br/>Raw RGB | 1/4.2" |
3030
| SC030IOT| 640 x 480 | color | YUV/YCbCr422<br/>RAW Bayer | 1/6.5" |
31+
| SC031GS | 640 x 480 | monochrome | RAW MONO<br/>Grayscale | 1/6" |
3132

3233
## Important to Remember
3334

driver/esp_camera.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
#if CONFIG_SC030IOT_SUPPORT
6767
#include "sc030iot.h"
6868
#endif
69+
#if CONFIG_SC031GS_SUPPORT
70+
#include "sc031gs.h"
71+
#endif
6972

7073
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
7174
#include "esp32-hal-log.h"
@@ -137,6 +140,9 @@ static const sensor_func_t g_sensors[] = {
137140
#if CONFIG_SC030IOT_SUPPORT
138141
{sc030iot_detect, sc030iot_init},
139142
#endif
143+
#if CONFIG_SC031GS_SUPPORT
144+
{sc031gs_detect, sc031gs_init},
145+
#endif
140146
};
141147

142148
static esp_err_t camera_probe(const camera_config_t *config, camera_model_t *out_camera_model)

driver/include/sensor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef enum {
3030
BF20A6_PID = 0x20a6,
3131
SC101IOT_PID = 0xda4a,
3232
SC030IOT_PID = 0x9a46,
33+
SC031GS_PID = 0x0031,
3334
} camera_pid_t;
3435

3536
typedef enum {
@@ -46,6 +47,7 @@ typedef enum {
4647
CAMERA_BF20A6,
4748
CAMERA_SC101IOT,
4849
CAMERA_SC030IOT,
50+
CAMERA_SC031GS,
4951
CAMERA_MODEL_MAX,
5052
CAMERA_NONE,
5153
} camera_model_t;
@@ -64,6 +66,7 @@ typedef enum {
6466
BF20A6_SCCB_ADDR = 0x6E,
6567
SC101IOT_SCCB_ADDR = 0x68,// 0xd0 >> 1
6668
SC030IOT_SCCB_ADDR = 0x68,// 0xd0 >> 1
69+
SC031GS_SCCB_ADDR = 0x30,
6770
} camera_sccb_addr_t;
6871

6972
typedef enum {

driver/sensor.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const camera_sensor_info_t camera_sensor[CAMERA_MODEL_MAX] = {
1616
{CAMERA_BF20A6, "BF20A6", BF20A6_SCCB_ADDR, BF20A6_PID, FRAMESIZE_VGA, false},
1717
{CAMERA_SC101IOT, "SC101IOT", SC101IOT_SCCB_ADDR, SC101IOT_PID, FRAMESIZE_HD, false},
1818
{CAMERA_SC030IOT, "SC030IOT", SC030IOT_SCCB_ADDR, SC030IOT_PID, FRAMESIZE_VGA, false},
19+
{CAMERA_SC031GS, "SC031GS", SC031GS_SCCB_ADDR, SC031GS_PID, FRAMESIZE_VGA, false},
1920
};
2021

2122
const resolution_info_t resolution[FRAMESIZE_INVALID] = {

sensors/private_include/sc031gs.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
*
3+
* SC031GS DVP driver.
4+
*
5+
*/
6+
#ifndef __SC031GS_H__
7+
#define __SC030GS_H__
8+
9+
#include "sensor.h"
10+
11+
/**
12+
* @brief Detect sensor pid
13+
*
14+
* @param slv_addr SCCB address
15+
* @param id Detection result
16+
* @return
17+
* 0: Can't detect this sensor
18+
* Nonzero: This sensor has been detected
19+
*/
20+
int sc031gs_detect(int slv_addr, sensor_id_t *id);
21+
22+
/**
23+
* @brief initialize sensor function pointers
24+
*
25+
* @param sensor pointer of sensor
26+
* @return
27+
* Always 0
28+
*/
29+
int sc031gs_init(sensor_t *sensor);
30+
31+
#endif // __SC031GS_H__
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
// Copyright 2022-2023 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//Preview Type:0:DVP Raw 10 bit// 1:Raw 8 bit// 2:YUV422// 3:RAW16
16+
//Preview Type:4:RGB565// 5:Pixart SPI// 6:MIPI 10bit// 7:MIPI 12bit// 8: MTK SPI
17+
//port 0:MIPI// 1:Parallel// 2:MTK// 3:SPI// 4:TEST// 5: HISPI// 6 : Z2P/Z4P
18+
//I2C Mode :0:Normal 8Addr,8Data// 1:Samsung 8 Addr,8Data// 2:Micron 8 Addr,16Data
19+
//I2C Mode :3:Stmicro 16Addr,8Data//4:Micron2 16 Addr,16Data
20+
//Out Format :0:YCbYCr/RG_GB// 1:YCrYCb/GR_BG// 2:CbYCrY/GB_RG// 3:CrYCbY/BG_GR
21+
//MCLK Speed :0:6M//1:8M//2:10M//3:11.4M//4:12M//5:12.5M//6:13.5M//7:15M//8:18M//9:24M
22+
//pin :BIT0 pwdn// BIT1:reset
23+
//avdd 0:2.8V// 1:2.5V// 2:1.8V
24+
//dovdd 0:2.8V// 1:2.5V// 2:1.8V
25+
//dvdd 0:1.8V// 1:1.5V// 2:1.2V
26+
27+
/*
28+
[database]
29+
DBName=Dothinkey
30+
31+
[vendor]
32+
VendorName=SmartSens
33+
34+
[sensor]
35+
SensorName=SC031GS
36+
width=200
37+
height=200
38+
port=1
39+
type=1
40+
pin=2
41+
SlaveID=0x60
42+
mode=3
43+
FlagReg=0x36FF
44+
FlagMask=0xff
45+
FlagData=0x00
46+
FlagReg1=0x36FF
47+
FlagMask1=0xff
48+
FlagData1=0x00
49+
outformat=3
50+
mclk=10
51+
avdd=2.800000
52+
dovdd=2.800000
53+
dvdd=1.500000
54+
55+
Ext0=0
56+
Ext1=0
57+
Ext2=0
58+
AFVCC=2.513000
59+
VPP=0.000000
60+
*/
61+
#include <stdint.h>
62+
63+
#define SC031GS_OUTPUT_WINDOW_START_X_H_REG 0x3212
64+
#define SC031GS_OUTPUT_WINDOW_START_X_L_REG 0x3213
65+
#define SC031GS_OUTPUT_WINDOW_START_Y_H_REG 0x3210
66+
#define SC031GS_OUTPUT_WINDOW_START_Y_L_REG 0x3211
67+
#define SC031GS_OUTPUT_WINDOW_WIDTH_H_REG 0x3208
68+
#define SC031GS_OUTPUT_WINDOW_WIDTH_L_REG 0x3209
69+
#define SC031GS_OUTPUT_WINDOW_HIGH_H_REG 0x320a
70+
#define SC031GS_OUTPUT_WINDOW_HIGH_L_REG 0x320b
71+
#define SC031GS_LED_STROBE_ENABLE_REG 0x3361 // When the camera is in exposure, this PAD LEDSTROBE will be high to drive the external LED.
72+
73+
#define REG_NULL 0xFFFF
74+
#define REG_DELAY 0X0000
75+
76+
struct sc031gs_regval {
77+
uint16_t addr;
78+
uint8_t val;
79+
};
80+
81+
// 200*200, xclk=10M, fps=120fps
82+
static const struct sc031gs_regval sc031gs_default_init_regs[] = {
83+
{0x0103, 0x01}, // soft reset.
84+
{REG_DELAY, 10}, // delay.
85+
{0x0100, 0x00},
86+
{0x36e9, 0x80},
87+
{0x36f9, 0x80},
88+
{0x300f, 0x0f},
89+
{0x3018, 0x1f},
90+
{0x3019, 0xff},
91+
{0x301c, 0xb4},
92+
{0x301f, 0x7b},
93+
{0x3028, 0x82},
94+
{0x3200, 0x00},
95+
{0x3201, 0xdc},
96+
{0x3202, 0x00},
97+
{0x3203, 0x98},
98+
{0x3204, 0x01},
99+
{0x3205, 0xb3},
100+
{0x3206, 0x01},
101+
{0x3207, 0x67},
102+
{SC031GS_OUTPUT_WINDOW_WIDTH_H_REG, 0x00},
103+
{SC031GS_OUTPUT_WINDOW_WIDTH_L_REG, 0xc8},
104+
{SC031GS_OUTPUT_WINDOW_HIGH_H_REG, 0x00},
105+
{SC031GS_OUTPUT_WINDOW_HIGH_L_REG, 0xc8},
106+
{0x320c, 0x03},
107+
{0x320d, 0x6b},
108+
{0x320e, 0x01}, //default 120fps: {0x320e, 0x01},{0x320f, 0x40}, 58fps: {0x320e, 0x02},{0x320f, 0xab}; 30fps: {0x320e, 0x05}, {0x320f, 0x34}
109+
{0x320f, 0x40},
110+
{SC031GS_OUTPUT_WINDOW_START_Y_H_REG, 0x00},
111+
{SC031GS_OUTPUT_WINDOW_START_Y_L_REG, 0x08},
112+
{SC031GS_OUTPUT_WINDOW_START_X_H_REG, 0x00},
113+
{SC031GS_OUTPUT_WINDOW_START_X_L_REG, 0x04},
114+
{0x3220, 0x10},
115+
{0x3223, 0x50},
116+
{0x3250, 0xf0},
117+
{0x3251, 0x02},
118+
{0x3252, 0x01},
119+
{0x3253, 0x3b},
120+
{0x3254, 0x02},
121+
{0x3255, 0x07},
122+
{0x3304, 0x48},
123+
{0x3306, 0x38},
124+
{0x3309, 0x50},
125+
{0x330b, 0xe0},
126+
{0x330c, 0x18},
127+
{0x330f, 0x20},
128+
{0x3310, 0x10},
129+
{0x3314, 0x70},
130+
{0x3315, 0x38},
131+
{0x3316, 0x68},
132+
{0x3317, 0x0d},
133+
{0x3329, 0x5c},
134+
{0x332d, 0x5c},
135+
{0x332f, 0x60},
136+
{0x3335, 0x64},
137+
{0x3344, 0x64},
138+
{0x335b, 0x80},
139+
{0x335f, 0x80},
140+
{0x3366, 0x06},
141+
{0x3385, 0x41},
142+
{0x3387, 0x49},
143+
{0x3389, 0x01},
144+
{0x33b1, 0x03},
145+
{0x33b2, 0x06},
146+
{0x3621, 0xa4},
147+
{0x3622, 0x05},
148+
{0x3624, 0x47},
149+
{0x3631, 0x48},
150+
{0x3633, 0x52},
151+
{0x3635, 0x18},
152+
{0x3636, 0x25},
153+
{0x3637, 0x89},
154+
{0x3638, 0x0f},
155+
{0x3639, 0x08},
156+
{0x363a, 0x00},
157+
{0x363b, 0x48},
158+
{0x363c, 0x06},
159+
{0x363e, 0xf8},
160+
{0x3640, 0x00},
161+
{0x3641, 0x01},
162+
{0x36ea, 0x39},
163+
{0x36eb, 0x1e},
164+
{0x36ec, 0x0e},
165+
{0x36ed, 0x23},
166+
{0x36fa, 0x39},
167+
{0x36fb, 0x10},
168+
{0x36fc, 0x01},
169+
{0x36fd, 0x03},
170+
{0x3908, 0x91},
171+
{0x3d08, 0x01},
172+
{0x3d04, 0x04},
173+
{0x3e01, 0x13},
174+
{0x3e02, 0xa0},
175+
{0x3e06, 0x0c},
176+
{0x3f04, 0x03},
177+
{0x3f05, 0x4b},
178+
{0x4500, 0x59},
179+
{0x4501, 0xc4},
180+
{0x4809, 0x01},
181+
{0x4837, 0x39},
182+
{0x5011, 0x00},
183+
{0x36e9, 0x04},
184+
{0x36f9, 0x04},
185+
{0x0100, 0x01},
186+
187+
//delay 10ms
188+
{REG_DELAY, 0X0a},
189+
{0x4418, 0x08},
190+
{0x4419, 0x80},
191+
{0x363d, 0x10},
192+
{0x3630, 0x48},
193+
194+
// [gain<4]
195+
{0x3317, 0x0d},
196+
{0x3314, 0x70},
197+
198+
// [gain>=4]
199+
{0x3314, 0x68},
200+
{0x3317, 0x0e},
201+
{REG_NULL, 0x00},
202+
};

0 commit comments

Comments
 (0)