12 changed files with 602 additions and 3 deletions
@ -0,0 +1,31 @@
@@ -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__
|
@ -0,0 +1,202 @@
@@ -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}, |
||||
}; |
@ -0,0 +1,346 @@
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* SC031GS driver. |
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
#include <stdint.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
#include <stdio.h> |
||||
#include "sccb.h" |
||||
#include "xclk.h" |
||||
#include "freertos/FreeRTOS.h" |
||||
#include "freertos/task.h" |
||||
|
||||
#include "sc031gs.h" |
||||
#include "sc031gs_settings.h" |
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) |
||||
#include "esp32-hal-log.h" |
||||
#else |
||||
#include "esp_log.h" |
||||
static const char* TAG = "sc031gs"; |
||||
#endif |
||||
|
||||
#define SC031GS_PID_LOW_REG 0x3107 |
||||
#define SC031GS_PID_HIGH_REG 0x3108 |
||||
#define SC031GS_MAX_FRAME_WIDTH (640) |
||||
#define SC031GS_MAX_FRAME_HIGH (480) |
||||
#define SC031GS_GAIN_CTRL_COARSE_REG 0x3e08 |
||||
#define SC031GS_GAIN_CTRL_FINE_REG 0x3e09 |
||||
|
||||
#define SC031GS_PIDH_MAGIC 0x00 // High byte of sensor ID
|
||||
#define SC031GS_PIDL_MAGIC 0x31 // Low byte of sensor ID
|
||||
|
||||
static int get_reg(sensor_t *sensor, int reg, int mask) |
||||
{ |
||||
int ret = SCCB_Read16(sensor->slv_addr, reg & 0xFFFF); |
||||
if(ret > 0){ |
||||
ret &= mask; |
||||
} |
||||
return ret; |
||||
} |
||||
|
||||
static int set_reg(sensor_t *sensor, int reg, int mask, int value) |
||||
{ |
||||
int ret = 0; |
||||
ret = SCCB_Read16(sensor->slv_addr, reg & 0xFFFF); |
||||
if(ret < 0){ |
||||
return ret; |
||||
} |
||||
value = (ret & ~mask) | (value & mask); |
||||
ret = SCCB_Write16(sensor->slv_addr, reg & 0xFFFF, value); |
||||
return ret; |
||||
} |
||||
|
||||
static int set_reg_bits(sensor_t *sensor, uint16_t reg, uint8_t offset, uint8_t length, uint8_t value) |
||||
{ |
||||
int ret = 0; |
||||
ret = SCCB_Read16(sensor->slv_addr, reg); |
||||
if(ret < 0){ |
||||
return ret; |
||||
} |
||||
uint8_t mask = ((1 << length) - 1) << offset; |
||||
value = (ret & ~mask) | ((value << offset) & mask); |
||||
ret = SCCB_Write16(sensor->slv_addr, reg, value); |
||||
return ret; |
||||
} |
||||
|
||||
static int write_regs(uint8_t slv_addr, const struct sc031gs_regval *regs) |
||||
{ |
||||
int i = 0, ret = 0; |
||||
while (!ret && regs[i].addr != REG_NULL) { |
||||
if (regs[i].addr == REG_DELAY) { |
||||
vTaskDelay(regs[i].val / portTICK_PERIOD_MS); |
||||
} else { |
||||
ret = SCCB_Write16(slv_addr, regs[i].addr, regs[i].val); |
||||
} |
||||
i++; |
||||
} |
||||
return ret; |
||||
} |
||||
|
||||
#define WRITE_REGS_OR_RETURN(regs) ret = write_regs(slv_addr, regs); if(ret){return ret;} |
||||
#define WRITE_REG_OR_RETURN(reg, val) ret = set_reg(sensor, reg, 0xFF, val); if(ret){return ret;} |
||||
#define SET_REG_BITS_OR_RETURN(reg, offset, length, val) ret = set_reg_bits(sensor, reg, offset, length, val); if(ret){return ret;} |
||||
|
||||
static int set_hmirror(sensor_t *sensor, int enable) |
||||
{ |
||||
int ret = 0; |
||||
if(enable) { |
||||
SET_REG_BITS_OR_RETURN(0x3221, 1, 2, 0x3); // mirror on
|
||||
} else { |
||||
SET_REG_BITS_OR_RETURN(0x3221, 1, 2, 0x0); // mirror off
|
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int set_vflip(sensor_t *sensor, int enable) |
||||
{ |
||||
int ret = 0; |
||||
if(enable) { |
||||
SET_REG_BITS_OR_RETURN(0x3221, 5, 2, 0x3); // flip on
|
||||
} else { |
||||
SET_REG_BITS_OR_RETURN(0x3221, 5, 2, 0x0); // flip off
|
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int set_colorbar(sensor_t *sensor, int enable) |
||||
{ |
||||
int ret = 0; |
||||
SET_REG_BITS_OR_RETURN(0x4501, 3, 1, enable & 0x01); // enable test pattern mode
|
||||
SET_REG_BITS_OR_RETURN(0x3902, 6, 1, 1); // enable auto BLC, disable auto BLC if set to 0
|
||||
SET_REG_BITS_OR_RETURN(0x3e06, 0, 2, 3); // digital gain: 00->1x, 01->2x, 03->4x.
|
||||
return ret; |
||||
} |
||||
|
||||
static int set_special_effect(sensor_t *sensor, int sleep_mode_enable) // For sc03ags sensor, This API used for sensor sleep mode control.
|
||||
{ |
||||
// Add some others special control in this API, use switch to control different funcs, such as ctrl_id.
|
||||
int ret = 0; |
||||
SET_REG_BITS_OR_RETURN(0x0100, 0, 1, !(sleep_mode_enable & 0x01)); // 0: enable sleep mode. In sleep mode, the registers can be accessed.
|
||||
return ret; |
||||
} |
||||
|
||||
int set_bpc(sensor_t *sensor, int enable) // // For sc03ags sensor, This API used to control BLC
|
||||
{ |
||||
int ret = 0; |
||||
SET_REG_BITS_OR_RETURN(0x3900, 0, 1, enable & 0x01); |
||||
SET_REG_BITS_OR_RETURN(0x3902, 6, 1, enable & 0x01); |
||||
return ret; |
||||
} |
||||
|
||||
static int set_agc_gain(sensor_t *sensor, int gain) |
||||
{ |
||||
// sc031gs doesn't support AGC, use this func to control.
|
||||
int ret = 0; |
||||
uint32_t coarse_gain, fine_gain, fine_again_reg_v, coarse_gain_reg_v; |
||||
|
||||
if (gain < 0x20) { |
||||
WRITE_REG_OR_RETURN(0x3314, 0x3a); |
||||
WRITE_REG_OR_RETURN(0x3317, 0x20); |
||||
} else { |
||||
WRITE_REG_OR_RETURN(0x3314, 0x44); |
||||
WRITE_REG_OR_RETURN(0x3317, 0x0f); |
||||
} |
||||
|
||||
if (gain < 0x20) { /*1x ~ 2x*/ |
||||
fine_gain = gain - 16; |
||||
coarse_gain = 0x03; |
||||
fine_again_reg_v = ((0x01 << 4) & 0x10) | |
||||
(fine_gain & 0x0f); |
||||
coarse_gain_reg_v = coarse_gain & 0x1F; |
||||
} else if (gain < 0x40) { /*2x ~ 4x*/ |
||||
fine_gain = (gain >> 1) - 16; |
||||
coarse_gain = 0x7; |
||||
fine_again_reg_v = ((0x01 << 4) & 0x10) | |
||||
(fine_gain & 0x0f); |
||||
coarse_gain_reg_v = coarse_gain & 0x1F; |
||||
} else if (gain < 0x80) { /*4x ~ 8x*/ |
||||
fine_gain = (gain >> 2) - 16; |
||||
coarse_gain = 0xf; |
||||
fine_again_reg_v = ((0x01 << 4) & 0x10) | |
||||
(fine_gain & 0x0f); |
||||
coarse_gain_reg_v = coarse_gain & 0x1F; |
||||
} else { /*8x ~ 16x*/ |
||||
fine_gain = (gain >> 3) - 16; |
||||
coarse_gain = 0x1f; |
||||
fine_again_reg_v = ((0x01 << 4) & 0x10) | |
||||
(fine_gain & 0x0f); |
||||
coarse_gain_reg_v = coarse_gain & 0x1F; |
||||
} |
||||
|
||||
WRITE_REG_OR_RETURN(SC031GS_GAIN_CTRL_COARSE_REG, coarse_gain_reg_v); |
||||
WRITE_REG_OR_RETURN(SC031GS_GAIN_CTRL_FINE_REG, fine_again_reg_v); |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int set_aec_value(sensor_t *sensor, int value) |
||||
{ |
||||
// For now, HDR is disabled, the sensor work in normal mode.
|
||||
int ret = 0; |
||||
WRITE_REG_OR_RETURN(0x3e01, value & 0xFF); // AE target high
|
||||
WRITE_REG_OR_RETURN(0x3e02, (value >> 8) & 0xFF); // AE target low
|
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int reset(sensor_t *sensor) |
||||
{ |
||||
int ret = write_regs(sensor->slv_addr, sc031gs_default_init_regs); |
||||
if (ret) { |
||||
ESP_LOGE(TAG, "reset fail"); |
||||
} |
||||
// printf("reg 0x3d04=%02x\r\n", get_reg(sensor, 0x3d04, 0xff));
|
||||
// set_colorbar(sensor, 1);
|
||||
return ret; |
||||
} |
||||
|
||||
static int set_output_window(sensor_t *sensor, int offset_x, int offset_y, int w, int h) |
||||
{ |
||||
int ret = 0; |
||||
//sc:H_start={0x3212[1:0],0x3213},H_length={0x3208[1:0],0x3209},
|
||||
// printf("%d, %d, %d, %d\r\n", ((offset_x>>8) & 0x03), offset_x & 0xff, ((w>>8) & 0x03), w & 0xff);
|
||||
|
||||
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_START_X_H_REG, 0x0); // For now, we use x_start is 0x04
|
||||
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_START_X_L_REG, 0x04); |
||||
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_WIDTH_H_REG, ((w>>8) & 0x03)); |
||||
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_WIDTH_L_REG, w & 0xff); |
||||
|
||||
//sc:V_start={0x3210[1:0],0x3211},V_length={0x320a[1:0],0x320b},
|
||||
// printf("%d, %d, %d, %d\r\n", ((offset_y>>8) & 0x03), offset_y & 0xff, ((h>>8) & 0x03), h & 0xff);
|
||||
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_START_Y_H_REG, 0x0); // For now, we use y_start is 0x08
|
||||
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_START_Y_L_REG, 0x08); |
||||
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_HIGH_H_REG, ((h>>8) & 0x03)); |
||||
WRITE_REG_OR_RETURN(SC031GS_OUTPUT_WINDOW_HIGH_L_REG, h & 0xff); |
||||
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS); |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int set_framesize(sensor_t *sensor, framesize_t framesize) |
||||
{ |
||||
uint16_t w = resolution[framesize].width; |
||||
uint16_t h = resolution[framesize].height; |
||||
if(w > SC031GS_MAX_FRAME_WIDTH || h > SC031GS_MAX_FRAME_HIGH) { |
||||
goto err; |
||||
} |
||||
|
||||
if(w != 200 || h != 200) { |
||||
ESP_LOGE(TAG, "Only support 200*200 for now, contact us if you want to use other resolutions"); |
||||
goto err; |
||||
} |
||||
|
||||
uint16_t offset_x = (640-w) /2 + 4; |
||||
uint16_t offset_y = (480-h) /2 + 4; |
||||
|
||||
if(set_output_window(sensor, offset_x, offset_y, w, h)) { |
||||
goto err; |
||||
} |
||||
|
||||
sensor->status.framesize = framesize; |
||||
return 0; |
||||
err: |
||||
ESP_LOGE(TAG, "frame size err"); |
||||
return -1; |
||||
} |
||||
|
||||
static int set_pixformat(sensor_t *sensor, pixformat_t pixformat) |
||||
{ |
||||
int ret=0; |
||||
sensor->pixformat = pixformat; |
||||
|
||||
switch (pixformat) { |
||||
case PIXFORMAT_GRAYSCALE: |
||||
break; |
||||
default: |
||||
ESP_LOGE(TAG, "Only support GRAYSCALE(Y8)"); |
||||
return -1; |
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int init_status(sensor_t *sensor) |
||||
{ |
||||
return 0; |
||||
} |
||||
|
||||
static int set_dummy(sensor_t *sensor, int val){ return -1; } |
||||
|
||||
static int set_xclk(sensor_t *sensor, int timer, int xclk) |
||||
{ |
||||
int ret = 0; |
||||
sensor->xclk_freq_hz = xclk * 1000000U; |
||||
ret = xclk_timer_conf(timer, sensor->xclk_freq_hz); |
||||
return ret; |
||||
} |
||||
|
||||
int sc031gs_detect(int slv_addr, sensor_id_t *id) |
||||
{ |
||||
if (SC031GS_SCCB_ADDR == slv_addr) { |
||||
uint8_t MIDL = SCCB_Read16(slv_addr, SC031GS_PID_HIGH_REG); |
||||
uint8_t MIDH = SCCB_Read16(slv_addr, SC031GS_PID_LOW_REG); |
||||
uint16_t PID = MIDH << 8 | MIDL; |
||||
if (SC031GS_PID == PID) { |
||||
id->PID = PID; |
||||
return PID; |
||||
} else { |
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID); |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int sc031gs_init(sensor_t *sensor) |
||||
{ |
||||
// Set function pointers
|
||||
sensor->reset = reset; |
||||
sensor->init_status = init_status; |
||||
sensor->set_pixformat = set_pixformat; |
||||
sensor->set_framesize = set_framesize; |
||||
|
||||
sensor->set_colorbar = set_colorbar; |
||||
sensor->set_hmirror = set_hmirror; |
||||
sensor->set_vflip = set_vflip; |
||||
sensor->set_agc_gain = set_agc_gain; |
||||
sensor->set_aec_value = set_aec_value; |
||||
sensor->set_special_effect = set_special_effect; |
||||
|
||||
//not supported
|
||||
sensor->set_awb_gain = set_dummy; |
||||
sensor->set_contrast = set_dummy; |
||||
sensor->set_sharpness = set_dummy; |
||||
sensor->set_saturation= set_dummy; |
||||
sensor->set_denoise = set_dummy; |
||||
sensor->set_quality = set_dummy; |
||||
sensor->set_special_effect = set_dummy; |
||||
sensor->set_wb_mode = set_dummy; |
||||
sensor->set_ae_level = set_dummy; |
||||
|
||||
sensor->get_reg = get_reg; |
||||
sensor->set_reg = set_reg; |
||||
sensor->set_xclk = set_xclk; |
||||
|
||||
ESP_LOGD(TAG, "sc031gs Attached"); |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue