Skip to content

Commit efe711d

Browse files
fix: add SC031GS VGA framesize support (#581)
1 parent 772aefd commit efe711d

File tree

2 files changed

+127
-15
lines changed

2 files changed

+127
-15
lines changed

sensors/private_include/sc031gs_settings.h

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ struct sc031gs_regval {
7878
uint8_t val;
7979
};
8080

81-
// 200*200, xclk=10M, fps=120fps
82-
static const struct sc031gs_regval sc031gs_default_init_regs[] = {
83-
{0x0103, 0x01}, // soft reset.
81+
static const struct sc031gs_regval sc031gs_reset_regs[] = {
82+
{0x0103, 0x01}, // soft reset.
8483
{REG_DELAY, 10}, // delay.
84+
};
85+
86+
// 200*200, xclk=10M, fps=120fps
87+
static const struct sc031gs_regval sc031gs_200x200_init_regs[] = {
8588
{0x0100, 0x00},
8689
{0x36e9, 0x80},
8790
{0x36f9, 0x80},
@@ -200,3 +203,114 @@ static const struct sc031gs_regval sc031gs_default_init_regs[] = {
200203
{0x3317, 0x0e},
201204
{REG_NULL, 0x00},
202205
};
206+
207+
// 640*480, xclk=20M, fps=50fps, xclk=10M, fps=25fps
208+
static const struct sc031gs_regval sc031gs_640x480_50fps_init_regs[] = {
209+
{0x0100, 0x00},
210+
{0x36e9, 0x80},
211+
{0x36f9, 0x80},
212+
{0x300f, 0x0f},
213+
{0x3018, 0x1f},
214+
{0x3019, 0xff},
215+
{0x301c, 0xb4},
216+
{0x301f, 0x6c},
217+
{0x3028, 0x82},
218+
{0x3200, 0x00},
219+
{0x3201, 0x00},
220+
{0x3202, 0x00},
221+
{0x3203, 0x08},
222+
{0x3204, 0x02},
223+
{0x3205, 0x8f},
224+
{0x3206, 0x01},
225+
{0x3207, 0xf7},
226+
{SC031GS_OUTPUT_WINDOW_WIDTH_H_REG, 0x02},
227+
{SC031GS_OUTPUT_WINDOW_WIDTH_L_REG, 0x80},
228+
{SC031GS_OUTPUT_WINDOW_HIGH_H_REG, 0x01},
229+
{SC031GS_OUTPUT_WINDOW_HIGH_L_REG, 0xe0},
230+
{0x320c, 0x03},
231+
{0x320d, 0x6e},
232+
{0x320e, 0x04},
233+
{0x320f, 0x72},
234+
{SC031GS_OUTPUT_WINDOW_START_Y_H_REG, 0x00},
235+
{SC031GS_OUTPUT_WINDOW_START_Y_L_REG, 0x08},
236+
{SC031GS_OUTPUT_WINDOW_START_X_H_REG, 0x00},
237+
{SC031GS_OUTPUT_WINDOW_START_X_L_REG, 0x08},
238+
{0x3220, 0x10},
239+
{0x3223, 0x50},
240+
{0x3250, 0xf0},
241+
{0x3251, 0x02},
242+
{0x3252, 0x03},
243+
{0x3253, 0xb0},
244+
{0x3254, 0x02},
245+
{0x3255, 0x07},
246+
{0x3304, 0x48},
247+
{0x3306, 0x38},
248+
{0x3309, 0x68},
249+
{0x330b, 0xe0},
250+
{0x330c, 0x18},
251+
{0x330f, 0x20},
252+
{0x3310, 0x10},
253+
{0x3314, 0x6d},
254+
{0x3315, 0x38},
255+
{0x3316, 0x68},
256+
{0x3317, 0x0f},
257+
{0x3329, 0x5c},
258+
{0x332d, 0x5c},
259+
{0x332f, 0x60},
260+
{0x3335, 0x64},
261+
{0x3344, 0x64},
262+
{0x335b, 0x80},
263+
{0x335f, 0x80},
264+
{0x3366, 0x06},
265+
{0x3385, 0x31},
266+
{0x3387, 0x51},
267+
{0x3389, 0x01},
268+
{0x33b1, 0x03},
269+
{0x33b2, 0x06},
270+
{0x3621, 0xa4},
271+
{0x3622, 0x05},
272+
{0x3624, 0x47},
273+
{0x3631, 0x48},
274+
{0x3633, 0x52},
275+
{0x3635, 0x18},
276+
{0x3636, 0x25},
277+
{0x3637, 0x89},
278+
{0x3638, 0x0f},
279+
{0x3639, 0x08},
280+
{0x363a, 0x00},
281+
{0x363b, 0x48},
282+
{0x363c, 0x06},
283+
{0x363e, 0xf8},
284+
{0x3640, 0x00},
285+
{0x3641, 0x01},
286+
{0x36ea, 0x36},
287+
{0x36eb, 0x1a},
288+
{0x36ec, 0x0a},
289+
{0x36ed, 0x23},
290+
{0x36fa, 0x36},
291+
{0x36fb, 0x10},
292+
{0x36fc, 0x01},
293+
{0x36fd, 0x03},
294+
{0x3908, 0x91},
295+
{0x3d08, 0x01},
296+
{0x3e01, 0x14},
297+
{0x3e02, 0x80},
298+
{0x3e06, 0x0c},
299+
{0x3f04, 0x03},
300+
{0x3f05, 0x4e},
301+
{0x4500, 0x59},
302+
{0x4501, 0xc4},
303+
{0x4809, 0x01},
304+
{0x4837, 0x1b},
305+
{0x5011, 0x00},
306+
{0x36e9, 0x20},
307+
{0x36f9, 0x24},
308+
{0x0100, 0x01}, // must write 0x0100 with 0x01, must delay no less then 7ms
309+
//delay 10ms
310+
{REG_DELAY, 0X0a},
311+
{0x4418, 0x08},
312+
{0x4419, 0x80},
313+
{0x363d, 0x10},
314+
{0x3630, 0x48},
315+
{REG_NULL, 0x00},
316+
};

sensors/sc031gs.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int set_aec_value(sensor_t *sensor, int value)
204204

205205
static int reset(sensor_t *sensor)
206206
{
207-
int ret = write_regs(sensor->slv_addr, sc031gs_default_init_regs);
207+
int ret = write_regs(sensor->slv_addr, sc031gs_reset_regs);
208208
if (ret) {
209209
ESP_LOGE(TAG, "reset fail");
210210
}
@@ -217,17 +217,11 @@ static int set_output_window(sensor_t *sensor, int offset_x, int offset_y, int w
217217
{
218218
int ret = 0;
219219
//sc:H_start={0x3212[1:0],0x3213},H_length={0x3208[1:0],0x3209},
220-
// printf("%d, %d, %d, %d\r\n", ((offset_x>>8) & 0x03), offset_x & 0xff, ((w>>8) & 0x03), w & 0xff);
221220

222-
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_START_X_H_REG, 0x0); // For now, we use x_start is 0x04
223-
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_START_X_L_REG, 0x04);
224221
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_WIDTH_H_REG, ((w>>8) & 0x03));
225222
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_WIDTH_L_REG, w & 0xff);
226223

227224
//sc:V_start={0x3210[1:0],0x3211},V_length={0x320a[1:0],0x320b},
228-
// printf("%d, %d, %d, %d\r\n", ((offset_y>>8) & 0x03), offset_y & 0xff, ((h>>8) & 0x03), h & 0xff);
229-
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_START_Y_H_REG, 0x0); // For now, we use y_start is 0x08
230-
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_START_Y_L_REG, 0x08);
231225
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_HIGH_H_REG, ((h>>8) & 0x03));
232226
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_HIGH_L_REG, h & 0xff);
233227

@@ -240,17 +234,21 @@ static int set_framesize(sensor_t *sensor, framesize_t framesize)
240234
{
241235
uint16_t w = resolution[framesize].width;
242236
uint16_t h = resolution[framesize].height;
243-
if(w > SC031GS_MAX_FRAME_WIDTH || h > SC031GS_MAX_FRAME_HIGH) {
244-
goto err;
245-
}
246237

247-
if(w != 200 || h != 200) {
248-
ESP_LOGE(TAG, "Only support 200*200 for now, contact us if you want to use other resolutions");
238+
struct sc031gs_regval const *framesize_regs = sc031gs_200x200_init_regs;
239+
if(framesize > FRAMESIZE_VGA) {
249240
goto err;
241+
} else if(framesize > FRAMESIZE_QVGA) {
242+
framesize_regs = sc031gs_640x480_50fps_init_regs;
250243
}
251244

252245
uint16_t offset_x = (640-w) /2 + 4;
253246
uint16_t offset_y = (480-h) /2 + 4;
247+
248+
int ret = write_regs(sensor->slv_addr, framesize_regs);
249+
if (ret) {
250+
ESP_LOGE(TAG, "reset fail");
251+
}
254252

255253
if(set_output_window(sensor, offset_x, offset_y, w, h)) {
256254
goto err;

0 commit comments

Comments
 (0)