Skip to content

Commit

Permalink
feat: add SC031GS camera sensor support
Browse files Browse the repository at this point in the history
  • Loading branch information
WangYuxin-esp committed Sep 26, 2022
1 parent de025b8 commit 9d9e7d6
Show file tree
Hide file tree
Showing 12 changed files with 602 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
sensors/bf20a6.c
sensors/sc101iot.c
sensors/sc030iot.c
sensors/sc031gs.c
)

list(APPEND COMPONENT_PRIV_INCLUDEDIRS
Expand Down
8 changes: 8 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ menu "Camera configuration"
help
Enable this option if you want to use the SC030IOT.
Disable this option to save memory.

config SC031GS_SUPPORT
bool "Support SC031GS VGA"
default n
help
SC031GS is a global shutter CMOS sensor with high frame rate and single-frame HDR.
Enable this option if you want to use the SC031GS.
Disable this option to save memory.

choice SCCB_HARDWARE_I2C_PORT
bool "I2C peripheral to use for SCCB"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This repository hosts ESP32 series Soc compatible driver for image sensors. Addi
| BF20A6 | 640 x 480 | color | YUV/YCbCr422<br/>RAW Bayer | 1/10" |
| SC101IOT| 1280 x 720 | color | YUV/YCbCr422<br/>Raw RGB | 1/4.2" |
| SC030IOT| 640 x 480 | color | YUV/YCbCr422<br/>RAW Bayer | 1/6.5" |
| SC031GS | 640 x 480 | monochrome | RAW MONO<br/>Grayscale | 1/6" |

## Important to Remember

Expand Down
6 changes: 6 additions & 0 deletions driver/esp_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
#if CONFIG_SC030IOT_SUPPORT
#include "sc030iot.h"
#endif
#if CONFIG_SC031GS_SUPPORT
#include "sc031gs.h"
#endif

#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
Expand Down Expand Up @@ -137,6 +140,9 @@ static const sensor_func_t g_sensors[] = {
#if CONFIG_SC030IOT_SUPPORT
{sc030iot_detect, sc030iot_init},
#endif
#if CONFIG_SC031GS_SUPPORT
{sc031gs_detect, sc031gs_init},
#endif
};

static esp_err_t camera_probe(const camera_config_t *config, camera_model_t *out_camera_model)
Expand Down
3 changes: 3 additions & 0 deletions driver/include/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef enum {
BF20A6_PID = 0x20a6,
SC101IOT_PID = 0xda4a,
SC030IOT_PID = 0x9a46,
SC031GS_PID = 0x0031,
} camera_pid_t;

typedef enum {
Expand All @@ -46,6 +47,7 @@ typedef enum {
CAMERA_BF20A6,
CAMERA_SC101IOT,
CAMERA_SC030IOT,
CAMERA_SC031GS,
CAMERA_MODEL_MAX,
CAMERA_NONE,
} camera_model_t;
Expand All @@ -64,6 +66,7 @@ typedef enum {
BF20A6_SCCB_ADDR = 0x6E,
SC101IOT_SCCB_ADDR = 0x68,// 0xd0 >> 1
SC030IOT_SCCB_ADDR = 0x68,// 0xd0 >> 1
SC031GS_SCCB_ADDR = 0x30,
} camera_sccb_addr_t;

typedef enum {
Expand Down
1 change: 1 addition & 0 deletions driver/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const camera_sensor_info_t camera_sensor[CAMERA_MODEL_MAX] = {
{CAMERA_BF20A6, "BF20A6", BF20A6_SCCB_ADDR, BF20A6_PID, FRAMESIZE_VGA, false},
{CAMERA_SC101IOT, "SC101IOT", SC101IOT_SCCB_ADDR, SC101IOT_PID, FRAMESIZE_HD, false},
{CAMERA_SC030IOT, "SC030IOT", SC030IOT_SCCB_ADDR, SC030IOT_PID, FRAMESIZE_VGA, false},
{CAMERA_SC031GS, "SC031GS", SC031GS_SCCB_ADDR, SC031GS_PID, FRAMESIZE_VGA, false},
};

const resolution_info_t resolution[FRAMESIZE_INVALID] = {
Expand Down
31 changes: 31 additions & 0 deletions sensors/private_include/sc031gs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* SC031GS DVP driver.
*
*/
#ifndef __SC031GS_H__
#define __SC030GS_H__

#include "sensor.h"

/**
* @brief Detect sensor pid
*
* @param slv_addr SCCB address
* @param id Detection result
* @return
* 0: Can't detect this sensor
* Nonzero: This sensor has been detected
*/
int sc031gs_detect(int slv_addr, sensor_id_t *id);

/**
* @brief initialize sensor function pointers
*
* @param sensor pointer of sensor
* @return
* Always 0
*/
int sc031gs_init(sensor_t *sensor);

#endif // __SC031GS_H__
202 changes: 202 additions & 0 deletions sensors/private_include/sc031gs_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// Copyright 2022-2023 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//Preview Type:0:DVP Raw 10 bit// 1:Raw 8 bit// 2:YUV422// 3:RAW16
//Preview Type:4:RGB565// 5:Pixart SPI// 6:MIPI 10bit// 7:MIPI 12bit// 8: MTK SPI
//port 0:MIPI// 1:Parallel// 2:MTK// 3:SPI// 4:TEST// 5: HISPI// 6 : Z2P/Z4P
//I2C Mode :0:Normal 8Addr,8Data// 1:Samsung 8 Addr,8Data// 2:Micron 8 Addr,16Data
//I2C Mode :3:Stmicro 16Addr,8Data//4:Micron2 16 Addr,16Data
//Out Format :0:YCbYCr/RG_GB// 1:YCrYCb/GR_BG// 2:CbYCrY/GB_RG// 3:CrYCbY/BG_GR
//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
//pin :BIT0 pwdn// BIT1:reset
//avdd 0:2.8V// 1:2.5V// 2:1.8V
//dovdd 0:2.8V// 1:2.5V// 2:1.8V
//dvdd 0:1.8V// 1:1.5V// 2:1.2V

/*
[database]
DBName=Dothinkey
[vendor]
VendorName=SmartSens
[sensor]
SensorName=SC031GS
width=200
height=200
port=1
type=1
pin=2
SlaveID=0x60
mode=3
FlagReg=0x36FF
FlagMask=0xff
FlagData=0x00
FlagReg1=0x36FF
FlagMask1=0xff
FlagData1=0x00
outformat=3
mclk=10
avdd=2.800000
dovdd=2.800000
dvdd=1.500000
Ext0=0
Ext1=0
Ext2=0
AFVCC=2.513000
VPP=0.000000
*/
#include <stdint.h>

#define SC031GS_OUTPUT_WINDOW_START_X_H_REG 0x3212
#define SC031GS_OUTPUT_WINDOW_START_X_L_REG 0x3213
#define SC031GS_OUTPUT_WINDOW_START_Y_H_REG 0x3210
#define SC031GS_OUTPUT_WINDOW_START_Y_L_REG 0x3211
#define SC031GS_OUTPUT_WINDOW_WIDTH_H_REG 0x3208
#define SC031GS_OUTPUT_WINDOW_WIDTH_L_REG 0x3209
#define SC031GS_OUTPUT_WINDOW_HIGH_H_REG 0x320a
#define SC031GS_OUTPUT_WINDOW_HIGH_L_REG 0x320b
#define SC031GS_LED_STROBE_ENABLE_REG 0x3361 // When the camera is in exposure, this PAD LEDSTROBE will be high to drive the external LED.

#define REG_NULL 0xFFFF
#define REG_DELAY 0X0000

struct sc031gs_regval {
uint16_t addr;
uint8_t val;
};

// 200*200, xclk=10M, fps=120fps
static const struct sc031gs_regval sc031gs_default_init_regs[] = {
{0x0103, 0x01}, // soft reset.
{REG_DELAY, 10}, // delay.
{0x0100, 0x00},
{0x36e9, 0x80},
{0x36f9, 0x80},
{0x300f, 0x0f},
{0x3018, 0x1f},
{0x3019, 0xff},
{0x301c, 0xb4},
{0x301f, 0x7b},
{0x3028, 0x82},
{0x3200, 0x00},
{0x3201, 0xdc},
{0x3202, 0x00},
{0x3203, 0x98},
{0x3204, 0x01},
{0x3205, 0xb3},
{0x3206, 0x01},
{0x3207, 0x67},
{SC031GS_OUTPUT_WINDOW_WIDTH_H_REG, 0x00},
{SC031GS_OUTPUT_WINDOW_WIDTH_L_REG, 0xc8},
{SC031GS_OUTPUT_WINDOW_HIGH_H_REG, 0x00},
{SC031GS_OUTPUT_WINDOW_HIGH_L_REG, 0xc8},
{0x320c, 0x03},
{0x320d, 0x6b},
{0x320e, 0x01}, //default 120fps: {0x320e, 0x01},{0x320f, 0x40}, 58fps: {0x320e, 0x02},{0x320f, 0xab}; 30fps: {0x320e, 0x05}, {0x320f, 0x34}
{0x320f, 0x40},
{SC031GS_OUTPUT_WINDOW_START_Y_H_REG, 0x00},
{SC031GS_OUTPUT_WINDOW_START_Y_L_REG, 0x08},
{SC031GS_OUTPUT_WINDOW_START_X_H_REG, 0x00},
{SC031GS_OUTPUT_WINDOW_START_X_L_REG, 0x04},
{0x3220, 0x10},
{0x3223, 0x50},
{0x3250, 0xf0},
{0x3251, 0x02},
{0x3252, 0x01},
{0x3253, 0x3b},
{0x3254, 0x02},
{0x3255, 0x07},
{0x3304, 0x48},
{0x3306, 0x38},
{0x3309, 0x50},
{0x330b, 0xe0},
{0x330c, 0x18},
{0x330f, 0x20},
{0x3310, 0x10},
{0x3314, 0x70},
{0x3315, 0x38},
{0x3316, 0x68},
{0x3317, 0x0d},
{0x3329, 0x5c},
{0x332d, 0x5c},
{0x332f, 0x60},
{0x3335, 0x64},
{0x3344, 0x64},
{0x335b, 0x80},
{0x335f, 0x80},
{0x3366, 0x06},
{0x3385, 0x41},
{0x3387, 0x49},
{0x3389, 0x01},
{0x33b1, 0x03},
{0x33b2, 0x06},
{0x3621, 0xa4},
{0x3622, 0x05},
{0x3624, 0x47},
{0x3631, 0x48},
{0x3633, 0x52},
{0x3635, 0x18},
{0x3636, 0x25},
{0x3637, 0x89},
{0x3638, 0x0f},
{0x3639, 0x08},
{0x363a, 0x00},
{0x363b, 0x48},
{0x363c, 0x06},
{0x363e, 0xf8},
{0x3640, 0x00},
{0x3641, 0x01},
{0x36ea, 0x39},
{0x36eb, 0x1e},
{0x36ec, 0x0e},
{0x36ed, 0x23},
{0x36fa, 0x39},
{0x36fb, 0x10},
{0x36fc, 0x01},
{0x36fd, 0x03},
{0x3908, 0x91},
{0x3d08, 0x01},
{0x3d04, 0x04},
{0x3e01, 0x13},
{0x3e02, 0xa0},
{0x3e06, 0x0c},
{0x3f04, 0x03},
{0x3f05, 0x4b},
{0x4500, 0x59},
{0x4501, 0xc4},
{0x4809, 0x01},
{0x4837, 0x39},
{0x5011, 0x00},
{0x36e9, 0x04},
{0x36f9, 0x04},
{0x0100, 0x01},

//delay 10ms
{REG_DELAY, 0X0a},
{0x4418, 0x08},
{0x4419, 0x80},
{0x363d, 0x10},
{0x3630, 0x48},

// [gain<4]
{0x3317, 0x0d},
{0x3314, 0x70},

// [gain>=4]
{0x3314, 0x68},
{0x3317, 0x0e},
{REG_NULL, 0x00},
};
Loading

0 comments on commit 9d9e7d6

Please sign in to comment.