Compare commits
5 commits
master
...
feature/lc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
caf2efb650 | ||
|
|
853cfb2eec | ||
|
|
edcf853f8f | ||
|
|
717fa36bc3 | ||
|
|
f6d04d8019 |
89 changed files with 1086 additions and 11902 deletions
31
.github/workflows/build.yml
vendored
31
.github/workflows/build.yml
vendored
|
|
@ -1,31 +0,0 @@
|
|||
name: Build examples
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build-examples:
|
||||
name: Build for ${{ matrix.idf_target }} on ${{ matrix.idf_ver }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
idf_ver: ["release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3", "latest"]
|
||||
idf_target: ["esp32", "esp32s2", "esp32s3", "esp32c2", "esp32c3"]
|
||||
container: espressif/idf:${{ matrix.idf_ver }}
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
with:
|
||||
submodules: 'true'
|
||||
- name: esp-idf build
|
||||
env:
|
||||
IDF_TARGET: ${{ matrix.idf_target }}
|
||||
shell: bash
|
||||
working-directory: examples/camera_example
|
||||
run: |
|
||||
. ${IDF_PATH}/export.sh
|
||||
export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
|
||||
export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
|
||||
export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}"
|
||||
idf.py build
|
||||
27
.github/workflows/stale.yml
vendored
27
.github/workflows/stale.yml
vendored
|
|
@ -1,27 +0,0 @@
|
|||
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
|
||||
#
|
||||
# You can adjust the behavior by modifying this file.
|
||||
# For more information, see:
|
||||
# https://github.com/actions/stale
|
||||
name: Mark stale issues and pull requests
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '20 9 * * *'
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-issue-message: 'This issue appears to be stale. Please close it if its no longer valid.'
|
||||
stale-pr-message: 'This pull request appears to be stale. Please close it if its no longer valid.'
|
||||
stale-issue-label: 'no-issue-activity'
|
||||
stale-pr-label: 'no-pr-activity'
|
||||
19
.github/workflows/upload_component.yml
vendored
19
.github/workflows/upload_component.yml
vendored
|
|
@ -1,19 +0,0 @@
|
|||
name: Push component to https://components.espressif.com
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
jobs:
|
||||
upload_components:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
with:
|
||||
submodules: "recursive"
|
||||
- name: Upload component to the component registry
|
||||
uses: espressif/upload-components-ci-action@v1
|
||||
with:
|
||||
name: "esp32-camera"
|
||||
namespace: "espressif"
|
||||
version: ${{ github.ref_name }}
|
||||
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1,6 +1 @@
|
|||
*.DS_Store
|
||||
.vscode
|
||||
**/build
|
||||
**/sdkconfig
|
||||
**/sdkconfig.old
|
||||
**/dependencies.lock
|
||||
119
CMakeLists.txt
119
CMakeLists.txt
|
|
@ -1,31 +1,7 @@
|
|||
# get IDF version for comparison
|
||||
set(idf_version "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}")
|
||||
|
||||
# set conversion sources
|
||||
set(srcs
|
||||
conversions/yuv.c
|
||||
conversions/to_jpg.cpp
|
||||
conversions/to_bmp.c
|
||||
conversions/jpge.cpp
|
||||
conversions/esp_jpg_decode.c
|
||||
)
|
||||
|
||||
set(priv_include_dirs
|
||||
conversions/private_include
|
||||
)
|
||||
|
||||
set(include_dirs
|
||||
driver/include
|
||||
conversions/include
|
||||
)
|
||||
|
||||
set(COMPONENT_REQUIRES driver)
|
||||
|
||||
# set driver sources only for supported platforms
|
||||
if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET STREQUAL "esp32s3")
|
||||
list(APPEND srcs
|
||||
driver/esp_camera.c
|
||||
driver/cam_hal.c
|
||||
#if(IDF_TARGET STREQUAL "esp32")
|
||||
set(COMPONENT_SRCS
|
||||
driver/camera.c
|
||||
driver/sccb.c
|
||||
driver/sensor.c
|
||||
sensors/ov2640.c
|
||||
sensors/ov3660.c
|
||||
|
|
@ -33,80 +9,27 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
|
|||
sensors/ov7725.c
|
||||
sensors/ov7670.c
|
||||
sensors/nt99141.c
|
||||
sensors/gc0308.c
|
||||
sensors/gc2145.c
|
||||
sensors/gc032a.c
|
||||
sensors/bf3005.c
|
||||
sensors/bf20a6.c
|
||||
sensors/sc101iot.c
|
||||
sensors/sc030iot.c
|
||||
sensors/sc031gs.c
|
||||
conversions/yuv.c
|
||||
conversions/to_jpg.cpp
|
||||
conversions/to_bmp.c
|
||||
conversions/jpge.cpp
|
||||
conversions/esp_jpg_decode.c
|
||||
conversions/tjpgd.c
|
||||
)
|
||||
|
||||
list(APPEND priv_include_dirs
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
driver/include
|
||||
conversions/include
|
||||
)
|
||||
|
||||
set(COMPONENT_PRIV_INCLUDEDIRS
|
||||
driver/private_include
|
||||
sensors/private_include
|
||||
target/private_include
|
||||
conversions/private_include
|
||||
)
|
||||
|
||||
if(IDF_TARGET STREQUAL "esp32")
|
||||
list(APPEND srcs
|
||||
target/xclk.c
|
||||
target/esp32/ll_cam.c
|
||||
)
|
||||
endif()
|
||||
set(COMPONENT_REQUIRES driver)
|
||||
set(COMPONENT_PRIV_REQUIRES freertos nvs_flash esp32_lcd_cam)
|
||||
|
||||
if(IDF_TARGET STREQUAL "esp32s2")
|
||||
list(APPEND srcs
|
||||
target/xclk.c
|
||||
target/esp32s2/ll_cam.c
|
||||
target/tjpgd.c
|
||||
)
|
||||
|
||||
list(APPEND priv_include_dirs
|
||||
target/esp32s2/private_include
|
||||
)
|
||||
endif()
|
||||
|
||||
if(IDF_TARGET STREQUAL "esp32s3")
|
||||
list(APPEND srcs
|
||||
target/esp32s3/ll_cam.c
|
||||
)
|
||||
endif()
|
||||
|
||||
set(priv_requires freertos nvs_flash)
|
||||
|
||||
set(min_version_for_esp_timer "4.2")
|
||||
if (idf_version VERSION_GREATER_EQUAL min_version_for_esp_timer)
|
||||
list(APPEND priv_requires esp_timer)
|
||||
endif()
|
||||
|
||||
# include the SCCB I2C driver
|
||||
# this uses either the legacy I2C API or the newwer version from IDF v5.4
|
||||
# as this features a method to obtain the I2C driver from a port number
|
||||
if (idf_version VERSION_GREATER_EQUAL "5.4")
|
||||
list(APPEND srcs driver/sccb-ng.c)
|
||||
else()
|
||||
list(APPEND srcs driver/sccb.c)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
# CONFIG_ESP_ROM_HAS_JPEG_DECODE is available from IDF v4.4 but
|
||||
# previous IDF supported chips already support JPEG decoder, hence okay to use this
|
||||
if(idf_version VERSION_GREATER_EQUAL "4.4" AND NOT CONFIG_ESP_ROM_HAS_JPEG_DECODE)
|
||||
list(APPEND srcs
|
||||
target/tjpgd.c
|
||||
)
|
||||
list(APPEND priv_include_dirs
|
||||
target/jpeg_include/
|
||||
)
|
||||
endif()
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${srcs}
|
||||
INCLUDE_DIRS ${include_dirs}
|
||||
PRIV_INCLUDE_DIRS ${priv_include_dirs}
|
||||
REQUIRES driver # due to include of driver/gpio.h in esp_camera.h
|
||||
PRIV_REQUIRES ${priv_requires}
|
||||
)
|
||||
register_component()
|
||||
#endif()
|
||||
|
|
|
|||
182
Kconfig
182
Kconfig
|
|
@ -5,11 +5,11 @@ menu "Camera configuration"
|
|||
default y
|
||||
help
|
||||
Enable this option if you want to use the OV7670.
|
||||
Disable this option to save memory.
|
||||
Disable this option to safe memory.
|
||||
|
||||
config OV7725_SUPPORT
|
||||
bool "Support OV7725 VGA"
|
||||
default y
|
||||
bool "Support OV7725 SVGA"
|
||||
default n
|
||||
help
|
||||
Enable this option if you want to use the OV7725.
|
||||
Disable this option to save memory.
|
||||
|
|
@ -42,81 +42,6 @@ menu "Camera configuration"
|
|||
Enable this option if you want to use the OV5640.
|
||||
Disable this option to save memory.
|
||||
|
||||
config GC2145_SUPPORT
|
||||
bool "Support GC2145 2MP"
|
||||
default y
|
||||
help
|
||||
Enable this option if you want to use the GC2145.
|
||||
Disable this option to save memory.
|
||||
|
||||
config GC032A_SUPPORT
|
||||
bool "Support GC032A VGA"
|
||||
default y
|
||||
help
|
||||
Enable this option if you want to use the GC032A.
|
||||
Disable this option to save memory.
|
||||
|
||||
config GC0308_SUPPORT
|
||||
bool "Support GC0308 VGA"
|
||||
default y
|
||||
help
|
||||
Enable this option if you want to use the GC0308.
|
||||
Disable this option to save memory.
|
||||
|
||||
config BF3005_SUPPORT
|
||||
bool "Support BF3005(BYD3005) VGA"
|
||||
default y
|
||||
help
|
||||
Enable this option if you want to use the BF3005.
|
||||
Disable this option to save memory.
|
||||
|
||||
config BF20A6_SUPPORT
|
||||
bool "Support BF20A6(BYD20A6) VGA"
|
||||
default y
|
||||
help
|
||||
Enable this option if you want to use the BF20A6.
|
||||
Disable this option to save memory.
|
||||
|
||||
config SC101IOT_SUPPORT
|
||||
bool "Support SC101IOT HD"
|
||||
default n
|
||||
help
|
||||
Enable this option if you want to use the SC101IOT.
|
||||
Disable this option to save memory.
|
||||
|
||||
choice SC101_REGS_SELECT
|
||||
prompt "SC101iot default regs"
|
||||
default SC101IOT_720P_15FPS_ENABLED
|
||||
depends on SC101IOT_SUPPORT
|
||||
help
|
||||
Currently SC010iot has several register sets available.
|
||||
Select the one that matches your needs.
|
||||
|
||||
config SC101IOT_720P_15FPS_ENABLED
|
||||
bool "xclk20M_720p_15fps"
|
||||
help
|
||||
Select this option means that when xclk is 20M, the frame rate is 15fps at 720p resolution.
|
||||
config SC101IOT_VGA_25FPS_ENABLED
|
||||
bool "xclk20M_VGA_25fps"
|
||||
help
|
||||
Select this option means that when xclk is 20M, the frame rate is 25fps at VGA resolution.
|
||||
endchoice
|
||||
|
||||
config SC030IOT_SUPPORT
|
||||
bool "Support SC030IOT VGA"
|
||||
default y
|
||||
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"
|
||||
default SCCB_HARDWARE_I2C_PORT1
|
||||
|
|
@ -128,34 +53,6 @@ menu "Camera configuration"
|
|||
|
||||
endchoice
|
||||
|
||||
config SCCB_CLK_FREQ
|
||||
int "SCCB clk frequency"
|
||||
default 100000
|
||||
range 100000 400000
|
||||
help
|
||||
Increasing this value can reduce the initialization time of the sensor.
|
||||
Please refer to the relevant instructions of the sensor to adjust the value.
|
||||
|
||||
choice GC_SENSOR_WINDOW_MODE
|
||||
bool "GalaxyCore Sensor Window Mode"
|
||||
depends on (GC2145_SUPPORT || GC032A_SUPPORT || GC0308_SUPPORT)
|
||||
default GC_SENSOR_SUBSAMPLE_MODE
|
||||
help
|
||||
This option determines how to reduce the output size when the resolution you set is less than the maximum resolution.
|
||||
SUBSAMPLE_MODE has a bigger perspective and WINDOWING_MODE has a higher frame rate.
|
||||
|
||||
config GC_SENSOR_WINDOWING_MODE
|
||||
bool "Windowing Mode"
|
||||
config GC_SENSOR_SUBSAMPLE_MODE
|
||||
bool "Subsample Mode"
|
||||
endchoice
|
||||
|
||||
config CAMERA_TASK_STACK_SIZE
|
||||
int "CAM task stack size"
|
||||
default 2048
|
||||
help
|
||||
Camera task stack size
|
||||
|
||||
choice CAMERA_TASK_PINNED_TO_CORE
|
||||
bool "Camera task pinned to core"
|
||||
default CAMERA_CORE0
|
||||
|
|
@ -171,77 +68,4 @@ menu "Camera configuration"
|
|||
|
||||
endchoice
|
||||
|
||||
config CAMERA_DMA_BUFFER_SIZE_MAX
|
||||
int "DMA buffer size"
|
||||
range 8192 32768
|
||||
default 32768
|
||||
help
|
||||
Maximum value of DMA buffer
|
||||
Larger values may fail to allocate due to insufficient contiguous memory blocks, and smaller value may cause DMA interrupt to be too frequent.
|
||||
|
||||
choice CAMERA_JPEG_MODE_FRAME_SIZE_OPTION
|
||||
prompt "JPEG mode frame size option"
|
||||
default CAMERA_JPEG_MODE_FRAME_SIZE_AUTO
|
||||
help
|
||||
Select whether to use automatic calculation for JPEG mode frame size or specify a custom value.
|
||||
|
||||
config CAMERA_JPEG_MODE_FRAME_SIZE_AUTO
|
||||
bool "Use automatic calculation (width * height / 5)"
|
||||
help
|
||||
Use the default calculation for JPEG mode frame size.
|
||||
Note: In very low resolutions like QQVGA, the default calculation tends to result in insufficient buffer size.
|
||||
|
||||
config CAMERA_JPEG_MODE_FRAME_SIZE_CUSTOM
|
||||
bool "Specify custom frame size"
|
||||
help
|
||||
Specify a custom frame size in bytes for JPEG mode.
|
||||
|
||||
endchoice
|
||||
|
||||
config CAMERA_JPEG_MODE_FRAME_SIZE
|
||||
int "Custom JPEG mode frame size (bytes)"
|
||||
default 8192
|
||||
depends on CAMERA_JPEG_MODE_FRAME_SIZE_CUSTOM
|
||||
help
|
||||
This option sets the custom frame size in JPEG mode.
|
||||
Specify the desired buffer size in bytes.
|
||||
|
||||
config CAMERA_CONVERTER_ENABLED
|
||||
bool "Enable camera RGB/YUV converter"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
default n
|
||||
help
|
||||
Enable this option if you want to use RGB565/YUV422/YUV420/YUV411 format conversion.
|
||||
|
||||
choice CAMERA_CONV_PROTOCOL
|
||||
bool "Camera converter protocol"
|
||||
depends on CAMERA_CONVERTER_ENABLED
|
||||
default LCD_CAM_CONV_BT601_ENABLED
|
||||
help
|
||||
Supports format conversion under both BT601 and BT709 standards.
|
||||
|
||||
config LCD_CAM_CONV_BT601_ENABLED
|
||||
bool "BT601"
|
||||
config LCD_CAM_CONV_BT709_ENABLED
|
||||
bool "BT709"
|
||||
endchoice
|
||||
|
||||
config LCD_CAM_CONV_FULL_RANGE_ENABLED
|
||||
bool "Camera converter full range mode"
|
||||
depends on CAMERA_CONVERTER_ENABLED
|
||||
default y
|
||||
help
|
||||
Supports format conversion under both full color range mode and limited color range mode.
|
||||
If full color range mode is selected, the color range of RGB or YUV is 0~255.
|
||||
If limited color range mode is selected, the color range of RGB is 16~240, and the color range of YUV is Y[16~240], UV[16~235].
|
||||
Full color range mode has a wider color range, so details in the image show more clearly.
|
||||
Please confirm the color range mode of the current camera sensor, incorrect color range mode may cause color difference in the final converted image.
|
||||
Full range mode is used by default. If this option is not selected, the format conversion function will be done using the limited range mode.
|
||||
|
||||
config LCD_CAM_ISR_IRAM_SAFE
|
||||
bool "Execute camera ISR from IRAM"
|
||||
depends on (IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3)
|
||||
default n
|
||||
help
|
||||
If this option is enabled, camera ISR will execute from IRAM.
|
||||
endmenu
|
||||
|
|
|
|||
115
README.md
115
README.md
|
|
@ -1,34 +1,8 @@
|
|||
# ESP32 Camera Driver
|
||||
|
||||
[](https://github.com/espressif/esp32-camera/actions/workflows/build.yml) [](https://components.espressif.com/components/espressif/esp32-camera)
|
||||
## General Information
|
||||
|
||||
This repository hosts ESP32 series Soc compatible driver for image sensors. Additionally it provides a few tools, which allow converting the captured frame data to the more common BMP and JPEG formats.
|
||||
|
||||
### Supported Soc
|
||||
|
||||
- ESP32
|
||||
- ESP32-S2
|
||||
- ESP32-S3
|
||||
|
||||
### Supported Sensor
|
||||
|
||||
| model | max resolution | color type | output format | Len Size |
|
||||
| ------- | -------------- | ---------- | ------------------------------------------------------------ | -------- |
|
||||
| OV2640 | 1600 x 1200 | color | YUV(422/420)/YCbCr422<br>RGB565/555<br>8-bit compressed data<br>8/10-bit Raw RGB data | 1/4" |
|
||||
| OV3660 | 2048 x 1536 | color | raw RGB data<br/>RGB565/555/444<br/>CCIR656<br/>YCbCr422<br/>compression | 1/5" |
|
||||
| OV5640 | 2592 x 1944 | color | RAW RGB<br/>RGB565/555/444<br/>CCIR656<br/>YUV422/420<br/>YCbCr422<br/>compression | 1/4" |
|
||||
| OV7670 | 640 x 480 | color | Raw Bayer RGB<br/>Processed Bayer RGB<br>YUV/YCbCr422<br>GRB422<br>RGB565/555 | 1/6" |
|
||||
| OV7725 | 640 x 480 | color | Raw RGB<br/>GRB 422<br/>RGB565/555/444<br/>YCbCr 422 | 1/4" |
|
||||
| NT99141 | 1280 x 720 | color | YCbCr 422<br/>RGB565/555/444<br/>Raw<br/>CCIR656<br/>JPEG compression | 1/4" |
|
||||
| GC032A | 640 x 480 | color | YUV/YCbCr422<br/>RAW Bayer<br/>RGB565 | 1/10" |
|
||||
| GC0308 | 640 x 480 | color | YUV/YCbCr422<br/>RAW Bayer<br/>RGB565<br/>Grayscale | 1/6.5" |
|
||||
| GC2145 | 1600 x 1200 | color | YUV/YCbCr422<br/>RAW Bayer<br/>RGB565 | 1/5" |
|
||||
| BF3005 | 640 x 480 | color | YUV/YCbCr422<br/>RAW Bayer<br/>RGB565 | 1/4" |
|
||||
| BF20A6 | 640 x 480 | color | YUV/YCbCr422<br/>RAW Bayer<br/>Only Y | 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" |
|
||||
This repository hosts ESP32 compatible driver for OV2640, OV3660, OV5640, OV7670 and OV7725 image sensors. Additionally it provides a few tools, which allow converting the captured frame data to the more common BMP and JPEG formats.
|
||||
|
||||
## Important to Remember
|
||||
|
||||
|
|
@ -40,25 +14,13 @@ This repository hosts ESP32 series Soc compatible driver for image sensors. Addi
|
|||
## Installation Instructions
|
||||
|
||||
|
||||
### Using with ESP-IDF
|
||||
### Using esp-idf
|
||||
|
||||
- Add a dependency on `espressif/esp32-camera` component:
|
||||
```bash
|
||||
idf.py add-dependency "espressif/esp32-camera"
|
||||
```
|
||||
(or add it manually in idf_component.yml of your project)
|
||||
- Enable PSRAM in `menuconfig` (also set Flash and PSRAM frequiencies to 80MHz)
|
||||
- Clone or download and extract the repository to the components folder of your ESP-IDF project
|
||||
- Enable PSRAM in `menuconfig`
|
||||
- Include `esp_camera.h` in your code
|
||||
|
||||
These instructions also work for PlatformIO, if you are using `framework=espidf`.
|
||||
|
||||
### Using with Arduino
|
||||
|
||||
#### Arduino IDE
|
||||
|
||||
If you are using the arduino-esp32 core in Arduino IDE, no installation is needed! You can use esp32-camera right away.
|
||||
|
||||
#### PlatformIO
|
||||
### Using PlatformIO
|
||||
|
||||
The easy way -- on the `env` section of `platformio.ini`, add the following:
|
||||
|
||||
|
|
@ -80,16 +42,53 @@ Enable PSRAM on `menuconfig` or type it direclty on `sdkconfig`. Check the [offi
|
|||
CONFIG_ESP32_SPIRAM_SUPPORT=y
|
||||
```
|
||||
|
||||
***Arduino*** The easy-way (content above) only seems to work if you're using `framework=arduino` which seems to take a bunch of the guesswork out (thanks Arduino!) but also suck up a lot more memory and flash, almost crippling the performance. If you plan to use the `framework=espidf` then read the sections below carefully!!
|
||||
|
||||
## Platform.io lib/submodule (for framework=espidf)
|
||||
|
||||
It's probably easier to just skip the platform.io library registry version and link the git repo as a submodule. (i.e. using code outside the platform.io library management). In this example we will install this as a submodule inside the platform.io $project/lib folder:
|
||||
```
|
||||
cd $project\lib
|
||||
git submodule add -b master https://github.com/espressif/esp32-camera.git
|
||||
```
|
||||
|
||||
Then in `platformio.ini` file
|
||||
```
|
||||
build_flags =
|
||||
-I../lib/esp32-camera
|
||||
```
|
||||
After that `#include "esp_camera.h"` statement will be available. Now the module is included, and you're hopefully back to the same place as the easy-Arduino way.
|
||||
|
||||
**Warning about platform.io/espidf and fresh (not initialized) git repos**
|
||||
There is a sharp-edge on you'll discover in the platform.io build process (in espidf v3.3 & 4.0.1) where a project which has only had `git init` but nothing committed will crash platform.io build process with highly non-useful output. The cause is due to lack of a version (making you think you did something wrong, when you didn't at all) - the output is horribly non-descript. Solution: the devs want you to create a file called version.txt with a number in it, or simply commit any file to the projects git repo and use git. This happens because platform.io build process tries to be too clever and determine the build version number from the git repo - it's a sharp edge you'll only encounter if you're experimenting on a new project with no commits .. like wtf is my camera not working let's try a 'clean project'?! </rant>
|
||||
|
||||
## Platform.io Kconfig
|
||||
Kconfig is used by the platform.io menuconfig (accessed by running: `pio run -t menuconfig`) to interactively manage the various #ifdef statements throughout the espidf and supporting libraries (i.e. this repo: esp32-camera and arduino-esp32.git). The menuconfig process generates the `sdkconfig` file which is ultimately used behind the scenes by espidf compile+build process.
|
||||
|
||||
**Make sure to append or symlink** [this `Kconfig`](./Kconfig) content into the `Kconfig` of your project.
|
||||
|
||||
You symlink (or copy) the included Kconfig into your platform.io projects src directory. The file should be named `Kconfig.projbuild` in your projects src\ directory or you could also add the library path to a CMakefile.txt and hope the `Kconfig` (or `Kconfig.projbuild`) gets discovered by the menuconfig process, though this unpredictable for me.
|
||||
|
||||
The unpredictable wonky behavior in platform.io build process around Kconfig naming (Kconfig vs. Kconfig.projbuild) occurs between espidf versions 3.3 and 4.0 - but if you don't see "Camera configuration" in your `pio run -t menuconfig` then there is no point trying to test camera code (it may compile, but it probably won't work!) and it seems the platform.io devs (when they built their wrapper around the espidf menuconfig) didn't implement it properly. You've probably already figured out you can't use the espidf build tools since the files are in totally different locations and also different versions with sometimes different syntax. This is one of those times you might consider changing the `platformio.ini` from `platform=espressif32` to `platform=https://github.com/platformio/platform-espressif32.git#develop` to get a more recent version of the espidf 4.0 tools.
|
||||
|
||||
However with a bit of patience and experimenting you'll figure the Kconfig out. Once Kconfig (or Kconfig.projbuild) is working then you will be able to choose the configurations according to your setup or the camera libraries will be compiled. Although you might also need to delete your .pio/build directory before the options appear .. again, the `pio run -t menuconfig` doens't always notice the new Kconfig files!
|
||||
|
||||
If you miss-skip-ignore this critical step the camera module will compile but camera logic inside the library will be 'empty' because the Kconfig sets the proper #ifdef statements during the build process to initialize the selected cameras. It's very not optional!
|
||||
|
||||
### Kconfig options
|
||||
|
||||
| config | description | default |
|
||||
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------ |
|
||||
| CONFIG_OV2640_SUPPORT | Support for OV2640 camera | enabled |
|
||||
| CONFIG_OV7725_SUPPORT | Support for OV7725 camera | disabled |
|
||||
| CONFIG_OV3660_SUPPORT | Support for OV3660 camera | enabled |
|
||||
| CONFIG_OV5640_SUPPORT | Support for OV5640 camera | enabled |
|
||||
| CONFIG_SCCB_HARDWARE_I2C | Enable this option if you want to use hardware I2C to control the camera. Disable this option to use software I2C. | enabled |
|
||||
| CONFIG_SCCB_HARDWARE_I2C_PORT | I2C peripheral to use for SCCB. Can be I2C0 and I2C1. | CONFIG_SCCB_HARDWARE_I2C_PORT1 |
|
||||
| CONFIG_CAMERA_TASK_PINNED_TO_CORE | Pin the camera handle task to a certain core(0/1). It can also be done automatically choosing NO_AFFINITY. Can be CAMERA_CORE0, CAMERA_CORE1 or NO_AFFINITY. | CONFIG_CAMERA_CORE0 |
|
||||
|
||||
## Examples
|
||||
|
||||
This component comes with a basic example illustrating how to get frames from the camera. You can try out the example using the following command:
|
||||
|
||||
```
|
||||
idf.py create-project-from-example "espressif/esp32-camera:camera_example"
|
||||
```
|
||||
|
||||
This command will download the example into `camera_example` directory. It comes already pre-configured with the correct settings in menuconfig.
|
||||
|
||||
### Initialization
|
||||
|
||||
```c
|
||||
|
|
@ -118,8 +117,8 @@ static camera_config_t camera_config = {
|
|||
.pin_pwdn = CAM_PIN_PWDN,
|
||||
.pin_reset = CAM_PIN_RESET,
|
||||
.pin_xclk = CAM_PIN_XCLK,
|
||||
.pin_sccb_sda = CAM_PIN_SIOD,
|
||||
.pin_sccb_scl = CAM_PIN_SIOC,
|
||||
.pin_sscb_sda = CAM_PIN_SIOD,
|
||||
.pin_sscb_scl = CAM_PIN_SIOC,
|
||||
|
||||
.pin_d7 = CAM_PIN_D7,
|
||||
.pin_d6 = CAM_PIN_D6,
|
||||
|
|
@ -133,16 +132,16 @@ static camera_config_t camera_config = {
|
|||
.pin_href = CAM_PIN_HREF,
|
||||
.pin_pclk = CAM_PIN_PCLK,
|
||||
|
||||
.xclk_freq_hz = 20000000,//EXPERIMENTAL: Set to 16MHz on ESP32-S2 or ESP32-S3 to enable EDMA mode
|
||||
//XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
|
||||
.xclk_freq_hz = 20000000,
|
||||
.ledc_timer = LEDC_TIMER_0,
|
||||
.ledc_channel = LEDC_CHANNEL_0,
|
||||
|
||||
.pixel_format = PIXFORMAT_JPEG,//YUV422,GRAYSCALE,RGB565,JPEG
|
||||
.frame_size = FRAMESIZE_UXGA,//QQVGA-UXGA, For ESP32, do not use sizes above QVGA when not JPEG. The performance of the ESP32-S series has improved a lot, but JPEG mode always gives better frame rates.
|
||||
.frame_size = FRAMESIZE_UXGA,//QQVGA-QXGA Do not use sizes above QVGA when not JPEG
|
||||
|
||||
.jpeg_quality = 12, //0-63, for OV series camera sensors, lower number means higher quality
|
||||
.fb_count = 1, //When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
|
||||
.grab_mode = CAMERA_GRAB_WHEN_EMPTY//CAMERA_GRAB_LATEST. Sets when buffers should be filled
|
||||
.jpeg_quality = 12, //0-63 lower number means higher quality
|
||||
.fb_count = 1 //if more than one, i2s runs in continuous mode. Use only with JPEG
|
||||
};
|
||||
|
||||
esp_err_t camera_init(){
|
||||
|
|
|
|||
4
component.mk
Executable file
4
component.mk
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
COMPONENT_ADD_INCLUDEDIRS := driver/include conversions/include
|
||||
COMPONENT_PRIV_INCLUDEDIRS := driver/private_include conversions/private_include sensors/private_include
|
||||
COMPONENT_SRCDIRS := driver conversions sensors
|
||||
CXXFLAGS += -fno-rtti
|
||||
|
|
@ -17,14 +17,12 @@
|
|||
#if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
|
||||
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||
#include "esp32/rom/tjpgd.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "tjpgd.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/rom/tjpgd.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
#include "esp32c3/rom/tjpgd.h"
|
||||
#elif CONFIG_ESP_ROM_HAS_JPEG_DECODE // available since IDF 4.4
|
||||
#include "rom/tjpgd.h" // latest IDFs have `rom/` includes available
|
||||
#else
|
||||
#include "tjpgd.h" // using software decoder
|
||||
#error Target CONFIG_IDF_TARGET is not supported
|
||||
#endif
|
||||
#else // ESP32 Before IDF 4.0
|
||||
#include "rom/tjpgd.h"
|
||||
|
|
@ -59,7 +57,7 @@ static const char * jd_errors[] = {
|
|||
"Not supported JPEG standard"
|
||||
};
|
||||
|
||||
static unsigned int _jpg_write(JDEC *decoder, void *bitmap, JRECT *rect)
|
||||
static uint32_t _jpg_write(JDEC *decoder, void *bitmap, JRECT *rect)
|
||||
{
|
||||
uint16_t x = rect->left;
|
||||
uint16_t y = rect->top;
|
||||
|
|
@ -75,7 +73,7 @@ static unsigned int _jpg_write(JDEC *decoder, void *bitmap, JRECT *rect)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int _jpg_read(JDEC *decoder, uint8_t *buf, unsigned int len)
|
||||
static uint32_t _jpg_read(JDEC *decoder, uint8_t *buf, uint32_t len)
|
||||
{
|
||||
esp_jpg_decoder_t * jpeg = (esp_jpg_decoder_t *)decoder->device;
|
||||
if (jpeg->len && len > (jpeg->len - jpeg->index)) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_camera.h"
|
||||
#include "esp_jpg_decode.h"
|
||||
|
||||
typedef size_t (* jpg_out_cb)(void * arg, size_t index, const void* data, size_t len);
|
||||
|
||||
|
|
@ -121,8 +120,6 @@ bool frame2bmp(camera_fb_t * fb, uint8_t ** out, size_t * out_len);
|
|||
*/
|
||||
bool fmt2rgb888(const uint8_t *src_buf, size_t src_len, pixformat_t format, uint8_t * rgb_buf);
|
||||
|
||||
bool jpg2rgb565(const uint8_t *src, size_t src_len, uint8_t * out, jpg_scale_t scale);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
97
conversions/include/tjpgd.h
Normal file
97
conversions/include/tjpgd.h
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/*----------------------------------------------------------------------------/
|
||||
/ TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2012
|
||||
/----------------------------------------------------------------------------*/
|
||||
#ifndef _TJPGDEC
|
||||
#define _TJPGDEC
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* System Configurations */
|
||||
|
||||
#define JD_SZBUF 512 /* Size of stream input buffer */
|
||||
#define JD_FORMAT 0 /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */
|
||||
#define JD_USE_SCALE 1 /* Use descaling feature for output */
|
||||
#define JD_TBLCLIP 1 /* Use table for saturation (might be a bit faster but increases 1K bytes of code size) */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* These types must be 16-bit, 32-bit or larger integer */
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* These types must be 8-bit integer */
|
||||
typedef char CHAR;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
/* These types must be 16-bit integer */
|
||||
typedef short SHORT;
|
||||
typedef unsigned short USHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned short WCHAR;
|
||||
|
||||
/* These types must be 32-bit integer */
|
||||
typedef long LONG;
|
||||
typedef unsigned long ULONG;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
|
||||
/* Error code */
|
||||
typedef enum {
|
||||
JDR_OK = 0, /* 0: Succeeded */
|
||||
JDR_INTR, /* 1: Interrupted by output function */
|
||||
JDR_INP, /* 2: Device error or wrong termination of input stream */
|
||||
JDR_MEM1, /* 3: Insufficient memory pool for the image */
|
||||
JDR_MEM2, /* 4: Insufficient stream input buffer */
|
||||
JDR_PAR, /* 5: Parameter error */
|
||||
JDR_FMT1, /* 6: Data format error (may be damaged data) */
|
||||
JDR_FMT2, /* 7: Right format but not supported */
|
||||
JDR_FMT3 /* 8: Not supported JPEG standard */
|
||||
} JRESULT;
|
||||
|
||||
|
||||
|
||||
/* Rectangular structure */
|
||||
typedef struct {
|
||||
WORD left, right, top, bottom;
|
||||
} JRECT;
|
||||
|
||||
|
||||
|
||||
/* Decompressor object structure */
|
||||
typedef struct JDEC JDEC;
|
||||
struct JDEC {
|
||||
UINT dctr; /* Number of bytes available in the input buffer */
|
||||
BYTE *dptr; /* Current data read ptr */
|
||||
BYTE *inbuf; /* Bit stream input buffer */
|
||||
BYTE dmsk; /* Current bit in the current read byte */
|
||||
BYTE scale; /* Output scaling ratio */
|
||||
BYTE msx, msy; /* MCU size in unit of block (width, height) */
|
||||
BYTE qtid[3]; /* Quantization table ID of each component */
|
||||
SHORT dcv[3]; /* Previous DC element of each component */
|
||||
WORD nrst; /* Restart inverval */
|
||||
UINT width, height; /* Size of the input image (pixel) */
|
||||
BYTE *huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
|
||||
WORD *huffcode[2][2]; /* Huffman code word tables [id][dcac] */
|
||||
BYTE *huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
|
||||
LONG *qttbl[4]; /* Dequaitizer tables [id] */
|
||||
void *workbuf; /* Working buffer for IDCT and RGB output */
|
||||
BYTE *mcubuf; /* Working buffer for the MCU */
|
||||
void *pool; /* Pointer to available memory pool */
|
||||
UINT sz_pool; /* Size of momory pool (bytes available) */
|
||||
UINT (*infunc)(JDEC *, BYTE *, UINT); /* Pointer to jpeg stream input function */
|
||||
void *device; /* Pointer to I/O device identifiler for the session */
|
||||
};
|
||||
|
||||
/* TJpgDec API functions */
|
||||
JRESULT jd_prepare (JDEC *, UINT(*)(JDEC *, BYTE *, UINT), void *, UINT, void *);
|
||||
JRESULT jd_decomp (JDEC *, UINT(*)(JDEC *, void *, JRECT *), BYTE);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TJPGDEC */
|
||||
|
|
@ -29,12 +29,7 @@ namespace jpge {
|
|||
if(b){
|
||||
return b;
|
||||
}
|
||||
// check if SPIRAM is enabled and allocate on SPIRAM if allocatable
|
||||
#if (CONFIG_SPIRAM_SUPPORT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC))
|
||||
return heap_caps_malloc(nSize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
static inline void jpge_free(void *p) { free(p); }
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@
|
|||
/ Sep 03,'12 R0.01b Added JD_TBLCLIP option.
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#if CONFIG_IDF_TARGET_ESP32S2
|
||||
|
||||
#include "tjpgd.h"
|
||||
|
||||
#define SUPPORT_JPEG 1
|
||||
|
|
@ -967,4 +970,4 @@ JRESULT jd_decomp (
|
|||
}
|
||||
#endif//SUPPORT_JPEG
|
||||
|
||||
|
||||
#endif //CONFIG_IDF_TARGET_ESP32S2
|
||||
|
|
@ -21,6 +21,19 @@
|
|||
#include "esp_jpg_decode.h"
|
||||
|
||||
#include "esp_system.h"
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
|
||||
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||
#include "esp32/spiram.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/spiram.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/spiram.h"
|
||||
#else
|
||||
#error Target CONFIG_IDF_TARGET is not supported
|
||||
#endif
|
||||
#else // ESP32 Before IDF 4.0
|
||||
#include "esp_spiram.h"
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
||||
#include "esp32-hal-log.h"
|
||||
|
|
@ -59,12 +72,7 @@ typedef struct {
|
|||
|
||||
static void *_malloc(size_t size)
|
||||
{
|
||||
// check if SPIRAM is enabled and allocate on SPIRAM if allocatable
|
||||
#if (CONFIG_SPIRAM_SUPPORT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC))
|
||||
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
#endif
|
||||
// try allocating in internal memory
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
//output buffer and image width
|
||||
|
|
@ -111,56 +119,8 @@ static bool _rgb_write(void * arg, uint16_t x, uint16_t y, uint16_t w, uint16_t
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool _rgb565_write(void * arg, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t *data)
|
||||
{
|
||||
rgb_jpg_decoder * jpeg = (rgb_jpg_decoder *)arg;
|
||||
if(!data){
|
||||
if(x == 0 && y == 0){
|
||||
//write start
|
||||
jpeg->width = w;
|
||||
jpeg->height = h;
|
||||
//if output is null, this is BMP
|
||||
if(!jpeg->output){
|
||||
jpeg->output = (uint8_t *)_malloc((w*h*3)+jpeg->data_offset);
|
||||
if(!jpeg->output){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//write end
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t jw = jpeg->width*3;
|
||||
size_t jw2 = jpeg->width*2;
|
||||
size_t t = y * jw;
|
||||
size_t t2 = y * jw2;
|
||||
size_t b = t + (h * jw);
|
||||
size_t l = x * 2;
|
||||
uint8_t *out = jpeg->output+jpeg->data_offset;
|
||||
uint8_t *o = out;
|
||||
size_t iy, iy2, ix, ix2;
|
||||
|
||||
w = w * 3;
|
||||
|
||||
for(iy=t, iy2=t2; iy<b; iy+=jw, iy2+=jw2) {
|
||||
o = out+iy2+l;
|
||||
for(ix2=ix=0; ix<w; ix+= 3, ix2 +=2) {
|
||||
uint16_t r = data[ix];
|
||||
uint16_t g = data[ix+1];
|
||||
uint16_t b = data[ix+2];
|
||||
uint16_t c = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||
o[ix2+1] = c>>8;
|
||||
o[ix2] = c&0xff;
|
||||
}
|
||||
data+=w;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//input buffer
|
||||
static unsigned int _jpg_read(void * arg, size_t index, uint8_t *buf, size_t len)
|
||||
static uint32_t _jpg_read(void * arg, size_t index, uint8_t *buf, size_t len)
|
||||
{
|
||||
rgb_jpg_decoder * jpeg = (rgb_jpg_decoder *)arg;
|
||||
if(buf) {
|
||||
|
|
@ -184,21 +144,6 @@ static bool jpg2rgb888(const uint8_t *src, size_t src_len, uint8_t * out, jpg_sc
|
|||
return true;
|
||||
}
|
||||
|
||||
bool jpg2rgb565(const uint8_t *src, size_t src_len, uint8_t * out, jpg_scale_t scale)
|
||||
{
|
||||
rgb_jpg_decoder jpeg;
|
||||
jpeg.width = 0;
|
||||
jpeg.height = 0;
|
||||
jpeg.input = src;
|
||||
jpeg.output = out;
|
||||
jpeg.data_offset = 0;
|
||||
|
||||
if(esp_jpg_decode(src_len, scale, _jpg_read, _rgb565_write, (void*)&jpeg) != ESP_OK){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool jpg2bmp(const uint8_t *src, size_t src_len, uint8_t ** out, size_t * out_len)
|
||||
{
|
||||
|
||||
|
|
@ -302,13 +247,7 @@ bool fmt2bmp(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixf
|
|||
*out_len = 0;
|
||||
|
||||
int pix_count = width*height;
|
||||
|
||||
// With BMP, 8-bit greyscale requires a palette.
|
||||
// For a 640x480 image though, that's a savings
|
||||
// over going RGB-24.
|
||||
int bpp = (format == PIXFORMAT_GRAYSCALE) ? 1 : 3;
|
||||
int palette_size = (format == PIXFORMAT_GRAYSCALE) ? 4 * 256 : 0;
|
||||
size_t out_size = (pix_count * bpp) + BMP_HEADER_LEN + palette_size;
|
||||
size_t out_size = (pix_count * 3) + BMP_HEADER_LEN;
|
||||
uint8_t * out_buf = (uint8_t *)_malloc(out_size);
|
||||
if(!out_buf) {
|
||||
ESP_LOGE(TAG, "_malloc failed! %u", out_size);
|
||||
|
|
@ -320,51 +259,45 @@ bool fmt2bmp(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixf
|
|||
bmp_header_t * bitmap = (bmp_header_t*)&out_buf[2];
|
||||
bitmap->reserved = 0;
|
||||
bitmap->filesize = out_size;
|
||||
bitmap->fileoffset_to_pixelarray = BMP_HEADER_LEN + palette_size;
|
||||
bitmap->fileoffset_to_pixelarray = BMP_HEADER_LEN;
|
||||
bitmap->dibheadersize = 40;
|
||||
bitmap->width = width;
|
||||
bitmap->height = -height;//set negative for top to bottom
|
||||
bitmap->planes = 1;
|
||||
bitmap->bitsperpixel = bpp * 8;
|
||||
bitmap->bitsperpixel = 24;
|
||||
bitmap->compression = 0;
|
||||
bitmap->imagesize = pix_count * bpp;
|
||||
bitmap->imagesize = pix_count * 3;
|
||||
bitmap->ypixelpermeter = 0x0B13 ; //2835 , 72 DPI
|
||||
bitmap->xpixelpermeter = 0x0B13 ; //2835 , 72 DPI
|
||||
bitmap->numcolorspallette = 0;
|
||||
bitmap->mostimpcolor = 0;
|
||||
|
||||
uint8_t * palette_buf = out_buf + BMP_HEADER_LEN;
|
||||
uint8_t * pix_buf = palette_buf + palette_size;
|
||||
uint8_t * rgb_buf = out_buf + BMP_HEADER_LEN;
|
||||
uint8_t * src_buf = src;
|
||||
|
||||
if (palette_size > 0) {
|
||||
// Grayscale palette
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
*palette_buf = i;
|
||||
palette_buf++;
|
||||
}
|
||||
// Reserved / alpha channel.
|
||||
*palette_buf = 0;
|
||||
palette_buf++;
|
||||
}
|
||||
}
|
||||
|
||||
//convert data to RGB888
|
||||
if(format == PIXFORMAT_RGB888) {
|
||||
memcpy(pix_buf, src_buf, pix_count*3);
|
||||
memcpy(rgb_buf, src_buf, pix_count*3);
|
||||
} else if(format == PIXFORMAT_RGB565) {
|
||||
int i;
|
||||
uint8_t hb, lb;
|
||||
for(i=0; i<pix_count; i++) {
|
||||
hb = *src_buf++;
|
||||
lb = *src_buf++;
|
||||
*pix_buf++ = (lb & 0x1F) << 3;
|
||||
*pix_buf++ = (hb & 0x07) << 5 | (lb & 0xE0) >> 3;
|
||||
*pix_buf++ = hb & 0xF8;
|
||||
*rgb_buf++ = (lb & 0x1F) << 3;
|
||||
*rgb_buf++ = (hb & 0x07) << 5 | (lb & 0xE0) >> 3;
|
||||
*rgb_buf++ = hb & 0xF8;
|
||||
}
|
||||
} else if(format == PIXFORMAT_GRAYSCALE) {
|
||||
memcpy(pix_buf, src_buf, pix_count);
|
||||
int i;
|
||||
uint8_t b;
|
||||
for(i=0; i<pix_count; i++) {
|
||||
b = *src_buf++;
|
||||
*rgb_buf++ = b;
|
||||
*rgb_buf++ = b;
|
||||
*rgb_buf++ = b;
|
||||
}
|
||||
} else if(format == PIXFORMAT_YUV422) {
|
||||
int i, maxi = pix_count / 2;
|
||||
uint8_t y0, y1, u, v;
|
||||
|
|
@ -376,14 +309,14 @@ bool fmt2bmp(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixf
|
|||
v = *src_buf++;
|
||||
|
||||
yuv2rgb(y0, u, v, &r, &g, &b);
|
||||
*pix_buf++ = b;
|
||||
*pix_buf++ = g;
|
||||
*pix_buf++ = r;
|
||||
*rgb_buf++ = b;
|
||||
*rgb_buf++ = g;
|
||||
*rgb_buf++ = r;
|
||||
|
||||
yuv2rgb(y1, u, v, &r, &g, &b);
|
||||
*pix_buf++ = b;
|
||||
*pix_buf++ = g;
|
||||
*pix_buf++ = r;
|
||||
*rgb_buf++ = b;
|
||||
*rgb_buf++ = g;
|
||||
*rgb_buf++ = r;
|
||||
}
|
||||
}
|
||||
*out = out_buf;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,21 @@
|
|||
#include "jpge.h"
|
||||
#include "yuv.h"
|
||||
|
||||
#include "esp_system.h"
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
|
||||
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||
#include "esp32/spiram.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/spiram.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/spiram.h"
|
||||
#else
|
||||
#error Target CONFIG_IDF_TARGET is not supported
|
||||
#endif
|
||||
#else // ESP32 Before IDF 4.0
|
||||
#include "esp_spiram.h"
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
||||
#include "esp32-hal-log.h"
|
||||
#define TAG ""
|
||||
|
|
@ -35,12 +50,7 @@ static void *_malloc(size_t size)
|
|||
if(res) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// check if SPIRAM is enabled and is allocatable
|
||||
#if (CONFIG_SPIRAM_SUPPORT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC))
|
||||
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static IRAM_ATTR void convert_line_format(uint8_t * src, pixformat_t format, uint8_t * dst, size_t width, size_t in_channels, size_t line)
|
||||
|
|
@ -189,7 +199,7 @@ public:
|
|||
return true;
|
||||
}
|
||||
if ((size_t)len > (max_len - index)) {
|
||||
//ESP_LOGW(TAG, "JPG output overflow: %d bytes (%d,%d,%d)", len - (max_len - index), len, index, max_len);
|
||||
ESP_LOGW(TAG, "JPG output overflow: %d bytes", len - (max_len - index));
|
||||
len = max_len - index;
|
||||
}
|
||||
if (len) {
|
||||
|
|
@ -209,7 +219,7 @@ bool fmt2jpg(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixf
|
|||
{
|
||||
//todo: allocate proper buffer for holding JPEG data
|
||||
//this should be enough for CIF frame size
|
||||
int jpg_buf_len = 128*1024;
|
||||
int jpg_buf_len = 64*1024;
|
||||
|
||||
|
||||
uint8_t * jpg_buf = (uint8_t *)_malloc(jpg_buf_len);
|
||||
|
|
|
|||
536
driver/cam_hal.c
536
driver/cam_hal.c
|
|
@ -1,536 +0,0 @@
|
|||
// Copyright 2010-2020 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdalign.h>
|
||||
#include "esp_heap_caps.h"
|
||||
#include "ll_cam.h"
|
||||
#include "cam_hal.h"
|
||||
|
||||
#if (ESP_IDF_VERSION_MAJOR == 3) && (ESP_IDF_VERSION_MINOR == 3)
|
||||
#include "rom/ets_sys.h"
|
||||
#else
|
||||
#include "esp_timer.h"
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include "esp32/rom/ets_sys.h" // will be removed in idf v5.0
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/rom/ets_sys.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/rom/ets_sys.h"
|
||||
#endif
|
||||
#endif // ESP_IDF_VERSION_MAJOR
|
||||
#define ESP_CAMERA_ETS_PRINTF ets_printf
|
||||
|
||||
#if CONFIG_CAMERA_TASK_STACK_SIZE
|
||||
#define CAM_TASK_STACK CONFIG_CAMERA_TASK_STACK_SIZE
|
||||
#else
|
||||
#define CAM_TASK_STACK (2*1024)
|
||||
#endif
|
||||
|
||||
static const char *TAG = "cam_hal";
|
||||
static cam_obj_t *cam_obj = NULL;
|
||||
|
||||
static const uint32_t JPEG_SOI_MARKER = 0xFFD8FF; // written in little-endian for esp32
|
||||
static const uint16_t JPEG_EOI_MARKER = 0xD9FF; // written in little-endian for esp32
|
||||
|
||||
static int cam_verify_jpeg_soi(const uint8_t *inbuf, uint32_t length)
|
||||
{
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
if (memcmp(&inbuf[i], &JPEG_SOI_MARKER, 3) == 0) {
|
||||
//ESP_LOGW(TAG, "SOI: %d", (int) i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
ESP_LOGW(TAG, "NO-SOI");
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int cam_verify_jpeg_eoi(const uint8_t *inbuf, uint32_t length)
|
||||
{
|
||||
int offset = -1;
|
||||
uint8_t *dptr = (uint8_t *)inbuf + length - 2;
|
||||
while (dptr > inbuf) {
|
||||
if (memcmp(dptr, &JPEG_EOI_MARKER, 2) == 0) {
|
||||
offset = dptr - inbuf;
|
||||
//ESP_LOGW(TAG, "EOI: %d", length - (offset + 2));
|
||||
return offset;
|
||||
}
|
||||
dptr--;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool cam_get_next_frame(int * frame_pos)
|
||||
{
|
||||
if(!cam_obj->frames[*frame_pos].en){
|
||||
for (int x = 0; x < cam_obj->frame_cnt; x++) {
|
||||
if (cam_obj->frames[x].en) {
|
||||
*frame_pos = x;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool cam_start_frame(int * frame_pos)
|
||||
{
|
||||
if (cam_get_next_frame(frame_pos)) {
|
||||
if(ll_cam_start(cam_obj, *frame_pos)){
|
||||
// Vsync the frame manually
|
||||
ll_cam_do_vsync(cam_obj);
|
||||
uint64_t us = (uint64_t)esp_timer_get_time();
|
||||
cam_obj->frames[*frame_pos].fb.timestamp.tv_sec = us / 1000000UL;
|
||||
cam_obj->frames[*frame_pos].fb.timestamp.tv_usec = us % 1000000UL;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void IRAM_ATTR ll_cam_send_event(cam_obj_t *cam, cam_event_t cam_event, BaseType_t * HPTaskAwoken)
|
||||
{
|
||||
if (xQueueSendFromISR(cam->event_queue, (void *)&cam_event, HPTaskAwoken) != pdTRUE) {
|
||||
ll_cam_stop(cam);
|
||||
cam->state = CAM_STATE_IDLE;
|
||||
ESP_CAMERA_ETS_PRINTF(DRAM_STR("cam_hal: EV-%s-OVF\r\n"), cam_event==CAM_IN_SUC_EOF_EVENT ? DRAM_STR("EOF") : DRAM_STR("VSYNC"));
|
||||
}
|
||||
}
|
||||
|
||||
//Copy fram from DMA dma_buffer to fram dma_buffer
|
||||
static void cam_task(void *arg)
|
||||
{
|
||||
int cnt = 0;
|
||||
int frame_pos = 0;
|
||||
cam_obj->state = CAM_STATE_IDLE;
|
||||
cam_event_t cam_event = 0;
|
||||
|
||||
xQueueReset(cam_obj->event_queue);
|
||||
|
||||
while (1) {
|
||||
xQueueReceive(cam_obj->event_queue, (void *)&cam_event, portMAX_DELAY);
|
||||
DBG_PIN_SET(1);
|
||||
switch (cam_obj->state) {
|
||||
|
||||
case CAM_STATE_IDLE: {
|
||||
if (cam_event == CAM_VSYNC_EVENT) {
|
||||
//DBG_PIN_SET(1);
|
||||
if(cam_start_frame(&frame_pos)){
|
||||
cam_obj->frames[frame_pos].fb.len = 0;
|
||||
cam_obj->state = CAM_STATE_READ_BUF;
|
||||
}
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CAM_STATE_READ_BUF: {
|
||||
camera_fb_t * frame_buffer_event = &cam_obj->frames[frame_pos].fb;
|
||||
size_t pixels_per_dma = (cam_obj->dma_half_buffer_size * cam_obj->fb_bytes_per_pixel) / (cam_obj->dma_bytes_per_item * cam_obj->in_bytes_per_pixel);
|
||||
|
||||
if (cam_event == CAM_IN_SUC_EOF_EVENT) {
|
||||
if(!cam_obj->psram_mode){
|
||||
if (cam_obj->fb_size < (frame_buffer_event->len + pixels_per_dma)) {
|
||||
ESP_LOGW(TAG, "FB-OVF");
|
||||
ll_cam_stop(cam_obj);
|
||||
DBG_PIN_SET(0);
|
||||
continue;
|
||||
}
|
||||
frame_buffer_event->len += ll_cam_memcpy(cam_obj,
|
||||
&frame_buffer_event->buf[frame_buffer_event->len],
|
||||
&cam_obj->dma_buffer[(cnt % cam_obj->dma_half_buffer_cnt) * cam_obj->dma_half_buffer_size],
|
||||
cam_obj->dma_half_buffer_size);
|
||||
}
|
||||
//Check for JPEG SOI in the first buffer. stop if not found
|
||||
if (cam_obj->jpeg_mode && cnt == 0 && cam_verify_jpeg_soi(frame_buffer_event->buf, frame_buffer_event->len) != 0) {
|
||||
ll_cam_stop(cam_obj);
|
||||
cam_obj->state = CAM_STATE_IDLE;
|
||||
}
|
||||
cnt++;
|
||||
|
||||
} else if (cam_event == CAM_VSYNC_EVENT) {
|
||||
//DBG_PIN_SET(1);
|
||||
ll_cam_stop(cam_obj);
|
||||
|
||||
if (cnt || !cam_obj->jpeg_mode || cam_obj->psram_mode) {
|
||||
if (cam_obj->jpeg_mode) {
|
||||
if (!cam_obj->psram_mode) {
|
||||
if (cam_obj->fb_size < (frame_buffer_event->len + pixels_per_dma)) {
|
||||
ESP_LOGW(TAG, "FB-OVF");
|
||||
cnt--;
|
||||
} else {
|
||||
frame_buffer_event->len += ll_cam_memcpy(cam_obj,
|
||||
&frame_buffer_event->buf[frame_buffer_event->len],
|
||||
&cam_obj->dma_buffer[(cnt % cam_obj->dma_half_buffer_cnt) * cam_obj->dma_half_buffer_size],
|
||||
cam_obj->dma_half_buffer_size);
|
||||
}
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
|
||||
cam_obj->frames[frame_pos].en = 0;
|
||||
|
||||
if (cam_obj->psram_mode) {
|
||||
if (cam_obj->jpeg_mode) {
|
||||
frame_buffer_event->len = cnt * cam_obj->dma_half_buffer_size;
|
||||
} else {
|
||||
frame_buffer_event->len = cam_obj->recv_size;
|
||||
}
|
||||
} else if (!cam_obj->jpeg_mode) {
|
||||
if (frame_buffer_event->len != cam_obj->fb_size) {
|
||||
cam_obj->frames[frame_pos].en = 1;
|
||||
ESP_LOGE(TAG, "FB-SIZE: %u != %u", frame_buffer_event->len, (unsigned) cam_obj->fb_size);
|
||||
}
|
||||
}
|
||||
//send frame
|
||||
if(!cam_obj->frames[frame_pos].en && xQueueSend(cam_obj->frame_buffer_queue, (void *)&frame_buffer_event, 0) != pdTRUE) {
|
||||
//pop frame buffer from the queue
|
||||
camera_fb_t * fb2 = NULL;
|
||||
if(xQueueReceive(cam_obj->frame_buffer_queue, &fb2, 0) == pdTRUE) {
|
||||
//push the new frame to the end of the queue
|
||||
if (xQueueSend(cam_obj->frame_buffer_queue, (void *)&frame_buffer_event, 0) != pdTRUE) {
|
||||
cam_obj->frames[frame_pos].en = 1;
|
||||
ESP_LOGE(TAG, "FBQ-SND");
|
||||
}
|
||||
//free the popped buffer
|
||||
cam_give(fb2);
|
||||
} else {
|
||||
//queue is full and we could not pop a frame from it
|
||||
cam_obj->frames[frame_pos].en = 1;
|
||||
ESP_LOGE(TAG, "FBQ-RCV");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!cam_start_frame(&frame_pos)){
|
||||
cam_obj->state = CAM_STATE_IDLE;
|
||||
} else {
|
||||
cam_obj->frames[frame_pos].fb.len = 0;
|
||||
}
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
DBG_PIN_SET(0);
|
||||
}
|
||||
}
|
||||
|
||||
static lldesc_t * allocate_dma_descriptors(uint32_t count, uint16_t size, uint8_t * buffer)
|
||||
{
|
||||
lldesc_t *dma = (lldesc_t *)heap_caps_malloc(count * sizeof(lldesc_t), MALLOC_CAP_DMA);
|
||||
if (dma == NULL) {
|
||||
return dma;
|
||||
}
|
||||
|
||||
for (int x = 0; x < count; x++) {
|
||||
dma[x].size = size;
|
||||
dma[x].length = 0;
|
||||
dma[x].sosf = 0;
|
||||
dma[x].eof = 0;
|
||||
dma[x].owner = 1;
|
||||
dma[x].buf = (buffer + size * x);
|
||||
dma[x].empty = (uint32_t)&dma[(x + 1) % count];
|
||||
}
|
||||
return dma;
|
||||
}
|
||||
|
||||
static esp_err_t cam_dma_config(const camera_config_t *config)
|
||||
{
|
||||
bool ret = ll_cam_dma_sizes(cam_obj);
|
||||
if (0 == ret) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
cam_obj->dma_node_cnt = (cam_obj->dma_buffer_size) / cam_obj->dma_node_buffer_size; // Number of DMA nodes
|
||||
cam_obj->frame_copy_cnt = cam_obj->recv_size / cam_obj->dma_half_buffer_size; // Number of interrupted copies, ping-pong copy
|
||||
|
||||
ESP_LOGI(TAG, "buffer_size: %d, half_buffer_size: %d, node_buffer_size: %d, node_cnt: %d, total_cnt: %d",
|
||||
(int) cam_obj->dma_buffer_size, (int) cam_obj->dma_half_buffer_size, (int) cam_obj->dma_node_buffer_size,
|
||||
(int) cam_obj->dma_node_cnt, (int) cam_obj->frame_copy_cnt);
|
||||
|
||||
cam_obj->dma_buffer = NULL;
|
||||
cam_obj->dma = NULL;
|
||||
|
||||
cam_obj->frames = (cam_frame_t *)heap_caps_aligned_calloc(alignof(cam_frame_t), 1, cam_obj->frame_cnt * sizeof(cam_frame_t), MALLOC_CAP_DEFAULT);
|
||||
CAM_CHECK(cam_obj->frames != NULL, "frames malloc failed", ESP_FAIL);
|
||||
|
||||
uint8_t dma_align = 0;
|
||||
size_t fb_size = cam_obj->fb_size;
|
||||
if (cam_obj->psram_mode) {
|
||||
dma_align = ll_cam_get_dma_align(cam_obj);
|
||||
if (cam_obj->fb_size < cam_obj->recv_size) {
|
||||
fb_size = cam_obj->recv_size;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate memory for frame buffer */
|
||||
size_t alloc_size = fb_size * sizeof(uint8_t) + dma_align;
|
||||
uint32_t _caps = MALLOC_CAP_8BIT;
|
||||
if (CAMERA_FB_IN_DRAM == config->fb_location) {
|
||||
_caps |= MALLOC_CAP_INTERNAL;
|
||||
} else {
|
||||
_caps |= MALLOC_CAP_SPIRAM;
|
||||
}
|
||||
for (int x = 0; x < cam_obj->frame_cnt; x++) {
|
||||
cam_obj->frames[x].dma = NULL;
|
||||
cam_obj->frames[x].fb_offset = 0;
|
||||
cam_obj->frames[x].en = 0;
|
||||
ESP_LOGI(TAG, "Allocating %d Byte frame buffer in %s", alloc_size, _caps & MALLOC_CAP_SPIRAM ? "PSRAM" : "OnBoard RAM");
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
|
||||
// In IDF v4.2 and earlier, memory returned by heap_caps_aligned_alloc must be freed using heap_caps_aligned_free.
|
||||
// And heap_caps_aligned_free is deprecated on v4.3.
|
||||
cam_obj->frames[x].fb.buf = (uint8_t *)heap_caps_aligned_alloc(16, alloc_size, _caps);
|
||||
#else
|
||||
cam_obj->frames[x].fb.buf = (uint8_t *)heap_caps_malloc(alloc_size, _caps);
|
||||
#endif
|
||||
CAM_CHECK(cam_obj->frames[x].fb.buf != NULL, "frame buffer malloc failed", ESP_FAIL);
|
||||
if (cam_obj->psram_mode) {
|
||||
//align PSRAM buffer. TODO: save the offset so proper address can be freed later
|
||||
cam_obj->frames[x].fb_offset = dma_align - ((uint32_t)cam_obj->frames[x].fb.buf & (dma_align - 1));
|
||||
cam_obj->frames[x].fb.buf += cam_obj->frames[x].fb_offset;
|
||||
ESP_LOGI(TAG, "Frame[%d]: Offset: %u, Addr: 0x%08X", x, cam_obj->frames[x].fb_offset, (unsigned) cam_obj->frames[x].fb.buf);
|
||||
cam_obj->frames[x].dma = allocate_dma_descriptors(cam_obj->dma_node_cnt, cam_obj->dma_node_buffer_size, cam_obj->frames[x].fb.buf);
|
||||
CAM_CHECK(cam_obj->frames[x].dma != NULL, "frame dma malloc failed", ESP_FAIL);
|
||||
}
|
||||
cam_obj->frames[x].en = 1;
|
||||
}
|
||||
|
||||
if (!cam_obj->psram_mode) {
|
||||
cam_obj->dma_buffer = (uint8_t *)heap_caps_malloc(cam_obj->dma_buffer_size * sizeof(uint8_t), MALLOC_CAP_DMA);
|
||||
if(NULL == cam_obj->dma_buffer) {
|
||||
ESP_LOGE(TAG,"%s(%d): DMA buffer %d Byte malloc failed, the current largest free block:%d Byte", __FUNCTION__, __LINE__,
|
||||
(int) cam_obj->dma_buffer_size, (int) heap_caps_get_largest_free_block(MALLOC_CAP_DMA));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
cam_obj->dma = allocate_dma_descriptors(cam_obj->dma_node_cnt, cam_obj->dma_node_buffer_size, cam_obj->dma_buffer);
|
||||
CAM_CHECK(cam_obj->dma != NULL, "dma malloc failed", ESP_FAIL);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t cam_init(const camera_config_t *config)
|
||||
{
|
||||
CAM_CHECK(NULL != config, "config pointer is invalid", ESP_ERR_INVALID_ARG);
|
||||
|
||||
esp_err_t ret = ESP_OK;
|
||||
cam_obj = (cam_obj_t *)heap_caps_calloc(1, sizeof(cam_obj_t), MALLOC_CAP_DMA);
|
||||
CAM_CHECK(NULL != cam_obj, "lcd_cam object malloc error", ESP_ERR_NO_MEM);
|
||||
|
||||
cam_obj->swap_data = 0;
|
||||
cam_obj->vsync_pin = config->pin_vsync;
|
||||
cam_obj->vsync_invert = true;
|
||||
|
||||
ll_cam_set_pin(cam_obj, config);
|
||||
ret = ll_cam_config(cam_obj, config);
|
||||
CAM_CHECK_GOTO(ret == ESP_OK, "ll_cam initialize failed", err);
|
||||
|
||||
#if CAMERA_DBG_PIN_ENABLE
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[DBG_PIN_NUM], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(DBG_PIN_NUM, GPIO_MODE_OUTPUT);
|
||||
gpio_set_pull_mode(DBG_PIN_NUM, GPIO_FLOATING);
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "cam init ok");
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
free(cam_obj);
|
||||
cam_obj = NULL;
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t cam_config(const camera_config_t *config, framesize_t frame_size, uint16_t sensor_pid)
|
||||
{
|
||||
CAM_CHECK(NULL != config, "config pointer is invalid", ESP_ERR_INVALID_ARG);
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret = ll_cam_set_sample_mode(cam_obj, (pixformat_t)config->pixel_format, config->xclk_freq_hz, sensor_pid);
|
||||
|
||||
cam_obj->jpeg_mode = config->pixel_format == PIXFORMAT_JPEG;
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
cam_obj->psram_mode = false;
|
||||
#else
|
||||
cam_obj->psram_mode = (config->xclk_freq_hz == 16000000);
|
||||
#endif
|
||||
cam_obj->frame_cnt = config->fb_count;
|
||||
cam_obj->width = resolution[frame_size].width;
|
||||
cam_obj->height = resolution[frame_size].height;
|
||||
|
||||
if(cam_obj->jpeg_mode){
|
||||
#ifdef CONFIG_CAMERA_JPEG_MODE_FRAME_SIZE_AUTO
|
||||
cam_obj->recv_size = cam_obj->width * cam_obj->height / 5;
|
||||
#else
|
||||
cam_obj->recv_size = CONFIG_CAMERA_JPEG_MODE_FRAME_SIZE;
|
||||
#endif
|
||||
cam_obj->fb_size = cam_obj->recv_size;
|
||||
} else {
|
||||
cam_obj->recv_size = cam_obj->width * cam_obj->height * cam_obj->in_bytes_per_pixel;
|
||||
cam_obj->fb_size = cam_obj->width * cam_obj->height * cam_obj->fb_bytes_per_pixel;
|
||||
}
|
||||
|
||||
ret = cam_dma_config(config);
|
||||
CAM_CHECK_GOTO(ret == ESP_OK, "cam_dma_config failed", err);
|
||||
|
||||
size_t queue_size = cam_obj->dma_half_buffer_cnt - 1;
|
||||
if (queue_size == 0) {
|
||||
queue_size = 1;
|
||||
}
|
||||
cam_obj->event_queue = xQueueCreate(queue_size, sizeof(cam_event_t));
|
||||
CAM_CHECK_GOTO(cam_obj->event_queue != NULL, "event_queue create failed", err);
|
||||
|
||||
size_t frame_buffer_queue_len = cam_obj->frame_cnt;
|
||||
if (config->grab_mode == CAMERA_GRAB_LATEST && cam_obj->frame_cnt > 1) {
|
||||
frame_buffer_queue_len = cam_obj->frame_cnt - 1;
|
||||
}
|
||||
cam_obj->frame_buffer_queue = xQueueCreate(frame_buffer_queue_len, sizeof(camera_fb_t*));
|
||||
CAM_CHECK_GOTO(cam_obj->frame_buffer_queue != NULL, "frame_buffer_queue create failed", err);
|
||||
|
||||
ret = ll_cam_init_isr(cam_obj);
|
||||
CAM_CHECK_GOTO(ret == ESP_OK, "cam intr alloc failed", err);
|
||||
|
||||
|
||||
#if CONFIG_CAMERA_CORE0
|
||||
xTaskCreatePinnedToCore(cam_task, "cam_task", CAM_TASK_STACK, NULL, configMAX_PRIORITIES - 2, &cam_obj->task_handle, 0);
|
||||
#elif CONFIG_CAMERA_CORE1
|
||||
xTaskCreatePinnedToCore(cam_task, "cam_task", CAM_TASK_STACK, NULL, configMAX_PRIORITIES - 2, &cam_obj->task_handle, 1);
|
||||
#else
|
||||
xTaskCreate(cam_task, "cam_task", CAM_TASK_STACK, NULL, configMAX_PRIORITIES - 2, &cam_obj->task_handle);
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "cam config ok");
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
cam_deinit();
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t cam_deinit(void)
|
||||
{
|
||||
if (!cam_obj) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
cam_stop();
|
||||
if (cam_obj->task_handle) {
|
||||
vTaskDelete(cam_obj->task_handle);
|
||||
}
|
||||
if (cam_obj->event_queue) {
|
||||
vQueueDelete(cam_obj->event_queue);
|
||||
}
|
||||
if (cam_obj->frame_buffer_queue) {
|
||||
vQueueDelete(cam_obj->frame_buffer_queue);
|
||||
}
|
||||
|
||||
ll_cam_deinit(cam_obj);
|
||||
|
||||
if (cam_obj->dma) {
|
||||
free(cam_obj->dma);
|
||||
}
|
||||
if (cam_obj->dma_buffer) {
|
||||
free(cam_obj->dma_buffer);
|
||||
}
|
||||
if (cam_obj->frames) {
|
||||
for (int x = 0; x < cam_obj->frame_cnt; x++) {
|
||||
free(cam_obj->frames[x].fb.buf - cam_obj->frames[x].fb_offset);
|
||||
if (cam_obj->frames[x].dma) {
|
||||
free(cam_obj->frames[x].dma);
|
||||
}
|
||||
}
|
||||
free(cam_obj->frames);
|
||||
}
|
||||
|
||||
free(cam_obj);
|
||||
cam_obj = NULL;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void cam_stop(void)
|
||||
{
|
||||
ll_cam_vsync_intr_enable(cam_obj, false);
|
||||
ll_cam_stop(cam_obj);
|
||||
}
|
||||
|
||||
void cam_start(void)
|
||||
{
|
||||
ll_cam_vsync_intr_enable(cam_obj, true);
|
||||
}
|
||||
|
||||
camera_fb_t *cam_take(TickType_t timeout)
|
||||
{
|
||||
camera_fb_t *dma_buffer = NULL;
|
||||
TickType_t start = xTaskGetTickCount();
|
||||
xQueueReceive(cam_obj->frame_buffer_queue, (void *)&dma_buffer, timeout);
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
// Currently (22.01.2024) there is a bug in ESP-IDF v5.2, that causes
|
||||
// GDMA to fall into a strange state if it is running while WiFi STA is connecting.
|
||||
// This code tries to reset GDMA if frame is not received, to try and help with
|
||||
// this case. It is possible to have some side effects too, though none come to mind
|
||||
if (!dma_buffer) {
|
||||
ll_cam_dma_reset(cam_obj);
|
||||
xQueueReceive(cam_obj->frame_buffer_queue, (void *)&dma_buffer, timeout);
|
||||
}
|
||||
#endif
|
||||
if (dma_buffer) {
|
||||
if(cam_obj->jpeg_mode){
|
||||
// find the end marker for JPEG. Data after that can be discarded
|
||||
int offset_e = cam_verify_jpeg_eoi(dma_buffer->buf, dma_buffer->len);
|
||||
if (offset_e >= 0) {
|
||||
// adjust buffer length
|
||||
dma_buffer->len = offset_e + sizeof(JPEG_EOI_MARKER);
|
||||
return dma_buffer;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "NO-EOI");
|
||||
cam_give(dma_buffer);
|
||||
TickType_t ticks_spent = xTaskGetTickCount() - start;
|
||||
if (ticks_spent >= timeout) {
|
||||
return NULL; /* We are out of time */
|
||||
}
|
||||
return cam_take(timeout - ticks_spent);//recurse!!!!
|
||||
}
|
||||
} else if(cam_obj->psram_mode && cam_obj->in_bytes_per_pixel != cam_obj->fb_bytes_per_pixel){
|
||||
//currently this is used only for YUV to GRAYSCALE
|
||||
dma_buffer->len = ll_cam_memcpy(cam_obj, dma_buffer->buf, dma_buffer->buf, dma_buffer->len);
|
||||
}
|
||||
return dma_buffer;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Failed to get the frame on time!");
|
||||
// #if CONFIG_IDF_TARGET_ESP32S3
|
||||
// ll_cam_dma_print_state(cam_obj);
|
||||
// #endif
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void cam_give(camera_fb_t *dma_buffer)
|
||||
{
|
||||
for (int x = 0; x < cam_obj->frame_cnt; x++) {
|
||||
if (&cam_obj->frames[x].fb == dma_buffer) {
|
||||
cam_obj->frames[x].en = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cam_give_all(void) {
|
||||
for (int x = 0; x < cam_obj->frame_cnt; x++) {
|
||||
cam_obj->frames[x].en = 1;
|
||||
}
|
||||
}
|
||||
640
driver/camera.c
Executable file
640
driver/camera.c
Executable file
|
|
@ -0,0 +1,640 @@
|
|||
// Copyright 2015-2016 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "time.h"
|
||||
#include "sys/time.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/lcd_cam.h"
|
||||
#include "esp_system.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "nvs.h"
|
||||
#include "sensor.h"
|
||||
#include "sccb.h"
|
||||
#include "esp_camera.h"
|
||||
#include "camera_common.h"
|
||||
#if CONFIG_OV2640_SUPPORT
|
||||
#include "ov2640.h"
|
||||
#endif
|
||||
#if CONFIG_OV7725_SUPPORT
|
||||
#include "ov7725.h"
|
||||
#endif
|
||||
#if CONFIG_OV3660_SUPPORT
|
||||
#include "ov3660.h"
|
||||
#endif
|
||||
#if CONFIG_OV5640_SUPPORT
|
||||
#include "ov5640.h"
|
||||
#endif
|
||||
#if CONFIG_NT99141_SUPPORT
|
||||
#include "nt99141.h"
|
||||
#endif
|
||||
#if CONFIG_OV7670_SUPPORT
|
||||
#include "ov7670.h"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CAMERA_NONE = 0,
|
||||
CAMERA_UNKNOWN = 1,
|
||||
CAMERA_OV7725 = 7725,
|
||||
CAMERA_OV2640 = 2640,
|
||||
CAMERA_OV3660 = 3660,
|
||||
CAMERA_OV5640 = 5640,
|
||||
CAMERA_OV7670 = 7670,
|
||||
CAMERA_NT99141 = 9141,
|
||||
} camera_model_t;
|
||||
|
||||
#define REG_PID 0x0A
|
||||
#define REG_VER 0x0B
|
||||
#define REG_MIDH 0x1C
|
||||
#define REG_MIDL 0x1D
|
||||
|
||||
#define REG16_CHIDH 0x300A
|
||||
#define REG16_CHIDL 0x300B
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
||||
#include "esp32-hal-log.h"
|
||||
#define TAG ""
|
||||
#else
|
||||
#include "esp_log.h"
|
||||
static const char* TAG = "camera";
|
||||
#endif
|
||||
static const char* CAMERA_SENSOR_NVS_KEY = "sensor";
|
||||
static const char* CAMERA_PIXFORMAT_NVS_KEY = "pixformat";
|
||||
|
||||
typedef struct {
|
||||
camera_config_t config;
|
||||
sensor_t sensor;
|
||||
|
||||
size_t fb_size;
|
||||
size_t data_size;
|
||||
|
||||
size_t width;
|
||||
size_t height;
|
||||
size_t in_bytes_per_pixel;
|
||||
size_t fb_bytes_per_pixel;
|
||||
|
||||
lcd_cam_handle_t lcd_cam;
|
||||
lcd_cam_config_t lcd_cam_config;
|
||||
} camera_state_t;
|
||||
|
||||
camera_state_t* s_state = NULL;
|
||||
|
||||
static esp_err_t camera_probe(const camera_config_t* config, camera_model_t* out_camera_model)
|
||||
{
|
||||
if (s_state == NULL) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (config->pin_sscb_sda != -1) {
|
||||
ESP_LOGD(TAG, "Initializing SSCB");
|
||||
SCCB_Init(config->pin_sscb_sda, config->pin_sscb_scl);
|
||||
}
|
||||
|
||||
if(config->pin_pwdn >= 0) {
|
||||
ESP_LOGD(TAG, "Resetting camera by power down line");
|
||||
gpio_config_t conf = { 0 };
|
||||
conf.pin_bit_mask = 1LL << config->pin_pwdn;
|
||||
conf.mode = GPIO_MODE_OUTPUT;
|
||||
gpio_config(&conf);
|
||||
|
||||
// carefull, logic is inverted compared to reset pin
|
||||
gpio_set_level(config->pin_pwdn, 1);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
gpio_set_level(config->pin_pwdn, 0);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
if(config->pin_reset >= 0) {
|
||||
ESP_LOGD(TAG, "Resetting camera");
|
||||
gpio_config_t conf = { 0 };
|
||||
conf.pin_bit_mask = 1LL << config->pin_reset;
|
||||
conf.mode = GPIO_MODE_OUTPUT;
|
||||
gpio_config(&conf);
|
||||
|
||||
gpio_set_level(config->pin_reset, 0);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
gpio_set_level(config->pin_reset, 1);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Searching for camera address");
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
uint8_t slv_addr = SCCB_Probe();
|
||||
if (slv_addr == 0) {
|
||||
*out_camera_model = CAMERA_NONE;
|
||||
return ESP_ERR_CAMERA_NOT_DETECTED;
|
||||
}
|
||||
|
||||
//slv_addr = 0x30;
|
||||
ESP_LOGD(TAG, "Detected camera at address=0x%02x", slv_addr);
|
||||
sensor_id_t* id = &s_state->sensor.id;
|
||||
|
||||
#if CONFIG_OV2640_SUPPORT
|
||||
if (slv_addr == 0x30) {
|
||||
ESP_LOGD(TAG, "Resetting OV2640");
|
||||
//camera might be OV2640. try to reset it
|
||||
SCCB_Write(0x30, 0xFF, 0x01);//bank sensor
|
||||
SCCB_Write(0x30, 0x12, 0x80);//reset
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
slv_addr = SCCB_Probe();
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_NT99141_SUPPORT
|
||||
if (slv_addr == 0x2a)
|
||||
{
|
||||
ESP_LOGD(TAG, "Resetting NT99141");
|
||||
SCCB_Write16(0x2a, 0x3008, 0x01);//bank sensor
|
||||
}
|
||||
#endif
|
||||
|
||||
s_state->sensor.slv_addr = slv_addr;
|
||||
s_state->sensor.xclk_freq_hz = config->xclk_freq_hz;
|
||||
|
||||
#if (CONFIG_OV3660_SUPPORT || CONFIG_OV5640_SUPPORT || CONFIG_NT99141_SUPPORT)
|
||||
if(s_state->sensor.slv_addr == 0x3c){
|
||||
id->PID = SCCB_Read16(s_state->sensor.slv_addr, REG16_CHIDH);
|
||||
id->VER = SCCB_Read16(s_state->sensor.slv_addr, REG16_CHIDL);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
ESP_LOGD(TAG, "Camera PID=0x%02x VER=0x%02x", id->PID, id->VER);
|
||||
} else if(s_state->sensor.slv_addr == 0x2a){
|
||||
id->PID = SCCB_Read16(s_state->sensor.slv_addr, 0x3000);
|
||||
id->VER = SCCB_Read16(s_state->sensor.slv_addr, 0x3001);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
ESP_LOGD(TAG, "Camera PID=0x%02x VER=0x%02x", id->PID, id->VER);
|
||||
if(config->xclk_freq_hz > 10000000)
|
||||
{
|
||||
ESP_LOGE(TAG, "NT99141: only XCLK under 10MHz is supported, and XCLK is now set to 10M");
|
||||
s_state->sensor.xclk_freq_hz = 10000000;
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
id->PID = SCCB_Read(s_state->sensor.slv_addr, REG_PID);
|
||||
id->VER = SCCB_Read(s_state->sensor.slv_addr, REG_VER);
|
||||
id->MIDL = SCCB_Read(s_state->sensor.slv_addr, REG_MIDL);
|
||||
id->MIDH = SCCB_Read(s_state->sensor.slv_addr, REG_MIDH);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
ESP_LOGD(TAG, "Camera PID=0x%02x VER=0x%02x MIDL=0x%02x MIDH=0x%02x",
|
||||
id->PID, id->VER, id->MIDH, id->MIDL);
|
||||
|
||||
#if (CONFIG_OV3660_SUPPORT || CONFIG_OV5640_SUPPORT || CONFIG_NT99141_SUPPORT)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
switch (id->PID) {
|
||||
#if CONFIG_OV2640_SUPPORT
|
||||
case OV2640_PID:
|
||||
*out_camera_model = CAMERA_OV2640;
|
||||
ov2640_init(&s_state->sensor);
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_OV7725_SUPPORT
|
||||
case OV7725_PID:
|
||||
*out_camera_model = CAMERA_OV7725;
|
||||
ov7725_init(&s_state->sensor);
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_OV3660_SUPPORT
|
||||
case OV3660_PID:
|
||||
*out_camera_model = CAMERA_OV3660;
|
||||
ov3660_init(&s_state->sensor);
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_OV5640_SUPPORT
|
||||
case OV5640_PID:
|
||||
*out_camera_model = CAMERA_OV5640;
|
||||
ov5640_init(&s_state->sensor);
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_OV7670_SUPPORT
|
||||
case OV7670_PID:
|
||||
*out_camera_model = CAMERA_OV7670;
|
||||
ov7670_init(&s_state->sensor);
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_NT99141_SUPPORT
|
||||
case NT99141_PID:
|
||||
*out_camera_model = CAMERA_NT99141;
|
||||
NT99141_init(&s_state->sensor);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
id->PID = 0;
|
||||
*out_camera_model = CAMERA_UNKNOWN;
|
||||
ESP_LOGE(TAG, "Detected camera not supported.");
|
||||
return ESP_ERR_CAMERA_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Doing SW reset of sensor");
|
||||
s_state->sensor.reset(&s_state->sensor);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t camera_init(const camera_config_t* config)
|
||||
{
|
||||
if (!s_state) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (s_state->sensor.id.PID == 0) {
|
||||
return ESP_ERR_CAMERA_NOT_SUPPORTED;
|
||||
}
|
||||
memcpy(&s_state->config, config, sizeof(*config));
|
||||
esp_err_t err = ESP_OK;
|
||||
framesize_t frame_size = (framesize_t) config->frame_size;
|
||||
pixformat_t pix_format = (pixformat_t) config->pixel_format;
|
||||
|
||||
switch (s_state->sensor.id.PID) {
|
||||
#if CONFIG_OV2640_SUPPORT
|
||||
case OV2640_PID:
|
||||
if (frame_size > FRAMESIZE_UXGA) {
|
||||
frame_size = FRAMESIZE_UXGA;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_OV7725_SUPPORT
|
||||
case OV7725_PID:
|
||||
if (frame_size > FRAMESIZE_VGA) {
|
||||
frame_size = FRAMESIZE_VGA;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_OV3660_SUPPORT
|
||||
case OV3660_PID:
|
||||
if (frame_size > FRAMESIZE_QXGA) {
|
||||
frame_size = FRAMESIZE_QXGA;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_OV5640_SUPPORT
|
||||
case OV5640_PID:
|
||||
if (frame_size > FRAMESIZE_QSXGA) {
|
||||
frame_size = FRAMESIZE_QSXGA;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_OV7670_SUPPORT
|
||||
case OV7670_PID:
|
||||
if (frame_size > FRAMESIZE_VGA) {
|
||||
frame_size = FRAMESIZE_VGA;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_NT99141_SUPPORT
|
||||
case NT99141_PID:
|
||||
if (frame_size > FRAMESIZE_HD) {
|
||||
frame_size = FRAMESIZE_HD;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return ESP_ERR_CAMERA_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
s_state->width = resolution[frame_size].width;
|
||||
s_state->height = resolution[frame_size].height;
|
||||
|
||||
if (pix_format == PIXFORMAT_GRAYSCALE) {
|
||||
s_state->fb_size = s_state->width * s_state->height;
|
||||
if (s_state->sensor.id.PID == OV3660_PID || s_state->sensor.id.PID == OV5640_PID || s_state->sensor.id.PID == NT99141_PID) {
|
||||
s_state->in_bytes_per_pixel = 1; // camera sends Y8
|
||||
} else {
|
||||
s_state->in_bytes_per_pixel = 2; // camera sends YU/YV
|
||||
}
|
||||
s_state->fb_bytes_per_pixel = 1; // frame buffer stores Y8
|
||||
} else if (pix_format == PIXFORMAT_YUV422 || pix_format == PIXFORMAT_RGB565) {
|
||||
s_state->fb_size = s_state->width * s_state->height * 2;
|
||||
s_state->in_bytes_per_pixel = 2; // camera sends YU/YV
|
||||
s_state->fb_bytes_per_pixel = 2; // frame buffer stores YU/YV/RGB565
|
||||
} else if (pix_format == PIXFORMAT_RGB888) {
|
||||
s_state->fb_size = s_state->width * s_state->height * 3;
|
||||
s_state->in_bytes_per_pixel = 2; // camera sends RGB565
|
||||
s_state->fb_bytes_per_pixel = 3; // frame buffer stores RGB888
|
||||
} else if (pix_format == PIXFORMAT_JPEG) {
|
||||
if (s_state->sensor.id.PID != OV2640_PID && s_state->sensor.id.PID != OV3660_PID && s_state->sensor.id.PID != OV5640_PID && s_state->sensor.id.PID != NT99141_PID) {
|
||||
ESP_LOGE(TAG, "JPEG format is only supported for ov2640, ov3660 and ov5640");
|
||||
err = ESP_ERR_NOT_SUPPORTED;
|
||||
goto fail;
|
||||
}
|
||||
int qp = config->jpeg_quality;
|
||||
int compression_ratio_bound = 1;
|
||||
if (qp > 10) {
|
||||
compression_ratio_bound = 16;
|
||||
} else if (qp > 5) {
|
||||
compression_ratio_bound = 10;
|
||||
} else {
|
||||
compression_ratio_bound = 4;
|
||||
}
|
||||
(*s_state->sensor.set_quality)(&s_state->sensor, qp);
|
||||
s_state->in_bytes_per_pixel = 2;
|
||||
s_state->fb_bytes_per_pixel = 2;
|
||||
s_state->fb_size = (s_state->width * s_state->height * s_state->fb_bytes_per_pixel) / compression_ratio_bound;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Requested format is not supported");
|
||||
err = ESP_ERR_NOT_SUPPORTED;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "in_bpp: %d, fb_bpp: %d, fb_size: %d, width: %d height: %d",
|
||||
s_state->in_bytes_per_pixel, s_state->fb_bytes_per_pixel,
|
||||
s_state->fb_size,
|
||||
s_state->width, s_state->height);
|
||||
|
||||
s_state->sensor.status.framesize = frame_size;
|
||||
s_state->sensor.pixformat = pix_format;
|
||||
ESP_LOGD(TAG, "Setting frame size to %dx%d", s_state->width, s_state->height);
|
||||
if (s_state->sensor.set_framesize(&s_state->sensor, frame_size) != 0) {
|
||||
ESP_LOGE(TAG, "Failed to set frame size");
|
||||
err = ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE;
|
||||
goto fail;
|
||||
}
|
||||
s_state->sensor.set_pixformat(&s_state->sensor, pix_format);
|
||||
|
||||
if (s_state->sensor.id.PID == OV2640_PID) {
|
||||
s_state->sensor.set_gainceiling(&s_state->sensor, GAINCEILING_2X);
|
||||
s_state->sensor.set_bpc(&s_state->sensor, false);
|
||||
s_state->sensor.set_wpc(&s_state->sensor, true);
|
||||
s_state->sensor.set_lenc(&s_state->sensor, true);
|
||||
}
|
||||
|
||||
//todo: for some reason the first set of the quality does not work.
|
||||
if (pix_format == PIXFORMAT_JPEG) {
|
||||
(*s_state->sensor.set_quality)(&s_state->sensor, config->jpeg_quality);
|
||||
}
|
||||
s_state->sensor.init_status(&s_state->sensor);
|
||||
|
||||
//lcd_cam_init
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
fail:
|
||||
esp_camera_deinit();
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t camera_init_state(){
|
||||
if(s_state == NULL){
|
||||
s_state = (camera_state_t*) calloc(sizeof(*s_state), 1);
|
||||
if (!s_state) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
memset(s_state, 0, sizeof(camera_state_t));
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_initwith_lcd(const camera_config_t* config, lcd_config_t* lcd, lcd_cam_handle_t ** lcd_cam_handle)
|
||||
{
|
||||
esp_err_t err = camera_init_state();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Camera init state failed with error 0x%x", err);
|
||||
return err;
|
||||
}
|
||||
memcpy(&s_state->lcd_cam_config.lcd, lcd, sizeof(lcd_config_t));
|
||||
|
||||
err = esp_camera_init(config);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
*lcd_cam_handle = &s_state->lcd_cam;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_init(const camera_config_t* config)
|
||||
{
|
||||
camera_model_t camera_model = CAMERA_NONE;
|
||||
esp_err_t err = camera_init_state();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Camera init state failed with error 0x%x", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
//setup lcd_cam
|
||||
cam_config_t cam = {
|
||||
.en = true,
|
||||
.width = 8,
|
||||
.fre = config->xclk_freq_hz,
|
||||
.pin = {
|
||||
.xclk = config->pin_xclk,
|
||||
.pclk = config->pin_pclk,
|
||||
.vsync = config->pin_vsync,
|
||||
.href = config->pin_href,
|
||||
.data = {config->pin_d0, config->pin_d1, config->pin_d2, config->pin_d3, config->pin_d4, config->pin_d5, config->pin_d6, config->pin_d7},
|
||||
},
|
||||
.invert = {
|
||||
.xclk = false,
|
||||
.pclk = false,
|
||||
.vsync = true,
|
||||
.href = false,
|
||||
.data = {false, false, false, false, false, false, false, false},
|
||||
},
|
||||
.mode.jpeg = (config->pixel_format == PIXFORMAT_JPEG),
|
||||
.recv_size = (config->pixel_format == PIXFORMAT_JPEG)?resolution[config->frame_size].width * resolution[config->frame_size].height / 8:resolution[config->frame_size].width * resolution[config->frame_size].height * 2,
|
||||
.max_dma_buffer_size = 16 * 1024,
|
||||
.frame_cnt = 2,
|
||||
.frame_caps = MALLOC_CAP_SPIRAM,
|
||||
.task_stack = 1024,
|
||||
.task_pri = configMAX_PRIORITIES,
|
||||
.swap_data = false
|
||||
};
|
||||
if(config->pixel_format == PIXFORMAT_JPEG) {
|
||||
cam.recv_size /= 8;
|
||||
}
|
||||
memcpy(&s_state->lcd_cam_config.cam, &cam, sizeof(cam_config_t));
|
||||
|
||||
err = lcd_cam_init(&s_state->lcd_cam, &s_state->lcd_cam_config);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "LCD-Camera init failed with error 0x%x", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = camera_probe(config, &camera_model);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Camera probe failed with error 0x%x", err);
|
||||
goto fail;
|
||||
}
|
||||
if (camera_model == CAMERA_OV7725) {
|
||||
ESP_LOGI(TAG, "Detected OV7725 camera");
|
||||
if(config->pixel_format == PIXFORMAT_JPEG) {
|
||||
ESP_LOGE(TAG, "Camera does not support JPEG");
|
||||
err = ESP_ERR_CAMERA_NOT_SUPPORTED;
|
||||
goto fail;
|
||||
}
|
||||
} else if (camera_model == CAMERA_OV2640) {
|
||||
ESP_LOGI(TAG, "Detected OV2640 camera");
|
||||
} else if (camera_model == CAMERA_OV3660) {
|
||||
ESP_LOGI(TAG, "Detected OV3660 camera");
|
||||
} else if (camera_model == CAMERA_OV5640) {
|
||||
ESP_LOGI(TAG, "Detected OV5640 camera");
|
||||
} else if (camera_model == CAMERA_OV7670) {
|
||||
ESP_LOGI(TAG, "Detected OV7670 camera");
|
||||
} else if (camera_model == CAMERA_NT99141) {
|
||||
ESP_LOGI(TAG, "Detected NT99141 camera");
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Camera not supported");
|
||||
err = ESP_ERR_CAMERA_NOT_SUPPORTED;
|
||||
goto fail;
|
||||
}
|
||||
err = camera_init(config);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Camera init failed with error 0x%x", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
s_state->lcd_cam.cam.start();
|
||||
return ESP_OK;
|
||||
|
||||
fail:
|
||||
free(s_state);
|
||||
s_state = NULL;
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_deinit()
|
||||
{
|
||||
if (s_state == NULL) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
lcd_cam_deinit(&s_state->lcd_cam);
|
||||
free(s_state);
|
||||
s_state = NULL;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
camera_fb_t* esp_camera_fb_get()
|
||||
{
|
||||
if (s_state == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
camera_fb_t* fb = (camera_fb_t*)malloc(sizeof(camera_fb_t));
|
||||
if(!fb){
|
||||
return NULL;
|
||||
}
|
||||
fb->format = s_state->sensor.pixformat;
|
||||
fb->width = resolution[s_state->sensor.status.framesize].width;
|
||||
fb->height = resolution[s_state->sensor.status.framesize].height;
|
||||
fb->len = s_state->lcd_cam.cam.take(&fb->buf);
|
||||
uint64_t us = (uint64_t)esp_timer_get_time();
|
||||
fb->timestamp.tv_sec = us / 1000000UL;
|
||||
fb->timestamp.tv_usec = us % 1000000UL;
|
||||
return fb;
|
||||
}
|
||||
|
||||
void esp_camera_fb_return(camera_fb_t * fb)
|
||||
{
|
||||
if(fb == NULL) {
|
||||
return;
|
||||
}
|
||||
if(s_state != NULL) {
|
||||
s_state->lcd_cam.cam.give(fb->buf);
|
||||
}
|
||||
free(fb);
|
||||
}
|
||||
|
||||
sensor_t * esp_camera_sensor_get()
|
||||
{
|
||||
if (s_state == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return &s_state->sensor;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_save_to_nvs(const char *key)
|
||||
{
|
||||
#if ESP_IDF_VERSION_MAJOR > 3
|
||||
nvs_handle_t handle;
|
||||
#else
|
||||
nvs_handle handle;
|
||||
#endif
|
||||
esp_err_t ret = nvs_open(key,NVS_READWRITE,&handle);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
sensor_t *s = esp_camera_sensor_get();
|
||||
if (s != NULL) {
|
||||
ret = nvs_set_blob(handle,CAMERA_SENSOR_NVS_KEY,&s->status,sizeof(camera_status_t));
|
||||
if (ret == ESP_OK) {
|
||||
uint8_t pf = s->pixformat;
|
||||
ret = nvs_set_u8(handle,CAMERA_PIXFORMAT_NVS_KEY,pf);
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
return ESP_ERR_CAMERA_NOT_DETECTED;
|
||||
}
|
||||
nvs_close(handle);
|
||||
return ret;
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_load_from_nvs(const char *key)
|
||||
{
|
||||
#if ESP_IDF_VERSION_MAJOR > 3
|
||||
nvs_handle_t handle;
|
||||
#else
|
||||
nvs_handle handle;
|
||||
#endif
|
||||
uint8_t pf;
|
||||
|
||||
esp_err_t ret = nvs_open(key,NVS_READWRITE,&handle);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
sensor_t *s = esp_camera_sensor_get();
|
||||
camera_status_t st;
|
||||
if (s != NULL) {
|
||||
size_t size = sizeof(camera_status_t);
|
||||
ret = nvs_get_blob(handle,CAMERA_SENSOR_NVS_KEY,&st,&size);
|
||||
if (ret == ESP_OK) {
|
||||
s->set_ae_level(s,st.ae_level);
|
||||
s->set_aec2(s,st.aec2);
|
||||
s->set_aec_value(s,st.aec_value);
|
||||
s->set_agc_gain(s,st.agc_gain);
|
||||
s->set_awb_gain(s,st.awb_gain);
|
||||
s->set_bpc(s,st.bpc);
|
||||
s->set_brightness(s,st.brightness);
|
||||
s->set_colorbar(s,st.colorbar);
|
||||
s->set_contrast(s,st.contrast);
|
||||
s->set_dcw(s,st.dcw);
|
||||
s->set_denoise(s,st.denoise);
|
||||
s->set_exposure_ctrl(s,st.aec);
|
||||
s->set_framesize(s,st.framesize);
|
||||
s->set_gain_ctrl(s,st.agc);
|
||||
s->set_gainceiling(s,st.gainceiling);
|
||||
s->set_hmirror(s,st.hmirror);
|
||||
s->set_lenc(s,st.lenc);
|
||||
s->set_quality(s,st.quality);
|
||||
s->set_raw_gma(s,st.raw_gma);
|
||||
s->set_saturation(s,st.saturation);
|
||||
s->set_sharpness(s,st.sharpness);
|
||||
s->set_special_effect(s,st.special_effect);
|
||||
s->set_vflip(s,st.vflip);
|
||||
s->set_wb_mode(s,st.wb_mode);
|
||||
s->set_whitebal(s,st.awb);
|
||||
s->set_wpc(s,st.wpc);
|
||||
}
|
||||
ret = nvs_get_u8(handle,CAMERA_PIXFORMAT_NVS_KEY,&pf);
|
||||
if (ret == ESP_OK) {
|
||||
s->set_pixformat(s,pf);
|
||||
}
|
||||
} else {
|
||||
return ESP_ERR_CAMERA_NOT_DETECTED;
|
||||
}
|
||||
nvs_close(handle);
|
||||
return ret;
|
||||
} else {
|
||||
ESP_LOGW(TAG,"Error (%d) opening nvs key \"%s\"",ret,key);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,486 +0,0 @@
|
|||
// Copyright 2015-2016 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "time.h"
|
||||
#include "sys/time.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_system.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "nvs.h"
|
||||
#include "sensor.h"
|
||||
#include "sccb.h"
|
||||
#include "cam_hal.h"
|
||||
#include "esp_camera.h"
|
||||
#include "xclk.h"
|
||||
#if CONFIG_OV2640_SUPPORT
|
||||
#include "ov2640.h"
|
||||
#endif
|
||||
#if CONFIG_OV7725_SUPPORT
|
||||
#include "ov7725.h"
|
||||
#endif
|
||||
#if CONFIG_OV3660_SUPPORT
|
||||
#include "ov3660.h"
|
||||
#endif
|
||||
#if CONFIG_OV5640_SUPPORT
|
||||
#include "ov5640.h"
|
||||
#endif
|
||||
#if CONFIG_NT99141_SUPPORT
|
||||
#include "nt99141.h"
|
||||
#endif
|
||||
#if CONFIG_OV7670_SUPPORT
|
||||
#include "ov7670.h"
|
||||
#endif
|
||||
#if CONFIG_GC2145_SUPPORT
|
||||
#include "gc2145.h"
|
||||
#endif
|
||||
#if CONFIG_GC032A_SUPPORT
|
||||
#include "gc032a.h"
|
||||
#endif
|
||||
#if CONFIG_GC0308_SUPPORT
|
||||
#include "gc0308.h"
|
||||
#endif
|
||||
#if CONFIG_BF3005_SUPPORT
|
||||
#include "bf3005.h"
|
||||
#endif
|
||||
#if CONFIG_BF20A6_SUPPORT
|
||||
#include "bf20a6.h"
|
||||
#endif
|
||||
#if CONFIG_SC101IOT_SUPPORT
|
||||
#include "sc101iot.h"
|
||||
#endif
|
||||
#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"
|
||||
#define TAG ""
|
||||
#else
|
||||
#include "esp_log.h"
|
||||
static const char *TAG = "camera";
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
sensor_t sensor;
|
||||
camera_fb_t fb;
|
||||
} camera_state_t;
|
||||
|
||||
static const char *CAMERA_SENSOR_NVS_KEY = "sensor";
|
||||
static const char *CAMERA_PIXFORMAT_NVS_KEY = "pixformat";
|
||||
static camera_state_t *s_state = NULL;
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32S3 // LCD_CAM module of ESP32-S3 will generate xclk
|
||||
#define CAMERA_ENABLE_OUT_CLOCK(v)
|
||||
#define CAMERA_DISABLE_OUT_CLOCK()
|
||||
#else
|
||||
#define CAMERA_ENABLE_OUT_CLOCK(v) camera_enable_out_clock((v))
|
||||
#define CAMERA_DISABLE_OUT_CLOCK() camera_disable_out_clock()
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int (*detect)(int slv_addr, sensor_id_t *id);
|
||||
int (*init)(sensor_t *sensor);
|
||||
} sensor_func_t;
|
||||
|
||||
static const sensor_func_t g_sensors[] = {
|
||||
#if CONFIG_OV7725_SUPPORT
|
||||
{ov7725_detect, ov7725_init},
|
||||
#endif
|
||||
#if CONFIG_OV7670_SUPPORT
|
||||
{ov7670_detect, ov7670_init},
|
||||
#endif
|
||||
#if CONFIG_OV2640_SUPPORT
|
||||
{ov2640_detect, ov2640_init},
|
||||
#endif
|
||||
#if CONFIG_OV3660_SUPPORT
|
||||
{ov3660_detect, ov3660_init},
|
||||
#endif
|
||||
#if CONFIG_OV5640_SUPPORT
|
||||
{ov5640_detect, ov5640_init},
|
||||
#endif
|
||||
#if CONFIG_NT99141_SUPPORT
|
||||
{nt99141_detect, nt99141_init},
|
||||
#endif
|
||||
#if CONFIG_GC2145_SUPPORT
|
||||
{gc2145_detect, gc2145_init},
|
||||
#endif
|
||||
#if CONFIG_GC032A_SUPPORT
|
||||
{gc032a_detect, gc032a_init},
|
||||
#endif
|
||||
#if CONFIG_GC0308_SUPPORT
|
||||
{gc0308_detect, gc0308_init},
|
||||
#endif
|
||||
#if CONFIG_BF3005_SUPPORT
|
||||
{bf3005_detect, bf3005_init},
|
||||
#endif
|
||||
#if CONFIG_BF20A6_SUPPORT
|
||||
{bf20a6_detect, bf20a6_init},
|
||||
#endif
|
||||
#if CONFIG_SC101IOT_SUPPORT
|
||||
{sc101iot_detect, sc101iot_init},
|
||||
#endif
|
||||
#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)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
*out_camera_model = CAMERA_NONE;
|
||||
if (s_state != NULL) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
s_state = (camera_state_t *) calloc(1, sizeof(camera_state_t));
|
||||
if (!s_state) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
if (config->pin_xclk >= 0) {
|
||||
ESP_LOGD(TAG, "Enabling XCLK output");
|
||||
CAMERA_ENABLE_OUT_CLOCK(config);
|
||||
}
|
||||
|
||||
if (config->pin_sccb_sda != -1) {
|
||||
ESP_LOGD(TAG, "Initializing SCCB");
|
||||
ret = SCCB_Init(config->pin_sccb_sda, config->pin_sccb_scl);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Using existing I2C port");
|
||||
ret = SCCB_Use_Port(config->sccb_i2c_port);
|
||||
}
|
||||
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "sccb init err");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (config->pin_pwdn >= 0) {
|
||||
ESP_LOGD(TAG, "Resetting camera by power down line");
|
||||
gpio_config_t conf = { 0 };
|
||||
conf.pin_bit_mask = 1LL << config->pin_pwdn;
|
||||
conf.mode = GPIO_MODE_OUTPUT;
|
||||
gpio_config(&conf);
|
||||
|
||||
// carefull, logic is inverted compared to reset pin
|
||||
gpio_set_level(config->pin_pwdn, 1);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
gpio_set_level(config->pin_pwdn, 0);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
if (config->pin_reset >= 0) {
|
||||
ESP_LOGD(TAG, "Resetting camera");
|
||||
gpio_config_t conf = { 0 };
|
||||
conf.pin_bit_mask = 1LL << config->pin_reset;
|
||||
conf.mode = GPIO_MODE_OUTPUT;
|
||||
gpio_config(&conf);
|
||||
|
||||
gpio_set_level(config->pin_reset, 0);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
gpio_set_level(config->pin_reset, 1);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Searching for camera address");
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
|
||||
uint8_t slv_addr = SCCB_Probe();
|
||||
|
||||
if (slv_addr == 0) {
|
||||
ret = ESP_ERR_NOT_FOUND;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Detected camera at address=0x%02x", slv_addr);
|
||||
s_state->sensor.slv_addr = slv_addr;
|
||||
s_state->sensor.xclk_freq_hz = config->xclk_freq_hz;
|
||||
|
||||
/**
|
||||
* Read sensor ID and then initialize sensor
|
||||
* Attention: Some sensors have the same SCCB address. Therefore, several attempts may be made in the detection process
|
||||
*/
|
||||
sensor_id_t *id = &s_state->sensor.id;
|
||||
for (size_t i = 0; i < sizeof(g_sensors) / sizeof(sensor_func_t); i++) {
|
||||
if (g_sensors[i].detect(slv_addr, id)) {
|
||||
camera_sensor_info_t *info = esp_camera_sensor_get_info(id);
|
||||
if (NULL != info) {
|
||||
*out_camera_model = info->model;
|
||||
ESP_LOGI(TAG, "Detected %s camera", info->name);
|
||||
g_sensors[i].init(&s_state->sensor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (CAMERA_NONE == *out_camera_model) { //If no supported sensors are detected
|
||||
ESP_LOGE(TAG, "Detected camera not supported.");
|
||||
ret = ESP_ERR_NOT_SUPPORTED;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Camera PID=0x%02x VER=0x%02x MIDL=0x%02x MIDH=0x%02x",
|
||||
id->PID, id->VER, id->MIDH, id->MIDL);
|
||||
|
||||
ESP_LOGD(TAG, "Doing SW reset of sensor");
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
|
||||
return s_state->sensor.reset(&s_state->sensor);
|
||||
err :
|
||||
CAMERA_DISABLE_OUT_CLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if CONFIG_CAMERA_CONVERTER_ENABLED
|
||||
static pixformat_t get_output_data_format(camera_conv_mode_t conv_mode)
|
||||
{
|
||||
pixformat_t format = PIXFORMAT_RGB565;
|
||||
switch (conv_mode) {
|
||||
case YUV422_TO_YUV420:
|
||||
format = PIXFORMAT_YUV420;
|
||||
break;
|
||||
case YUV422_TO_RGB565: // default format is RGB565
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ESP_LOGD(TAG, "Convert to %d format enabled", format);
|
||||
return format;
|
||||
}
|
||||
#endif
|
||||
|
||||
esp_err_t esp_camera_init(const camera_config_t *config)
|
||||
{
|
||||
esp_err_t err;
|
||||
err = cam_init(config);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Camera init failed with error 0x%x", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
camera_model_t camera_model = CAMERA_NONE;
|
||||
err = camera_probe(config, &camera_model);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Camera probe failed with error 0x%x(%s)", err, esp_err_to_name(err));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
framesize_t frame_size = (framesize_t) config->frame_size;
|
||||
pixformat_t pix_format = (pixformat_t) config->pixel_format;
|
||||
|
||||
if (PIXFORMAT_JPEG == pix_format && (!camera_sensor[camera_model].support_jpeg)) {
|
||||
ESP_LOGE(TAG, "JPEG format is not supported on this sensor");
|
||||
err = ESP_ERR_NOT_SUPPORTED;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (frame_size > camera_sensor[camera_model].max_size) {
|
||||
ESP_LOGW(TAG, "The frame size exceeds the maximum for this sensor, it will be forced to the maximum possible value");
|
||||
frame_size = camera_sensor[camera_model].max_size;
|
||||
}
|
||||
|
||||
err = cam_config(config, frame_size, s_state->sensor.id.PID);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Camera config failed with error 0x%x", err);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
s_state->sensor.status.framesize = frame_size;
|
||||
s_state->sensor.pixformat = pix_format;
|
||||
|
||||
ESP_LOGD(TAG, "Setting frame size to %dx%d", resolution[frame_size].width, resolution[frame_size].height);
|
||||
if (s_state->sensor.set_framesize(&s_state->sensor, frame_size) != 0) {
|
||||
ESP_LOGE(TAG, "Failed to set frame size");
|
||||
err = ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE;
|
||||
goto fail;
|
||||
}
|
||||
s_state->sensor.set_pixformat(&s_state->sensor, pix_format);
|
||||
#if CONFIG_CAMERA_CONVERTER_ENABLED
|
||||
if(config->conv_mode) {
|
||||
s_state->sensor.pixformat = get_output_data_format(config->conv_mode); // If conversion enabled, change the out data format by conversion mode
|
||||
}
|
||||
#endif
|
||||
|
||||
if (s_state->sensor.id.PID == OV2640_PID) {
|
||||
s_state->sensor.set_gainceiling(&s_state->sensor, GAINCEILING_2X);
|
||||
s_state->sensor.set_bpc(&s_state->sensor, false);
|
||||
s_state->sensor.set_wpc(&s_state->sensor, true);
|
||||
s_state->sensor.set_lenc(&s_state->sensor, true);
|
||||
}
|
||||
|
||||
if (pix_format == PIXFORMAT_JPEG) {
|
||||
s_state->sensor.set_quality(&s_state->sensor, config->jpeg_quality);
|
||||
}
|
||||
s_state->sensor.init_status(&s_state->sensor);
|
||||
|
||||
cam_start();
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
fail:
|
||||
esp_camera_deinit();
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_deinit()
|
||||
{
|
||||
esp_err_t ret = cam_deinit();
|
||||
CAMERA_DISABLE_OUT_CLOCK();
|
||||
if (s_state) {
|
||||
SCCB_Deinit();
|
||||
|
||||
free(s_state);
|
||||
s_state = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define FB_GET_TIMEOUT (4000 / portTICK_PERIOD_MS)
|
||||
|
||||
camera_fb_t *esp_camera_fb_get()
|
||||
{
|
||||
if (s_state == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
camera_fb_t *fb = cam_take(FB_GET_TIMEOUT);
|
||||
//set the frame properties
|
||||
if (fb) {
|
||||
fb->width = resolution[s_state->sensor.status.framesize].width;
|
||||
fb->height = resolution[s_state->sensor.status.framesize].height;
|
||||
fb->format = s_state->sensor.pixformat;
|
||||
}
|
||||
return fb;
|
||||
}
|
||||
|
||||
void esp_camera_fb_return(camera_fb_t *fb)
|
||||
{
|
||||
if (s_state == NULL) {
|
||||
return;
|
||||
}
|
||||
cam_give(fb);
|
||||
}
|
||||
|
||||
sensor_t *esp_camera_sensor_get()
|
||||
{
|
||||
if (s_state == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return &s_state->sensor;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_save_to_nvs(const char *key)
|
||||
{
|
||||
#if ESP_IDF_VERSION_MAJOR > 3
|
||||
nvs_handle_t handle;
|
||||
#else
|
||||
nvs_handle handle;
|
||||
#endif
|
||||
esp_err_t ret = nvs_open(key, NVS_READWRITE, &handle);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
sensor_t *s = esp_camera_sensor_get();
|
||||
if (s != NULL) {
|
||||
ret = nvs_set_blob(handle, CAMERA_SENSOR_NVS_KEY, &s->status, sizeof(camera_status_t));
|
||||
if (ret == ESP_OK) {
|
||||
uint8_t pf = s->pixformat;
|
||||
ret = nvs_set_u8(handle, CAMERA_PIXFORMAT_NVS_KEY, pf);
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
return ESP_ERR_CAMERA_NOT_DETECTED;
|
||||
}
|
||||
nvs_close(handle);
|
||||
return ret;
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_load_from_nvs(const char *key)
|
||||
{
|
||||
#if ESP_IDF_VERSION_MAJOR > 3
|
||||
nvs_handle_t handle;
|
||||
#else
|
||||
nvs_handle handle;
|
||||
#endif
|
||||
uint8_t pf;
|
||||
|
||||
esp_err_t ret = nvs_open(key, NVS_READWRITE, &handle);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
sensor_t *s = esp_camera_sensor_get();
|
||||
camera_status_t st;
|
||||
if (s != NULL) {
|
||||
size_t size = sizeof(camera_status_t);
|
||||
ret = nvs_get_blob(handle, CAMERA_SENSOR_NVS_KEY, &st, &size);
|
||||
if (ret == ESP_OK) {
|
||||
s->set_ae_level(s, st.ae_level);
|
||||
s->set_aec2(s, st.aec2);
|
||||
s->set_aec_value(s, st.aec_value);
|
||||
s->set_agc_gain(s, st.agc_gain);
|
||||
s->set_awb_gain(s, st.awb_gain);
|
||||
s->set_bpc(s, st.bpc);
|
||||
s->set_brightness(s, st.brightness);
|
||||
s->set_colorbar(s, st.colorbar);
|
||||
s->set_contrast(s, st.contrast);
|
||||
s->set_dcw(s, st.dcw);
|
||||
s->set_denoise(s, st.denoise);
|
||||
s->set_exposure_ctrl(s, st.aec);
|
||||
s->set_framesize(s, st.framesize);
|
||||
s->set_gain_ctrl(s, st.agc);
|
||||
s->set_gainceiling(s, st.gainceiling);
|
||||
s->set_hmirror(s, st.hmirror);
|
||||
s->set_lenc(s, st.lenc);
|
||||
s->set_quality(s, st.quality);
|
||||
s->set_raw_gma(s, st.raw_gma);
|
||||
s->set_saturation(s, st.saturation);
|
||||
s->set_sharpness(s, st.sharpness);
|
||||
s->set_special_effect(s, st.special_effect);
|
||||
s->set_vflip(s, st.vflip);
|
||||
s->set_wb_mode(s, st.wb_mode);
|
||||
s->set_whitebal(s, st.awb);
|
||||
s->set_wpc(s, st.wpc);
|
||||
}
|
||||
ret = nvs_get_u8(handle, CAMERA_PIXFORMAT_NVS_KEY, &pf);
|
||||
if (ret == ESP_OK) {
|
||||
s->set_pixformat(s, pf);
|
||||
}
|
||||
} else {
|
||||
return ESP_ERR_CAMERA_NOT_DETECTED;
|
||||
}
|
||||
nvs_close(handle);
|
||||
return ret;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Error (%d) opening nvs key \"%s\"", ret, key);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
void esp_camera_return_all(void) {
|
||||
if (s_state == NULL) {
|
||||
return;
|
||||
}
|
||||
cam_give_all();
|
||||
}
|
||||
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
.pin_pwdn = PIN_PWDN,
|
||||
.pin_reset = PIN_RESET,
|
||||
.pin_xclk = PIN_XCLK,
|
||||
.pin_sccb_sda = PIN_SIOD,
|
||||
.pin_sccb_scl = PIN_SIOC,
|
||||
.pin_sscb_sda = PIN_SIOD,
|
||||
.pin_sscb_scl = PIN_SIOC,
|
||||
.pin_d7 = PIN_D7,
|
||||
.pin_d6 = PIN_D6,
|
||||
.pin_d5 = PIN_D5,
|
||||
|
|
@ -38,8 +38,7 @@
|
|||
.pixel_format = PIXFORMAT_JPEG,
|
||||
.frame_size = FRAMESIZE_SVGA,
|
||||
.jpeg_quality = 10,
|
||||
.fb_count = 2,
|
||||
.grab_mode = CAMERA_GRAB_WHEN_EMPTY
|
||||
.fb_count = 2
|
||||
};
|
||||
|
||||
esp_err_t camera_example_init(){
|
||||
|
|
@ -67,50 +66,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "sensor.h"
|
||||
#include "sys/time.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
/**
|
||||
* @brief define for if chip supports camera
|
||||
*/
|
||||
#define ESP_CAMERA_SUPPORTED (CONFIG_IDF_TARGET_ESP32 | CONFIG_IDF_TARGET_ESP32S3 | \
|
||||
CONFIG_IDF_TARGET_ESP32S2)
|
||||
#include "driver/lcd_cam.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Configuration structure for camera initialization
|
||||
*/
|
||||
typedef enum {
|
||||
CAMERA_GRAB_WHEN_EMPTY, /*!< Fills buffers when they are empty. Less resources but first 'fb_count' frames might be old */
|
||||
CAMERA_GRAB_LATEST /*!< Except when 1 frame buffer is used, queue will always contain the last 'fb_count' frames */
|
||||
} camera_grab_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Camera frame buffer location
|
||||
*/
|
||||
typedef enum {
|
||||
CAMERA_FB_IN_PSRAM, /*!< Frame buffer is placed in external PSRAM */
|
||||
CAMERA_FB_IN_DRAM /*!< Frame buffer is placed in internal DRAM */
|
||||
} camera_fb_location_t;
|
||||
|
||||
#if CONFIG_CAMERA_CONVERTER_ENABLED
|
||||
/**
|
||||
* @brief Camera RGB\YUV conversion mode
|
||||
*/
|
||||
typedef enum {
|
||||
CONV_DISABLE,
|
||||
RGB565_TO_YUV422,
|
||||
|
||||
YUV422_TO_RGB565,
|
||||
YUV422_TO_YUV420
|
||||
} camera_conv_mode_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Configuration structure for camera initialization
|
||||
*/
|
||||
|
|
@ -118,14 +81,8 @@ typedef struct {
|
|||
int pin_pwdn; /*!< GPIO pin for camera power down line */
|
||||
int pin_reset; /*!< GPIO pin for camera reset line */
|
||||
int pin_xclk; /*!< GPIO pin for camera XCLK line */
|
||||
union {
|
||||
int pin_sccb_sda; /*!< GPIO pin for camera SDA line */
|
||||
int pin_sscb_sda __attribute__((deprecated("please use pin_sccb_sda instead"))); /*!< GPIO pin for camera SDA line (legacy name) */
|
||||
};
|
||||
union {
|
||||
int pin_sccb_scl; /*!< GPIO pin for camera SCL line */
|
||||
int pin_sscb_scl __attribute__((deprecated("please use pin_sccb_scl instead"))); /*!< GPIO pin for camera SCL line (legacy name) */
|
||||
};
|
||||
int pin_sscb_sda; /*!< GPIO pin for camera SDA line */
|
||||
int pin_sscb_scl; /*!< GPIO pin for camera SCL line */
|
||||
int pin_d7; /*!< GPIO pin for camera D7 line */
|
||||
int pin_d6; /*!< GPIO pin for camera D6 line */
|
||||
int pin_d5; /*!< GPIO pin for camera D5 line */
|
||||
|
|
@ -138,23 +95,13 @@ typedef struct {
|
|||
int pin_href; /*!< GPIO pin for camera HREF line */
|
||||
int pin_pclk; /*!< GPIO pin for camera PCLK line */
|
||||
|
||||
int xclk_freq_hz; /*!< Frequency of XCLK signal, in Hz. EXPERIMENTAL: Set to 16MHz on ESP32-S2 or ESP32-S3 to enable EDMA mode */
|
||||
|
||||
ledc_timer_t ledc_timer; /*!< LEDC timer to be used for generating XCLK */
|
||||
ledc_channel_t ledc_channel; /*!< LEDC channel to be used for generating XCLK */
|
||||
int xclk_freq_hz; /*!< Frequency of XCLK signal, in Hz. Either 20KHz or 10KHz for OV2640 double FPS (Experimental) */
|
||||
|
||||
pixformat_t pixel_format; /*!< Format of the pixel data: PIXFORMAT_ + YUV422|GRAYSCALE|RGB565|JPEG */
|
||||
framesize_t frame_size; /*!< Size of the output image: FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA */
|
||||
|
||||
int jpeg_quality; /*!< Quality of JPEG output. 0-63 lower means higher quality */
|
||||
size_t fb_count; /*!< Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed) */
|
||||
camera_fb_location_t fb_location; /*!< The location where the frame buffer will be allocated */
|
||||
camera_grab_mode_t grab_mode; /*!< When buffers should be filled */
|
||||
#if CONFIG_CAMERA_CONVERTER_ENABLED
|
||||
camera_conv_mode_t conv_mode; /*!< RGB<->YUV Conversion mode */
|
||||
#endif
|
||||
|
||||
int sccb_i2c_port; /*!< If pin_sccb_sda is -1, use the already configured I2C bus by number */
|
||||
} camera_config_t;
|
||||
|
||||
/**
|
||||
|
|
@ -191,7 +138,8 @@ typedef struct {
|
|||
*
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_camera_init(const camera_config_t* config);
|
||||
esp_err_t esp_camera_init(const camera_config_t* config);//lcd_config_t lcd
|
||||
esp_err_t esp_camera_initwith_lcd(const camera_config_t* config, lcd_config_t* lcd, lcd_cam_handle_t ** lcd_cam_handle);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the camera driver
|
||||
|
|
@ -200,14 +148,14 @@ esp_err_t esp_camera_init(const camera_config_t* config);
|
|||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if the driver hasn't been initialized yet
|
||||
*/
|
||||
esp_err_t esp_camera_deinit(void);
|
||||
esp_err_t esp_camera_deinit();
|
||||
|
||||
/**
|
||||
* @brief Obtain pointer to a frame buffer.
|
||||
*
|
||||
* @return pointer to the frame buffer
|
||||
*/
|
||||
camera_fb_t* esp_camera_fb_get(void);
|
||||
camera_fb_t* esp_camera_fb_get();
|
||||
|
||||
/**
|
||||
* @brief Return the frame buffer to be reused again.
|
||||
|
|
@ -221,7 +169,7 @@ void esp_camera_fb_return(camera_fb_t * fb);
|
|||
*
|
||||
* @return pointer to the sensor
|
||||
*/
|
||||
sensor_t * esp_camera_sensor_get(void);
|
||||
sensor_t * esp_camera_sensor_get();
|
||||
|
||||
/**
|
||||
* @brief Save camera settings to non-volatile-storage (NVS)
|
||||
|
|
@ -237,12 +185,6 @@ esp_err_t esp_camera_save_to_nvs(const char *key);
|
|||
*/
|
||||
esp_err_t esp_camera_load_from_nvs(const char *key);
|
||||
|
||||
/**
|
||||
* @brief Return all frame buffers to be reused again.
|
||||
*/
|
||||
void esp_camera_return_all(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,68 +11,17 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
OV9650_PID = 0x96,
|
||||
OV7725_PID = 0x77,
|
||||
OV2640_PID = 0x26,
|
||||
OV3660_PID = 0x3660,
|
||||
OV5640_PID = 0x5640,
|
||||
OV7670_PID = 0x76,
|
||||
NT99141_PID = 0x1410,
|
||||
GC2145_PID = 0x2145,
|
||||
GC032A_PID = 0x232a,
|
||||
GC0308_PID = 0x9b,
|
||||
BF3005_PID = 0x30,
|
||||
BF20A6_PID = 0x20a6,
|
||||
SC101IOT_PID = 0xda4a,
|
||||
SC030IOT_PID = 0x9a46,
|
||||
SC031GS_PID = 0x0031,
|
||||
} camera_pid_t;
|
||||
|
||||
typedef enum {
|
||||
CAMERA_OV7725,
|
||||
CAMERA_OV2640,
|
||||
CAMERA_OV3660,
|
||||
CAMERA_OV5640,
|
||||
CAMERA_OV7670,
|
||||
CAMERA_NT99141,
|
||||
CAMERA_GC2145,
|
||||
CAMERA_GC032A,
|
||||
CAMERA_GC0308,
|
||||
CAMERA_BF3005,
|
||||
CAMERA_BF20A6,
|
||||
CAMERA_SC101IOT,
|
||||
CAMERA_SC030IOT,
|
||||
CAMERA_SC031GS,
|
||||
CAMERA_MODEL_MAX,
|
||||
CAMERA_NONE,
|
||||
} camera_model_t;
|
||||
|
||||
typedef enum {
|
||||
OV2640_SCCB_ADDR = 0x30,// 0x60 >> 1
|
||||
OV5640_SCCB_ADDR = 0x3C,// 0x78 >> 1
|
||||
OV3660_SCCB_ADDR = 0x3C,// 0x78 >> 1
|
||||
OV7725_SCCB_ADDR = 0x21,// 0x42 >> 1
|
||||
OV7670_SCCB_ADDR = 0x21,// 0x42 >> 1
|
||||
NT99141_SCCB_ADDR = 0x2A,// 0x54 >> 1
|
||||
GC2145_SCCB_ADDR = 0x3C,// 0x78 >> 1
|
||||
GC032A_SCCB_ADDR = 0x21,// 0x42 >> 1
|
||||
GC0308_SCCB_ADDR = 0x21,// 0x42 >> 1
|
||||
BF3005_SCCB_ADDR = 0x6E,
|
||||
BF20A6_SCCB_ADDR = 0x6E,
|
||||
SC101IOT_SCCB_ADDR = 0x68,// 0xd0 >> 1
|
||||
SC030IOT_SCCB_ADDR = 0x68,// 0xd0 >> 1
|
||||
SC031GS_SCCB_ADDR = 0x30,
|
||||
} camera_sccb_addr_t;
|
||||
#define NT99141_PID (0x14)
|
||||
#define OV9650_PID (0x96)
|
||||
#define OV7725_PID (0x77)
|
||||
#define OV2640_PID (0x26)
|
||||
#define OV3660_PID (0x36)
|
||||
#define OV5640_PID (0x56)
|
||||
#define OV7670_PID (0x76)
|
||||
|
||||
typedef enum {
|
||||
PIXFORMAT_RGB565, // 2BPP/RGB565
|
||||
PIXFORMAT_YUV422, // 2BPP/YUV422
|
||||
PIXFORMAT_YUV420, // 1.5BPP/YUV420
|
||||
PIXFORMAT_GRAYSCALE, // 1BPP/GRAYSCALE
|
||||
PIXFORMAT_JPEG, // JPEG/COMPRESSED
|
||||
PIXFORMAT_RGB888, // 3BPP/RGB888
|
||||
|
|
@ -109,15 +58,6 @@ typedef enum {
|
|||
FRAMESIZE_INVALID
|
||||
} framesize_t;
|
||||
|
||||
typedef struct {
|
||||
const camera_model_t model;
|
||||
const char *name;
|
||||
const camera_sccb_addr_t sccb_addr;
|
||||
const camera_pid_t pid;
|
||||
const framesize_t max_size;
|
||||
const bool support_jpeg;
|
||||
} camera_sensor_info_t;
|
||||
|
||||
typedef enum {
|
||||
ASPECT_RATIO_4X3,
|
||||
ASPECT_RATIO_3X2,
|
||||
|
|
@ -161,13 +101,11 @@ typedef struct {
|
|||
|
||||
// Resolution table (in sensor.c)
|
||||
extern const resolution_info_t resolution[];
|
||||
// camera sensor table (in sensor.c)
|
||||
extern const camera_sensor_info_t camera_sensor[];
|
||||
|
||||
typedef struct {
|
||||
uint8_t MIDH;
|
||||
uint8_t MIDL;
|
||||
uint16_t PID;
|
||||
uint8_t PID;
|
||||
uint8_t VER;
|
||||
} sensor_id_t;
|
||||
|
||||
|
|
@ -212,7 +150,7 @@ typedef struct _sensor {
|
|||
|
||||
// Sensor function pointers
|
||||
int (*init_status) (sensor_t *sensor);
|
||||
int (*reset) (sensor_t *sensor); // Reset the configuration of the sensor, and return ESP_OK if reset is successful
|
||||
int (*reset) (sensor_t *sensor);
|
||||
int (*set_pixformat) (sensor_t *sensor, pixformat_t pixformat);
|
||||
int (*set_framesize) (sensor_t *sensor, framesize_t framesize);
|
||||
int (*set_contrast) (sensor_t *sensor, int level);
|
||||
|
|
@ -252,10 +190,4 @@ typedef struct _sensor {
|
|||
int (*set_xclk) (sensor_t *sensor, int timer, int xclk);
|
||||
} sensor_t;
|
||||
|
||||
camera_sensor_info_t *esp_camera_sensor_get_info(sensor_id_t *id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __SENSOR_H__ */
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
// Copyright 2010-2020 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esp_camera.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Uninitialize the lcd_cam module
|
||||
*
|
||||
* @param handle Provide handle pointer to release resources
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL Uninitialize fail
|
||||
*/
|
||||
esp_err_t cam_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize the lcd_cam module
|
||||
*
|
||||
* @param config Configurations - see lcd_cam_config_t struct
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NO_MEM No memory to initialize lcd_cam
|
||||
* - ESP_FAIL Initialize fail
|
||||
*/
|
||||
esp_err_t cam_init(const camera_config_t *config);
|
||||
|
||||
esp_err_t cam_config(const camera_config_t *config, framesize_t frame_size, uint16_t sensor_pid);
|
||||
|
||||
void cam_stop(void);
|
||||
|
||||
void cam_start(void);
|
||||
|
||||
camera_fb_t *cam_take(TickType_t timeout);
|
||||
|
||||
void cam_give(camera_fb_t *dma_buffer);
|
||||
|
||||
void cam_give_all(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
13
driver/private_include/camera_common.h
Executable file
13
driver/private_include/camera_common.h
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_camera.h"
|
||||
#include "sensor.h"
|
||||
#include "esp_system.h"
|
||||
|
|
@ -10,13 +10,9 @@
|
|||
#define __SCCB_H__
|
||||
#include <stdint.h>
|
||||
int SCCB_Init(int pin_sda, int pin_scl);
|
||||
int SCCB_Use_Port(int sccb_i2c_port);
|
||||
int SCCB_Deinit(void);
|
||||
uint8_t SCCB_Probe(void);
|
||||
uint8_t SCCB_Probe();
|
||||
uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg);
|
||||
int SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data);
|
||||
uint8_t SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data);
|
||||
uint8_t SCCB_Read16(uint8_t slv_addr, uint16_t reg);
|
||||
int SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data);
|
||||
uint16_t SCCB_Read_Addr16_Val16(uint8_t slv_addr, uint16_t reg);
|
||||
int SCCB_Write_Addr16_Val16(uint8_t slv_addr, uint16_t reg, uint16_t data);
|
||||
uint8_t SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data);
|
||||
#endif // __SCCB_H__
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "esp_camera.h"
|
||||
|
||||
esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz);
|
||||
|
||||
esp_err_t camera_enable_out_clock(const camera_config_t *config);
|
||||
|
||||
void camera_disable_out_clock(void);
|
||||
358
driver/sccb-ng.c
358
driver/sccb-ng.c
|
|
@ -1,358 +0,0 @@
|
|||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* Copyright (c) 2013/2014 Ibrahim Abdelkader <i.abdalkader@gmail.com>
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* SCCB (I2C like) driver with the new esp-idf I2C API.
|
||||
*
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include "sccb.h"
|
||||
#include "sensor.h"
|
||||
#include <stdio.h>
|
||||
#include "sdkconfig.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 = "sccb-ng";
|
||||
#endif
|
||||
|
||||
#define LITTLETOBIG(x) ((x << 8) | (x >> 8))
|
||||
|
||||
#include "esp_private/i2c_platform.h"
|
||||
#include "driver/i2c_master.h"
|
||||
#include "driver/i2c_types.h"
|
||||
|
||||
// support IDF 5.x
|
||||
#ifndef portTICK_RATE_MS
|
||||
#define portTICK_RATE_MS portTICK_PERIOD_MS
|
||||
#endif
|
||||
|
||||
#define TIMEOUT_MS 1000 /*!< I2C timeout duration */
|
||||
#define SCCB_FREQ CONFIG_SCCB_CLK_FREQ /*!< I2C master frequency */
|
||||
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
|
||||
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
|
||||
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave */
|
||||
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
|
||||
#define ACK_VAL 0x0 /*!< I2C ack value */
|
||||
#define NACK_VAL 0x1 /*!< I2C nack value */
|
||||
#if CONFIG_SCCB_HARDWARE_I2C_PORT1
|
||||
const int SCCB_I2C_PORT_DEFAULT = 1;
|
||||
#else
|
||||
const int SCCB_I2C_PORT_DEFAULT = 0;
|
||||
#endif
|
||||
|
||||
#define MAX_DEVICES UINT8_MAX-1
|
||||
|
||||
/*
|
||||
The legacy I2C driver used addresses to differentiate between devices, whereas the new driver uses
|
||||
i2c_master_dev_handle_t structs which are registed to the bus.
|
||||
To avoid re-writing all camera dependant code, we simply translate the devices address to the corresponding
|
||||
device_handle. This keeps all interfaces to the drivers identical.
|
||||
To perform this conversion the following local struct is used.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
i2c_master_dev_handle_t dev_handle;
|
||||
uint16_t address;
|
||||
} device_t;
|
||||
|
||||
static device_t devices[MAX_DEVICES];
|
||||
static uint8_t device_count = 0;
|
||||
static int sccb_i2c_port;
|
||||
static bool sccb_owns_i2c_port;
|
||||
|
||||
i2c_master_dev_handle_t *get_handle_from_address(uint8_t slv_addr)
|
||||
{
|
||||
for (uint8_t i = 0; i < device_count; i++)
|
||||
{
|
||||
|
||||
if (slv_addr == devices[i].address)
|
||||
{
|
||||
return &(devices[i].dev_handle);
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGE(TAG, "Device with address %02x not found", slv_addr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int SCCB_Install_Device(uint8_t slv_addr)
|
||||
{
|
||||
esp_err_t ret;
|
||||
i2c_master_bus_handle_t bus_handle;
|
||||
|
||||
if (device_count > MAX_DEVICES)
|
||||
{
|
||||
ESP_LOGE(TAG, "cannot add more than %d devices", MAX_DEVICES);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ret = i2c_master_get_bus_handle(sccb_i2c_port, &bus_handle);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "failed to get SCCB I2C Bus handle for port %d", sccb_i2c_port);
|
||||
return ret;
|
||||
}
|
||||
|
||||
i2c_device_config_t dev_cfg = {
|
||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||
.device_address = slv_addr, // not yet set
|
||||
.scl_speed_hz = SCCB_FREQ,
|
||||
};
|
||||
|
||||
ret = i2c_master_bus_add_device(bus_handle, &dev_cfg, &(devices[device_count].dev_handle));
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "failed to install SCCB I2C device: %s", esp_err_to_name(ret));
|
||||
return -1;
|
||||
}
|
||||
|
||||
devices[device_count].address = slv_addr;
|
||||
device_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SCCB_Init(int pin_sda, int pin_scl)
|
||||
{
|
||||
ESP_LOGI(TAG, "pin_sda %d pin_scl %d", pin_sda, pin_scl);
|
||||
// i2c_config_t conf;
|
||||
esp_err_t ret;
|
||||
|
||||
sccb_i2c_port = SCCB_I2C_PORT_DEFAULT;
|
||||
sccb_owns_i2c_port = true;
|
||||
ESP_LOGI(TAG, "sccb_i2c_port=%d", sccb_i2c_port);
|
||||
|
||||
i2c_master_bus_config_t i2c_mst_config = {
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.i2c_port = SCCB_I2C_PORT_DEFAULT,
|
||||
.scl_io_num = pin_scl,
|
||||
.sda_io_num = pin_sda,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.flags.enable_internal_pullup = 1};
|
||||
|
||||
i2c_master_bus_handle_t bus_handle;
|
||||
ret = i2c_new_master_bus(&i2c_mst_config, &bus_handle);
|
||||
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "failed to install SCCB I2C master bus on port %d: %s", sccb_i2c_port, esp_err_to_name(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int SCCB_Use_Port(int i2c_num)
|
||||
{ // sccb use an already initialized I2C port
|
||||
if (sccb_owns_i2c_port)
|
||||
{
|
||||
SCCB_Deinit();
|
||||
}
|
||||
if (i2c_num < 0 || i2c_num > I2C_NUM_MAX)
|
||||
{
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
sccb_i2c_port = i2c_num;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int SCCB_Deinit(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
for (uint8_t i = 0; i < device_count; i++)
|
||||
{
|
||||
ret = i2c_master_bus_rm_device(devices[i].dev_handle);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "failed to remove SCCB I2C Device");
|
||||
return ret;
|
||||
}
|
||||
|
||||
devices[i].dev_handle = NULL;
|
||||
devices[i].address = 0;
|
||||
}
|
||||
device_count = 0;
|
||||
|
||||
if (!sccb_owns_i2c_port)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
sccb_owns_i2c_port = false;
|
||||
|
||||
i2c_master_bus_handle_t bus_handle;
|
||||
ret = i2c_master_get_bus_handle(sccb_i2c_port, &bus_handle);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "failed to get SCCB I2C Bus handle for port %d", sccb_i2c_port);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = i2c_del_master_bus(bus_handle);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "failed to get delete SCCB I2C Master Bus at port %d", sccb_i2c_port);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint8_t SCCB_Probe(void)
|
||||
{
|
||||
uint8_t slave_addr = 0x0;
|
||||
esp_err_t ret;
|
||||
i2c_master_bus_handle_t bus_handle;
|
||||
|
||||
ret = i2c_master_get_bus_handle(sccb_i2c_port, &bus_handle);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "failed to get SCCB I2C Bus handle for port %d", sccb_i2c_port);
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < CAMERA_MODEL_MAX; i++)
|
||||
{
|
||||
if (slave_addr == camera_sensor[i].sccb_addr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
slave_addr = camera_sensor[i].sccb_addr;
|
||||
|
||||
ret = i2c_master_probe(bus_handle, slave_addr, TIMEOUT_MS);
|
||||
|
||||
if (ret == ESP_OK)
|
||||
{
|
||||
if (SCCB_Install_Device(slave_addr) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return slave_addr;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
|
||||
{
|
||||
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
|
||||
|
||||
uint8_t tx_buffer[1];
|
||||
uint8_t rx_buffer[1];
|
||||
|
||||
tx_buffer[0] = reg;
|
||||
|
||||
esp_err_t ret = i2c_master_transmit_receive(dev_handle, tx_buffer, 1, rx_buffer, 1, TIMEOUT_MS);
|
||||
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "SCCB_Read Failed addr:0x%02x, reg:0x%02x, data:0x%02x, ret:%d", slv_addr, reg, rx_buffer[0], ret);
|
||||
}
|
||||
|
||||
return rx_buffer[0];
|
||||
}
|
||||
|
||||
int SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data)
|
||||
{
|
||||
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
|
||||
|
||||
uint8_t tx_buffer[2];
|
||||
tx_buffer[0] = reg;
|
||||
tx_buffer[1] = data;
|
||||
|
||||
esp_err_t ret = i2c_master_transmit(dev_handle, tx_buffer, 2, TIMEOUT_MS);
|
||||
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "SCCB_Write Failed addr:0x%02x, reg:0x%02x, data:0x%02x, ret:%d", slv_addr, reg, data, ret);
|
||||
}
|
||||
|
||||
return ret == ESP_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
uint8_t SCCB_Read16(uint8_t slv_addr, uint16_t reg)
|
||||
{
|
||||
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
|
||||
|
||||
uint8_t rx_buffer[1];
|
||||
|
||||
uint16_t reg_htons = LITTLETOBIG(reg);
|
||||
uint8_t *reg_u8 = (uint8_t *)®_htons;
|
||||
|
||||
esp_err_t ret = i2c_master_transmit_receive(dev_handle, reg_u8, 2, rx_buffer, 1, TIMEOUT_MS);
|
||||
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "W [%04x]=%02x fail\n", reg, rx_buffer[0]);
|
||||
}
|
||||
|
||||
return rx_buffer[0];
|
||||
}
|
||||
|
||||
int SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data)
|
||||
{
|
||||
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
|
||||
|
||||
uint16_t reg_htons = LITTLETOBIG(reg);
|
||||
|
||||
uint8_t tx_buffer[3];
|
||||
tx_buffer[0] = reg_htons >> 8;
|
||||
tx_buffer[1] = reg_htons & 0x00ff;
|
||||
tx_buffer[2] = data;
|
||||
|
||||
esp_err_t ret = i2c_master_transmit(dev_handle, tx_buffer, 3, TIMEOUT_MS);
|
||||
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "W [%04x]=%02x fail\n", reg, data);
|
||||
}
|
||||
return ret == ESP_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
uint16_t SCCB_Read_Addr16_Val16(uint8_t slv_addr, uint16_t reg)
|
||||
{
|
||||
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
|
||||
|
||||
uint8_t rx_buffer[2];
|
||||
|
||||
uint16_t reg_htons = LITTLETOBIG(reg);
|
||||
uint8_t *reg_u8 = (uint8_t *)®_htons;
|
||||
|
||||
esp_err_t ret = i2c_master_transmit_receive(dev_handle, reg_u8, 2, rx_buffer, 2, TIMEOUT_MS);
|
||||
uint16_t data = ((uint16_t)rx_buffer[0] << 8) | (uint16_t)rx_buffer[1];
|
||||
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "W [%04x]=%02x fail\n", reg, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int SCCB_Write_Addr16_Val16(uint8_t slv_addr, uint16_t reg, uint16_t data)
|
||||
{
|
||||
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
|
||||
|
||||
uint16_t reg_htons = LITTLETOBIG(reg);
|
||||
|
||||
uint8_t tx_buffer[4];
|
||||
tx_buffer[0] = reg_htons >> 8;
|
||||
tx_buffer[1] = reg_htons & 0x00ff;
|
||||
tx_buffer[2] = data >> 8;
|
||||
tx_buffer[3] = data & 0x00ff;
|
||||
|
||||
esp_err_t ret = i2c_master_transmit(dev_handle, tx_buffer, 4, TIMEOUT_MS);
|
||||
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "W [%04x]=%02x fail\n", reg, data);
|
||||
}
|
||||
return ret == ESP_OK ? 0 : -1;
|
||||
return 0;
|
||||
}
|
||||
158
driver/sccb.c
158
driver/sccb.c
|
|
@ -6,13 +6,11 @@
|
|||
* SCCB (I2C like) driver.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include "sccb.h"
|
||||
#include "sensor.h"
|
||||
#include <stdio.h>
|
||||
#include "sdkconfig.h"
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
||||
|
|
@ -26,39 +24,26 @@ static const char* TAG = "sccb";
|
|||
|
||||
#include "driver/i2c.h"
|
||||
|
||||
// support IDF 5.x
|
||||
#ifndef portTICK_RATE_MS
|
||||
#define portTICK_RATE_MS portTICK_PERIOD_MS
|
||||
#endif
|
||||
|
||||
#define SCCB_FREQ CONFIG_SCCB_CLK_FREQ /*!< I2C master frequency*/
|
||||
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
|
||||
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
|
||||
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
|
||||
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
|
||||
#define ACK_VAL 0x0 /*!< I2C ack value */
|
||||
#define NACK_VAL 0x1 /*!< I2C nack value */
|
||||
#define SCCB_FREQ 100000 /*!< I2C master frequency*/
|
||||
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
|
||||
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
|
||||
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
|
||||
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
|
||||
#define ACK_VAL 0x0 /*!< I2C ack value */
|
||||
#define NACK_VAL 0x1 /*!< I2C nack value */
|
||||
#if CONFIG_SCCB_HARDWARE_I2C_PORT1
|
||||
const int SCCB_I2C_PORT_DEFAULT = 1;
|
||||
const int SCCB_I2C_PORT = 1;
|
||||
#else
|
||||
const int SCCB_I2C_PORT_DEFAULT = 0;
|
||||
const int SCCB_I2C_PORT = 0;
|
||||
#endif
|
||||
|
||||
static int sccb_i2c_port;
|
||||
static bool sccb_owns_i2c_port;
|
||||
static uint8_t ESP_SLAVE_ADDR = 0x3c;
|
||||
|
||||
int SCCB_Init(int pin_sda, int pin_scl)
|
||||
{
|
||||
ESP_LOGI(TAG, "pin_sda %d pin_scl %d", pin_sda, pin_scl);
|
||||
ESP_LOGI(TAG, "pin_sda %d pin_scl %d\n", pin_sda, pin_scl);
|
||||
//log_i("SCCB_Init start");
|
||||
i2c_config_t conf;
|
||||
esp_err_t ret;
|
||||
|
||||
memset(&conf, 0, sizeof(i2c_config_t));
|
||||
|
||||
sccb_i2c_port = SCCB_I2C_PORT_DEFAULT;
|
||||
sccb_owns_i2c_port = true;
|
||||
ESP_LOGI(TAG, "sccb_i2c_port=%d", sccb_i2c_port);
|
||||
|
||||
conf.mode = I2C_MODE_MASTER;
|
||||
conf.sda_io_num = pin_sda;
|
||||
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
|
||||
|
|
@ -66,53 +51,32 @@ int SCCB_Init(int pin_sda, int pin_scl)
|
|||
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
|
||||
conf.master.clk_speed = SCCB_FREQ;
|
||||
|
||||
if ((ret = i2c_param_config(sccb_i2c_port, &conf)) != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return i2c_driver_install(sccb_i2c_port, conf.mode, 0, 0, 0);
|
||||
i2c_param_config(SCCB_I2C_PORT, &conf);
|
||||
i2c_driver_install(SCCB_I2C_PORT, conf.mode, 0, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SCCB_Use_Port(int i2c_num) { // sccb use an already initialized I2C port
|
||||
if (sccb_owns_i2c_port) {
|
||||
SCCB_Deinit();
|
||||
}
|
||||
if (i2c_num < 0 || i2c_num > I2C_NUM_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
sccb_i2c_port = i2c_num;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int SCCB_Deinit(void)
|
||||
{
|
||||
if (!sccb_owns_i2c_port) {
|
||||
return ESP_OK;
|
||||
}
|
||||
sccb_owns_i2c_port = false;
|
||||
return i2c_driver_delete(sccb_i2c_port);
|
||||
}
|
||||
|
||||
uint8_t SCCB_Probe(void)
|
||||
uint8_t SCCB_Probe()
|
||||
{
|
||||
uint8_t slave_addr = 0x0;
|
||||
|
||||
for (size_t i = 0; i < CAMERA_MODEL_MAX; i++) {
|
||||
if (slave_addr == camera_sensor[i].sccb_addr) {
|
||||
continue;
|
||||
}
|
||||
slave_addr = camera_sensor[i].sccb_addr;
|
||||
while(slave_addr < 0x7f) {
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, ( slave_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
esp_err_t ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
esp_err_t ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if( ret == ESP_OK) {
|
||||
return slave_addr;
|
||||
ESP_LOGI(TAG, "SCCB Device @ 0x%02x", slave_addr);
|
||||
if(slave_addr == 0x21 || slave_addr == 0x2A || slave_addr == 0x30 || slave_addr == 0x3C){
|
||||
ESP_LOGI(TAG, "SCCB Camera @ 0x%02x", slave_addr);
|
||||
ESP_SLAVE_ADDR = slave_addr;
|
||||
return ESP_SLAVE_ADDR;
|
||||
}
|
||||
}
|
||||
slave_addr++;
|
||||
}
|
||||
return 0;
|
||||
return ESP_SLAVE_ADDR;
|
||||
}
|
||||
|
||||
uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
|
||||
|
|
@ -124,7 +88,7 @@ uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
|
|||
i2c_master_write_byte(cmd, ( slv_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ret != ESP_OK) return -1;
|
||||
cmd = i2c_cmd_link_create();
|
||||
|
|
@ -132,7 +96,7 @@ uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
|
|||
i2c_master_write_byte(cmd, ( slv_addr << 1 ) | READ_BIT, ACK_CHECK_EN);
|
||||
i2c_master_read_byte(cmd, &data, NACK_VAL);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "SCCB_Read Failed addr:0x%02x, reg:0x%02x, data:0x%02x, ret:%d", slv_addr, reg, data, ret);
|
||||
|
|
@ -140,7 +104,7 @@ uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
|
|||
return data;
|
||||
}
|
||||
|
||||
int SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data)
|
||||
uint8_t SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data)
|
||||
{
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
|
|
@ -149,7 +113,7 @@ int SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data)
|
|||
i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, data, ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "SCCB_Write Failed addr:0x%02x, reg:0x%02x, data:0x%02x, ret:%d", slv_addr, reg, data, ret);
|
||||
|
|
@ -169,7 +133,7 @@ uint8_t SCCB_Read16(uint8_t slv_addr, uint16_t reg)
|
|||
i2c_master_write_byte(cmd, reg_u8[0], ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, reg_u8[1], ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ret != ESP_OK) return -1;
|
||||
cmd = i2c_cmd_link_create();
|
||||
|
|
@ -177,7 +141,7 @@ uint8_t SCCB_Read16(uint8_t slv_addr, uint16_t reg)
|
|||
i2c_master_write_byte(cmd, ( slv_addr << 1 ) | READ_BIT, ACK_CHECK_EN);
|
||||
i2c_master_read_byte(cmd, &data, NACK_VAL);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "W [%04x]=%02x fail\n", reg, data);
|
||||
|
|
@ -185,7 +149,7 @@ uint8_t SCCB_Read16(uint8_t slv_addr, uint16_t reg)
|
|||
return data;
|
||||
}
|
||||
|
||||
int SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data)
|
||||
uint8_t SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data)
|
||||
{
|
||||
static uint16_t i = 0;
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
|
|
@ -198,64 +162,10 @@ int SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data)
|
|||
i2c_master_write_byte(cmd, reg_u8[1], ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, data, ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "W [%04x]=%02x %d fail\n", reg, data, i++);
|
||||
}
|
||||
return ret == ESP_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
uint16_t SCCB_Read_Addr16_Val16(uint8_t slv_addr, uint16_t reg)
|
||||
{
|
||||
uint16_t data = 0;
|
||||
uint8_t *data_u8 = (uint8_t *)&data;
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
uint16_t reg_htons = LITTLETOBIG(reg);
|
||||
uint8_t *reg_u8 = (uint8_t *)®_htons;
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, ( slv_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, reg_u8[0], ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, reg_u8[1], ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ret != ESP_OK) return -1;
|
||||
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, ( slv_addr << 1 ) | READ_BIT, ACK_CHECK_EN);
|
||||
i2c_master_read_byte(cmd, &data_u8[1], ACK_VAL);
|
||||
i2c_master_read_byte(cmd, &data_u8[0], NACK_VAL);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "W [%04x]=%04x fail\n", reg, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
int SCCB_Write_Addr16_Val16(uint8_t slv_addr, uint16_t reg, uint16_t data)
|
||||
{
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
uint16_t reg_htons = LITTLETOBIG(reg);
|
||||
uint8_t *reg_u8 = (uint8_t *)®_htons;
|
||||
uint16_t data_htons = LITTLETOBIG(data);
|
||||
uint8_t *data_u8 = (uint8_t *)&data_htons;
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, ( slv_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, reg_u8[0], ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, reg_u8[1], ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, data_u8[0], ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, data_u8[1], ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "W [%04x]=%04x fail\n", reg, data);
|
||||
}
|
||||
return ret == ESP_OK ? 0 : -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include "sensor.h"
|
||||
|
||||
const camera_sensor_info_t camera_sensor[CAMERA_MODEL_MAX] = {
|
||||
// The sequence must be consistent with camera_model_t
|
||||
{CAMERA_OV7725, "OV7725", OV7725_SCCB_ADDR, OV7725_PID, FRAMESIZE_VGA, false},
|
||||
{CAMERA_OV2640, "OV2640", OV2640_SCCB_ADDR, OV2640_PID, FRAMESIZE_UXGA, true},
|
||||
{CAMERA_OV3660, "OV3660", OV3660_SCCB_ADDR, OV3660_PID, FRAMESIZE_QXGA, true},
|
||||
{CAMERA_OV5640, "OV5640", OV5640_SCCB_ADDR, OV5640_PID, FRAMESIZE_QSXGA, true},
|
||||
{CAMERA_OV7670, "OV7670", OV7670_SCCB_ADDR, OV7670_PID, FRAMESIZE_VGA, false},
|
||||
{CAMERA_NT99141, "NT99141", NT99141_SCCB_ADDR, NT99141_PID, FRAMESIZE_HD, true},
|
||||
{CAMERA_GC2145, "GC2145", GC2145_SCCB_ADDR, GC2145_PID, FRAMESIZE_UXGA, false},
|
||||
{CAMERA_GC032A, "GC032A", GC032A_SCCB_ADDR, GC032A_PID, FRAMESIZE_VGA, false},
|
||||
{CAMERA_GC0308, "GC0308", GC0308_SCCB_ADDR, GC0308_PID, FRAMESIZE_VGA, false},
|
||||
{CAMERA_BF3005, "BF3005", BF3005_SCCB_ADDR, BF3005_PID, FRAMESIZE_VGA, false},
|
||||
{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] = {
|
||||
{ 96, 96, ASPECT_RATIO_1X1 }, /* 96x96 */
|
||||
{ 160, 120, ASPECT_RATIO_4X3 }, /* QQVGA */
|
||||
|
|
@ -45,13 +26,3 @@ const resolution_info_t resolution[FRAMESIZE_INVALID] = {
|
|||
{ 1088, 1920, ASPECT_RATIO_9X16 }, /* Portrait FHD */
|
||||
{ 2560, 1920, ASPECT_RATIO_4X3 }, /* QSXGA */
|
||||
};
|
||||
|
||||
camera_sensor_info_t *esp_camera_sensor_get_info(sensor_id_t *id)
|
||||
{
|
||||
for (int i = 0; i < CAMERA_MODEL_MAX; i++) {
|
||||
if (id->PID == camera_sensor[i].pid) {
|
||||
return (camera_sensor_info_t *)&camera_sensor[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
# The following lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(COMPONENTS main)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(camera_example)
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
idf_component_register(SRCS take_picture.c
|
||||
PRIV_INCLUDE_DIRS .
|
||||
PRIV_REQUIRES nvs_flash)
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
dependencies:
|
||||
espressif/esp32-camera:
|
||||
version: "*"
|
||||
override_path: "../../../"
|
||||
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x10000
|
||||
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
|
||||
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
|
||||
|
||||
CONFIG_SPIRAM_SUPPORT=y
|
||||
CONFIG_ESP32_SPIRAM_SUPPORT=y
|
||||
CONFIG_ESP32S2_SPIRAM_SUPPORT=y
|
||||
CONFIG_ESP32S3_SPIRAM_SUPPORT=y
|
||||
CONFIG_SPIRAM_SPEED_80M=y
|
||||
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
// ================================ CODE ======================================
|
||||
|
||||
#include <esp_event_loop.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_system.h>
|
||||
#include <nvs_flash.h>
|
||||
|
|
@ -38,15 +39,8 @@
|
|||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
// support IDF 5.x
|
||||
#ifndef portTICK_RATE_MS
|
||||
#define portTICK_RATE_MS portTICK_PERIOD_MS
|
||||
#endif
|
||||
|
||||
#include "esp_camera.h"
|
||||
|
||||
#define BOARD_WROVER_KIT 1
|
||||
|
||||
// WROVER-KIT PIN Map
|
||||
#ifdef BOARD_WROVER_KIT
|
||||
|
||||
|
|
@ -95,13 +89,12 @@
|
|||
|
||||
static const char *TAG = "example:take_picture";
|
||||
|
||||
#if ESP_CAMERA_SUPPORTED
|
||||
static camera_config_t camera_config = {
|
||||
.pin_pwdn = CAM_PIN_PWDN,
|
||||
.pin_reset = CAM_PIN_RESET,
|
||||
.pin_xclk = CAM_PIN_XCLK,
|
||||
.pin_sccb_sda = CAM_PIN_SIOD,
|
||||
.pin_sccb_scl = CAM_PIN_SIOC,
|
||||
.pin_sscb_sda = CAM_PIN_SIOD,
|
||||
.pin_sscb_scl = CAM_PIN_SIOC,
|
||||
|
||||
.pin_d7 = CAM_PIN_D7,
|
||||
.pin_d6 = CAM_PIN_D6,
|
||||
|
|
@ -120,16 +113,14 @@ static camera_config_t camera_config = {
|
|||
.ledc_timer = LEDC_TIMER_0,
|
||||
.ledc_channel = LEDC_CHANNEL_0,
|
||||
|
||||
.pixel_format = PIXFORMAT_RGB565, //YUV422,GRAYSCALE,RGB565,JPEG
|
||||
.frame_size = FRAMESIZE_QVGA, //QQVGA-UXGA, For ESP32, do not use sizes above QVGA when not JPEG. The performance of the ESP32-S series has improved a lot, but JPEG mode always gives better frame rates.
|
||||
.pixel_format = PIXFORMAT_JPEG, //YUV422,GRAYSCALE,RGB565,JPEG
|
||||
.frame_size = FRAMESIZE_VGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG
|
||||
|
||||
.jpeg_quality = 12, //0-63, for OV series camera sensors, lower number means higher quality
|
||||
.fb_count = 1, //When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
|
||||
.fb_location = CAMERA_FB_IN_PSRAM,
|
||||
.grab_mode = CAMERA_GRAB_WHEN_EMPTY,
|
||||
.jpeg_quality = 12, //0-63 lower number means higher quality
|
||||
.fb_count = 1 //if more than one, i2s runs in continuous mode. Use only with JPEG
|
||||
};
|
||||
|
||||
static esp_err_t init_camera(void)
|
||||
static esp_err_t init_camera()
|
||||
{
|
||||
//initialize the camera
|
||||
esp_err_t err = esp_camera_init(&camera_config);
|
||||
|
|
@ -141,14 +132,10 @@ static esp_err_t init_camera(void)
|
|||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
void app_main(void)
|
||||
void app_main()
|
||||
{
|
||||
#if ESP_CAMERA_SUPPORTED
|
||||
if(ESP_OK != init_camera()) {
|
||||
return;
|
||||
}
|
||||
init_camera();
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
|
@ -157,12 +144,7 @@ void app_main(void)
|
|||
|
||||
// use pic->buf to access the image
|
||||
ESP_LOGI(TAG, "Picture taken! Its size was: %zu bytes", pic->len);
|
||||
esp_camera_fb_return(pic);
|
||||
|
||||
vTaskDelay(5000 / portTICK_RATE_MS);
|
||||
}
|
||||
#else
|
||||
ESP_LOGE(TAG, "Camera support is not available for this chip");
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
description: ESP32 compatible driver for OV2640, OV3660, OV5640, OV7670 and OV7725 image sensors.
|
||||
url: https://github.com/espressif/esp32-camera
|
||||
issues: https://github.com/espressif/esp32-camera/issues
|
||||
documentation: https://github.com/espressif/esp32-camera/tree/main/README.md
|
||||
repository: https://github.com/espressif/esp32-camera.git
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "esp32-camera",
|
||||
"version": "2.0.0",
|
||||
"version": "1.0.0",
|
||||
"keywords": "esp32, camera, espressif, esp32-cam",
|
||||
"description": "ESP32 compatible driver for OV2640, OV3660, OV5640, OV7670 and OV7725 image sensors.",
|
||||
"repository": {
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
"-Idriver/private_include",
|
||||
"-Iconversions/private_include",
|
||||
"-Isensors/private_include",
|
||||
"-Itarget/private_include",
|
||||
"-fno-rtti"
|
||||
],
|
||||
"includeDir": ".",
|
||||
|
|
|
|||
410
sensors/bf20a6.c
410
sensors/bf20a6.c
|
|
@ -1,410 +0,0 @@
|
|||
// Copyright 2015-2021 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 "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "sccb.h"
|
||||
#include "bf20a6.h"
|
||||
#include "bf20a6_regs.h"
|
||||
#include "bf20a6_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 = "bf20a6";
|
||||
#endif
|
||||
|
||||
#define H8(v) ((v)>>8)
|
||||
#define L8(v) ((v)&0xff)
|
||||
|
||||
//#define REG_DEBUG_ON
|
||||
|
||||
static int read_reg(uint8_t slv_addr, const uint16_t reg)
|
||||
{
|
||||
int ret = SCCB_Read(slv_addr, reg);
|
||||
// ESP_LOGI(TAG, "READ Register 0x%02x VALUE: 0x%02x", reg, ret);
|
||||
#ifdef REG_DEBUG_ON
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "READ REG 0x%04x FAILED: %d", reg, ret);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_reg(uint8_t slv_addr, const uint16_t reg, uint8_t value)
|
||||
{
|
||||
int ret = SCCB_Write(slv_addr, reg, value);
|
||||
#ifdef REG_DEBUG_ON
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "WRITE REG 0x%04x FAILED: %d", reg, ret);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PRINT_REG
|
||||
static int check_reg_mask(uint8_t slv_addr, uint16_t reg, uint8_t mask)
|
||||
{
|
||||
return (read_reg(slv_addr, reg) & mask) == mask;
|
||||
}
|
||||
|
||||
static void print_regs(uint8_t slv_addr)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
ESP_LOGI(TAG, "REG list look ======================");
|
||||
for (size_t i = 0xf0; i <= 0xfe; i++) {
|
||||
ESP_LOGI(TAG, "reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
ESP_LOGI(TAG, "\npage 0 ===");
|
||||
write_reg(slv_addr, 0xfe, 0x00); // page 0
|
||||
for (size_t i = 0x03; i <= 0x24; i++) {
|
||||
ESP_LOGI(TAG, "p0 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
for (size_t i = 0x40; i <= 0x95; i++) {
|
||||
ESP_LOGI(TAG, "p0 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
ESP_LOGI(TAG, "\npage 3 ===");
|
||||
write_reg(slv_addr, 0xfe, 0x03); // page 3
|
||||
for (size_t i = 0x01; i <= 0x43; i++) {
|
||||
ESP_LOGI(TAG, "p3 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
}
|
||||
|
||||
static int read_regs(uint8_t slv_addr, const uint16_t(*regs)[2])
|
||||
{
|
||||
int i = 0, ret = 0;
|
||||
while (regs[i][0] != REGLIST_TAIL) {
|
||||
if (regs[i][0] == REG_DLY) {
|
||||
vTaskDelay(regs[i][1] / portTICK_PERIOD_MS);
|
||||
} else {
|
||||
ret = read_reg(slv_addr, regs[i][0]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int set_reg_bits(sensor_t *sensor, uint8_t reg, uint8_t offset, uint8_t length, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = SCCB_Read(sensor->slv_addr, reg);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
uint8_t mask = ((1 << length) - 1) << offset;
|
||||
value = (ret & ~mask) | ((value << offset) & mask);
|
||||
ret = SCCB_Write(sensor->slv_addr, reg & 0xFF, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_regs(uint8_t slv_addr, const uint16_t(*regs)[2])
|
||||
{
|
||||
int i = 0, ret = 0;
|
||||
while (!ret && regs[i][0] != REGLIST_TAIL) {
|
||||
if (regs[i][0] == REG_DLY) {
|
||||
vTaskDelay(regs[i][1] / portTICK_PERIOD_MS);
|
||||
} else {
|
||||
ret = write_reg(slv_addr, regs[i][0], regs[i][1]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int reset(sensor_t *sensor)
|
||||
{
|
||||
int ret;
|
||||
// Software Reset: clear all registers and reset them to their default values
|
||||
ret = write_reg(sensor->slv_addr, RESET_RELATED, 0x01);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "Software Reset FAILED!");
|
||||
return ret;
|
||||
}
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
|
||||
ret = write_regs(sensor->slv_addr, bf20a6_default_init_regs);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Camera defaults loaded");
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
// int test_value = read_regs(sensor->slv_addr, bf20a6_default_init_regs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_pixformat(sensor_t *sensor, pixformat_t pixformat)
|
||||
{
|
||||
int ret = 0;
|
||||
switch (pixformat) {
|
||||
case PIXFORMAT_YUV422:
|
||||
set_reg_bits(sensor, 0x12, 0, 1, 0);
|
||||
break;
|
||||
case PIXFORMAT_RAW:
|
||||
set_reg_bits(sensor, 0x12, 0, 1, 0x1);
|
||||
break;
|
||||
case PIXFORMAT_GRAYSCALE:
|
||||
write_reg(sensor->slv_addr, 0x12, 0x23);
|
||||
write_reg(sensor->slv_addr, 0x3a, 0x00);
|
||||
write_reg(sensor->slv_addr, 0xe1, 0x92);
|
||||
write_reg(sensor->slv_addr, 0xe3, 0x02);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "set_pix unsupport format");
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
if (ret == 0) {
|
||||
sensor->pixformat = pixformat;
|
||||
ESP_LOGD(TAG, "Set pixformat to: %u", pixformat);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
||||
{
|
||||
int ret = 0;
|
||||
if (framesize > FRAMESIZE_VGA) {
|
||||
return -1;
|
||||
}
|
||||
uint16_t w = resolution[framesize].width;
|
||||
uint16_t h = resolution[framesize].height;
|
||||
|
||||
sensor->status.framesize = framesize;
|
||||
|
||||
// Write MSBs
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x17, 0);
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x18, w >> 2);
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x19, 0);
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x1a, h >> 2);
|
||||
|
||||
// Write LSBs
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x1b, 0);
|
||||
|
||||
if ((w <= 320) && (h <= 240)) {
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x17, (80 - w / 4));
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x18, (80 + w / 4));
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x19, (60 - h / 4));
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x1a, (60 + h / 4));
|
||||
|
||||
} else if ((w <= 640) && (h <= 480)) {
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x17, (80 - w / 8));
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x18, (80 + w / 8));
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x19, (60 - h / 8));
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x1a, (60 + h / 8));
|
||||
}
|
||||
|
||||
// Delay
|
||||
vTaskDelay(30 / portTICK_PERIOD_MS);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_hmirror(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
sensor->status.hmirror = enable;
|
||||
//ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor, 0x4a, 3, 0x01, enable);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set h-mirror to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_vflip(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
sensor->status.vflip = enable;
|
||||
//ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor, 0x4a, 2, 0x01, enable);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set v-flip to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_colorbar(sensor_t *sensor, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = write_reg(sensor->slv_addr, 0xb6, value);
|
||||
if (ret == 0) {
|
||||
sensor->status.colorbar = value;
|
||||
ESP_LOGD(TAG, "Set colorbar to: %d", value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_sharpness(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = SCCB_Write(sensor->slv_addr, 0x70, level);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set sharpness to: %d", level);
|
||||
sensor->status.sharpness = level;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int get_reg(sensor_t *sensor, int reg, int mask)
|
||||
{
|
||||
int ret = 0;
|
||||
if (mask > 0xFF) {
|
||||
ESP_LOGE(TAG, "mask should not more than 0xff");
|
||||
} else {
|
||||
ret = read_reg(sensor->slv_addr, reg);
|
||||
}
|
||||
if (ret > 0) {
|
||||
ret &= mask;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_reg(sensor_t *sensor, int reg, int mask, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
if (mask > 0xFF) {
|
||||
ESP_LOGE(TAG, "mask should not more than 0xff");
|
||||
} else {
|
||||
ret = read_reg(sensor->slv_addr, reg);
|
||||
}
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
value = (ret & ~mask) | (value & mask);
|
||||
|
||||
if (mask > 0xFF) {
|
||||
|
||||
} else {
|
||||
ret = write_reg(sensor->slv_addr, reg, value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int init_status(sensor_t *sensor)
|
||||
{
|
||||
// write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
sensor->status.brightness = SCCB_Read(sensor->slv_addr, 0x6f);
|
||||
sensor->status.contrast = SCCB_Read(sensor->slv_addr, 0xd6);
|
||||
sensor->status.saturation = 0;
|
||||
sensor->status.sharpness = SCCB_Read(sensor->slv_addr, 0x70);
|
||||
sensor->status.denoise = 0;
|
||||
sensor->status.ae_level = 0;
|
||||
sensor->status.gainceiling = SCCB_Read(sensor->slv_addr, 0x13);
|
||||
sensor->status.awb = 0;
|
||||
sensor->status.dcw = 0;
|
||||
sensor->status.agc = 0;
|
||||
sensor->status.aec = 0;
|
||||
sensor->status.hmirror = 0;// check_reg_mask(sensor->slv_addr, P0_CISCTL_MODE1, 0x01);
|
||||
sensor->status.vflip = 0;// check_reg_mask(sensor->slv_addr, P0_CISCTL_MODE1, 0x02);
|
||||
sensor->status.colorbar = 0;
|
||||
sensor->status.bpc = 0;
|
||||
sensor->status.wpc = 0;
|
||||
sensor->status.raw_gma = 0;
|
||||
sensor->status.lenc = 0;
|
||||
sensor->status.quality = 0;
|
||||
sensor->status.special_effect = 0;
|
||||
sensor->status.wb_mode = 0;
|
||||
sensor->status.awb_gain = 0;
|
||||
sensor->status.agc_gain = 0;
|
||||
sensor->status.aec_value = 0;
|
||||
sensor->status.aec2 = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_dummy(sensor_t *sensor, int val)
|
||||
{
|
||||
ESP_LOGW(TAG, "dummy Unsupported");
|
||||
return -1;
|
||||
}
|
||||
static int set_gainceiling_dummy(sensor_t *sensor, gainceiling_t val)
|
||||
{
|
||||
ESP_LOGW(TAG, "gainceiling Unsupported");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bf20a6_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (BF20A6_SCCB_ADDR == slv_addr) {
|
||||
uint8_t MIDL = SCCB_Read(slv_addr, SENSOR_ID_LOW);
|
||||
uint8_t MIDH = SCCB_Read(slv_addr, SENSOR_ID_HIGH);
|
||||
uint16_t PID = MIDH << 8 | MIDL;
|
||||
if (BF20A6_PID == PID) {
|
||||
id->PID = PID;
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bf20a6_init(sensor_t *sensor)
|
||||
{
|
||||
sensor->init_status = init_status;
|
||||
sensor->reset = reset;
|
||||
sensor->set_pixformat = set_pixformat;
|
||||
sensor->set_framesize = set_framesize;
|
||||
sensor->set_contrast = set_dummy;
|
||||
sensor->set_brightness = set_dummy;
|
||||
sensor->set_saturation = set_dummy;
|
||||
sensor->set_sharpness = set_sharpness;
|
||||
sensor->set_denoise = set_dummy;
|
||||
sensor->set_gainceiling = set_gainceiling_dummy;
|
||||
sensor->set_quality = set_dummy;
|
||||
sensor->set_colorbar = set_colorbar;
|
||||
sensor->set_whitebal = set_dummy;
|
||||
sensor->set_gain_ctrl = set_dummy;
|
||||
sensor->set_exposure_ctrl = set_dummy;
|
||||
sensor->set_hmirror = set_hmirror; // set_hmirror;
|
||||
sensor->set_vflip = set_vflip; // set_vflip;
|
||||
|
||||
sensor->set_aec2 = set_dummy;
|
||||
sensor->set_awb_gain = set_dummy;
|
||||
sensor->set_agc_gain = set_dummy;
|
||||
sensor->set_aec_value = set_dummy;
|
||||
|
||||
sensor->set_special_effect = set_dummy;
|
||||
sensor->set_wb_mode = set_dummy;
|
||||
sensor->set_ae_level = set_dummy;
|
||||
|
||||
sensor->set_dcw = set_dummy;
|
||||
sensor->set_bpc = set_dummy;
|
||||
sensor->set_wpc = set_dummy;
|
||||
|
||||
sensor->set_raw_gma = set_dummy;
|
||||
sensor->set_lenc = set_dummy;
|
||||
|
||||
sensor->get_reg = get_reg;
|
||||
sensor->set_reg = set_reg;
|
||||
sensor->set_res_raw = NULL;
|
||||
sensor->set_pll = NULL;
|
||||
sensor->set_xclk = NULL;
|
||||
|
||||
ESP_LOGD(TAG, "BF20A6 Attached");
|
||||
return 0;
|
||||
}
|
||||
541
sensors/bf3005.c
541
sensors/bf3005.c
|
|
@ -1,541 +0,0 @@
|
|||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* Copyright (c) 2013/2014 Ibrahim Abdelkader <i.abdalkader@gmail.com>
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* BF3005 driver.
|
||||
*
|
||||
* Copyright 2015-2021 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 "bf3005.h"
|
||||
#include "bf3005_regs.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.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 = "bf3005";
|
||||
#endif
|
||||
|
||||
static const uint8_t default_regs[][2] = {
|
||||
{0x12, 0x40}, //soft reset
|
||||
{0xff, 0xff}, //delay
|
||||
{0xff, 0xff}, //delay
|
||||
{0xff, 0xff}, //delay
|
||||
{0xff, 0xff}, //delay
|
||||
{0x13, 0x10},
|
||||
{0x8c, 0x00},
|
||||
{0x8d, 0x64},
|
||||
{0x87, 0x10},
|
||||
{0x13, 0x17},
|
||||
{0x00, 0x20},
|
||||
{0x01, 0x1a},
|
||||
{0x02, 0x22},
|
||||
{0x09, 0x03},
|
||||
{0x0c, 0x80},
|
||||
{0x0d, 0x24},
|
||||
{0x0e, 0x21},
|
||||
{0x0f, 0x28},
|
||||
{0x11, 0x08},
|
||||
{0x15, 0x10}, // 0X10
|
||||
{0x16, 0x03},
|
||||
{0x1e, 0x30},
|
||||
{0x20, 0x8a},
|
||||
{0x21, 0x03},
|
||||
{0x23, 0x55},
|
||||
{0x24, 0x68},
|
||||
{0x25, 0x78},
|
||||
{0x2a, 0x00},
|
||||
{0x2b, 0x00},
|
||||
{0x2d, 0x4f},
|
||||
{0x2e, 0x98},
|
||||
{0x2f, 0x04},
|
||||
{0x30, 0xad},
|
||||
{0x31, 0x17},
|
||||
{0x32, 0x6e},
|
||||
{0x33, 0x20},
|
||||
{0x35, 0xa6},
|
||||
{0x3b, 0x00},
|
||||
{0x3e, 0x00},
|
||||
{0x3f, 0xA8},
|
||||
{0x40, 0x38},
|
||||
{0x41, 0x32},
|
||||
{0x42, 0x2b},
|
||||
{0x43, 0x26},
|
||||
{0x44, 0x1a},
|
||||
{0x45, 0x16},
|
||||
{0x46, 0x10},
|
||||
{0x47, 0x0f},
|
||||
{0x48, 0x0c},
|
||||
{0x49, 0x0a},
|
||||
{0x4b, 0x09},
|
||||
{0x4c, 0x08},
|
||||
{0x4d, 0x3c},
|
||||
{0x4e, 0x06},
|
||||
{0x4f, 0x05},
|
||||
{0x50, 0x03},
|
||||
{0x51, 0x25},
|
||||
{0x52, 0x88},
|
||||
{0x53, 0x03},
|
||||
{0x63, 0x20},
|
||||
{0x64, 0x02},
|
||||
{0x65, 0xa6},
|
||||
{0x66, 0xb6},
|
||||
{0x69, 0x00},
|
||||
{0x70, 0xFF},
|
||||
{0x71, 0xa6},
|
||||
{0x72, 0x2f},
|
||||
{0x73, 0x2f},
|
||||
{0x74, 0x2F},
|
||||
{0x75, 0x0e},
|
||||
{0x76, 0x1e},
|
||||
{0x77, 0x00},
|
||||
{0x78, 0x1e},
|
||||
{0x79, 0x8a},
|
||||
{0x7d, 0xe2},
|
||||
{0x80, 0x44},
|
||||
{0x81, 0x00},
|
||||
{0x82, 0x18},
|
||||
{0x83, 0x1b},
|
||||
{0x84, 0x24},
|
||||
{0x85, 0x2a},
|
||||
{0x86, 0x4f},
|
||||
{0x89, 0x82}, //0x82
|
||||
{0x8b, 0x02},
|
||||
{0x8e, 0x03},
|
||||
{0x8f, 0xFC},
|
||||
{0x9d, 0x4d},
|
||||
{0x9e, 0x41},
|
||||
{0xa1, 0x21},
|
||||
{0xa2, 0x12},
|
||||
{0xa3, 0x32},
|
||||
{0xa4, 0x05},
|
||||
{0xa5, 0x32},
|
||||
{0xa6, 0x04},
|
||||
{0xa7, 0x7f},
|
||||
{0xa8, 0x7f},
|
||||
{0xa9, 0x21},
|
||||
{0xaa, 0x21},
|
||||
{0xab, 0x21},
|
||||
{0xac, 0x0a},
|
||||
{0xad, 0xf0},
|
||||
{0xae, 0xff},
|
||||
{0xaf, 0x1d},
|
||||
{0xb0, 0x94},
|
||||
{0xb1, 0xc0},
|
||||
{0xb2, 0xc0},
|
||||
{0xd2, 0x30},
|
||||
{0xe0, 0x0d},
|
||||
{0xe1, 0x44},
|
||||
{0xe7, 0x7c},
|
||||
{0xe8, 0x89},
|
||||
{0xe9, 0x01},
|
||||
{0xea, 0x01},
|
||||
{0xf0, 0x01},
|
||||
{0xf3, 0x49},
|
||||
{0xf4, 0xff},
|
||||
{0xf5, 0x01},
|
||||
{0xf6, 0xf2},
|
||||
{0xf7, 0x6f},
|
||||
{0x1b, 0x80},
|
||||
{0x00, 0x00},
|
||||
};
|
||||
|
||||
static int get_reg(sensor_t *sensor, int reg, int mask)
|
||||
{
|
||||
int ret = SCCB_Read(sensor->slv_addr, reg & 0xFF);
|
||||
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_Read(sensor->slv_addr, reg & 0xFF);
|
||||
if(ret < 0){
|
||||
return ret;
|
||||
}
|
||||
value = (ret & ~mask) | (value & mask);
|
||||
ret = SCCB_Write(sensor->slv_addr, reg & 0xFF, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_reg_bits(sensor_t *sensor, uint8_t reg, uint8_t offset, uint8_t length, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = SCCB_Read(sensor->slv_addr, reg);
|
||||
if(ret < 0){
|
||||
return ret;
|
||||
}
|
||||
uint8_t mask = ((1 << length) - 1) << offset;
|
||||
value = (ret & ~mask) | ((value << offset) & mask);
|
||||
ret = SCCB_Write(sensor->slv_addr, reg & 0xFF, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int get_reg_bits(sensor_t *sensor, uint8_t reg, uint8_t offset, uint8_t length)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = SCCB_Read(sensor->slv_addr, reg);
|
||||
if(ret < 0){
|
||||
return ret;
|
||||
}
|
||||
uint8_t mask = ((1 << length) - 1) << offset;
|
||||
return (ret & mask) >> offset;
|
||||
}
|
||||
|
||||
|
||||
static int reset(sensor_t *sensor)
|
||||
{
|
||||
int i=0;
|
||||
const uint8_t (*regs)[2];
|
||||
|
||||
// Write default regsiters
|
||||
for (i=0, regs = default_regs; regs[i][0]; i++) {
|
||||
SCCB_Write(sensor->slv_addr, regs[i][0], regs[i][1]);
|
||||
}
|
||||
|
||||
// Delay
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_pixformat(sensor_t *sensor, pixformat_t pixformat)
|
||||
{
|
||||
int ret=0;
|
||||
sensor->pixformat = pixformat;
|
||||
|
||||
switch (pixformat) {
|
||||
case PIXFORMAT_RGB565:
|
||||
set_reg_bits(sensor, 0x12, 2, 1, 1);
|
||||
break;
|
||||
case PIXFORMAT_RAW:
|
||||
set_reg_bits(sensor, 0x12, 0, 3, 0x4);
|
||||
break;
|
||||
case PIXFORMAT_YUV422:
|
||||
case PIXFORMAT_GRAYSCALE:
|
||||
set_reg_bits(sensor, 0x12, 2, 1, 0);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Delay
|
||||
vTaskDelay(30 / portTICK_PERIOD_MS);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
||||
{
|
||||
int ret=0;
|
||||
if (framesize > FRAMESIZE_VGA) {
|
||||
return -1;
|
||||
}
|
||||
uint16_t w = resolution[framesize].width;
|
||||
uint16_t h = resolution[framesize].height;
|
||||
// uint8_t reg = SCCB_Read(sensor->slv_addr, COM7);
|
||||
|
||||
sensor->status.framesize = framesize;
|
||||
|
||||
// Write MSBs
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x17, 0);
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x18, w>>2);
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x19, 0);
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x1a, h>>2);
|
||||
|
||||
// Write LSBs
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x03, 0);
|
||||
printf("%s %d\r\n", __func__, __LINE__);
|
||||
if((w<=320)&&(h<=240))
|
||||
{
|
||||
printf("%s %d\r\n", __func__, __LINE__);
|
||||
// Enable auto-scaling/zooming factors
|
||||
//ret |= SCCB_Write(sensor->slv_addr, 0x12, 0x50);
|
||||
set_reg_bits(sensor, 0x12, 4, 1, 1);
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x17, (80-w/4));
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x18, (80+w/4));
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x19, (60-h/4));
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x1a, (60+h/4));
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x03, 0);
|
||||
|
||||
} else if((w<=640)&&(h<=480))
|
||||
{
|
||||
// Enable auto-scaling/zooming factors
|
||||
//ret |= SCCB_Write(sensor->slv_addr, 0x12, 0x40);
|
||||
set_reg_bits(sensor, 0x12, 4, 1, 0);
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x17, (80-w/8));
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x18, (80+w/8));
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x19, (60-h/8));
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x1a, (60+h/8));
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0x03, 0);
|
||||
}
|
||||
|
||||
// Delay
|
||||
vTaskDelay(30 / portTICK_PERIOD_MS);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_colorbar(sensor_t *sensor, int value)
|
||||
{
|
||||
int ret=0;
|
||||
sensor->status.colorbar = value;
|
||||
|
||||
ret |= SCCB_Write(sensor->slv_addr, 0xb9, value);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_whitebal(sensor_t *sensor, int enable)
|
||||
{
|
||||
if(set_reg_bits(sensor, 0x13, 1, 1, enable) >= 0){
|
||||
sensor->status.awb = !!enable;
|
||||
}
|
||||
return sensor->status.awb;
|
||||
}
|
||||
|
||||
|
||||
static int set_gain_ctrl(sensor_t *sensor, int enable)
|
||||
{
|
||||
if(set_reg_bits(sensor, 0x13, 2, 1, enable) >= 0){
|
||||
sensor->status.agc = !!enable;
|
||||
}
|
||||
return sensor->status.agc;
|
||||
}
|
||||
|
||||
|
||||
static int set_exposure_ctrl(sensor_t *sensor, int enable)
|
||||
{
|
||||
if(set_reg_bits(sensor, 0x13, 0, 1, enable) >= 0){
|
||||
sensor->status.aec = !!enable;
|
||||
}
|
||||
return sensor->status.aec;
|
||||
}
|
||||
|
||||
static int set_hmirror(sensor_t *sensor, int enable)
|
||||
{
|
||||
if(set_reg_bits(sensor, 0x1e, 5, 1, enable) >= 0){
|
||||
sensor->status.hmirror = !!enable;
|
||||
}
|
||||
return sensor->status.hmirror;
|
||||
}
|
||||
|
||||
static int set_vflip(sensor_t *sensor, int enable)
|
||||
{
|
||||
if(set_reg_bits(sensor, 0x1e, 4, 1, enable) >= 0){
|
||||
sensor->status.vflip = !!enable;
|
||||
}
|
||||
return sensor->status.vflip;
|
||||
}
|
||||
|
||||
static int set_raw_gma_dsp(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = set_reg_bits(sensor, 0xf1, 1, 1, !enable);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set raw_gma to: %d", !enable);
|
||||
sensor->status.raw_gma = !enable;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int set_lenc_dsp(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = set_reg_bits(sensor, 0xf1, 0, 1, !enable);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set lenc to: %d", !enable);
|
||||
sensor->status.lenc = !enable;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_agc_gain(sensor_t *sensor, int option)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = set_reg_bits(sensor, 0x13, 4, 1, !!option);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set gain to: %d", !!option);
|
||||
sensor->status.agc_gain = !!option;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_awb_gain_dsp(sensor_t *sensor, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = SCCB_Write(sensor->slv_addr, 0xa6, value);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set awb gain threthold to: %d", value);
|
||||
sensor->status.awb_gain = value;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_brightness(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = SCCB_Write(sensor->slv_addr, 0x55, level);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set brightness to: %d", level);
|
||||
sensor->status.brightness = level;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_contrast(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = SCCB_Write(sensor->slv_addr, 0x56, level);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set contrast to: %d", level);
|
||||
sensor->status.contrast = level;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_sharpness(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = SCCB_Write(sensor->slv_addr, 0x70, level);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set sharpness to: %d", level);
|
||||
sensor->status.sharpness = level;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int init_status(sensor_t *sensor)
|
||||
{
|
||||
sensor->status.brightness = SCCB_Read(sensor->slv_addr, 0x55);
|
||||
sensor->status.contrast = SCCB_Read(sensor->slv_addr, 0x56);
|
||||
sensor->status.saturation = 0;
|
||||
sensor->status.ae_level = 0;
|
||||
|
||||
sensor->status.gainceiling = SCCB_Read(sensor->slv_addr, 0x87);
|
||||
sensor->status.awb = get_reg_bits(sensor, 0x13, 1, 1);
|
||||
sensor->status.awb_gain = SCCB_Read(sensor->slv_addr, 0xa6);
|
||||
sensor->status.aec = get_reg_bits(sensor, 0x13, 0, 1);
|
||||
|
||||
sensor->status.agc = get_reg_bits(sensor, 0x13, 2, 1);
|
||||
|
||||
sensor->status.raw_gma = get_reg_bits(sensor, 0xf1, 1, 1);
|
||||
sensor->status.lenc = get_reg_bits(sensor, 0xf1, 0, 1);
|
||||
sensor->status.hmirror = get_reg_bits(sensor, 0x1e, 5, 1);
|
||||
sensor->status.vflip = get_reg_bits(sensor, 0x1e, 4, 1);
|
||||
|
||||
sensor->status.colorbar = SCCB_Read(sensor->slv_addr, 0xb9);
|
||||
sensor->status.sharpness = SCCB_Read(sensor->slv_addr, 0x70);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_dummy(sensor_t *sensor, int val){ return -1; }
|
||||
static int set_gainceiling_dummy(sensor_t *sensor, gainceiling_t val){ return -1; }
|
||||
static int set_res_raw(sensor_t *sensor, int startX, int startY, int endX, int endY, int offsetX, int offsetY, int totalX, int totalY, int outputX, int outputY, bool scale, bool binning){return -1;}
|
||||
static int _set_pll(sensor_t *sensor, int bypass, int multiplier, int sys_div, int root_2x, int pre_div, int seld5, int pclk_manual, int pclk_div){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 bf3005_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (BF3005_SCCB_ADDR == slv_addr) {
|
||||
uint16_t PID = SCCB_Read(slv_addr, 0xFC);
|
||||
if (BF3005_PID == PID) {
|
||||
id->PID = PID;
|
||||
id->VER = SCCB_Read(slv_addr, 0xFD);
|
||||
id->MIDL = SCCB_Read(slv_addr, 0xFC);
|
||||
id->MIDH = SCCB_Read(slv_addr, 0xFD);
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bf3005_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_brightness = set_brightness;
|
||||
sensor->set_contrast = set_contrast;
|
||||
|
||||
sensor->set_colorbar = set_colorbar;
|
||||
|
||||
sensor->set_gain_ctrl = set_gain_ctrl;
|
||||
sensor->set_exposure_ctrl = set_exposure_ctrl;
|
||||
sensor->set_hmirror = set_hmirror;
|
||||
sensor->set_vflip = set_vflip;
|
||||
|
||||
sensor->set_whitebal = set_whitebal;
|
||||
|
||||
sensor->set_awb_gain = set_awb_gain_dsp;
|
||||
sensor->set_agc_gain = set_agc_gain;
|
||||
|
||||
sensor->set_raw_gma = set_raw_gma_dsp;
|
||||
sensor->set_lenc = set_lenc_dsp;
|
||||
|
||||
sensor->set_sharpness = set_sharpness;
|
||||
//not supported
|
||||
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->set_gainceiling = set_gainceiling_dummy;
|
||||
|
||||
|
||||
sensor->get_reg = get_reg;
|
||||
sensor->set_reg = set_reg;
|
||||
sensor->set_res_raw = set_res_raw;
|
||||
sensor->set_pll = _set_pll;
|
||||
sensor->set_xclk = set_xclk;
|
||||
|
||||
ESP_LOGD(TAG, "BF3005 Attached");
|
||||
|
||||
return 0;
|
||||
}
|
||||
472
sensors/gc0308.c
472
sensors/gc0308.c
|
|
@ -1,472 +0,0 @@
|
|||
// Copyright 2015-2021 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 "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "sccb.h"
|
||||
#include "gc0308.h"
|
||||
#include "gc0308_regs.h"
|
||||
#include "gc0308_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 = "gc0308";
|
||||
#endif
|
||||
|
||||
#define H8(v) ((v)>>8)
|
||||
#define L8(v) ((v)&0xff)
|
||||
|
||||
//#define REG_DEBUG_ON
|
||||
|
||||
static int read_reg(uint8_t slv_addr, const uint16_t reg)
|
||||
{
|
||||
int ret = SCCB_Read(slv_addr, reg);
|
||||
#ifdef REG_DEBUG_ON
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "READ REG 0x%04x FAILED: %d", reg, ret);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_reg(uint8_t slv_addr, const uint16_t reg, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifndef REG_DEBUG_ON
|
||||
ret = SCCB_Write(slv_addr, reg, value);
|
||||
#else
|
||||
int old_value = read_reg(slv_addr, reg);
|
||||
if (old_value < 0) {
|
||||
return old_value;
|
||||
}
|
||||
if ((uint8_t)old_value != value) {
|
||||
ESP_LOGI(TAG, "NEW REG 0x%04x: 0x%02x to 0x%02x", reg, (uint8_t)old_value, value);
|
||||
ret = SCCB_Write(slv_addr, reg, value);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "OLD REG 0x%04x: 0x%02x", reg, (uint8_t)old_value);
|
||||
ret = SCCB_Write(slv_addr, reg, value);//maybe not?
|
||||
}
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "WRITE REG 0x%04x FAILED: %d", reg, ret);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int check_reg_mask(uint8_t slv_addr, uint16_t reg, uint8_t mask)
|
||||
{
|
||||
return (read_reg(slv_addr, reg) & mask) == mask;
|
||||
}
|
||||
|
||||
static int set_reg_bits(uint8_t slv_addr, uint16_t reg, uint8_t offset, uint8_t mask, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t c_value, new_value;
|
||||
ret = read_reg(slv_addr, reg);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
c_value = ret;
|
||||
new_value = (c_value & ~(mask << offset)) | ((value & mask) << offset);
|
||||
ret = write_reg(slv_addr, reg, new_value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_regs(uint8_t slv_addr, const uint8_t (*regs)[2], size_t regs_size)
|
||||
{
|
||||
int i = 0, ret = 0;
|
||||
while (!ret && (i < regs_size)) {
|
||||
if (regs[i][0] == REG_DLY) {
|
||||
vTaskDelay(regs[i][1] / portTICK_PERIOD_MS);
|
||||
} else {
|
||||
ret = write_reg(slv_addr, regs[i][0], regs[i][1]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void print_regs(uint8_t slv_addr)
|
||||
{
|
||||
#ifdef DEBUG_PRINT_REG
|
||||
ESP_LOGI(TAG, "REG list look ======================");
|
||||
for (size_t i = 0xf0; i <= 0xfe; i++) {
|
||||
ESP_LOGI(TAG, "reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
ESP_LOGI(TAG, "\npage 0 ===");
|
||||
write_reg(slv_addr, 0xfe, 0x00); // page 0
|
||||
for (size_t i = 0x03; i <= 0xa2; i++) {
|
||||
ESP_LOGI(TAG, "p0 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "\npage 3 ===");
|
||||
write_reg(slv_addr, 0xfe, 0x03); // page 3
|
||||
for (size_t i = 0x01; i <= 0x43; i++) {
|
||||
ESP_LOGI(TAG, "p3 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int reset(sensor_t *sensor)
|
||||
{
|
||||
int ret = 0;
|
||||
// Software Reset: clear all registers and reset them to their default values
|
||||
ret = write_reg(sensor->slv_addr, RESET_RELATED, 0xf0);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "Software Reset FAILED!");
|
||||
return ret;
|
||||
}
|
||||
|
||||
vTaskDelay(80 / portTICK_PERIOD_MS);
|
||||
ret = write_regs(sensor->slv_addr, gc0308_sensor_default_regs, sizeof(gc0308_sensor_default_regs)/(sizeof(uint8_t) * 2));
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Camera defaults loaded");
|
||||
vTaskDelay(80 / portTICK_PERIOD_MS);
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
set_reg_bits(sensor->slv_addr, 0x28, 4, 0x07, 1); //frequency division for esp32, ensure pclk <= 15MHz
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_pixformat(sensor_t *sensor, pixformat_t pixformat)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (pixformat) {
|
||||
case PIXFORMAT_RGB565:
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret = set_reg_bits(sensor->slv_addr, 0x24, 0, 0x0f, 6); //RGB565
|
||||
break;
|
||||
|
||||
case PIXFORMAT_YUV422:
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret = set_reg_bits(sensor->slv_addr, 0x24, 0, 0x0f, 2); //yuv422 Y Cb Y Cr
|
||||
break;
|
||||
case PIXFORMAT_GRAYSCALE:
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret = write_reg(sensor->slv_addr, 0x24, 0xb1);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "unsupport format");
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
sensor->pixformat = pixformat;
|
||||
ESP_LOGD(TAG, "Set pixformat to: %u", pixformat);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
||||
{
|
||||
int ret = 0;
|
||||
if (framesize > FRAMESIZE_VGA) {
|
||||
ESP_LOGW(TAG, "Invalid framesize: %u", framesize);
|
||||
framesize = FRAMESIZE_VGA;
|
||||
}
|
||||
sensor->status.framesize = framesize;
|
||||
uint16_t w = resolution[framesize].width;
|
||||
uint16_t h = resolution[framesize].height;
|
||||
uint16_t row_s = (resolution[FRAMESIZE_VGA].height - h) / 2;
|
||||
uint16_t col_s = (resolution[FRAMESIZE_VGA].width - w) / 2;
|
||||
(void)row_s;
|
||||
(void)col_s;
|
||||
|
||||
#if CONFIG_GC_SENSOR_SUBSAMPLE_MODE
|
||||
struct subsample_cfg {
|
||||
uint16_t ratio_numerator;
|
||||
uint16_t ratio_denominator;
|
||||
uint8_t reg0x54;
|
||||
uint8_t reg0x56;
|
||||
uint8_t reg0x57;
|
||||
uint8_t reg0x58;
|
||||
uint8_t reg0x59;
|
||||
};
|
||||
const struct subsample_cfg subsample_cfgs[] = { // define some subsample ratio
|
||||
{84, 420, 0x55, 0x00, 0x00, 0x00, 0x00}, //1/5
|
||||
{105, 420, 0x44, 0x00, 0x00, 0x00, 0x00},//1/4
|
||||
{140, 420, 0x33, 0x00, 0x00, 0x00, 0x00},//1/3
|
||||
{210, 420, 0x22, 0x00, 0x00, 0x00, 0x00},//1/2
|
||||
{240, 420, 0x77, 0x02, 0x46, 0x02, 0x46},//4/7
|
||||
{252, 420, 0x55, 0x02, 0x04, 0x02, 0x04},//3/5
|
||||
{280, 420, 0x33, 0x02, 0x00, 0x02, 0x00},//2/3
|
||||
{420, 420, 0x11, 0x00, 0x00, 0x00, 0x00},//1/1
|
||||
};
|
||||
uint16_t win_w = 640;
|
||||
uint16_t win_h = 480;
|
||||
const struct subsample_cfg *cfg = NULL;
|
||||
/**
|
||||
* Strategy: try to keep the maximum perspective
|
||||
*/
|
||||
for (size_t i = 0; i < sizeof(subsample_cfgs) / sizeof(struct subsample_cfg); i++) {
|
||||
cfg = &subsample_cfgs[i];
|
||||
if ((win_w * cfg->ratio_numerator / cfg->ratio_denominator >= w) && (win_h * cfg->ratio_numerator / cfg->ratio_denominator >= h)) {
|
||||
win_w = w * cfg->ratio_denominator / cfg->ratio_numerator;
|
||||
win_h = h * cfg->ratio_denominator / cfg->ratio_numerator;
|
||||
row_s = (resolution[FRAMESIZE_VGA].height - win_h) / 2;
|
||||
col_s = (resolution[FRAMESIZE_VGA].width - win_w) / 2;
|
||||
ESP_LOGI(TAG, "subsample win:%dx%d, ratio:%f", win_w, win_h, (float)cfg->ratio_numerator / (float)cfg->ratio_denominator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
|
||||
write_reg(sensor->slv_addr, 0x05, H8(row_s));
|
||||
write_reg(sensor->slv_addr, 0x06, L8(row_s));
|
||||
write_reg(sensor->slv_addr, 0x07, H8(col_s));
|
||||
write_reg(sensor->slv_addr, 0x08, L8(col_s));
|
||||
write_reg(sensor->slv_addr, 0x09, H8(win_h + 8));
|
||||
write_reg(sensor->slv_addr, 0x0a, L8(win_h + 8));
|
||||
write_reg(sensor->slv_addr, 0x0b, H8(win_w + 8));
|
||||
write_reg(sensor->slv_addr, 0x0c, L8(win_w + 8));
|
||||
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x01);
|
||||
set_reg_bits(sensor->slv_addr, 0x53, 7, 0x01, 1);
|
||||
set_reg_bits(sensor->slv_addr, 0x55, 0, 0x01, 1);
|
||||
write_reg(sensor->slv_addr, 0x54, cfg->reg0x54);
|
||||
write_reg(sensor->slv_addr, 0x56, cfg->reg0x56);
|
||||
write_reg(sensor->slv_addr, 0x57, cfg->reg0x57);
|
||||
write_reg(sensor->slv_addr, 0x58, cfg->reg0x58);
|
||||
write_reg(sensor->slv_addr, 0x59, cfg->reg0x59);
|
||||
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
|
||||
#elif CONFIG_GC_SENSOR_WINDOWING_MODE
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
|
||||
write_reg(sensor->slv_addr, 0xf7, col_s / 4);
|
||||
write_reg(sensor->slv_addr, 0xf8, row_s / 4);
|
||||
write_reg(sensor->slv_addr, 0xf9, (col_s + w) / 4);
|
||||
write_reg(sensor->slv_addr, 0xfa, (row_s + h) / 4);
|
||||
|
||||
write_reg(sensor->slv_addr, 0x05, H8(row_s));
|
||||
write_reg(sensor->slv_addr, 0x06, L8(row_s));
|
||||
write_reg(sensor->slv_addr, 0x07, H8(col_s));
|
||||
write_reg(sensor->slv_addr, 0x08, L8(col_s));
|
||||
|
||||
write_reg(sensor->slv_addr, 0x09, H8(h + 8));
|
||||
write_reg(sensor->slv_addr, 0x0a, L8(h + 8));
|
||||
write_reg(sensor->slv_addr, 0x0b, H8(w + 8));
|
||||
write_reg(sensor->slv_addr, 0x0c, L8(w + 8));
|
||||
|
||||
#endif
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set framesize to: %ux%u", w, h);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_contrast(sensor_t *sensor, int contrast)
|
||||
{
|
||||
if (contrast != 0) {
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
write_reg(sensor->slv_addr, 0xb3, contrast);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_global_gain(sensor_t *sensor, int gain_level)
|
||||
{
|
||||
if (gain_level != 0) {
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
write_reg(sensor->slv_addr, 0x50, gain_level);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_hmirror(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
sensor->status.hmirror = enable;
|
||||
ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor->slv_addr, 0x14, 0, 0x01, enable != 0);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set h-mirror to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_vflip(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
sensor->status.vflip = enable;
|
||||
ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor->slv_addr, 0x14, 1, 0x01, enable != 0);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set v-flip to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_colorbar(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor->slv_addr, 0x2e, 0, 0x01, enable);
|
||||
if (ret == 0) {
|
||||
sensor->status.colorbar = enable;
|
||||
ESP_LOGD(TAG, "Set colorbar to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int get_reg(sensor_t *sensor, int reg, int mask)
|
||||
{
|
||||
int ret = 0;
|
||||
if (mask > 0xFF) {
|
||||
ESP_LOGE(TAG, "mask should not more than 0xff");
|
||||
} else {
|
||||
ret = read_reg(sensor->slv_addr, reg);
|
||||
}
|
||||
if (ret > 0) {
|
||||
ret &= mask;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_reg(sensor_t *sensor, int reg, int mask, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
if (mask > 0xFF) {
|
||||
ESP_LOGE(TAG, "mask should not more than 0xff");
|
||||
} else {
|
||||
ret = read_reg(sensor->slv_addr, reg);
|
||||
}
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
value = (ret & ~mask) | (value & mask);
|
||||
|
||||
if (mask > 0xFF) {
|
||||
|
||||
} else {
|
||||
ret = write_reg(sensor->slv_addr, reg, value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int init_status(sensor_t *sensor)
|
||||
{
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
sensor->status.brightness = 0;
|
||||
sensor->status.contrast = 0;
|
||||
sensor->status.saturation = 0;
|
||||
sensor->status.sharpness = 0;
|
||||
sensor->status.denoise = 0;
|
||||
sensor->status.ae_level = 0;
|
||||
sensor->status.gainceiling = 0;
|
||||
sensor->status.awb = 0;
|
||||
sensor->status.dcw = 0;
|
||||
sensor->status.agc = 0;
|
||||
sensor->status.aec = 0;
|
||||
sensor->status.hmirror = check_reg_mask(sensor->slv_addr, 0x14, 0x01);
|
||||
sensor->status.vflip = check_reg_mask(sensor->slv_addr, 0x14, 0x02);
|
||||
sensor->status.colorbar = 0;
|
||||
sensor->status.bpc = 0;
|
||||
sensor->status.wpc = 0;
|
||||
sensor->status.raw_gma = 0;
|
||||
sensor->status.lenc = 0;
|
||||
sensor->status.quality = 0;
|
||||
sensor->status.special_effect = 0;
|
||||
sensor->status.wb_mode = 0;
|
||||
sensor->status.awb_gain = 0;
|
||||
sensor->status.agc_gain = 0;
|
||||
sensor->status.aec_value = 0;
|
||||
sensor->status.aec2 = 0;
|
||||
|
||||
print_regs(sensor->slv_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_dummy(sensor_t *sensor, int val)
|
||||
{
|
||||
ESP_LOGW(TAG, "Unsupported");
|
||||
return -1;
|
||||
}
|
||||
static int set_gainceiling_dummy(sensor_t *sensor, gainceiling_t val)
|
||||
{
|
||||
ESP_LOGW(TAG, "Unsupported");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int gc0308_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (GC0308_SCCB_ADDR == slv_addr) {
|
||||
write_reg(slv_addr, 0xfe, 0x00);
|
||||
uint8_t PID = SCCB_Read(slv_addr, 0x00);
|
||||
if (GC0308_PID == PID) {
|
||||
id->PID = PID;
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gc0308_init(sensor_t *sensor)
|
||||
{
|
||||
sensor->init_status = init_status;
|
||||
sensor->reset = reset;
|
||||
sensor->set_pixformat = set_pixformat;
|
||||
sensor->set_framesize = set_framesize;
|
||||
sensor->set_contrast = set_contrast;
|
||||
sensor->set_brightness = set_dummy;
|
||||
sensor->set_saturation = set_dummy;
|
||||
sensor->set_sharpness = set_dummy;
|
||||
sensor->set_denoise = set_dummy;
|
||||
sensor->set_gainceiling = set_gainceiling_dummy;
|
||||
sensor->set_quality = set_dummy;
|
||||
sensor->set_colorbar = set_colorbar;
|
||||
sensor->set_whitebal = set_dummy;
|
||||
sensor->set_gain_ctrl = set_global_gain;
|
||||
sensor->set_exposure_ctrl = set_dummy;
|
||||
sensor->set_hmirror = set_hmirror;
|
||||
sensor->set_vflip = set_vflip;
|
||||
|
||||
sensor->set_aec2 = set_dummy;
|
||||
sensor->set_awb_gain = set_dummy;
|
||||
sensor->set_agc_gain = set_dummy;
|
||||
sensor->set_aec_value = set_dummy;
|
||||
|
||||
sensor->set_special_effect = set_dummy;
|
||||
sensor->set_wb_mode = set_dummy;
|
||||
sensor->set_ae_level = set_dummy;
|
||||
|
||||
sensor->set_dcw = set_dummy;
|
||||
sensor->set_bpc = set_dummy;
|
||||
sensor->set_wpc = set_dummy;
|
||||
|
||||
sensor->set_raw_gma = set_dummy;
|
||||
sensor->set_lenc = set_dummy;
|
||||
|
||||
sensor->get_reg = get_reg;
|
||||
sensor->set_reg = set_reg;
|
||||
sensor->set_res_raw = NULL;
|
||||
sensor->set_pll = NULL;
|
||||
sensor->set_xclk = NULL;
|
||||
|
||||
ESP_LOGD(TAG, "GC0308 Attached");
|
||||
return 0;
|
||||
}
|
||||
391
sensors/gc032a.c
391
sensors/gc032a.c
|
|
@ -1,391 +0,0 @@
|
|||
// Copyright 2015-2021 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 "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "sccb.h"
|
||||
#include "gc032a.h"
|
||||
#include "gc032a_regs.h"
|
||||
#include "gc032a_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 = "gc032a";
|
||||
#endif
|
||||
|
||||
#define H8(v) ((v)>>8)
|
||||
#define L8(v) ((v)&0xff)
|
||||
|
||||
//#define REG_DEBUG_ON
|
||||
|
||||
static int read_reg(uint8_t slv_addr, const uint16_t reg)
|
||||
{
|
||||
int ret = SCCB_Read(slv_addr, reg);
|
||||
#ifdef REG_DEBUG_ON
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "READ REG 0x%04x FAILED: %d", reg, ret);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_reg(uint8_t slv_addr, const uint16_t reg, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifndef REG_DEBUG_ON
|
||||
ret = SCCB_Write(slv_addr, reg, value);
|
||||
#else
|
||||
int old_value = read_reg(slv_addr, reg);
|
||||
if (old_value < 0) {
|
||||
return old_value;
|
||||
}
|
||||
if ((uint8_t)old_value != value) {
|
||||
ESP_LOGI(TAG, "NEW REG 0x%04x: 0x%02x to 0x%02x", reg, (uint8_t)old_value, value);
|
||||
ret = SCCB_Write(slv_addr, reg, value);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "OLD REG 0x%04x: 0x%02x", reg, (uint8_t)old_value);
|
||||
ret = SCCB_Write(slv_addr, reg, value);//maybe not?
|
||||
}
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "WRITE REG 0x%04x FAILED: %d", reg, ret);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int check_reg_mask(uint8_t slv_addr, uint16_t reg, uint8_t mask)
|
||||
{
|
||||
return (read_reg(slv_addr, reg) & mask) == mask;
|
||||
}
|
||||
|
||||
static void print_regs(uint8_t slv_addr)
|
||||
{
|
||||
#ifdef DEBUG_PRINT_REG
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
ESP_LOGI(TAG, "REG list look ======================");
|
||||
for (size_t i = 0xf0; i <= 0xfe; i++) {
|
||||
ESP_LOGI(TAG, "reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
ESP_LOGI(TAG, "\npage 0 ===");
|
||||
write_reg(slv_addr, 0xfe, 0x00); // page 0
|
||||
for (size_t i = 0x03; i <= 0x24; i++) {
|
||||
ESP_LOGI(TAG, "p0 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
for (size_t i = 0x40; i <= 0x95; i++) {
|
||||
ESP_LOGI(TAG, "p0 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
ESP_LOGI(TAG, "\npage 3 ===");
|
||||
write_reg(slv_addr, 0xfe, 0x03); // page 3
|
||||
for (size_t i = 0x01; i <= 0x43; i++) {
|
||||
ESP_LOGI(TAG, "p3 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int set_reg_bits(uint8_t slv_addr, uint16_t reg, uint8_t offset, uint8_t mask, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t c_value, new_value;
|
||||
ret = read_reg(slv_addr, reg);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
c_value = ret;
|
||||
new_value = (c_value & ~(mask << offset)) | ((value & mask) << offset);
|
||||
ret = write_reg(slv_addr, reg, new_value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_regs(uint8_t slv_addr, const uint16_t (*regs)[2])
|
||||
{
|
||||
int i = 0, ret = 0;
|
||||
while (!ret && regs[i][0] != REGLIST_TAIL) {
|
||||
if (regs[i][0] == REG_DLY) {
|
||||
vTaskDelay(regs[i][1] / portTICK_PERIOD_MS);
|
||||
} else {
|
||||
ret = write_reg(slv_addr, regs[i][0], regs[i][1]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int reset(sensor_t *sensor)
|
||||
{
|
||||
int ret;
|
||||
// Software Reset: clear all registers and reset them to their default values
|
||||
ret = write_reg(sensor->slv_addr, RESET_RELATED, 0xf0);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "Software Reset FAILED!");
|
||||
return ret;
|
||||
}
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
|
||||
ret = write_regs(sensor->slv_addr, gc032a_default_regs);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Camera defaults loaded");
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
set_reg_bits(sensor->slv_addr, 0xf7, 1, 0x01, 1); // PLL_mode1:div2en
|
||||
set_reg_bits(sensor->slv_addr, 0xf7, 7, 0x01, 1); // PLL_mode1:dvp mode
|
||||
set_reg_bits(sensor->slv_addr, 0xf8, 0, 0x3f, 8); //PLL_mode2 :divx4
|
||||
set_reg_bits(sensor->slv_addr, 0xfa, 4, 0x0f, 2); //vlk div mode :divide_by
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_pixformat(sensor_t *sensor, pixformat_t pixformat)
|
||||
{
|
||||
int ret = 0;
|
||||
switch (pixformat) {
|
||||
case PIXFORMAT_RGB565:
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret = set_reg_bits(sensor->slv_addr, 0x44, 0, 0x1f, 6); //RGB565
|
||||
break;
|
||||
|
||||
case PIXFORMAT_YUV422:
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret = set_reg_bits(sensor->slv_addr, 0x44, 0, 0x1f, 3);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "unsupport format");
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
if (ret == 0) {
|
||||
sensor->pixformat = pixformat;
|
||||
ESP_LOGD(TAG, "Set pixformat to: %u", pixformat);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
||||
{
|
||||
ESP_LOGI(TAG, "set_framesize");
|
||||
int ret = 0;
|
||||
if (framesize > FRAMESIZE_VGA) {
|
||||
ESP_LOGW(TAG, "Invalid framesize: %u", framesize);
|
||||
framesize = FRAMESIZE_VGA;
|
||||
}
|
||||
sensor->status.framesize = framesize;
|
||||
uint16_t w = resolution[framesize].width;
|
||||
uint16_t h = resolution[framesize].height;
|
||||
uint16_t row_s = (resolution[FRAMESIZE_VGA].height - h) / 2;
|
||||
uint16_t col_s = (resolution[FRAMESIZE_VGA].width - w) / 2;
|
||||
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
write_reg(sensor->slv_addr, P0_ROW_START_HIGH, H8(row_s)); // Row_start[8]
|
||||
write_reg(sensor->slv_addr, P0_ROW_START_LOW, L8(row_s)); // Row_start[7:0]
|
||||
write_reg(sensor->slv_addr, P0_COLUMN_START_HIGH, H8(col_s)); // Column_start[9:8]
|
||||
write_reg(sensor->slv_addr, P0_COLUMN_START_LOW, L8(col_s)); // Column_start[7:0]
|
||||
write_reg(sensor->slv_addr, P0_WINDOW_HEIGHT_HIGH, H8(h + 8)); //window_height [8]
|
||||
write_reg(sensor->slv_addr, P0_WINDOW_HEIGHT_LOW, L8(h + 8)); //window_height [7:0]
|
||||
write_reg(sensor->slv_addr, P0_WINDOW_WIDTH_HIGH, H8(w + 8)); //window_width [9:8]
|
||||
write_reg(sensor->slv_addr, P0_WINDOW_WIDTH_LOW, L8(w + 8)); //window_width [7:0]
|
||||
|
||||
write_reg(sensor->slv_addr, P0_WIN_MODE, 0x01);
|
||||
write_reg(sensor->slv_addr, P0_OUT_WIN_HEIGHT_HIGH, H8(h));
|
||||
write_reg(sensor->slv_addr, P0_OUT_WIN_HEIGHT_LOW, L8(h));
|
||||
write_reg(sensor->slv_addr, P0_OUT_WIN_WIDTH_HIGH, H8(w));
|
||||
write_reg(sensor->slv_addr, P0_OUT_WIN_WIDTH_LOW, L8(w));
|
||||
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set framesize to: %ux%u", w, h);
|
||||
}
|
||||
print_regs(sensor->slv_addr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_hmirror(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
sensor->status.hmirror = enable;
|
||||
ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor->slv_addr, P0_CISCTL_MODE1, 0, 0x01, enable);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set h-mirror to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_vflip(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
sensor->status.vflip = enable;
|
||||
ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor->slv_addr, P0_CISCTL_MODE1, 1, 0x01, enable);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set v-flip to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_colorbar(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor->slv_addr, P0_DEBUG_MODE2, 3, 0x01, enable);
|
||||
if (ret == 0) {
|
||||
sensor->status.colorbar = enable;
|
||||
ESP_LOGD(TAG, "Set colorbar to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int get_reg(sensor_t *sensor, int reg, int mask)
|
||||
{
|
||||
int ret = 0;
|
||||
if (mask > 0xFF) {
|
||||
ESP_LOGE(TAG, "mask should not more than 0xff");
|
||||
} else {
|
||||
ret = read_reg(sensor->slv_addr, reg);
|
||||
}
|
||||
if (ret > 0) {
|
||||
ret &= mask;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_reg(sensor_t *sensor, int reg, int mask, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
if (mask > 0xFF) {
|
||||
ESP_LOGE(TAG, "mask should not more than 0xff");
|
||||
} else {
|
||||
ret = read_reg(sensor->slv_addr, reg);
|
||||
}
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
value = (ret & ~mask) | (value & mask);
|
||||
|
||||
if (mask > 0xFF) {
|
||||
|
||||
} else {
|
||||
ret = write_reg(sensor->slv_addr, reg, value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int init_status(sensor_t *sensor)
|
||||
{
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
sensor->status.brightness = 0;
|
||||
sensor->status.contrast = 0;
|
||||
sensor->status.saturation = 0;
|
||||
sensor->status.sharpness = 0;
|
||||
sensor->status.denoise = 0;
|
||||
sensor->status.ae_level = 0;
|
||||
sensor->status.gainceiling = 0;
|
||||
sensor->status.awb = 0;
|
||||
sensor->status.dcw = 0;
|
||||
sensor->status.agc = 0;
|
||||
sensor->status.aec = 0;
|
||||
sensor->status.hmirror = check_reg_mask(sensor->slv_addr, P0_CISCTL_MODE1, 0x01);
|
||||
sensor->status.vflip = check_reg_mask(sensor->slv_addr, P0_CISCTL_MODE1, 0x02);
|
||||
sensor->status.colorbar = 0;
|
||||
sensor->status.bpc = 0;
|
||||
sensor->status.wpc = 0;
|
||||
sensor->status.raw_gma = 0;
|
||||
sensor->status.lenc = 0;
|
||||
sensor->status.quality = 0;
|
||||
sensor->status.special_effect = 0;
|
||||
sensor->status.wb_mode = 0;
|
||||
sensor->status.awb_gain = 0;
|
||||
sensor->status.agc_gain = 0;
|
||||
sensor->status.aec_value = 0;
|
||||
sensor->status.aec2 = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_dummy(sensor_t *sensor, int val)
|
||||
{
|
||||
ESP_LOGW(TAG, "Unsupported");
|
||||
return -1;
|
||||
}
|
||||
static int set_gainceiling_dummy(sensor_t *sensor, gainceiling_t val)
|
||||
{
|
||||
ESP_LOGW(TAG, "Unsupported");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int gc032a_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (GC032A_SCCB_ADDR == slv_addr) {
|
||||
uint8_t MIDL = SCCB_Read(slv_addr, SENSOR_ID_LOW);
|
||||
uint8_t MIDH = SCCB_Read(slv_addr, SENSOR_ID_HIGH);
|
||||
uint16_t PID = MIDH << 8 | MIDL;
|
||||
if (GC032A_PID == PID) {
|
||||
id->PID = PID;
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gc032a_init(sensor_t *sensor)
|
||||
{
|
||||
sensor->init_status = init_status;
|
||||
sensor->reset = reset;
|
||||
sensor->set_pixformat = set_pixformat;
|
||||
sensor->set_framesize = set_framesize;
|
||||
sensor->set_contrast = set_dummy;
|
||||
sensor->set_brightness = set_dummy;
|
||||
sensor->set_saturation = set_dummy;
|
||||
sensor->set_sharpness = set_dummy;
|
||||
sensor->set_denoise = set_dummy;
|
||||
sensor->set_gainceiling = set_gainceiling_dummy;
|
||||
sensor->set_quality = set_dummy;
|
||||
sensor->set_colorbar = set_colorbar;
|
||||
sensor->set_whitebal = set_dummy;
|
||||
sensor->set_gain_ctrl = set_dummy;
|
||||
sensor->set_exposure_ctrl = set_dummy;
|
||||
sensor->set_hmirror = set_hmirror;
|
||||
sensor->set_vflip = set_vflip;
|
||||
|
||||
sensor->set_aec2 = set_dummy;
|
||||
sensor->set_awb_gain = set_dummy;
|
||||
sensor->set_agc_gain = set_dummy;
|
||||
sensor->set_aec_value = set_dummy;
|
||||
|
||||
sensor->set_special_effect = set_dummy;
|
||||
sensor->set_wb_mode = set_dummy;
|
||||
sensor->set_ae_level = set_dummy;
|
||||
|
||||
sensor->set_dcw = set_dummy;
|
||||
sensor->set_bpc = set_dummy;
|
||||
sensor->set_wpc = set_dummy;
|
||||
|
||||
sensor->set_raw_gma = set_dummy;
|
||||
sensor->set_lenc = set_dummy;
|
||||
|
||||
sensor->get_reg = get_reg;
|
||||
sensor->set_reg = set_reg;
|
||||
sensor->set_res_raw = NULL;
|
||||
sensor->set_pll = NULL;
|
||||
sensor->set_xclk = NULL;
|
||||
|
||||
ESP_LOGD(TAG, "GC032A Attached");
|
||||
return 0;
|
||||
}
|
||||
477
sensors/gc2145.c
477
sensors/gc2145.c
|
|
@ -1,477 +0,0 @@
|
|||
// Copyright 2015-2021 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 "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "sccb.h"
|
||||
#include "gc2145.h"
|
||||
#include "gc2145_regs.h"
|
||||
#include "gc2145_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 = "gc2145";
|
||||
#endif
|
||||
|
||||
#define H8(v) ((v)>>8)
|
||||
#define L8(v) ((v)&0xff)
|
||||
|
||||
//#define REG_DEBUG_ON
|
||||
|
||||
static int read_reg(uint8_t slv_addr, const uint16_t reg)
|
||||
{
|
||||
int ret = SCCB_Read(slv_addr, reg);
|
||||
#ifdef REG_DEBUG_ON
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "READ REG 0x%04x FAILED: %d", reg, ret);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_reg(uint8_t slv_addr, const uint16_t reg, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifndef REG_DEBUG_ON
|
||||
ret = SCCB_Write(slv_addr, reg, value);
|
||||
#else
|
||||
int old_value = read_reg(slv_addr, reg);
|
||||
if (old_value < 0) {
|
||||
return old_value;
|
||||
}
|
||||
if ((uint8_t)old_value != value) {
|
||||
ESP_LOGI(TAG, "NEW REG 0x%04x: 0x%02x to 0x%02x", reg, (uint8_t)old_value, value);
|
||||
ret = SCCB_Write(slv_addr, reg, value);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "OLD REG 0x%04x: 0x%02x", reg, (uint8_t)old_value);
|
||||
ret = SCCB_Write(slv_addr, reg, value);//maybe not?
|
||||
}
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "WRITE REG 0x%04x FAILED: %d", reg, ret);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int check_reg_mask(uint8_t slv_addr, uint16_t reg, uint8_t mask)
|
||||
{
|
||||
return (read_reg(slv_addr, reg) & mask) == mask;
|
||||
}
|
||||
|
||||
static int set_reg_bits(uint8_t slv_addr, uint16_t reg, uint8_t offset, uint8_t mask, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t c_value, new_value;
|
||||
ret = read_reg(slv_addr, reg);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
c_value = ret;
|
||||
new_value = (c_value & ~(mask << offset)) | ((value & mask) << offset);
|
||||
ret = write_reg(slv_addr, reg, new_value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_regs(uint8_t slv_addr, const uint16_t (*regs)[2])
|
||||
{
|
||||
int i = 0, ret = 0;
|
||||
while (!ret && regs[i][0] != REGLIST_TAIL) {
|
||||
if (regs[i][0] == REG_DLY) {
|
||||
vTaskDelay(regs[i][1] / portTICK_PERIOD_MS);
|
||||
} else {
|
||||
ret = write_reg(slv_addr, regs[i][0], regs[i][1]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void print_regs(uint8_t slv_addr)
|
||||
{
|
||||
#ifdef DEBUG_PRINT_REG
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
ESP_LOGI(TAG, "REG list look ======================");
|
||||
for (size_t i = 0xf0; i <= 0xfe; i++) {
|
||||
ESP_LOGI(TAG, "reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
ESP_LOGI(TAG, "\npage 0 ===");
|
||||
write_reg(slv_addr, 0xfe, 0x00); // page 0
|
||||
for (size_t i = 0x03; i <= 0x24; i++) {
|
||||
ESP_LOGI(TAG, "p0 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
for (size_t i = 0x80; i <= 0xa2; i++) {
|
||||
ESP_LOGI(TAG, "p0 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
ESP_LOGI(TAG, "\npage 3 ===");
|
||||
write_reg(slv_addr, 0xfe, 0x03); // page 3
|
||||
for (size_t i = 0x01; i <= 0x43; i++) {
|
||||
ESP_LOGI(TAG, "p3 reg[0x%02x] = 0x%02x", i, read_reg(slv_addr, i));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int reset(sensor_t *sensor)
|
||||
{
|
||||
int ret = 0;
|
||||
// Software Reset: clear all registers and reset them to their default values
|
||||
ret = write_reg(sensor->slv_addr, RESET_RELATED, 0xe0);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "Software Reset FAILED!");
|
||||
return ret;
|
||||
}
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
ret = write_regs(sensor->slv_addr, gc2145_default_init_regs);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Camera defaults loaded");
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
//ensure pclk <= 15MHz for esp32
|
||||
set_reg_bits(sensor->slv_addr, 0xf8, 0, 0x3f, 2); // divx4
|
||||
set_reg_bits(sensor->slv_addr, 0xfa, 4, 0x0f, 2); // divide_by
|
||||
#endif
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_pixformat(sensor_t *sensor, pixformat_t pixformat)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (pixformat) {
|
||||
case PIXFORMAT_RGB565:
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret = set_reg_bits(sensor->slv_addr, P0_OUTPUT_FORMAT, 0, 0x1f, 6); //RGB565
|
||||
break;
|
||||
|
||||
case PIXFORMAT_YUV422:
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret = set_reg_bits(sensor->slv_addr, P0_OUTPUT_FORMAT, 0, 0x1f, 2); //yuv422
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "unsupport format");
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
sensor->pixformat = pixformat;
|
||||
ESP_LOGD(TAG, "Set pixformat to: %u", pixformat);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
||||
{
|
||||
int ret = 0;
|
||||
if (framesize > FRAMESIZE_UXGA) {
|
||||
ESP_LOGW(TAG, "Invalid framesize: %u", framesize);
|
||||
framesize = FRAMESIZE_UXGA;
|
||||
}
|
||||
sensor->status.framesize = framesize;
|
||||
uint16_t w = resolution[framesize].width;
|
||||
uint16_t h = resolution[framesize].height;
|
||||
uint16_t row_s = (resolution[FRAMESIZE_UXGA].height - h) / 2;
|
||||
uint16_t col_s = (resolution[FRAMESIZE_UXGA].width - w) / 2;
|
||||
(void)row_s;
|
||||
(void)col_s;
|
||||
|
||||
#if CONFIG_GC_SENSOR_SUBSAMPLE_MODE
|
||||
struct subsample_cfg {
|
||||
uint16_t ratio_numerator;
|
||||
uint16_t ratio_denominator;
|
||||
uint8_t reg0x99;
|
||||
uint8_t reg0x9b;
|
||||
uint8_t reg0x9c;
|
||||
uint8_t reg0x9d;
|
||||
uint8_t reg0x9e;
|
||||
uint8_t reg0x9f;
|
||||
uint8_t reg0xa0;
|
||||
uint8_t reg0xa1;
|
||||
uint8_t reg0xa2;
|
||||
};
|
||||
const struct subsample_cfg subsample_cfgs[] = { // define some subsample ratio
|
||||
// {60, 420, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //1/7 // A smaller ratio brings a larger view, but it reduces the frame rate
|
||||
// {84, 420, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //1/5
|
||||
// {105, 420, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},//1/4
|
||||
{140, 420, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},//1/3
|
||||
{210, 420, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},//1/2
|
||||
{240, 420, 0x77, 0x02, 0x46, 0x02, 0x46, 0x02, 0x46, 0x02, 0x46},//4/7
|
||||
{252, 420, 0x55, 0x02, 0x04, 0x02, 0x04, 0x02, 0x04, 0x02, 0x04},//3/5
|
||||
{280, 420, 0x33, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00},//2/3
|
||||
{420, 420, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},//1/1
|
||||
};
|
||||
uint16_t win_w = resolution[FRAMESIZE_UXGA].width;
|
||||
uint16_t win_h = resolution[FRAMESIZE_UXGA].height;
|
||||
const struct subsample_cfg *cfg = NULL;
|
||||
/**
|
||||
* Strategy: try to keep the maximum perspective
|
||||
*/
|
||||
uint8_t i = 0;
|
||||
if (framesize >= FRAMESIZE_QVGA) {
|
||||
i = 1;
|
||||
}
|
||||
for (; i < sizeof(subsample_cfgs) / sizeof(struct subsample_cfg); i++) {
|
||||
cfg = &subsample_cfgs[i];
|
||||
if ((win_w * cfg->ratio_numerator / cfg->ratio_denominator >= w) && (win_h * cfg->ratio_numerator / cfg->ratio_denominator >= h)) {
|
||||
win_w = w * cfg->ratio_denominator / cfg->ratio_numerator;
|
||||
win_h = h * cfg->ratio_denominator / cfg->ratio_numerator;
|
||||
row_s = (resolution[FRAMESIZE_UXGA].height - win_h) / 2;
|
||||
col_s = (resolution[FRAMESIZE_UXGA].width - win_w) / 2;
|
||||
ESP_LOGI(TAG, "subsample win:%dx%d, ratio:%f", win_w, win_h, (float)cfg->ratio_numerator / (float)cfg->ratio_denominator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
write_reg(sensor->slv_addr, P0_CROP_ENABLE, 0x01);
|
||||
write_reg(sensor->slv_addr, 0x09, H8(row_s));
|
||||
write_reg(sensor->slv_addr, 0x0a, L8(row_s));
|
||||
write_reg(sensor->slv_addr, 0x0b, H8(col_s));
|
||||
write_reg(sensor->slv_addr, 0x0c, L8(col_s));
|
||||
write_reg(sensor->slv_addr, 0x0d, H8(win_h + 8));
|
||||
write_reg(sensor->slv_addr, 0x0e, L8(win_h + 8));
|
||||
write_reg(sensor->slv_addr, 0x0f, H8(win_w + 16));
|
||||
write_reg(sensor->slv_addr, 0x10, L8(win_w + 16));
|
||||
|
||||
write_reg(sensor->slv_addr, 0x99, cfg->reg0x99);
|
||||
write_reg(sensor->slv_addr, 0x9b, cfg->reg0x9b);
|
||||
write_reg(sensor->slv_addr, 0x9c, cfg->reg0x9c);
|
||||
write_reg(sensor->slv_addr, 0x9d, cfg->reg0x9d);
|
||||
write_reg(sensor->slv_addr, 0x9e, cfg->reg0x9e);
|
||||
write_reg(sensor->slv_addr, 0x9f, cfg->reg0x9f);
|
||||
write_reg(sensor->slv_addr, 0xa0, cfg->reg0xa0);
|
||||
write_reg(sensor->slv_addr, 0xa1, cfg->reg0xa1);
|
||||
write_reg(sensor->slv_addr, 0xa2, cfg->reg0xa2);
|
||||
|
||||
write_reg(sensor->slv_addr, 0x95, H8(h));
|
||||
write_reg(sensor->slv_addr, 0x96, L8(h));
|
||||
write_reg(sensor->slv_addr, 0x97, H8(w));
|
||||
write_reg(sensor->slv_addr, 0x98, L8(w));
|
||||
|
||||
|
||||
#elif CONFIG_GC_SENSOR_WINDOWING_MODE
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
|
||||
write_reg(sensor->slv_addr, P0_CROP_ENABLE, 0x01);
|
||||
// write_reg(sensor->slv_addr, 0xec, col_s / 8); //measure window
|
||||
// write_reg(sensor->slv_addr, 0xed, row_s / 8);
|
||||
// write_reg(sensor->slv_addr, 0xee, (col_s + h) / 8);
|
||||
// write_reg(sensor->slv_addr, 0xef, (row_s + w) / 8);
|
||||
|
||||
write_reg(sensor->slv_addr, 0x09, H8(row_s));
|
||||
write_reg(sensor->slv_addr, 0x0a, L8(row_s));
|
||||
write_reg(sensor->slv_addr, 0x0b, H8(col_s));
|
||||
write_reg(sensor->slv_addr, 0x0c, L8(col_s));
|
||||
write_reg(sensor->slv_addr, 0x0d, H8(h + 8));
|
||||
write_reg(sensor->slv_addr, 0x0e, L8(h + 8));
|
||||
write_reg(sensor->slv_addr, 0x0f, H8(w + 8));
|
||||
write_reg(sensor->slv_addr, 0x10, L8(w + 8));
|
||||
|
||||
write_reg(sensor->slv_addr, 0x95, H8(h));
|
||||
write_reg(sensor->slv_addr, 0x96, L8(h));
|
||||
write_reg(sensor->slv_addr, 0x97, H8(w));
|
||||
write_reg(sensor->slv_addr, 0x98, L8(w));
|
||||
|
||||
#endif
|
||||
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set framesize to: %ux%u", w, h);
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
static int set_hmirror(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
sensor->status.hmirror = enable;
|
||||
ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor->slv_addr, P0_ANALOG_MODE1, 0, 0x01, enable != 0);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set h-mirror to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_vflip(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
sensor->status.vflip = enable;
|
||||
ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
ret |= set_reg_bits(sensor->slv_addr, P0_ANALOG_MODE1, 1, 0x01, enable != 0);
|
||||
if (ret == 0) {
|
||||
ESP_LOGD(TAG, "Set v-flip to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_colorbar(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
// ret = write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
// ret |= set_reg_bits(sensor->slv_addr, P0_DEBUG_MODE3, 3, 0x01, enable);
|
||||
if (ret == 0) {
|
||||
sensor->status.colorbar = enable;
|
||||
ESP_LOGD(TAG, "Set colorbar to: %d", enable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int get_reg(sensor_t *sensor, int reg, int mask)
|
||||
{
|
||||
int ret = 0;
|
||||
if (mask > 0xFF) {
|
||||
ESP_LOGE(TAG, "mask should not more than 0xff");
|
||||
} else {
|
||||
ret = read_reg(sensor->slv_addr, reg);
|
||||
}
|
||||
if (ret > 0) {
|
||||
ret &= mask;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_reg(sensor_t *sensor, int reg, int mask, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
if (mask > 0xFF) {
|
||||
ESP_LOGE(TAG, "mask should not more than 0xff");
|
||||
} else {
|
||||
ret = read_reg(sensor->slv_addr, reg);
|
||||
}
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
value = (ret & ~mask) | (value & mask);
|
||||
|
||||
if (mask > 0xFF) {
|
||||
|
||||
} else {
|
||||
ret = write_reg(sensor->slv_addr, reg, value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int init_status(sensor_t *sensor)
|
||||
{
|
||||
write_reg(sensor->slv_addr, 0xfe, 0x00);
|
||||
sensor->status.brightness = 0;
|
||||
sensor->status.contrast = 0;
|
||||
sensor->status.saturation = 0;
|
||||
sensor->status.sharpness = 0;
|
||||
sensor->status.denoise = 0;
|
||||
sensor->status.ae_level = 0;
|
||||
sensor->status.gainceiling = 0;
|
||||
sensor->status.awb = 0;
|
||||
sensor->status.dcw = 0;
|
||||
sensor->status.agc = 0;
|
||||
sensor->status.aec = 0;
|
||||
sensor->status.hmirror = check_reg_mask(sensor->slv_addr, P0_ANALOG_MODE1, 0x01);
|
||||
sensor->status.vflip = check_reg_mask(sensor->slv_addr, P0_ANALOG_MODE1, 0x02);
|
||||
sensor->status.colorbar = 0;
|
||||
sensor->status.bpc = 0;
|
||||
sensor->status.wpc = 0;
|
||||
sensor->status.raw_gma = 0;
|
||||
sensor->status.lenc = 0;
|
||||
sensor->status.quality = 0;
|
||||
sensor->status.special_effect = 0;
|
||||
sensor->status.wb_mode = 0;
|
||||
sensor->status.awb_gain = 0;
|
||||
sensor->status.agc_gain = 0;
|
||||
sensor->status.aec_value = 0;
|
||||
sensor->status.aec2 = 0;
|
||||
|
||||
print_regs(sensor->slv_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_dummy(sensor_t *sensor, int val)
|
||||
{
|
||||
ESP_LOGW(TAG, "Unsupported");
|
||||
return -1;
|
||||
}
|
||||
static int set_gainceiling_dummy(sensor_t *sensor, gainceiling_t val)
|
||||
{
|
||||
ESP_LOGW(TAG, "Unsupported");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int gc2145_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (GC2145_SCCB_ADDR == slv_addr) {
|
||||
uint8_t MIDL = SCCB_Read(slv_addr, CHIP_ID_LOW);
|
||||
uint8_t MIDH = SCCB_Read(slv_addr, CHIP_ID_HIGH);
|
||||
uint16_t PID = MIDH << 8 | MIDL;
|
||||
if (GC2145_PID == PID) {
|
||||
id->PID = PID;
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gc2145_init(sensor_t *sensor)
|
||||
{
|
||||
sensor->init_status = init_status;
|
||||
sensor->reset = reset;
|
||||
sensor->set_pixformat = set_pixformat;
|
||||
sensor->set_framesize = set_framesize;
|
||||
sensor->set_contrast = set_dummy;
|
||||
sensor->set_brightness = set_dummy;
|
||||
sensor->set_saturation = set_dummy;
|
||||
sensor->set_sharpness = set_dummy;
|
||||
sensor->set_denoise = set_dummy;
|
||||
sensor->set_gainceiling = set_gainceiling_dummy;
|
||||
sensor->set_quality = set_dummy;
|
||||
sensor->set_colorbar = set_colorbar;
|
||||
sensor->set_whitebal = set_dummy;
|
||||
sensor->set_gain_ctrl = set_dummy;
|
||||
sensor->set_exposure_ctrl = set_dummy;
|
||||
sensor->set_hmirror = set_hmirror;
|
||||
sensor->set_vflip = set_vflip;
|
||||
|
||||
sensor->set_aec2 = set_dummy;
|
||||
sensor->set_awb_gain = set_dummy;
|
||||
sensor->set_agc_gain = set_dummy;
|
||||
sensor->set_aec_value = set_dummy;
|
||||
|
||||
sensor->set_special_effect = set_dummy;
|
||||
sensor->set_wb_mode = set_dummy;
|
||||
sensor->set_ae_level = set_dummy;
|
||||
|
||||
sensor->set_dcw = set_dummy;
|
||||
sensor->set_bpc = set_dummy;
|
||||
sensor->set_wpc = set_dummy;
|
||||
|
||||
sensor->set_raw_gma = set_dummy;
|
||||
sensor->set_lenc = set_dummy;
|
||||
|
||||
sensor->get_reg = get_reg;
|
||||
sensor->set_reg = set_reg;
|
||||
sensor->set_res_raw = NULL;
|
||||
sensor->set_pll = NULL;
|
||||
sensor->set_xclk = NULL;
|
||||
|
||||
ESP_LOGD(TAG, "GC2145 Attached");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -10,7 +10,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sccb.h"
|
||||
#include "xclk.h"
|
||||
#include "nt99141.h"
|
||||
#include "nt99141_regs.h"
|
||||
#include "nt99141_settings.h"
|
||||
|
|
@ -145,6 +144,28 @@ static int write_addr_reg(uint8_t slv_addr, const uint16_t reg, uint16_t x_value
|
|||
|
||||
#define write_reg_bits(slv_addr, reg, mask, enable) set_reg_bits(slv_addr, reg, 0, mask, enable?mask:0)
|
||||
|
||||
static int calc_sysclk(int xclk, bool pll_bypass, int pll_multiplier, int pll_sys_div, int pll_pre_div, bool pll_root_2x, int pll_seld5, bool pclk_manual, int pclk_div)
|
||||
{
|
||||
const int pll_pre_div2x_map[] = { 2, 3, 4, 6 };//values are multiplied by two to avoid floats
|
||||
const int pll_seld52x_map[] = { 2, 2, 4, 5 };
|
||||
|
||||
if (!pll_sys_div) {
|
||||
pll_sys_div = 1;
|
||||
}
|
||||
|
||||
int pll_pre_div2x = pll_pre_div2x_map[pll_pre_div];
|
||||
int pll_root_div = pll_root_2x ? 2 : 1;
|
||||
int pll_seld52x = pll_seld52x_map[pll_seld5];
|
||||
|
||||
int VCO = (xclk / 1000) * pll_multiplier * pll_root_div * 2 / pll_pre_div2x;
|
||||
int PLLCLK = pll_bypass ? (xclk) : (VCO * 1000 * 2 / pll_sys_div / pll_seld52x);
|
||||
int PCLK = PLLCLK / 2 / ((pclk_manual && pclk_div) ? pclk_div : 1);
|
||||
int SYSCLK = PLLCLK / 4;
|
||||
|
||||
ESP_LOGD(TAG, "Calculated VCO: %d Hz, PLLCLK: %d Hz, SYSCLK: %d Hz, PCLK: %d Hz", VCO * 1000, PLLCLK, SYSCLK, PCLK);
|
||||
return SYSCLK;
|
||||
}
|
||||
|
||||
static int set_pll(sensor_t *sensor, bool bypass, uint8_t multiplier, uint8_t sys_div, uint8_t pre_div, bool root_2x, uint8_t seld5, bool pclk_manual, uint8_t pclk_div)
|
||||
{
|
||||
return -1;
|
||||
|
|
@ -288,7 +309,7 @@ static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
|||
ret = write_regs(sensor->slv_addr, sensor_framesize_VGA);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_hmirror(sensor_t *sensor, int enable)
|
||||
|
|
@ -661,6 +682,7 @@ static int set_brightness(sensor_t *sensor, int level)
|
|||
{
|
||||
int ret = 0;
|
||||
uint8_t value = 0;
|
||||
bool negative = false;
|
||||
|
||||
switch (level) {
|
||||
case 3:
|
||||
|
|
@ -677,14 +699,17 @@ static int set_brightness(sensor_t *sensor, int level)
|
|||
|
||||
case -1:
|
||||
value = 0x78;
|
||||
negative = true;
|
||||
break;
|
||||
|
||||
case -2:
|
||||
value = 0x70;
|
||||
negative = true;
|
||||
break;
|
||||
|
||||
case -3:
|
||||
value = 0x60;
|
||||
negative = true;
|
||||
break;
|
||||
|
||||
default: // 0
|
||||
|
|
@ -705,6 +730,7 @@ static int set_contrast(sensor_t *sensor, int level)
|
|||
{
|
||||
int ret = 0;
|
||||
uint8_t value1 = 0, value2 = 0 ;
|
||||
bool negative = false;
|
||||
|
||||
switch (level) {
|
||||
case 3:
|
||||
|
|
@ -921,6 +947,7 @@ static int _set_pll(sensor_t *sensor, int bypass, int multiplier, int sys_div, i
|
|||
return set_pll(sensor, bypass > 0, multiplier, sys_div, pre_div, root_2x > 0, seld5, pclk_manual > 0, pclk_div);
|
||||
}
|
||||
|
||||
esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz);
|
||||
static int set_xclk(sensor_t *sensor, int timer, int xclk)
|
||||
{
|
||||
int ret = 0;
|
||||
|
|
@ -929,28 +956,11 @@ static int set_xclk(sensor_t *sensor, int timer, int xclk)
|
|||
ESP_LOGE(TAG, "only XCLK under 10MHz is supported, and XCLK is now set to 10M");
|
||||
xclk = 10;
|
||||
}
|
||||
sensor->xclk_freq_hz = xclk * 1000000U;
|
||||
ret = xclk_timer_conf(timer, sensor->xclk_freq_hz);
|
||||
// sensor->xclk_freq_hz = xclk * 1000000U;
|
||||
// ret = xclk_timer_conf(timer, sensor->xclk_freq_hz);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int nt99141_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (NT99141_SCCB_ADDR == slv_addr) {
|
||||
SCCB_Write16(slv_addr, 0x3008, 0x01);//bank sensor
|
||||
uint16_t h = SCCB_Read16(slv_addr, 0x3000);
|
||||
uint16_t l = SCCB_Read16(slv_addr, 0x3001);
|
||||
uint16_t PID = (h<<8) | l;
|
||||
if (NT99141_PID == PID) {
|
||||
id->PID = PID;
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init_status(sensor_t *sensor)
|
||||
{
|
||||
sensor->status.brightness = 0;
|
||||
|
|
@ -981,7 +991,7 @@ static int init_status(sensor_t *sensor)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int nt99141_init(sensor_t *sensor)
|
||||
int NT99141_init(sensor_t *sensor)
|
||||
{
|
||||
sensor->reset = reset;
|
||||
sensor->set_pixformat = set_pixformat;
|
||||
|
|
|
|||
|
|
@ -10,13 +10,16 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sccb.h"
|
||||
#include "xclk.h"
|
||||
#include "ov2640.h"
|
||||
#include "ov2640_regs.h"
|
||||
#include "ov2640_settings.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET
|
||||
#define CONFIG_IDF_TARGET_ESP32 1
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
||||
#include "esp32-hal-log.h"
|
||||
#else
|
||||
|
|
@ -150,7 +153,7 @@ static int set_window(sensor_t *sensor, ov2640_sensor_mode_t mode, int offset_x,
|
|||
{VSIZE, max_y & 0xFF},
|
||||
{XOFFL, offset_x & 0xFF},
|
||||
{YOFFL, offset_y & 0xFF},
|
||||
{VHYX, ((max_y >> 1) & 0X80) | ((offset_y >> 4) & 0X70) | ((max_x >> 5) & 0X08) | ((offset_x >> 8) & 0X07)},
|
||||
{VHYX, ((max_y >> 1) & 0X80) | ((offset_y >> 4) & 0X70) | ((max_x >> 5) & 0X08) | ((offset_y >> 8) & 0X07)},
|
||||
{TEST, (max_x >> 2) & 0X80},
|
||||
{ZMOW, (w)&0xFF},
|
||||
{ZMOH, (h)&0xFF},
|
||||
|
|
@ -158,40 +161,32 @@ static int set_window(sensor_t *sensor, ov2640_sensor_mode_t mode, int offset_x,
|
|||
{0, 0}
|
||||
};
|
||||
|
||||
if (sensor->pixformat == PIXFORMAT_JPEG) {
|
||||
c.clk_2x = 0;
|
||||
c.clk_div = 0;
|
||||
c.pclk_auto = 0;
|
||||
c.pclk_div = 8;
|
||||
if(mode == OV2640_MODE_UXGA) {
|
||||
c.pclk_div = 12;
|
||||
}
|
||||
// if (sensor->xclk_freq_hz == 16000000) {
|
||||
// c.pclk_div = c.pclk_div / 2;
|
||||
// }
|
||||
} else {
|
||||
c.pclk_auto = 0;
|
||||
c.pclk_div = 8;
|
||||
c.clk_2x = 0;
|
||||
c.clk_div = 0;
|
||||
|
||||
if(sensor->pixformat != PIXFORMAT_JPEG){
|
||||
c.pclk_auto = 1;
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
c.clk_2x = 0;
|
||||
#else
|
||||
c.clk_div = 7;
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
c.clk_2x = sensor->status.framesize <= FRAMESIZE_HVGA;
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
c.clk_2x = 1;
|
||||
#endif
|
||||
c.clk_div = 7;
|
||||
c.pclk_auto = 1;
|
||||
c.pclk_div = 8;
|
||||
if (mode == OV2640_MODE_CIF) {
|
||||
c.clk_div = 3;
|
||||
} else if(mode == OV2640_MODE_UXGA) {
|
||||
c.pclk_div = 12;
|
||||
}
|
||||
}
|
||||
ESP_LOGI(TAG, "Set PLL: clk_2x: %u, clk_div: %u, pclk_auto: %u, pclk_div: %u", c.clk_2x, c.clk_div, c.pclk_auto, c.pclk_div);
|
||||
|
||||
if (mode == OV2640_MODE_CIF) {
|
||||
regs = ov2640_settings_to_cif;
|
||||
if(sensor->pixformat != PIXFORMAT_JPEG){
|
||||
c.clk_div = 3;
|
||||
}
|
||||
} else if (mode == OV2640_MODE_SVGA) {
|
||||
regs = ov2640_settings_to_svga;
|
||||
} else {
|
||||
regs = ov2640_settings_to_uxga;
|
||||
c.pclk_div = 12;
|
||||
}
|
||||
|
||||
WRITE_REG_OR_RETURN(BANK_DSP, R_BYPASS, R_BYPASS_DSP_BYPAS);
|
||||
|
|
@ -495,11 +490,12 @@ static int _set_pll(sensor_t *sensor, int bypass, int multiplier, int sys_div, i
|
|||
return -1;
|
||||
}
|
||||
|
||||
esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz);
|
||||
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);
|
||||
// sensor->xclk_freq_hz = xclk * 1000000U;
|
||||
// ret = xclk_timer_conf(timer, sensor->xclk_freq_hz);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -545,24 +541,6 @@ static int init_status(sensor_t *sensor){
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ov2640_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (OV2640_SCCB_ADDR == slv_addr) {
|
||||
SCCB_Write(slv_addr, 0xFF, 0x01);//bank sensor
|
||||
uint16_t PID = SCCB_Read(slv_addr, 0x0A);
|
||||
if (OV2640_PID == PID) {
|
||||
id->PID = PID;
|
||||
id->VER = SCCB_Read(slv_addr, REG_VER);
|
||||
id->MIDL = SCCB_Read(slv_addr, REG_MIDL);
|
||||
id->MIDH = SCCB_Read(slv_addr, REG_MIDH);
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ov2640_init(sensor_t *sensor)
|
||||
{
|
||||
sensor->reset = reset;
|
||||
|
|
|
|||
|
|
@ -10,13 +10,16 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sccb.h"
|
||||
#include "xclk.h"
|
||||
#include "ov3660.h"
|
||||
#include "ov3660_regs.h"
|
||||
#include "ov3660_settings.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET
|
||||
#define CONFIG_IDF_TARGET_ESP32 1
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
||||
#include "esp32-hal-log.h"
|
||||
#else
|
||||
|
|
@ -143,7 +146,7 @@ static int calc_sysclk(int xclk, bool pll_bypass, int pll_multiplier, int pll_sy
|
|||
int PCLK = PLLCLK / 2 / ((pclk_manual && pclk_div)?pclk_div:1);
|
||||
int SYSCLK = PLLCLK / 4;
|
||||
|
||||
ESP_LOGI(TAG, "Calculated VCO: %d Hz, PLLCLK: %d Hz, SYSCLK: %d Hz, PCLK: %d Hz", VCO*1000, PLLCLK, SYSCLK, PCLK);
|
||||
ESP_LOGD(TAG, "Calculated VCO: %d Hz, PLLCLK: %d Hz, SYSCLK: %d Hz, PCLK: %d Hz", VCO*1000, PLLCLK, SYSCLK, PCLK);
|
||||
return SYSCLK;
|
||||
}
|
||||
|
||||
|
|
@ -311,13 +314,13 @@ static int set_image_options(sensor_t *sensor)
|
|||
static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if(framesize > FRAMESIZE_QXGA){
|
||||
ESP_LOGW(TAG, "Invalid framesize: %u", framesize);
|
||||
framesize = FRAMESIZE_QXGA;
|
||||
}
|
||||
framesize_t old_framesize = sensor->status.framesize;
|
||||
sensor->status.framesize = framesize;
|
||||
|
||||
if(framesize > FRAMESIZE_QXGA){
|
||||
ESP_LOGE(TAG, "Invalid framesize: %u", framesize);
|
||||
return -1;
|
||||
}
|
||||
uint16_t w = resolution[framesize].width;
|
||||
uint16_t h = resolution[framesize].height;
|
||||
aspect_ratio_t ratio = resolution[sensor->status.framesize].aspect_ratio;
|
||||
|
|
@ -356,7 +359,7 @@ static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
|||
}
|
||||
|
||||
if (sensor->pixformat == PIXFORMAT_JPEG) {
|
||||
if (framesize == FRAMESIZE_QXGA || sensor->xclk_freq_hz == 16000000) {
|
||||
if (framesize == FRAMESIZE_QXGA) {
|
||||
//40MHz SYSCLK and 10MHz PCLK
|
||||
ret = set_pll(sensor, false, 24, 1, 3, false, 0, true, 8);
|
||||
} else {
|
||||
|
|
@ -364,17 +367,19 @@ static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
|||
ret = set_pll(sensor, false, 30, 1, 3, false, 0, true, 10);
|
||||
}
|
||||
} else {
|
||||
//tuned for 16MHz XCLK and 8MHz PCLK
|
||||
if (framesize > FRAMESIZE_HVGA) {
|
||||
//8MHz SYSCLK and 8MHz PCLK (4.44 FPS)
|
||||
ret = set_pll(sensor, false, 4, 1, 0, false, 2, true, 2);
|
||||
} else if (framesize >= FRAMESIZE_QVGA) {
|
||||
//16MHz SYSCLK and 8MHz PCLK (10.25 FPS)
|
||||
ret = set_pll(sensor, false, 8, 1, 0, false, 2, true, 4);
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
if (framesize > FRAMESIZE_CIF) {
|
||||
//10MHz SYSCLK and 10MHz PCLK (6.19 FPS)
|
||||
ret = set_pll(sensor, false, 2, 1, 0, false, 0, true, 2);
|
||||
} else {
|
||||
//32MHz SYSCLK and 8MHz PCLK (17.77 FPS)
|
||||
ret = set_pll(sensor, false, 8, 1, 0, false, 0, true, 8);
|
||||
//25MHz SYSCLK and 10MHz PCLK (15.45 FPS)
|
||||
ret = set_pll(sensor, false, 5, 1, 0, false, 0, true, 5);
|
||||
}
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
ret = set_pll(sensor, false, 15, 1, 0, false, 0, true, 5); // 39 fps
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
ret = set_pll(sensor, false, 15, 1, 0, false, 0, true, 5); // 39 fps
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
|
|
@ -958,11 +963,12 @@ static int _set_pll(sensor_t *sensor, int bypass, int multiplier, int sys_div, i
|
|||
return set_pll(sensor, bypass > 0, multiplier, sys_div, pre_div, root_2x > 0, seld5, pclk_manual > 0, pclk_div);
|
||||
}
|
||||
|
||||
esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz);
|
||||
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);
|
||||
// sensor->xclk_freq_hz = xclk * 1000000U;
|
||||
// ret = xclk_timer_conf(timer, sensor->xclk_freq_hz);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -996,22 +1002,6 @@ static int init_status(sensor_t *sensor)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ov3660_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (OV3660_SCCB_ADDR == slv_addr) {
|
||||
uint8_t h = SCCB_Read16(slv_addr, 0x300A);
|
||||
uint8_t l = SCCB_Read16(slv_addr, 0x300B);
|
||||
uint16_t PID = (h<<8) | l;
|
||||
if (OV3660_PID == PID) {
|
||||
id->PID = PID;
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ov3660_init(sensor_t *sensor)
|
||||
{
|
||||
sensor->reset = reset;
|
||||
|
|
|
|||
|
|
@ -10,13 +10,16 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sccb.h"
|
||||
#include "xclk.h"
|
||||
#include "ov5640.h"
|
||||
#include "ov5640_regs.h"
|
||||
#include "ov5640_settings.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET
|
||||
#define CONFIG_IDF_TARGET_ESP32 1
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
||||
#include "esp32-hal-log.h"
|
||||
#else
|
||||
|
|
@ -197,7 +200,7 @@ static int calc_sysclk(int xclk, bool pll_bypass, int pll_multiplier, int pll_sy
|
|||
|
||||
unsigned int SYSCLK = PLL_CLK / 4;
|
||||
|
||||
ESP_LOGI(TAG, "Calculated XVCLK: %d Hz, REFIN: %u Hz, VCO: %u Hz, PLL_CLK: %u Hz, SYSCLK: %u Hz, PCLK: %u Hz", xclk, REFIN, VCO, PLL_CLK, SYSCLK, PCLK);
|
||||
ESP_LOGD(TAG, "Calculated XVCLK: %d Hz, REFIN: %u Hz, VCO: %u Hz, PLL_CLK: %u Hz, SYSCLK: %u Hz, PCLK: %u Hz", xclk, REFIN, VCO, PLL_CLK, SYSCLK, PCLK);
|
||||
return SYSCLK;
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +213,6 @@ static int set_pll(sensor_t *sensor, bool bypass, uint8_t multiplier, uint8_t sy
|
|||
if(multiplier > 127){
|
||||
multiplier &= 0xFE;//only even integers above 127
|
||||
}
|
||||
ESP_LOGI(TAG, "Set PLL: bypass: %u, multiplier: %u, sys_div: %u, pre_div: %u, root_2x: %u, pclk_root_div: %u, pclk_manual: %u, pclk_div: %u", bypass, multiplier, sys_div, pre_div, root_2x, pclk_root_div, pclk_manual, pclk_div);
|
||||
|
||||
calc_sysclk(sensor->xclk_freq_hz, bypass, multiplier, sys_div, pre_div, root_2x, pclk_root_div, pclk_manual, pclk_div);
|
||||
|
||||
|
|
@ -434,22 +436,20 @@ static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
|||
if (sensor->pixformat == PIXFORMAT_JPEG) {
|
||||
//10MHz PCLK
|
||||
uint8_t sys_mul = 200;
|
||||
if(framesize < FRAMESIZE_QVGA || sensor->xclk_freq_hz == 16000000){
|
||||
if(framesize < FRAMESIZE_QVGA){
|
||||
sys_mul = 160;
|
||||
} else if(framesize < FRAMESIZE_XGA){
|
||||
sys_mul = 180;
|
||||
}
|
||||
ret = set_pll(sensor, false, sys_mul, 4, 2, false, 2, true, 4);
|
||||
//Set PLL: bypass: 0, multiplier: sys_mul, sys_div: 4, pre_div: 2, root_2x: 0, pclk_root_div: 2, pclk_manual: 1, pclk_div: 4
|
||||
} else {
|
||||
//ret = set_pll(sensor, false, 8, 1, 1, false, 1, true, 4);
|
||||
if (framesize > FRAMESIZE_HVGA) {
|
||||
ret = set_pll(sensor, false, 10, 1, 2, false, 1, true, 2);
|
||||
} else if (framesize >= FRAMESIZE_QVGA) {
|
||||
ret = set_pll(sensor, false, 8, 1, 1, false, 1, true, 4);
|
||||
} else {
|
||||
ret = set_pll(sensor, false, 20, 1, 1, false, 1, true, 8);
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
ret = set_pll(sensor, false, 10, 1, 1, false, 1, true, 4);
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
ret = set_pll(sensor, false, 30, 1, 1, false, 1, true, 4); // 27 fps
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
ret = set_pll(sensor, false, 38, 1, 1, false, 1, true, 4); // 34 fps
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
|
|
@ -1035,11 +1035,12 @@ static int _set_pll(sensor_t *sensor, int bypass, int multiplier, int sys_div, i
|
|||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz);
|
||||
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);
|
||||
// sensor->xclk_freq_hz = xclk * 1000000U;
|
||||
// ret = xclk_timer_conf(timer, sensor->xclk_freq_hz);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -1073,22 +1074,6 @@ static int init_status(sensor_t *sensor)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ov5640_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (OV5640_SCCB_ADDR == slv_addr) {
|
||||
uint8_t h = SCCB_Read16(slv_addr, 0x300A);
|
||||
uint8_t l = SCCB_Read16(slv_addr, 0x300B);
|
||||
uint16_t PID = (h<<8) | l;
|
||||
if (OV5640_PID == PID) {
|
||||
id->PID = PID;
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ov5640_init(sensor_t *sensor)
|
||||
{
|
||||
sensor->reset = reset;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ static struct regval_list ov7670_default_regs[] = {
|
|||
{CLKRC, 0x00},
|
||||
{DBLV, 0x4A},
|
||||
|
||||
{COM10, COM10_VSYNC_NEG | COM10_PCLK_FREE},
|
||||
{COM10, COM10_VSYNC_NEG | COM10_PCLK_MASK},
|
||||
|
||||
/* Improve white balance */
|
||||
{COM4, 0x40},
|
||||
|
|
@ -173,7 +173,7 @@ int ret = 0;
|
|||
*/
|
||||
static int ov7670_frame_control(sensor_t *sensor, int hstart, int hstop, int vstart, int vstop)
|
||||
{
|
||||
struct regval_list frame[7];
|
||||
struct regval_list frame[7];
|
||||
|
||||
frame[0].reg_num = HSTART;
|
||||
frame[0].value = (hstart >> 3);
|
||||
|
|
@ -194,8 +194,8 @@ static int ov7670_frame_control(sensor_t *sensor, int hstart, int hstop, int vst
|
|||
frame[5].value = (((vstop & 0x02) << 2) | (vstart & 0x02));
|
||||
|
||||
/* End mark */
|
||||
frame[6].reg_num = 0xFF;
|
||||
frame[6].value = 0xFF;
|
||||
frame[5].reg_num = 0xFF;
|
||||
frame[5].value = 0xFF;
|
||||
|
||||
return ov7670_write_array(sensor, frame);
|
||||
}
|
||||
|
|
@ -277,7 +277,7 @@ static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
|||
case FRAMESIZE_QQVGA:
|
||||
if( (ret = ov7670_write_array(sensor, ov7670_qqvga)) == 0 ) {
|
||||
/* These values from Omnivision */
|
||||
ret = ov7670_frame_control(sensor, 158, 14, 12, 490);
|
||||
ret = ov7670_frame_control(sensor, 158, 14, 10, 490);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -393,24 +393,6 @@ static int init_status(sensor_t *sensor)
|
|||
static int set_dummy(sensor_t *sensor, int val){ return -1; }
|
||||
static int set_gainceiling_dummy(sensor_t *sensor, gainceiling_t val){ return -1; }
|
||||
|
||||
int ov7670_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (OV7670_SCCB_ADDR == slv_addr) {
|
||||
SCCB_Write(slv_addr, 0xFF, 0x01);//bank sensor
|
||||
uint16_t PID = SCCB_Read(slv_addr, 0x0A);
|
||||
if (OV7670_PID == PID) {
|
||||
id->PID = PID;
|
||||
id->VER = SCCB_Read(slv_addr, REG_VER);
|
||||
id->MIDL = SCCB_Read(slv_addr, REG_MIDL);
|
||||
id->MIDH = SCCB_Read(slv_addr, REG_MIDH);
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ov7670_init(sensor_t *sensor)
|
||||
{
|
||||
// Set function pointers
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "sccb.h"
|
||||
#include "xclk.h"
|
||||
#include "ov7725.h"
|
||||
#include "ov7725_regs.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
|
@ -59,10 +58,10 @@ static const uint8_t default_regs[][2] = {
|
|||
{COM8, 0xF0},
|
||||
{COM6, 0xC5},
|
||||
{COM9, 0x11},
|
||||
{COM10, COM10_VSYNC_NEG | COM10_PCLK_FREE}, //Invert VSYNC and MASK PCLK
|
||||
{COM10, COM10_VSYNC_NEG | COM10_PCLK_MASK}, //Invert VSYNC and MASK PCLK
|
||||
{BDBASE, 0x7F},
|
||||
{DBSTEP, 0x03},
|
||||
{AEW, 0x75},
|
||||
{AEW, 0x96},
|
||||
{AEB, 0x64},
|
||||
{VPT, 0xA1},
|
||||
{EXHCL, 0x00},
|
||||
|
|
@ -494,32 +493,15 @@ static int set_gainceiling_dummy(sensor_t *sensor, gainceiling_t val){ return -1
|
|||
static int set_res_raw(sensor_t *sensor, int startX, int startY, int endX, int endY, int offsetX, int offsetY, int totalX, int totalY, int outputX, int outputY, bool scale, bool binning){return -1;}
|
||||
static int _set_pll(sensor_t *sensor, int bypass, int multiplier, int sys_div, int root_2x, int pre_div, int seld5, int pclk_manual, int pclk_div){return -1;}
|
||||
|
||||
//esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz);
|
||||
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);
|
||||
// sensor->xclk_freq_hz = xclk * 1000000U;
|
||||
// ret = xclk_timer_conf(timer, sensor->xclk_freq_hz);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ov7725_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (OV7725_SCCB_ADDR == slv_addr) {
|
||||
SCCB_Write(slv_addr, 0xFF, 0x01);//bank sensor
|
||||
uint16_t PID = SCCB_Read(slv_addr, 0x0A);
|
||||
if (OV7725_PID == PID) {
|
||||
id->PID = PID;
|
||||
id->VER = SCCB_Read(slv_addr, REG_VER);
|
||||
id->MIDL = SCCB_Read(slv_addr, REG_MIDL);
|
||||
id->MIDH = SCCB_Read(slv_addr, REG_MIDH);
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ov7725_init(sensor_t *sensor)
|
||||
{
|
||||
// Set function pointers
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
|
||||
#ifndef __BF20A6_H__
|
||||
#define __BF20A6_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 bf20a6_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int bf20a6_init(sensor_t *sensor);
|
||||
|
||||
#endif // __BF20A6_H__
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
* BF20A6 register definitions.
|
||||
*/
|
||||
#ifndef __BF20A6_REG_REGS_H__
|
||||
#define __BF20A6_REG_REGS_H__
|
||||
|
||||
#define SENSOR_ID_HIGH 0XFC
|
||||
#define SENSOR_ID_LOW 0XFD
|
||||
#define RESET_RELATED 0XF2
|
||||
|
||||
|
||||
#endif //__BF20A6_REG_REGS_H__
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define REG_DLY 0xffff
|
||||
#define REGLIST_TAIL 0xffff /* Array end token */
|
||||
|
||||
static const uint16_t bf20a6_default_init_regs[][2] = {
|
||||
{0xf2,0x01},
|
||||
{0x12,0x20},
|
||||
{0x3a,0x00},
|
||||
{0xe1,0x92},
|
||||
{0xe3,0x12},// PLL Control, important for framerate(choice: 0x02\0x12\0x22\0x32\0x82)
|
||||
{0xe0,0x00},
|
||||
{0x2a,0x98},
|
||||
{0xcd,0x17},
|
||||
{0xc0,0x10},
|
||||
{0xc6,0x1d},
|
||||
{0x10,0x35},
|
||||
{0xe2,0x09},
|
||||
{0xe4,0x72},
|
||||
{0xe5,0x22},
|
||||
{0xe6,0x24},
|
||||
{0xe7,0x64},
|
||||
{0xe8,0xa2}, // DVP:a2}, SPI:f2 VDDIO=1.8V,E8[2]=1},VDDIO=2.8V,E8[2]=0},
|
||||
{0x4a,0x00},
|
||||
{0x00,0x03},
|
||||
{0x1f,0x02},
|
||||
{0x22,0x02},
|
||||
{0x0c,0x31},
|
||||
|
||||
{0x00,0x00},
|
||||
{0x60,0x81},
|
||||
{0x61,0x81},
|
||||
|
||||
{0xa0,0x08},
|
||||
{0x01,0x1a},
|
||||
// {0x01,0x1a},
|
||||
// {0x01,0x1a},
|
||||
// {0x02,0x15},
|
||||
// {0x02,0x15},
|
||||
{0x02,0x15},
|
||||
{0x13,0x08},
|
||||
{0x8a,0x96},
|
||||
{0x8b,0x06},
|
||||
{0x87,0x18},
|
||||
|
||||
|
||||
{0x34,0x48}, // lens
|
||||
{0x35,0x40},
|
||||
{0x36,0x40},
|
||||
|
||||
{0x71,0x44},
|
||||
{0x72,0x48},
|
||||
{0x74,0xa2},
|
||||
{0x75,0xa9},
|
||||
{0x78,0x12},
|
||||
{0x79,0xa0},
|
||||
{0x7a,0x94},
|
||||
{0x7c,0x97},
|
||||
{0x40,0x30},
|
||||
{0x41,0x30},
|
||||
{0x42,0x28},
|
||||
{0x43,0x1f},
|
||||
{0x44,0x1c},
|
||||
{0x45,0x16},
|
||||
{0x46,0x13},
|
||||
{0x47,0x10},
|
||||
{0x48,0x0D},
|
||||
{0x49,0x0C},
|
||||
{0x4B,0x0A},
|
||||
{0x4C,0x0B},
|
||||
{0x4E,0x09},
|
||||
{0x4F,0x08},
|
||||
{0x50,0x08},
|
||||
|
||||
|
||||
{0x5f,0x29},
|
||||
{0x23,0x33},
|
||||
{0xa1,0x10}, // AWB
|
||||
{0xa2,0x0d},
|
||||
{0xa3,0x30},
|
||||
{0xa4,0x06},
|
||||
{0xa5,0x22},
|
||||
{0xa6,0x56},
|
||||
{0xa7,0x18},
|
||||
{0xa8,0x1a},
|
||||
{0xa9,0x12},
|
||||
{0xaa,0x12},
|
||||
{0xab,0x16},
|
||||
{0xac,0xb1},
|
||||
{0xba,0x12},
|
||||
{0xbb,0x12},
|
||||
{0xad,0x12},
|
||||
{0xae,0x56},
|
||||
{0xaf,0x0a},
|
||||
{0x3b,0x30},
|
||||
{0x3c,0x12},
|
||||
{0x3d,0x22},
|
||||
{0x3e,0x3f},
|
||||
{0x3f,0x28},
|
||||
{0xb8,0xc3},
|
||||
{0xb9,0xa3},
|
||||
{0x39,0x47}, // pure color threshold
|
||||
{0x26,0x13},
|
||||
{0x27,0x16},
|
||||
{0x28,0x14},
|
||||
{0x29,0x18},
|
||||
{0xee,0x0d},
|
||||
|
||||
|
||||
{0x13,0x05},
|
||||
{0x24,0x3C},
|
||||
{0x81,0x20},
|
||||
{0x82,0x40},
|
||||
{0x83,0x30},
|
||||
{0x84,0x58},
|
||||
{0x85,0x30},
|
||||
{0x92,0x08},
|
||||
{0x86,0x80},
|
||||
{0x8a,0x96},
|
||||
{0x91,0xff},
|
||||
{0x94,0x62},
|
||||
{0x9a,0x18}, // outdoor threshold
|
||||
{0xf0,0x45}, // integral time control, important for framerate(choice: 0x46\0x45\0x44..)
|
||||
{0x51,0x17}, // color normal
|
||||
{0x52,0x03},
|
||||
{0x53,0x5F},
|
||||
{0x54,0x47},
|
||||
{0x55,0x66},
|
||||
{0x56,0x0F},
|
||||
{0x7e,0x14},
|
||||
{0x57,0x36}, // color
|
||||
{0x58,0x2A},
|
||||
{0x59,0xAA},
|
||||
{0x5a,0xA8},
|
||||
{0x5b,0x43},
|
||||
{0x5c,0x10},
|
||||
{0x5d,0x00},
|
||||
{0x7d,0x36},
|
||||
{0x5e,0x10},
|
||||
|
||||
{0xd6,0x88}, // contrast
|
||||
{0xd5,0x20}, // bright
|
||||
{0xb0,0x84}, // low light ctrl in gray section
|
||||
{0xb5,0x08}, // the threshold of GLB_GAIN
|
||||
{0xb1,0xc8}, // saturation
|
||||
{0xb2,0xc0},
|
||||
{0xb3,0xd0},
|
||||
{0xb4,0xB0},
|
||||
|
||||
{0x32,0x10},
|
||||
// {0x8a,0x00},
|
||||
// {0x8b,0x10},
|
||||
{0xa0,0x09},
|
||||
{0x00,0x03},
|
||||
{0x0b,0x02},
|
||||
{REGLIST_TAIL, 0x00},
|
||||
};
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* Copyright (c) 2013/2014 Ibrahim Abdelkader <i.abdalkader@gmail.com>
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* BF3005 driver.
|
||||
*
|
||||
*/
|
||||
#ifndef __BF3005_H__
|
||||
#define __BF3005_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 bf3005_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int bf3005_init(sensor_t *sensor);
|
||||
|
||||
#endif // __BF3005_H__
|
||||
|
|
@ -1,337 +0,0 @@
|
|||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* Copyright (c) 2013/2014 Ibrahim Abdelkader <i.abdalkader@gmail.com>
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* BF3005 register definitions.
|
||||
*/
|
||||
#ifndef __REG_REGS_H__
|
||||
#define __REG_REGS_H__
|
||||
#if 0
|
||||
#define GAIN 0x00 /* AGC ¨C Gain control gain setting */
|
||||
#define BLUE 0x01 /* AWB ¨C Blue channel gain setting */
|
||||
#define RED 0x02 /* AWB ¨C Red channel gain setting */
|
||||
#define GREEN 0x03 /* AWB ¨C Green channel gain setting */
|
||||
#define BAVG 0x05 /* U/B Average Level */
|
||||
#define GAVG 0x06 /* Y/Gb Average Level */
|
||||
#define RAVG 0x07 /* V/R Average Level */
|
||||
#define AECH 0x08 /* Exposure Value ¨C AEC MSBs */
|
||||
|
||||
#define COM2 0x09 /* Common Control 2 */
|
||||
#define COM2_SOFT_SLEEP 0x10 /* Soft sleep mode */
|
||||
#define COM2_OUT_DRIVE_1x 0x00 /* Output drive capability 1x */
|
||||
#define COM2_OUT_DRIVE_2x 0x01 /* Output drive capability 2x */
|
||||
#define COM2_OUT_DRIVE_3x 0x02 /* Output drive capability 3x */
|
||||
#define COM2_OUT_DRIVE_4x 0x03 /* Output drive capability 4x */
|
||||
|
||||
#define REG_PID 0x0A /* Product ID Number MSB */
|
||||
#define REG_VER 0x0B /* Product ID Number LSB */
|
||||
|
||||
#define COM3 0x0C /* Common Control 3 */
|
||||
#define COM3_VFLIP 0x80 /* Vertical flip image ON/OFF selection */
|
||||
#define COM3_MIRROR 0x40 /* Horizontal mirror image ON/OFF selection */
|
||||
#define COM3_SWAP_BR 0x20 /* Swap B/R output sequence in RGB output mode */
|
||||
#define COM3_SWAP_YUV 0x10 /* Swap Y/UV output sequence in YUV output mode */
|
||||
#define COM3_SWAP_MSB 0x08 /* Swap output MSB/LSB */
|
||||
#define COM3_TRI_CLOCK 0x04 /* Tri-state option for output clock at power-down period */
|
||||
#define COM3_TRI_DATA 0x02 /* Tri-state option for output data at power-down period */
|
||||
#define COM3_COLOR_BAR 0x01 /* Sensor color bar test pattern output enable */
|
||||
#define COM3_SET_CBAR(r, x) ((r&0xFE)|((x&1)<<0))
|
||||
#define COM3_SET_MIRROR(r, x) ((r&0xBF)|((x&1)<<6))
|
||||
#define COM3_SET_FLIP(r, x) ((r&0x7F)|((x&1)<<7))
|
||||
|
||||
#define COM4 0x0D /* Common Control 4 */
|
||||
#define COM4_PLL_BYPASS 0x00 /* Bypass PLL */
|
||||
#define COM4_PLL_4x 0x40 /* PLL frequency 4x */
|
||||
#define COM4_PLL_6x 0x80 /* PLL frequency 6x */
|
||||
#define COM4_PLL_8x 0xc0 /* PLL frequency 8x */
|
||||
#define COM4_AEC_FULL 0x00 /* AEC evaluate full window */
|
||||
#define COM4_AEC_1_2 0x10 /* AEC evaluate 1/2 window */
|
||||
#define COM4_AEC_1_4 0x20 /* AEC evaluate 1/4 window */
|
||||
#define COM4_AEC_2_3 0x30 /* AEC evaluate 2/3 window */
|
||||
|
||||
#define COM5 0x0E /* Common Control 5 */
|
||||
#define COM5_AFR 0x80 /* Auto frame rate control ON/OFF selection (night mode) */
|
||||
#define COM5_AFR_SPEED 0x40 /* Auto frame rate control speed selection */
|
||||
#define COM5_AFR_0 0x00 /* No reduction of frame rate */
|
||||
#define COM5_AFR_1_2 0x10 /* Max reduction to 1/2 frame rate */
|
||||
#define COM5_AFR_1_4 0x20 /* Max reduction to 1/4 frame rate */
|
||||
#define COM5_AFR_1_8 0x30 /* Max reduction to 1/8 frame rate */
|
||||
#define COM5_AFR_4x 0x04 /* Add frame when AGC reaches 4x gain */
|
||||
#define COM5_AFR_8x 0x08 /* Add frame when AGC reaches 8x gain */
|
||||
#define COM5_AFR_16x 0x0c /* Add frame when AGC reaches 16x gain */
|
||||
#define COM5_AEC_NO_LIMIT 0x01 /* No limit to AEC increase step */
|
||||
|
||||
#define COM6 0x0F /* Common Control 6 */
|
||||
#define COM6_AUTO_WINDOW 0x01 /* Auto window setting ON/OFF selection when format changes */
|
||||
|
||||
#define AEC 0x10 /* AEC[7:0] (see register AECH for AEC[15:8]) */
|
||||
#define CLKRC 0x11 /* Internal Clock */
|
||||
|
||||
#define COM7 0x12 /* Common Control 7 */
|
||||
#define COM7_RESET 0x80 /* SCCB Register Reset */
|
||||
#define COM7_RES_VGA 0x00 /* Resolution VGA */
|
||||
#define COM7_RES_QVGA 0x40 /* Resolution QVGA */
|
||||
#define COM7_BT656 0x20 /* BT.656 protocol ON/OFF */
|
||||
#define COM7_SENSOR_RAW 0x10 /* Sensor RAW */
|
||||
#define COM7_FMT_GBR422 0x00 /* RGB output format GBR422 */
|
||||
#define COM7_FMT_RGB565 0x04 /* RGB output format RGB565 */
|
||||
#define COM7_FMT_RGB555 0x08 /* RGB output format RGB555 */
|
||||
#define COM7_FMT_RGB444 0x0C /* RGB output format RGB444 */
|
||||
#define COM7_FMT_YUV 0x00 /* Output format YUV */
|
||||
#define COM7_FMT_P_BAYER 0x01 /* Output format Processed Bayer RAW */
|
||||
#define COM7_FMT_RGB 0x02 /* Output format RGB */
|
||||
#define COM7_FMT_R_BAYER 0x03 /* Output format Bayer RAW */
|
||||
#define COM7_SET_FMT(r, x) ((r&0xFC)|((x&0x3)<<0))
|
||||
#define COM7_SET_RGB(r, x) ((r&0xF0)|(x&0x0C)|COM7_FMT_RGB)
|
||||
|
||||
#define COM8 0x13 /* Common Control 8 */
|
||||
#define COM8_FAST_AUTO 0x80 /* Enable fast AGC/AEC algorithm */
|
||||
#define COM8_STEP_VSYNC 0x00 /* AEC - Step size limited to vertical blank */
|
||||
#define COM8_STEP_UNLIMIT 0x40 /* AEC - Step size unlimited step size */
|
||||
#define COM8_BANDF_EN 0x20 /* Banding filter ON/OFF */
|
||||
#define COM8_AEC_BANDF 0x10 /* Enable AEC below banding value */
|
||||
#define COM8_AEC_FINE_EN 0x08 /* Fine AEC ON/OFF control */
|
||||
#define COM8_AGC_EN 0x04 /* AGC Enable */
|
||||
#define COM8_AWB_EN 0x02 /* AWB Enable */
|
||||
#define COM8_AEC_EN 0x01 /* AEC Enable */
|
||||
#define COM8_SET_AGC(r, x) ((r&0xFB)|((x&0x1)<<2))
|
||||
#define COM8_SET_AWB(r, x) ((r&0xFD)|((x&0x1)<<1))
|
||||
#define COM8_SET_AEC(r, x) ((r&0xFE)|((x&0x1)<<0))
|
||||
|
||||
#define COM9 0x14 /* Common Control 9 */
|
||||
#define COM9_HISTO_AVG 0x80 /* Histogram or average based AEC/AGC selection */
|
||||
#define COM9_AGC_GAIN_2x 0x00 /* Automatic Gain Ceiling 2x */
|
||||
#define COM9_AGC_GAIN_4x 0x10 /* Automatic Gain Ceiling 4x */
|
||||
#define COM9_AGC_GAIN_8x 0x20 /* Automatic Gain Ceiling 8x */
|
||||
#define COM9_AGC_GAIN_16x 0x30 /* Automatic Gain Ceiling 16x */
|
||||
#define COM9_AGC_GAIN_32x 0x40 /* Automatic Gain Ceiling 32x */
|
||||
#define COM9_DROP_VSYNC 0x04 /* Drop VSYNC output of corrupt frame */
|
||||
#define COM9_DROP_HREF 0x02 /* Drop HREF output of corrupt frame */
|
||||
#define COM9_SET_AGC(r, x) ((r&0x8F)|((x&0x07)<<4))
|
||||
|
||||
#define COM10 0x15 /* Common Control 10 */
|
||||
#define COM10_NEGATIVE 0x80 /* Output negative data */
|
||||
#define COM10_HSYNC_EN 0x40 /* HREF changes to HSYNC */
|
||||
#define COM10_PCLK_FREE 0x00 /* PCLK output option: free running PCLK */
|
||||
#define COM10_PCLK_MASK 0x20 /* PCLK output option: masked during horizontal blank */
|
||||
#define COM10_PCLK_REV 0x10 /* PCLK reverse */
|
||||
#define COM10_HREF_REV 0x08 /* HREF reverse */
|
||||
#define COM10_VSYNC_FALLING 0x00 /* VSYNC changes on falling edge of PCLK */
|
||||
#define COM10_VSYNC_RISING 0x04 /* VSYNC changes on rising edge of PCLK */
|
||||
#define COM10_VSYNC_NEG 0x02 /* VSYNC negative */
|
||||
#define COM10_OUT_RANGE_8 0x01 /* Output data range: Full range */
|
||||
#define COM10_OUT_RANGE_10 0x00 /* Output data range: Data from [10] to [F0] (8 MSBs) */
|
||||
|
||||
#define REG16 0x16 /* Register 16 */
|
||||
#define REG16_BIT_SHIFT 0x80 /* Bit shift test pattern options */
|
||||
#define HSTART 0x17 /* Horizontal Frame (HREF column) Start 8 MSBs (2 LSBs are at HREF[5:4]) */
|
||||
#define HSIZE 0x18 /* Horizontal Sensor Size (2 LSBs are at HREF[1:0]) */
|
||||
#define VSTART 0x19 /* Vertical Frame (row) Start 8 MSBs (1 LSB is at HREF[6]) */
|
||||
#define VSIZE 0x1A /* Vertical Sensor Size (1 LSB is at HREF[2]) */
|
||||
#define PSHFT 0x1B /* Data Format - Pixel Delay Select */
|
||||
#define REG_MIDH 0x1C /* Manufacturer ID Byte ¨C High */
|
||||
#define REG_MIDL 0x1D /* Manufacturer ID Byte ¨C Low */
|
||||
#define LAEC 0x1F /* Fine AEC Value - defines exposure value less than one row period */
|
||||
|
||||
#define COM11 0x20 /* Common Control 11 */
|
||||
#define COM11_SNGL_FRAME_EN 0x02 /* Single frame ON/OFF selection */
|
||||
#define COM11_SNGL_XFR_TRIG 0x01 /* Single frame transfer trigger */
|
||||
|
||||
#define BDBASE 0x22 /* Banding Filter Minimum AEC Value */
|
||||
#define DBSTEP 0x23 /* Banding Filter Maximum Step */
|
||||
#define AEW 0x24 /* AGC/AEC - Stable Operating Region (Upper Limit) */
|
||||
#define AEB 0x25 /* AGC/AEC - Stable Operating Region (Lower Limit) */
|
||||
#define VPT 0x26 /* AGC/AEC Fast Mode Operating Region */
|
||||
#define REG28 0x28 /* Selection on the number of dummy rows, N */
|
||||
#define HOUTSIZE 0x29 /* Horizontal Data Output Size MSBs (2 LSBs at register EXHCH[1:0]) */
|
||||
#define EXHCH 0x2A /* Dummy Pixel Insert MSB */
|
||||
#define EXHCL 0x2B /* Dummy Pixel Insert LSB */
|
||||
#define VOUTSIZE 0x2C /* Vertical Data Output Size MSBs (LSB at register EXHCH[2]) */
|
||||
#define ADVFL 0x2D /* LSB of Insert Dummy Rows in Vertical Sync (1 bit equals 1 row) */
|
||||
#define ADVFH 0x2E /* MSB of Insert Dummy Rows in Vertical Sync */
|
||||
#define YAVE 0x2F /* Y/G Channel Average Value */
|
||||
#define LUMHTH 0x30 /* Histogram AEC/AGC Luminance High Level Threshold */
|
||||
#define LUMLTH 0x31 /* Histogram AEC/AGC Luminance Low Level Threshold */
|
||||
#define HREF 0x32 /* Image Start and Size Control */
|
||||
#define DM_LNL 0x33 /* Dummy Row Low 8 Bits */
|
||||
#define DM_LNH 0x34 /* Dummy Row High 8 Bits */
|
||||
#define ADOFF_B 0x35 /* AD Offset Compensation Value for B Channel */
|
||||
#define ADOFF_R 0x36 /* AD Offset Compensation Value for R Channel */
|
||||
#define ADOFF_GB 0x37 /* AD Offset Compensation Value for GB Channel */
|
||||
#define ADOFF_GR 0x38 /* AD Offset Compensation Value for GR Channel */
|
||||
#define OFF_B 0x39 /* AD Offset Compensation Value for B Channel */
|
||||
#define OFF_R 0x3A /* AD Offset Compensation Value for R Channel */
|
||||
#define OFF_GB 0x3B /* AD Offset Compensation Value for GB Channel */
|
||||
#define OFF_GR 0x3C /* AD Offset Compensation Value for GR Channel */
|
||||
#define COM12 0x3D /* DC offset compensation for analog process */
|
||||
|
||||
#define COM13 0x3E /* Common Control 13 */
|
||||
#define COM13_BLC_EN 0x80 /* BLC enable */
|
||||
#define COM13_ADC_EN 0x40 /* ADC channel BLC ON/OFF control */
|
||||
#define COM13_ANALOG_BLC 0x20 /* Analog processing channel BLC ON/OFF control */
|
||||
#define COM13_ABLC_GAIN_EN 0x04 /* ABLC gain trigger enable */
|
||||
|
||||
#define COM14 0x3F /* Common Control 14 */
|
||||
#define COM15 0x40 /* Common Control 15 */
|
||||
#define COM16 0x41 /* Common Control 16 */
|
||||
#define TGT_B 0x42 /* BLC Blue Channel Target Value */
|
||||
#define TGT_R 0x43 /* BLC Red Channel Target Value */
|
||||
#define TGT_GB 0x44 /* BLC Gb Channel Target Value */
|
||||
#define TGT_GR 0x45 /* BLC Gr Channel Target Value */
|
||||
|
||||
#define LC_CTR 0x46 /* Lens Correction Control */
|
||||
#define LC_CTR_RGB_COMP_1 0x00 /* R, G, and B channel compensation coefficient is set by LC_COEF (0x49) */
|
||||
#define LC_CTR_RGB_COMP_3 0x04 /* R, G, and B channel compensation coefficient is set by registers
|
||||
LC_COEFB (0x4B), LC_COEF (0x49), and LC_COEFR (0x4C), respectively */
|
||||
#define LC_CTR_EN 0x01 /* Lens correction enable */
|
||||
#define LC_XC 0x47 /* X Coordinate of Lens Correction Center Relative to Array Center */
|
||||
#define LC_YC 0x48 /* Y Coordinate of Lens Correction Center Relative to Array Center */
|
||||
#define LC_COEF 0x49 /* Lens Correction Coefficient */
|
||||
#define LC_RADI 0x4A /* Lens Correction Radius */
|
||||
#define LC_COEFB 0x4B /* Lens Correction B Channel Compensation Coefficient */
|
||||
#define LC_COEFR 0x4C /* Lens Correction R Channel Compensation Coefficient */
|
||||
|
||||
#define FIXGAIN 0x4D /* Analog Fix Gain Amplifier */
|
||||
#define AREF0 0x4E /* Sensor Reference Control */
|
||||
#define AREF1 0x4F /* Sensor Reference Current Control */
|
||||
#define AREF2 0x50 /* Analog Reference Control */
|
||||
#define AREF3 0x51 /* ADC Reference Control */
|
||||
#define AREF4 0x52 /* ADC Reference Control */
|
||||
#define AREF5 0x53 /* ADC Reference Control */
|
||||
#define AREF6 0x54 /* Analog Reference Control */
|
||||
#define AREF7 0x55 /* Analog Reference Control */
|
||||
#define UFIX 0x60 /* U Channel Fixed Value Output */
|
||||
#define VFIX 0x61 /* V Channel Fixed Value Output */
|
||||
#define AWBB_BLK 0x62 /* AWB Option for Advanced AWB */
|
||||
|
||||
#define AWB_CTRL0 0x63 /* AWB Control Byte 0 */
|
||||
#define AWB_CTRL0_GAIN_EN 0x80 /* AWB gain enable */
|
||||
#define AWB_CTRL0_CALC_EN 0x40 /* AWB calculate enable */
|
||||
#define AWB_CTRL0_WBC_MASK 0x0F /* WBC threshold 2 */
|
||||
|
||||
#define DSP_CTRL1 0x64 /* DSP Control Byte 1 */
|
||||
#define DSP_CTRL1_FIFO_EN 0x80 /* FIFO enable/disable selection */
|
||||
#define DSP_CTRL1_UV_EN 0x40 /* UV adjust function ON/OFF selection */
|
||||
#define DSP_CTRL1_SDE_EN 0x20 /* SDE enable */
|
||||
#define DSP_CTRL1_MTRX_EN 0x10 /* Color matrix ON/OFF selection */
|
||||
#define DSP_CTRL1_INTRP_EN 0x08 /* Interpolation ON/OFF selection */
|
||||
#define DSP_CTRL1_GAMMA_EN 0x04 /* Gamma function ON/OFF selection */
|
||||
#define DSP_CTRL1_BLACK_EN 0x02 /* Black defect auto correction ON/OFF */
|
||||
#define DSP_CTRL1_WHITE_EN 0x01 /* White defect auto correction ON/OFF */
|
||||
|
||||
#define DSP_CTRL2 0x65 /* DSP Control Byte 2 */
|
||||
#define DSP_CTRL2_VDCW_EN 0x08 /* Vertical DCW enable */
|
||||
#define DSP_CTRL2_HDCW_EN 0x04 /* Horizontal DCW enable */
|
||||
#define DSP_CTRL2_VZOOM_EN 0x02 /* Vertical zoom out enable */
|
||||
#define DSP_CTRL2_HZOOM_EN 0x01 /* Horizontal zoom out enable */
|
||||
|
||||
#define DSP_CTRL3 0x66 /* DSP Control Byte 3 */
|
||||
#define DSP_CTRL3_UV_EN 0x80 /* UV output sequence option */
|
||||
#define DSP_CTRL3_CBAR_EN 0x20 /* DSP color bar ON/OFF selection */
|
||||
#define DSP_CTRL3_FIFO_EN 0x08 /* FIFO power down ON/OFF selection */
|
||||
#define DSP_CTRL3_SCAL1_PWDN 0x04 /* Scaling module power down control 1 */
|
||||
#define DSP_CTRL3_SCAL2_PWDN 0x02 /* Scaling module power down control 2 */
|
||||
#define DSP_CTRL3_INTRP_PWDN 0x01 /* Interpolation module power down control */
|
||||
#define DSP_CTRL3_SET_CBAR(r, x) ((r&0xDF)|((x&1)<<5))
|
||||
|
||||
|
||||
#define DSP_CTRL4 0x67 /* DSP Control Byte 4 */
|
||||
#define DSP_CTRL4_YUV_RGB 0x00 /* Output selection YUV or RGB */
|
||||
#define DSP_CTRL4_RAW8 0x02 /* Output selection RAW8 */
|
||||
#define DSP_CTRL4_RAW10 0x03 /* Output selection RAW10 */
|
||||
|
||||
|
||||
#define AWB_BIAS 0x68 /* AWB BLC Level Clip */
|
||||
#define AWB_CTRL1 0x69 /* AWB Control 1 */
|
||||
#define AWB_CTRL2 0x6A /* AWB Control 2 */
|
||||
|
||||
#define AWB_CTRL3 0x6B /* AWB Control 3 */
|
||||
#define AWB_CTRL3_ADVANCED 0x80 /* AWB mode select - Advanced AWB */
|
||||
#define AWB_CTRL3_SIMPLE 0x00 /* AWB mode select - Simple AWB */
|
||||
|
||||
#define AWB_CTRL4 0x6C /* AWB Control 4 */
|
||||
#define AWB_CTRL5 0x6D /* AWB Control 5 */
|
||||
#define AWB_CTRL6 0x6E /* AWB Control 6 */
|
||||
#define AWB_CTRL7 0x6F /* AWB Control 7 */
|
||||
#define AWB_CTRL8 0x70 /* AWB Control 8 */
|
||||
#define AWB_CTRL9 0x71 /* AWB Control 9 */
|
||||
#define AWB_CTRL10 0x72 /* AWB Control 10 */
|
||||
#define AWB_CTRL11 0x73 /* AWB Control 11 */
|
||||
#define AWB_CTRL12 0x74 /* AWB Control 12 */
|
||||
#define AWB_CTRL13 0x75 /* AWB Control 13 */
|
||||
#define AWB_CTRL14 0x76 /* AWB Control 14 */
|
||||
#define AWB_CTRL15 0x77 /* AWB Control 15 */
|
||||
#define AWB_CTRL16 0x78 /* AWB Control 16 */
|
||||
#define AWB_CTRL17 0x79 /* AWB Control 17 */
|
||||
#define AWB_CTRL18 0x7A /* AWB Control 18 */
|
||||
#define AWB_CTRL19 0x7B /* AWB Control 19 */
|
||||
#define AWB_CTRL20 0x7C /* AWB Control 20 */
|
||||
#define AWB_CTRL21 0x7D /* AWB Control 21 */
|
||||
#define GAM1 0x7E /* Gamma Curve 1st Segment Input End Point 0x04 Output Value */
|
||||
#define GAM2 0x7F /* Gamma Curve 2nd Segment Input End Point 0x08 Output Value */
|
||||
#define GAM3 0x80 /* Gamma Curve 3rd Segment Input End Point 0x10 Output Value */
|
||||
#define GAM4 0x81 /* Gamma Curve 4th Segment Input End Point 0x20 Output Value */
|
||||
#define GAM5 0x82 /* Gamma Curve 5th Segment Input End Point 0x28 Output Value */
|
||||
#define GAM6 0x83 /* Gamma Curve 6th Segment Input End Point 0x30 Output Value */
|
||||
#define GAM7 0x84 /* Gamma Curve 7th Segment Input End Point 0x38 Output Value */
|
||||
#define GAM8 0x85 /* Gamma Curve 8th Segment Input End Point 0x40 Output Value */
|
||||
#define GAM9 0x86 /* Gamma Curve 9th Segment Input End Point 0x48 Output Value */
|
||||
#define GAM10 0x87 /* Gamma Curve 10th Segment Input End Point 0x50 Output Value */
|
||||
#define GAM11 0x88 /* Gamma Curve 11th Segment Input End Point 0x60 Output Value */
|
||||
#define GAM12 0x89 /* Gamma Curve 12th Segment Input End Point 0x70 Output Value */
|
||||
#define GAM13 0x8A /* Gamma Curve 13th Segment Input End Point 0x90 Output Value */
|
||||
#define GAM14 0x8B /* Gamma Curve 14th Segment Input End Point 0xB0 Output Value */
|
||||
#define GAM15 0x8C /* Gamma Curve 15th Segment Input End Point 0xD0 Output Value */
|
||||
#define SLOP 0x8D /* Gamma Curve Highest Segment Slope */
|
||||
#define DNSTH 0x8E /* De-noise Threshold */
|
||||
#define EDGE0 0x8F /* Edge Enhancement Strength Control */
|
||||
#define EDGE1 0x90 /* Edge Enhancement Threshold Control */
|
||||
#define DNSOFF 0x91 /* Auto De-noise Threshold Control */
|
||||
#define EDGE2 0x92 /* Edge Enhancement Strength Upper Limit */
|
||||
#define EDGE3 0x93 /* Edge Enhancement Strength Upper Limit */
|
||||
#define MTX1 0x94 /* Matrix Coefficient 1 */
|
||||
#define MTX2 0x95 /* Matrix Coefficient 2 */
|
||||
#define MTX3 0x96 /* Matrix Coefficient 3 */
|
||||
#define MTX4 0x97 /* Matrix Coefficient 4 */
|
||||
#define MTX5 0x98 /* Matrix Coefficient 5 */
|
||||
#define MTX6 0x99 /* Matrix Coefficient 6 */
|
||||
|
||||
#define MTX_CTRL 0x9A /* Matrix Control */
|
||||
#define MTX_CTRL_DBL_EN 0x80 /* Matrix double ON/OFF selection */
|
||||
|
||||
#define BRIGHTNESS 0x9B /* Brightness Control */
|
||||
#define CONTRAST 0x9C /* Contrast Gain */
|
||||
#define UVADJ0 0x9E /* Auto UV Adjust Control 0 */
|
||||
#define UVADJ1 0x9F /* Auto UV Adjust Control 1 */
|
||||
#define SCAL0 0xA0 /* DCW Ratio Control */
|
||||
#define SCAL1 0xA1 /* Horizontal Zoom Out Control */
|
||||
#define SCAL2 0xA2 /* Vertical Zoom Out Control */
|
||||
#define FIFODLYM 0xA3 /* FIFO Manual Mode Delay Control */
|
||||
#define FIFODLYA 0xA4 /* FIFO Auto Mode Delay Control */
|
||||
|
||||
#define SDE 0xA6 /* Special Digital Effect Control */
|
||||
#define SDE_NEGATIVE_EN 0x40 /* Negative image enable */
|
||||
#define SDE_GRAYSCALE_EN 0x20 /* Gray scale image enable */
|
||||
#define SDE_V_FIXED_EN 0x10 /* V fixed value enable */
|
||||
#define SDE_U_FIXED_EN 0x08 /* U fixed value enable */
|
||||
#define SDE_CONT_BRIGHT_EN 0x04 /* Contrast/Brightness enable */
|
||||
#define SDE_SATURATION_EN 0x02 /* Saturation enable */
|
||||
#define SDE_HUE_EN 0x01 /* Hue enable */
|
||||
|
||||
#define USAT 0xA7 /* U Component Saturation Gain */
|
||||
#define VSAT 0xA8 /* V Component Saturation Gain */
|
||||
#define HUECOS 0xA9 /* Cosine value ¡Á 0x80 */
|
||||
#define HUESIN 0xAA /* Sine value ¡Á 0x80 */
|
||||
#define SIGN_BIT 0xAB /* Sign Bit for Hue and Brightness */
|
||||
|
||||
#define DSPAUTO 0xAC /* DSP Auto Function ON/OFF Control */
|
||||
#define DSPAUTO_AWB_EN 0x80 /* AWB auto threshold control */
|
||||
#define DSPAUTO_DENOISE_EN 0x40 /* De-noise auto threshold control */
|
||||
#define DSPAUTO_EDGE_EN 0x20 /* Sharpness (edge enhancement) auto strength control */
|
||||
#define DSPAUTO_UV_EN 0x10 /* UV adjust auto slope control */
|
||||
#define DSPAUTO_SCAL0_EN 0x08 /* Auto scaling factor control (register SCAL0 (0xA0)) */
|
||||
#define DSPAUTO_SCAL1_EN 0x04 /* Auto scaling factor control (registers SCAL1 (0xA1 and SCAL2 (0xA2))*/
|
||||
#define SET_REG(reg, x) (##reg_DEFAULT|x)
|
||||
#endif //__REG_REGS_H__
|
||||
#endif
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "sensor.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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 gc0308_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int gc0308_init(sensor_t *sensor);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* GC0308 register definitions.
|
||||
*/
|
||||
#ifndef __GC0308_REG_REGS_H__
|
||||
#define __GC0308_REG_REGS_H__
|
||||
|
||||
#define RESET_RELATED 0xfe // Bit[7]: Software reset
|
||||
// Bit[6:5]: NA
|
||||
// Bit[4]: CISCTL_restart_n
|
||||
// Bit[3:1]: NA
|
||||
// Bit[0]: page select
|
||||
// 0:page0
|
||||
// 1:page1
|
||||
|
||||
|
||||
// page0:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief register value
|
||||
*/
|
||||
|
||||
|
||||
#endif // __GC0308_REG_REGS_H__
|
||||
|
|
@ -1,258 +0,0 @@
|
|||
#ifndef _GC0308_SETTINGS_H_
|
||||
#define _GC0308_SETTINGS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define REG_DLY 0xff
|
||||
|
||||
static const uint8_t gc0308_sensor_default_regs[][2] = {
|
||||
{0xfe, 0x00},
|
||||
{0xec, 0x20},
|
||||
{0x05, 0x00},
|
||||
{0x06, 0x00},
|
||||
{0x07, 0x00},
|
||||
{0x08, 0x00},
|
||||
{0x09, 0x01},
|
||||
{0x0a, 0xe8},
|
||||
{0x0b, 0x02},
|
||||
{0x0c, 0x88},
|
||||
{0x0d, 0x02},
|
||||
{0x0e, 0x02},
|
||||
{0x10, 0x26},
|
||||
{0x11, 0x0d},
|
||||
{0x12, 0x2a},
|
||||
{0x13, 0x00},
|
||||
{0x14, 0x11},
|
||||
{0x15, 0x0a},
|
||||
{0x16, 0x05},
|
||||
{0x17, 0x01},
|
||||
{0x18, 0x44},
|
||||
{0x19, 0x44},
|
||||
{0x1a, 0x2a},
|
||||
{0x1b, 0x00},
|
||||
{0x1c, 0x49},
|
||||
{0x1d, 0x9a},
|
||||
{0x1e, 0x61},
|
||||
{0x1f, 0x00}, //pad drv <=24MHz, use 0x00 is ok
|
||||
{0x20, 0x7f},
|
||||
{0x21, 0xfa},
|
||||
{0x22, 0x57},
|
||||
{0x24, 0xa2}, //YCbYCr
|
||||
{0x25, 0x0f},
|
||||
{0x26, 0x03}, // 0x01
|
||||
{0x28, 0x00},
|
||||
{0x2d, 0x0a},
|
||||
{0x2f, 0x01},
|
||||
{0x30, 0xf7},
|
||||
{0x31, 0x50},
|
||||
{0x32, 0x00},
|
||||
{0x33, 0x28},
|
||||
{0x34, 0x2a},
|
||||
{0x35, 0x28},
|
||||
{0x39, 0x04},
|
||||
{0x3a, 0x20},
|
||||
{0x3b, 0x20},
|
||||
{0x3c, 0x00},
|
||||
{0x3d, 0x00},
|
||||
{0x3e, 0x00},
|
||||
{0x3f, 0x00},
|
||||
{0x50, 0x14}, // 0x14
|
||||
{0x52, 0x41},
|
||||
{0x53, 0x80},
|
||||
{0x54, 0x80},
|
||||
{0x55, 0x80},
|
||||
{0x56, 0x80},
|
||||
{0x8b, 0x20},
|
||||
{0x8c, 0x20},
|
||||
{0x8d, 0x20},
|
||||
{0x8e, 0x14},
|
||||
{0x8f, 0x10},
|
||||
{0x90, 0x14},
|
||||
{0x91, 0x3c},
|
||||
{0x92, 0x50},
|
||||
//{0x8b,0x10},
|
||||
//{0x8c,0x10},
|
||||
//{0x8d,0x10},
|
||||
//{0x8e,0x10},
|
||||
//{0x8f,0x10},
|
||||
//{0x90,0x10},
|
||||
//{0x91,0x3c},
|
||||
//{0x92,0x50},
|
||||
{0x5d, 0x12},
|
||||
{0x5e, 0x1a},
|
||||
{0x5f, 0x24},
|
||||
{0x60, 0x07},
|
||||
{0x61, 0x15},
|
||||
{0x62, 0x08}, // 0x08
|
||||
{0x64, 0x03}, // 0x03
|
||||
{0x66, 0xe8},
|
||||
{0x67, 0x86},
|
||||
{0x68, 0x82},
|
||||
{0x69, 0x18},
|
||||
{0x6a, 0x0f},
|
||||
{0x6b, 0x00},
|
||||
{0x6c, 0x5f},
|
||||
{0x6d, 0x8f},
|
||||
{0x6e, 0x55},
|
||||
{0x6f, 0x38},
|
||||
{0x70, 0x15},
|
||||
{0x71, 0x33},
|
||||
{0x72, 0xdc},
|
||||
{0x73, 0x00},
|
||||
{0x74, 0x02},
|
||||
{0x75, 0x3f},
|
||||
{0x76, 0x02},
|
||||
{0x77, 0x38}, // 0x47
|
||||
{0x78, 0x88},
|
||||
{0x79, 0x81},
|
||||
{0x7a, 0x81},
|
||||
{0x7b, 0x22},
|
||||
{0x7c, 0xff},
|
||||
{0x93, 0x48}, //color matrix default
|
||||
{0x94, 0x02},
|
||||
{0x95, 0x07},
|
||||
{0x96, 0xe0},
|
||||
{0x97, 0x40},
|
||||
{0x98, 0xf0},
|
||||
{0xb1, 0x40},
|
||||
{0xb2, 0x40},
|
||||
{0xb3, 0x40}, //0x40
|
||||
{0xb6, 0xe0},
|
||||
{0xbd, 0x38},
|
||||
{0xbe, 0x36},
|
||||
{0xd0, 0xCB},
|
||||
{0xd1, 0x10},
|
||||
{0xd2, 0x90},
|
||||
{0xd3, 0x48},
|
||||
{0xd5, 0xF2},
|
||||
{0xd6, 0x16},
|
||||
{0xdb, 0x92},
|
||||
{0xdc, 0xA5},
|
||||
{0xdf, 0x23},
|
||||
{0xd9, 0x00},
|
||||
{0xda, 0x00},
|
||||
{0xe0, 0x09},
|
||||
{0xed, 0x04},
|
||||
{0xee, 0xa0},
|
||||
{0xef, 0x40},
|
||||
{0x80, 0x03},
|
||||
|
||||
{0x9F, 0x10},
|
||||
{0xA0, 0x20},
|
||||
{0xA1, 0x38},
|
||||
{0xA2, 0x4e},
|
||||
{0xA3, 0x63},
|
||||
{0xA4, 0x76},
|
||||
{0xA5, 0x87},
|
||||
{0xA6, 0xa2},
|
||||
{0xA7, 0xb8},
|
||||
{0xA8, 0xca},
|
||||
{0xA9, 0xd8},
|
||||
{0xAA, 0xe3},
|
||||
{0xAB, 0xeb},
|
||||
{0xAC, 0xf0},
|
||||
{0xAD, 0xF8},
|
||||
{0xAE, 0xFd},
|
||||
{0xAF, 0xFF},
|
||||
|
||||
{0xc0, 0x00},
|
||||
{0xc1, 0x10},
|
||||
{0xc2, 0x1c},
|
||||
{0xc3, 0x30},
|
||||
{0xc4, 0x43},
|
||||
{0xc5, 0x54},
|
||||
{0xc6, 0x65},
|
||||
{0xc7, 0x75},
|
||||
{0xc8, 0x93},
|
||||
{0xc9, 0xB0},
|
||||
{0xca, 0xCB},
|
||||
{0xcb, 0xE6},
|
||||
{0xcc, 0xFF},
|
||||
{0xf0, 0x02},
|
||||
{0xf1, 0x01},
|
||||
{0xf2, 0x02},
|
||||
{0xf3, 0x30},
|
||||
{0xf7, 0x04},
|
||||
{0xf8, 0x02},
|
||||
{0xf9, 0x9f},
|
||||
{0xfa, 0x78},
|
||||
{0xfe, 0x01},
|
||||
{0x00, 0xf5},
|
||||
{0x02, 0x20},
|
||||
{0x04, 0x10},
|
||||
{0x05, 0x08},
|
||||
{0x06, 0x20},
|
||||
{0x08, 0x0a},
|
||||
{0x0a, 0xa0},
|
||||
{0x0b, 0x60},
|
||||
{0x0c, 0x08},
|
||||
{0x0e, 0x44},
|
||||
{0x0f, 0x32},
|
||||
{0x10, 0x41},
|
||||
{0x11, 0x37},
|
||||
{0x12, 0x22},
|
||||
{0x13, 0x19},
|
||||
{0x14, 0x44},
|
||||
{0x15, 0x44},
|
||||
{0x16, 0xc2},
|
||||
{0x17, 0xA8},
|
||||
{0x18, 0x18},
|
||||
{0x19, 0x50},
|
||||
{0x1a, 0xd8},
|
||||
{0x1b, 0xf5},
|
||||
{0x70, 0x40},
|
||||
{0x71, 0x58},
|
||||
{0x72, 0x30},
|
||||
{0x73, 0x48},
|
||||
{0x74, 0x20},
|
||||
{0x75, 0x60},
|
||||
{0x77, 0x20},
|
||||
{0x78, 0x32},
|
||||
{0x30, 0x03},
|
||||
{0x31, 0x40},
|
||||
{0x32, 0x10},
|
||||
{0x33, 0xe0},
|
||||
{0x34, 0xe0},
|
||||
{0x35, 0x00},
|
||||
{0x36, 0x80},
|
||||
{0x37, 0x00},
|
||||
{0x38, 0x04},
|
||||
{0x39, 0x09},
|
||||
{0x3a, 0x12},
|
||||
{0x3b, 0x1C},
|
||||
{0x3c, 0x28},
|
||||
{0x3d, 0x31},
|
||||
{0x3e, 0x44},
|
||||
{0x3f, 0x57},
|
||||
{0x40, 0x6C},
|
||||
{0x41, 0x81},
|
||||
{0x42, 0x94},
|
||||
{0x43, 0xA7},
|
||||
{0x44, 0xB8},
|
||||
{0x45, 0xD6},
|
||||
{0x46, 0xEE},
|
||||
{0x47, 0x0d},
|
||||
{0x62, 0xf7},
|
||||
{0x63, 0x68},
|
||||
{0x64, 0xd3},
|
||||
{0x65, 0xd3},
|
||||
{0x66, 0x60},
|
||||
{0xfe, 0x00},
|
||||
|
||||
{0x01, 0x32}, //frame setting
|
||||
{0x02, 0x0c},
|
||||
{0x0f, 0x01},
|
||||
{0xe2, 0x00},
|
||||
{0xe3, 0x78},
|
||||
{0xe4, 0x00},
|
||||
{0xe5, 0xfe},
|
||||
{0xe6, 0x01},
|
||||
{0xe7, 0xe0},
|
||||
{0xe8, 0x01},
|
||||
{0xe9, 0xe0},
|
||||
{0xea, 0x01},
|
||||
{0xeb, 0xe0},
|
||||
{0xfe, 0x00},
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* GC032A driver.
|
||||
*
|
||||
*/
|
||||
#ifndef __GC032A_H__
|
||||
#define __GC032A_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 gc032a_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int gc032a_init(sensor_t *sensor);
|
||||
|
||||
#endif // __GC032A_H__
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* GC032A register definitions.
|
||||
*/
|
||||
#ifndef __GC032A_REG_REGS_H__
|
||||
#define __GC032A_REG_REGS_H__
|
||||
|
||||
#define SENSOR_ID_HIGH 0XF0
|
||||
#define SENSOR_ID_LOW 0XF1
|
||||
#define PAD_VB_HIZ_MODE 0XF2
|
||||
#define SYNC_OUTPUT 0XF3
|
||||
#define I2C_CONFIG 0XF4
|
||||
#define PLL_MODE1 0XF7
|
||||
#define PLL_MODE2 0XF8
|
||||
#define CM_MODE 0XF9
|
||||
#define ISP_DIV_MODE 0XFA
|
||||
#define I2C_DEVICE_ID 0XFB
|
||||
#define ANALOG_PWC 0XFC
|
||||
#define ISP_DIV_MODE2 0XFD
|
||||
#define RESET_RELATED 0XFE // Bit[7]: Software reset
|
||||
// Bit[6]: cm reset
|
||||
// Bit[5]: spi reset
|
||||
// Bit[4]: CISCTL_restart_n
|
||||
// Bit[3]: PLL_rst
|
||||
// Bit[2:0]: page select
|
||||
// 000:page0
|
||||
// 001:page1
|
||||
// 010:page2
|
||||
// 011:page3
|
||||
|
||||
//----page0-----------------------------
|
||||
#define P0_EXPOSURE_HIGH 0X03
|
||||
#define P0_EXPOSURE_LOW 0X04
|
||||
#define P0_HB_HIGH 0X05
|
||||
#define P0_HB_LOW 0X06
|
||||
#define P0_VB_HIGH 0X07
|
||||
#define P0_VB_LOW 0X08
|
||||
#define P0_ROW_START_HIGH 0X09
|
||||
#define P0_ROW_START_LOW 0X0A
|
||||
#define P0_COLUMN_START_HIGH 0X0B
|
||||
#define P0_COLUMN_START_LOW 0X0C
|
||||
#define P0_WINDOW_HEIGHT_HIGH 0X0D
|
||||
#define P0_WINDOW_HEIGHT_LOW 0X0E
|
||||
#define P0_WINDOW_WIDTH_HIGH 0X0F
|
||||
#define P0_WINDOW_WIDTH_LOW 0X10
|
||||
#define P0_SH_DELAY 0X11
|
||||
#define P0_VS_ST 0X12
|
||||
#define P0_VS_ET 0X13
|
||||
#define P0_CISCTL_MODE1 0X17
|
||||
|
||||
#define P0_BLOCK_ENABLE_1 0X40
|
||||
#define P0_AAAA_ENABLE 0X42
|
||||
#define P0_SPECIAL_EFFECT 0X43
|
||||
#define P0_SYNC_MODE 0X46
|
||||
#define P0_GAIN_CODE 0X48
|
||||
#define P0_DEBUG_MODE2 0X4C
|
||||
#define P0_WIN_MODE 0X50
|
||||
#define P0_OUT_WIN_Y1_HIGH 0X51
|
||||
#define P0_OUT_WIN_Y1_LOW 0X52
|
||||
#define P0_OUT_WIN_X1_HIGH 0X53
|
||||
#define P0_OUT_WIN_X1_LOW 0X54
|
||||
#define P0_OUT_WIN_HEIGHT_HIGH 0X55
|
||||
#define P0_OUT_WIN_HEIGHT_LOW 0X56
|
||||
#define P0_OUT_WIN_WIDTH_HIGH 0X57
|
||||
#define P0_OUT_WIN_WIDTH_LOW 0X58
|
||||
|
||||
#define P0_GLOBAL_SATURATION 0XD0
|
||||
#define P0_SATURATION_CB 0XD1
|
||||
#define P0_SATURATION_CR 0XD2
|
||||
#define P0_LUMA_CONTRAST 0XD3
|
||||
#define P0_CONTRAST_CENTER 0XD4
|
||||
#define P0_LUMA_OFFSET 0XD5
|
||||
#define P0_FIXED_CB 0XDA
|
||||
#define P0_FIXED_CR 0XDB
|
||||
|
||||
//----page3-----------------------------
|
||||
#define P3_IMAGE_WIDTH_LOW 0X5B
|
||||
#define P3_IMAGE_WIDTH_HIGH 0X5C
|
||||
#define P3_IMAGE_HEIGHT_LOW 0X5D
|
||||
#define P3_IMAGE_HEIGHT_HIGH 0X5E
|
||||
|
||||
|
||||
#endif //__GC032A_REG_REGS_H__
|
||||
|
|
@ -1,401 +0,0 @@
|
|||
#ifndef _GC032A_SETTINGS_H_
|
||||
#define _GC032A_SETTINGS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_attr.h"
|
||||
#include "gc032a_regs.h"
|
||||
|
||||
|
||||
#define REG_DLY 0xffff
|
||||
#define REGLIST_TAIL 0x0000
|
||||
|
||||
|
||||
/*
|
||||
* The default register settings, as obtained from OmniVision. There
|
||||
* is really no making sense of most of these - lots of "reserved" values
|
||||
* and such.
|
||||
*
|
||||
*/
|
||||
static const uint16_t gc032a_default_regs[][2] = {
|
||||
/*System*/
|
||||
{0xf3, 0xff},
|
||||
{0xf5, 0x06},
|
||||
{0xf7, 0x01},
|
||||
{0xf8, 0x03},
|
||||
{0xf9, 0xce},
|
||||
{0xfa, 0x00},
|
||||
{0xfc, 0x02},
|
||||
{0xfe, 0x02},
|
||||
{0x81, 0x03},
|
||||
|
||||
{0xfe, 0x00},
|
||||
{0x77, 0x64},
|
||||
{0x78, 0x40},
|
||||
{0x79, 0x60},
|
||||
/*ANALOG & CISCTL*/
|
||||
{0xfe, 0x00},
|
||||
{0x03, 0x01},
|
||||
{0x04, 0xce},
|
||||
{0x05, 0x01},
|
||||
{0x06, 0xad},
|
||||
{0x07, 0x00},
|
||||
{0x08, 0x10},
|
||||
{0x0a, 0x00},
|
||||
{0x0c, 0x00},
|
||||
{0x0d, 0x01},
|
||||
{0x0e, 0xe8}, // height 488
|
||||
{0x0f, 0x02},
|
||||
{0x10, 0x88}, // width 648
|
||||
{0x17, 0x54},
|
||||
{0x19, 0x08},
|
||||
{0x1a, 0x0a},
|
||||
{0x1f, 0x40},
|
||||
{0x20, 0x30},
|
||||
{0x2e, 0x80},
|
||||
{0x2f, 0x2b},
|
||||
{0x30, 0x1a},
|
||||
{0xfe, 0x02},
|
||||
{0x03, 0x02},
|
||||
{0x05, 0xd7},
|
||||
{0x06, 0x60},
|
||||
{0x08, 0x80},
|
||||
{0x12, 0x89},
|
||||
|
||||
/*blk*/
|
||||
{0xfe, 0x00},
|
||||
{0x18, 0x02},
|
||||
{0xfe, 0x02},
|
||||
{0x40, 0x22},
|
||||
{0x45, 0x00},
|
||||
{0x46, 0x00},
|
||||
{0x49, 0x20},
|
||||
{0x4b, 0x3c},
|
||||
{0x50, 0x20},
|
||||
{0x42, 0x10},
|
||||
|
||||
/*isp*/
|
||||
{0xfe, 0x01},
|
||||
{0x0a, 0xc5},
|
||||
{0x45, 0x00},
|
||||
{0xfe, 0x00},
|
||||
{0x40, 0xff},
|
||||
{0x41, 0x25},
|
||||
{0x42, 0xcf},
|
||||
{0x43, 0x10},
|
||||
{0x44, 0x83},
|
||||
{0x46, 0x23},
|
||||
{0x49, 0x03},
|
||||
{0x52, 0x02},
|
||||
{0x54, 0x00},
|
||||
{0xfe, 0x02},
|
||||
{0x22, 0xf6},
|
||||
|
||||
/*Shading*/
|
||||
{0xfe, 0x01},
|
||||
{0xc1, 0x38},
|
||||
{0xc2, 0x4c},
|
||||
{0xc3, 0x00},
|
||||
{0xc4, 0x32},
|
||||
{0xc5, 0x24},
|
||||
{0xc6, 0x16},
|
||||
{0xc7, 0x08},
|
||||
{0xc8, 0x08},
|
||||
{0xc9, 0x00},
|
||||
{0xca, 0x20},
|
||||
{0xdc, 0x8a},
|
||||
{0xdd, 0xa0},
|
||||
{0xde, 0xa6},
|
||||
{0xdf, 0x75},
|
||||
|
||||
/*AWB*/
|
||||
{0xfe, 0x01},
|
||||
{0x7c, 0x09},
|
||||
{0x65, 0x06},
|
||||
{0x7c, 0x08},
|
||||
{0x56, 0xf4},
|
||||
{0x66, 0x0f},
|
||||
{0x67, 0x84},
|
||||
{0x6b, 0x80},
|
||||
{0x6d, 0x12},
|
||||
{0x6e, 0xb0},
|
||||
{0x86, 0x00},
|
||||
{0x87, 0x00},
|
||||
{0x88, 0x00},
|
||||
{0x89, 0x00},
|
||||
{0x8a, 0x00},
|
||||
{0x8b, 0x00},
|
||||
{0x8c, 0x00},
|
||||
{0x8d, 0x00},
|
||||
{0x8e, 0x00},
|
||||
{0x8f, 0x00},
|
||||
{0x90, 0x00},
|
||||
{0x91, 0x00},
|
||||
{0x92, 0xf4},
|
||||
{0x93, 0xd5},
|
||||
{0x94, 0x50},
|
||||
{0x95, 0x0f},
|
||||
{0x96, 0xf4},
|
||||
{0x97, 0x2d},
|
||||
{0x98, 0x0f},
|
||||
{0x99, 0xa6},
|
||||
{0x9a, 0x2d},
|
||||
{0x9b, 0x0f},
|
||||
{0x9c, 0x59},
|
||||
{0x9d, 0x2d},
|
||||
{0x9e, 0xaa},
|
||||
{0x9f, 0x67},
|
||||
{0xa0, 0x59},
|
||||
{0xa1, 0x00},
|
||||
{0xa2, 0x00},
|
||||
{0xa3, 0x0a},
|
||||
{0xa4, 0x00},
|
||||
{0xa5, 0x00},
|
||||
{0xa6, 0xd4},
|
||||
{0xa7, 0x9f},
|
||||
{0xa8, 0x55},
|
||||
{0xa9, 0xd4},
|
||||
{0xaa, 0x9f},
|
||||
{0xab, 0xac},
|
||||
{0xac, 0x9f},
|
||||
{0xad, 0x55},
|
||||
{0xae, 0xd4},
|
||||
{0xaf, 0xac},
|
||||
{0xb0, 0xd4},
|
||||
{0xb1, 0xa3},
|
||||
{0xb2, 0x55},
|
||||
{0xb3, 0xd4},
|
||||
{0xb4, 0xac},
|
||||
{0xb5, 0x00},
|
||||
{0xb6, 0x00},
|
||||
{0xb7, 0x05},
|
||||
{0xb8, 0xd6},
|
||||
{0xb9, 0x8c},
|
||||
|
||||
/*CC*/
|
||||
{0xfe, 0x01},
|
||||
{0xd0, 0x40},
|
||||
{0xd1, 0xf8},
|
||||
{0xd2, 0x00},
|
||||
{0xd3, 0xfa},
|
||||
{0xd4, 0x45},
|
||||
{0xd5, 0x02},
|
||||
|
||||
{0xd6, 0x30},
|
||||
{0xd7, 0xfa},
|
||||
{0xd8, 0x08},
|
||||
{0xd9, 0x08},
|
||||
{0xda, 0x58},
|
||||
{0xdb, 0x02},
|
||||
{0xfe, 0x00},
|
||||
|
||||
/*Gamma*/
|
||||
{0xfe, 0x00},
|
||||
{0xba, 0x00},
|
||||
{0xbb, 0x04},
|
||||
{0xbc, 0x0a},
|
||||
{0xbd, 0x0e},
|
||||
{0xbe, 0x22},
|
||||
{0xbf, 0x30},
|
||||
{0xc0, 0x3d},
|
||||
{0xc1, 0x4a},
|
||||
{0xc2, 0x5d},
|
||||
{0xc3, 0x6b},
|
||||
{0xc4, 0x7a},
|
||||
{0xc5, 0x85},
|
||||
{0xc6, 0x90},
|
||||
{0xc7, 0xa5},
|
||||
{0xc8, 0xb5},
|
||||
{0xc9, 0xc2},
|
||||
{0xca, 0xcc},
|
||||
{0xcb, 0xd5},
|
||||
{0xcc, 0xde},
|
||||
{0xcd, 0xea},
|
||||
{0xce, 0xf5},
|
||||
{0xcf, 0xff},
|
||||
|
||||
/*Auto Gamma*/
|
||||
{0xfe, 0x00},
|
||||
{0x5a, 0x08},
|
||||
{0x5b, 0x0f},
|
||||
{0x5c, 0x15},
|
||||
{0x5d, 0x1c},
|
||||
{0x5e, 0x28},
|
||||
{0x5f, 0x36},
|
||||
{0x60, 0x45},
|
||||
{0x61, 0x51},
|
||||
{0x62, 0x6a},
|
||||
{0x63, 0x7d},
|
||||
{0x64, 0x8d},
|
||||
{0x65, 0x98},
|
||||
{0x66, 0xa2},
|
||||
{0x67, 0xb5},
|
||||
{0x68, 0xc3},
|
||||
{0x69, 0xcd},
|
||||
{0x6a, 0xd4},
|
||||
{0x6b, 0xdc},
|
||||
{0x6c, 0xe3},
|
||||
{0x6d, 0xf0},
|
||||
{0x6e, 0xf9},
|
||||
{0x6f, 0xff},
|
||||
|
||||
/*Gain*/
|
||||
{0xfe, 0x00},
|
||||
{0x70, 0x50},
|
||||
|
||||
/*AEC*/
|
||||
{0xfe, 0x00},
|
||||
{0x4f, 0x01},
|
||||
{0xfe, 0x01},
|
||||
{0x0d, 0x00},
|
||||
{0x12, 0xa0},
|
||||
{0x13, 0x3a},
|
||||
{0x44, 0x04},
|
||||
{0x1f, 0x30},
|
||||
{0x20, 0x40},
|
||||
{0x26, 0x9a},
|
||||
{0x3e, 0x20},
|
||||
{0x3f, 0x2d},
|
||||
{0x40, 0x40},
|
||||
{0x41, 0x5b},
|
||||
{0x42, 0x82},
|
||||
{0x43, 0xb7},
|
||||
{0x04, 0x0a},
|
||||
{0x02, 0x79},
|
||||
{0x03, 0xc0},
|
||||
|
||||
/*measure window*/
|
||||
{0xfe, 0x01},
|
||||
{0xcc, 0x08},
|
||||
{0xcd, 0x08},
|
||||
{0xce, 0xa4},
|
||||
{0xcf, 0xec},
|
||||
|
||||
/*DNDD*/
|
||||
{0xfe, 0x00},
|
||||
{0x81, 0xb8},
|
||||
{0x82, 0x12},
|
||||
{0x83, 0x0a},
|
||||
{0x84, 0x01},
|
||||
{0x86, 0x50},
|
||||
{0x87, 0x18},
|
||||
{0x88, 0x10},
|
||||
{0x89, 0x70},
|
||||
{0x8a, 0x20},
|
||||
{0x8b, 0x10},
|
||||
{0x8c, 0x08},
|
||||
{0x8d, 0x0a},
|
||||
|
||||
/*Intpee*/
|
||||
{0xfe, 0x00},
|
||||
{0x8f, 0xaa},
|
||||
{0x90, 0x9c},
|
||||
{0x91, 0x52},
|
||||
{0x92, 0x03},
|
||||
{0x93, 0x03},
|
||||
{0x94, 0x08},
|
||||
{0x95, 0x44},
|
||||
{0x97, 0x00},
|
||||
{0x98, 0x00},
|
||||
|
||||
/*ASDE*/
|
||||
{0xfe, 0x00},
|
||||
{0xa1, 0x30},
|
||||
{0xa2, 0x41},
|
||||
{0xa4, 0x30},
|
||||
{0xa5, 0x20},
|
||||
{0xaa, 0x30},
|
||||
{0xac, 0x32},
|
||||
|
||||
/*YCP*/
|
||||
{0xfe, 0x00},
|
||||
{0xd1, 0x3c},
|
||||
{0xd2, 0x3c},
|
||||
{0xd3, 0x38},
|
||||
{0xd6, 0xf4},
|
||||
{0xd7, 0x1d},
|
||||
{0xdd, 0x73},
|
||||
{0xde, 0x84},
|
||||
|
||||
/*Banding*/
|
||||
{0xfe, 0x00},
|
||||
{0x05, 0x01},
|
||||
{0x06, 0xad},
|
||||
{0x07, 0x00},
|
||||
{0x08, 0x10},
|
||||
|
||||
{0xfe, 0x01},
|
||||
{0x25, 0x00},
|
||||
{0x26, 0x9a},
|
||||
|
||||
{0x27, 0x01},
|
||||
{0x28, 0xce},
|
||||
{0x29, 0x02},
|
||||
{0x2a, 0x68},
|
||||
{0x2b, 0x02},
|
||||
{0x2c, 0x68},
|
||||
{0x2d, 0x07},
|
||||
{0x2e, 0xd2},
|
||||
{0x2f, 0x0b},
|
||||
{0x30, 0x6e},
|
||||
{0x31, 0x0e},
|
||||
{0x32, 0x70},
|
||||
{0x33, 0x12},
|
||||
{0x34, 0x0c},
|
||||
{0x3c, 0x30},
|
||||
|
||||
/*Analog&Cisctl*/
|
||||
{0xfe, 0x00},
|
||||
{0x05, 0x01},
|
||||
{0x06, 0xa0},
|
||||
{0x07, 0x00},
|
||||
{0x08, 0x20},
|
||||
{0x0a, 0x78},
|
||||
{0x0c, 0xa0},
|
||||
{0x0d, 0x00}, //window_height [8]
|
||||
{0x0e, 0xf8}, //window_height [7:0] 248
|
||||
{0x0f, 0x01}, //window_width [9:8]
|
||||
{0x10, 0x48}, //window_width [7:0] 328
|
||||
|
||||
{0x55, 0x00},
|
||||
{0x56, 0xf0}, // 240
|
||||
{0x57, 0x01},
|
||||
{0x58, 0x40}, // 320
|
||||
|
||||
/*SPI*/
|
||||
{0xfe, 0x03},
|
||||
{0x5b, 0x40},
|
||||
{0x5c, 0x01},
|
||||
{0x5d, 0xf0},
|
||||
{0x5e, 0x00},
|
||||
|
||||
/*AEC*/
|
||||
{0xfe, 0x01},
|
||||
{0x25, 0x00}, //step
|
||||
{0x26, 0x63},
|
||||
{0x27, 0x01},
|
||||
{0x28, 0x29},
|
||||
{0x29, 0x01},
|
||||
{0x2a, 0x29},
|
||||
{0x2b, 0x01},
|
||||
{0x2c, 0x29},
|
||||
{0x2d, 0x01},
|
||||
{0x2e, 0x29},
|
||||
{0x2f, 0x01},
|
||||
{0x30, 0x29},
|
||||
{0x31, 0x01},
|
||||
{0x32, 0x29},
|
||||
{0x33, 0x01},
|
||||
{0x34, 0x29},
|
||||
{0x3c, 0x00},
|
||||
|
||||
/*measure window*/
|
||||
{0xfe, 0x01},
|
||||
{0xcc, 0x04},
|
||||
{0xcd, 0x04},
|
||||
{0xce, 0x72},
|
||||
{0xcf, 0x52},
|
||||
{REGLIST_TAIL, 0x00},
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
|
||||
#ifndef __GC2145_H__
|
||||
#define __GC2145_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 gc2145_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int gc2145_init(sensor_t *sensor);
|
||||
|
||||
#endif // __GC2145_H__
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* GC2145 register definitions.
|
||||
*/
|
||||
#ifndef __GC2145_REG_REGS_H__
|
||||
#define __GC2145_REG_REGS_H__
|
||||
|
||||
#define CHIP_ID_HIGH 0XF0
|
||||
#define CHIP_ID_LOW 0XF1
|
||||
#define PLL_MODE1 0XF7
|
||||
#define PLL_MODE2 0XF8
|
||||
#define CM_MODE 0XF9
|
||||
#define CLK_DIV_MODE 0XFA
|
||||
#define RESET_RELATED 0xfe // Bit[7]: Software reset
|
||||
// Bit[6]: cm reset
|
||||
// Bit[5]: mipi reset
|
||||
// Bit[4]: CISCTL_restart_n
|
||||
// Bit[3]: NA
|
||||
// Bit[2:0]: page select
|
||||
// 000:page0
|
||||
// 001:page1
|
||||
// 010:page2
|
||||
// 011:page3
|
||||
|
||||
//-page0----------------
|
||||
|
||||
#define P0_EXPOSURE_HIGH 0X03
|
||||
#define P0_EXPOSURE_LOW 0X04
|
||||
#define P0_HB_HIGH 0X05
|
||||
#define P0_HB_LOW 0X06
|
||||
#define P0_VB_HIGH 0X07
|
||||
#define P0_VB_LOW 0X08
|
||||
#define P0_ROW_START_HIGH 0X09
|
||||
#define P0_ROW_START_LOW 0X0A
|
||||
#define P0_COL_START_HIGH 0X0B
|
||||
#define P0_COL_START_LOW 0X0C
|
||||
|
||||
#define P0_WIN_HEIGHT_HIGH 0X0D
|
||||
#define P0_WIN_HEIGHT_LOW 0X0E
|
||||
#define P0_WIN_WIDTH_HIGH 0X0F
|
||||
#define P0_WIN_WIDTH_LOW 0X10
|
||||
#define P0_ANALOG_MODE1 0X17
|
||||
#define P0_ANALOG_MODE2 0X18
|
||||
|
||||
#define P0_SPECIAL_EFFECT 0X83
|
||||
#define P0_OUTPUT_FORMAT 0x84 // Format select
|
||||
// Bit[7]:YUV420 row switch
|
||||
// Bit[6]:YUV420 col switch
|
||||
// Bit[7]:YUV420_legacy
|
||||
// Bit[4:0]:output data mode
|
||||
// 5’h00 Cb Y Cr Y
|
||||
// 5’h01 Cr Y Cb Y
|
||||
// 5’h02 Y Cb Y Cr
|
||||
// 5’h03 Y Cr Y Cb
|
||||
// 5’h04 LSC bypass, C/Y
|
||||
// 5’h05 LSC bypass, Y/C
|
||||
// 5’h06 RGB 565
|
||||
// 5’h0f bypass 10bits
|
||||
// 5’h17 switch odd/even column /row to controls output Bayer pattern
|
||||
// 00 RGBG
|
||||
// 01 RGGB
|
||||
// 10 BGGR
|
||||
// 11 GBRG
|
||||
// 5'h18 DNDD out mode
|
||||
// 5'h19 LSC out mode
|
||||
// 5;h1b EEINTP out mode
|
||||
#define P0_FRAME_START 0X85
|
||||
#define P0_SYNC_MODE 0X86
|
||||
#define P0_MODULE_GATING 0X88
|
||||
#define P0_BYPASS_MODE 0X89
|
||||
#define P0_DEBUG_MODE2 0X8C
|
||||
#define P0_DEBUG_MODE3 0X8D
|
||||
#define P0_CROP_ENABLE 0X90
|
||||
#define P0_OUT_WIN_Y1_HIGH 0X91
|
||||
#define P0_OUT_WIN_Y1_LOW 0X92
|
||||
#define P0_OUT_WIN_X1_HIGH 0X93
|
||||
#define P0_OUT_WIN_X1_LOW 0X94
|
||||
#define P0_OUT_WIN_HEIGHT_HIGH 0X95
|
||||
#define P0_OUT_WIN_HEIGHT_LOW 0X96
|
||||
#define P0_OUT_WIN_WIDTH_HIGH 0X97
|
||||
#define P0_OUT_WIN_WIDTH_LOW 0X98
|
||||
#define P0_SUBSAMPLE 0X99
|
||||
#define P0_SUBSAMPLE_MODE 0X9A
|
||||
|
||||
|
||||
#endif // __GC2145_REG_REGS_H__
|
||||
|
|
@ -1,719 +0,0 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define REG_DLY 0xffff
|
||||
#define REGLIST_TAIL 0x0000 /* Array end token */
|
||||
|
||||
static const uint16_t gc2145_default_init_regs[][2] = {
|
||||
{0xfe, 0xf0},
|
||||
{0xfe, 0xf0},
|
||||
{0xfe, 0xf0},
|
||||
|
||||
{0xfc, 0x06},
|
||||
{0xf6, 0x00},
|
||||
|
||||
{0xf7, 0x1d}, //37 //17 //37 //1d//05
|
||||
{0xf8, 0x83}, //87 //83 //82
|
||||
{0xfa, 0x00},
|
||||
{0xf9, 0xfe}, //ff
|
||||
{0xfd, 0x00},
|
||||
{0xc2, 0x00},
|
||||
{0xf2, 0x0f},
|
||||
//////////////////////////////////////////////////////
|
||||
//////////////////// Analog & Cisctl ////////////////
|
||||
//////////////////////////////////////////////////////
|
||||
{0xfe, 0x00},
|
||||
|
||||
{0x03, 0x04}, //exp time
|
||||
{0x04, 0x62}, //exp time
|
||||
|
||||
{0x05, 0x01}, //00 //hb[11:8]
|
||||
{0x06, 0x3b}, //0b //hb
|
||||
|
||||
{0x09, 0x00}, //row start
|
||||
{0x0a, 0x00}, //
|
||||
{0x0b, 0x00}, //col start
|
||||
{0x0c, 0x00},
|
||||
{0x0d, 0x04}, //height
|
||||
{0x0e, 0xc0},
|
||||
{0x0f, 0x06}, //width
|
||||
{0x10, 0x52},
|
||||
|
||||
{0x12, 0x2e}, //sh_delay 太短 YUV出图异常
|
||||
{0x17, 0x14}, //CISCTL Mode1 [1:0]mirror flip
|
||||
{0x18, 0x22}, //sdark mode
|
||||
{0x19, 0x0f}, // AD pipe number
|
||||
{0x1a, 0x01}, //AD manual switch mode
|
||||
|
||||
{0x1b, 0x4b}, //48 restg Width,SH width
|
||||
{0x1c, 0x07}, //06 帧率快后,横条纹 //12 //TX Width,Space Width
|
||||
{0x1d, 0x10}, //double reset
|
||||
{0x1e, 0x88}, //90//98 //fix 竖线//Analog Mode1,TX high,Coln_r
|
||||
{0x1f, 0x78}, //78 //38 //18 //Analog Mode2,txlow
|
||||
{0x20, 0x03}, //07 //Analog Mode3,comv,ad_clk mode
|
||||
{0x21, 0x40}, //10//20//40 //fix 灯管横条纹
|
||||
{0x22, 0xa0}, //d0//f0 //a2 //Vref vpix FPN严重
|
||||
{0x24, 0x1e},
|
||||
{0x25, 0x01}, //col sel
|
||||
{0x26, 0x10}, //Analog PGA gain1
|
||||
{0x2d, 0x60}, //40//40 //txl drv mode
|
||||
{0x30, 0x01}, //Analog Mode4
|
||||
{0x31, 0x90}, //b0//70 // Analog Mode7 [7:5]rsgh_r灯管横条纹[4:3]isp_g
|
||||
{0x33, 0x06}, //03//02//01 //EQ_hstart_width
|
||||
{0x34, 0x01},
|
||||
//
|
||||
///////////////////////////////////////////////////
|
||||
//////////////////// ISP reg //////////////////////
|
||||
//////////////////////////////////////////////////////
|
||||
{0x80, 0xff}, //outdoor gamma_en, GAMMA_en, CC_en, EE_en, INTP_en, DN_en, DD_en,LSC_en
|
||||
{0x81, 0x24}, //26//24 //BLK dither mode, ll_y_en ,skin_en, edge SA, new_skin_mode, autogray_en,ll_gamma_en,BFF test image
|
||||
{0x82, 0xfa}, //FA //auto_SA, auto_EE, auto_DN, auto_DD, auto_LSC, ABS_en, AWB_en, NA
|
||||
{0x83, 0x00}, //special_effect
|
||||
{0x84, 0x02}, //output format
|
||||
{0x86, 0x03}, //c2 //46 //c2 //sync mode
|
||||
{0x88, 0x03}, //[1]ctl_auto_gating [0]out_auto_gating
|
||||
{0x89, 0x03}, //bypass disable
|
||||
{0x85, 0x30}, //60//frame start cut
|
||||
{0x8a, 0x00}, //ISP_quiet_mode,close aaa pclk,BLK gate mode,exception,close first pipe clock,close dndd clock,close intp clock,DIV_gatedclk_en
|
||||
{0x8b, 0x00}, //[7:6]BFF_gate_mode,[5]BLK switch gain,[4]protect exp,[3:2]pipe gate mode,[1]not split sram,[0]dark current update
|
||||
|
||||
{0xb0, 0x55}, //60 //global gain
|
||||
{0xc3, 0x00}, //[7:4]auto_exp_gamma_th1[11:8],[3:0]auto_exp_gamma_th2[11:8]
|
||||
{0xc4, 0x80}, //auto_exp_gamma_th1[7:0] into
|
||||
{0xc5, 0x90}, //auto_exp_gamma_th2[7:0] out //outdoor gamma
|
||||
{0xc6, 0x38}, //auto_gamma_th1
|
||||
{0xc7, 0x40}, //auto_gamma_th2
|
||||
|
||||
{0xec, 0x06}, //measure window
|
||||
{0xed, 0x04},
|
||||
{0xee, 0x60}, //16 col
|
||||
{0xef, 0x90}, //8 row
|
||||
|
||||
{0xb6, 0x01}, //[0]aec en
|
||||
|
||||
{0x90, 0x01}, //crop
|
||||
{0x91, 0x00},
|
||||
{0x92, 0x00},
|
||||
{0x93, 0x00},
|
||||
{0x94, 0x00}, //08
|
||||
{0x95, 0x04},
|
||||
{0x96, 0xb0},
|
||||
{0x97, 0x06},
|
||||
{0x98, 0x40},
|
||||
|
||||
///////////////////////////////////////////////
|
||||
/////////// BLK ////////////////////////
|
||||
///////////////////////////////////////////////
|
||||
{0x18, 0x02},
|
||||
{0x40, 0x42}, //2b //27
|
||||
{0x41, 0x00}, //80 //dark row sel
|
||||
{0x43, 0x54}, //[7:4]BLK start not smooth [3:0]output start frame
|
||||
|
||||
{0x5e, 0x00}, //00//10 //18
|
||||
{0x5f, 0x00}, //00//10 //18
|
||||
{0x60, 0x00}, //00//10 //18
|
||||
{0x61, 0x00}, //00///10 //18
|
||||
{0x62, 0x00}, //00//10 //18
|
||||
{0x63, 0x00}, //00//10 //18
|
||||
{0x64, 0x00}, //00/10 //18
|
||||
{0x65, 0x00}, //00//10 //18
|
||||
{0x66, 0x20}, //1e
|
||||
{0x67, 0x20}, //1e
|
||||
{0x68, 0x20}, //1e
|
||||
{0x69, 0x20}, //1e
|
||||
|
||||
|
||||
{0x76, 0x00}, //0f
|
||||
|
||||
{0x6a, 0x00}, //06
|
||||
{0x6b, 0x00}, //06
|
||||
{0x6c, 0x3e}, //06
|
||||
{0x6d, 0x3e}, //06
|
||||
{0x6e, 0x3f}, //06
|
||||
{0x6f, 0x3f}, //06
|
||||
{0x70, 0x00}, //06
|
||||
{0x71, 0x00}, //06 //manual offset
|
||||
|
||||
{0x76, 0x00}, //1f//add offset
|
||||
{0x72, 0xf0}, //[7:4]BLK DD th [3:0]BLK various th
|
||||
{0x7e, 0x3c}, //ndark
|
||||
{0x7f, 0x00},
|
||||
|
||||
{0xfe, 0x02},
|
||||
{0x48, 0x15},
|
||||
{0x49, 0x00}, //04//04 //ASDE OFFSET SLOPE
|
||||
{0x4b, 0x0b}, //ASDE y OFFSET SLOPE
|
||||
{0xfe, 0x00},
|
||||
|
||||
///////////////////////////////////////////////
|
||||
/////////// AEC ////////////////////////
|
||||
///////////////////////////////////////////////
|
||||
{0xfe, 0x01},
|
||||
|
||||
{0x01, 0x04}, //AEC X1
|
||||
{0x02, 0xc0}, //AEC X2
|
||||
{0x03, 0x04}, //AEC Y1
|
||||
{0x04, 0x90}, //AEC Y2
|
||||
{0x05, 0x30}, //20 //AEC center X1
|
||||
{0x06, 0x90}, //40 //AEC center X2
|
||||
{0x07, 0x20}, //30 //AEC center Y1
|
||||
{0x08, 0x70}, //60 //AEC center Y2
|
||||
|
||||
{0x09, 0x00}, //AEC show mode
|
||||
{0x0a, 0xc2}, //[7]col gain enable
|
||||
{0x0b, 0x11}, //AEC every N
|
||||
{0x0c, 0x10}, //AEC_mode3 center weight
|
||||
{0x13, 0x40}, //2a //AEC Y target
|
||||
{0x17, 0x00}, //AEC ignore mode
|
||||
{0x1c, 0x11}, //
|
||||
{0x1e, 0x61}, //
|
||||
{0x1f, 0x30}, //40//50 //max pre gain
|
||||
{0x20, 0x40}, //60//40 //max post gain
|
||||
{0x22, 0x80}, //AEC outdoor THD
|
||||
{0x23, 0x20}, //target_Y_low_limit
|
||||
{0xfe, 0x02},
|
||||
{0x0f, 0x04}, //05
|
||||
{0xfe, 0x01},
|
||||
|
||||
{0x12, 0x35}, //35 //[5:4]group_size [3]slope_disable [2]outdoor_enable [0]histogram_enable
|
||||
{0x15, 0x50}, //target_Y_high_limit
|
||||
{0x10, 0x31}, //num_thd_high
|
||||
{0x3e, 0x28}, //num_thd_low
|
||||
{0x3f, 0xe0}, //luma_thd
|
||||
{0x40, 0x20}, //luma_slope
|
||||
{0x41, 0x0f}, //color_diff
|
||||
|
||||
{0xfe, 0x02},
|
||||
{0x0f, 0x05}, //max_col_level
|
||||
///////////////////////////
|
||||
////// INTPEE /////////////
|
||||
///////////////////////////
|
||||
{0xfe, 0x02}, //page2
|
||||
{0x90, 0x6c}, //ac //eeintp mode1
|
||||
{0x91, 0x03}, //02 ////eeintp mode2
|
||||
{0x92, 0xc8}, //44 //low criteria for direction
|
||||
{0x94, 0x66},
|
||||
{0x95, 0xb5},
|
||||
{0x97, 0x64}, //78 ////edge effect
|
||||
{0xa2, 0x11}, //fix direction
|
||||
{0xfe, 0x00},
|
||||
|
||||
/////////////////////////////
|
||||
//////// DNDD///////////////
|
||||
/////////////////////////////
|
||||
{0xfe, 0x02},
|
||||
{0x80, 0xc1}, //c1 //[7]share mode [6]skin mode [5]is 5x5 mode [1:0]noise value select 0:2 1:2.5 2:3 3:4
|
||||
{0x81, 0x08}, //
|
||||
{0x82, 0x08}, //signal a 0.6
|
||||
{0x83, 0x08}, //04 //signal b 2.5
|
||||
|
||||
{0x84, 0x0a}, //10 //05 dark_DD_TH
|
||||
{0x86, 0xf0}, //a0 Y_value_dd_th2
|
||||
{0x87, 0x50}, //90 Y_value_dd_th3
|
||||
{0x88, 0x15}, //60 Y_value_dd_th4
|
||||
|
||||
{0x89, 0x50}, //80 // asde th2
|
||||
{0x8a, 0x30}, //60 // asde th3
|
||||
{0x8b, 0x10}, //30 // asde th4
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
///////////// ASDE ////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
{0xfe, 0x01}, //page 1
|
||||
{0x21, 0x14}, //luma_value_div_sel(分频,与0xef呈2倍关系,增大1,0xef的值减小1倍)
|
||||
//ff ef luma_value read_only
|
||||
|
||||
{0xfe, 0x02}, //page2
|
||||
{0xa3, 0x40}, //ASDE_low_luma_value_LSC_th_H
|
||||
{0xa4, 0x20}, //ASDE_low_luma_value_LSC_th_L
|
||||
|
||||
{0xa5, 0x40}, //80 //ASDE_LSC_gain_dec_slope_H
|
||||
{0xa6, 0x80}, // 80 //ASDE_LSC_gain_dec_slope_L
|
||||
//ff a7 ASDE_LSC_gain_dec //read only
|
||||
|
||||
{0xab, 0x40}, //50 //ASDE_low_luma_value_OT_th
|
||||
|
||||
{0xae, 0x0c}, //[3]EE1_effect_inc_or_dec_high,[2]EE2_effect_inc_or_dec_high,
|
||||
//[1]EE1_effect_inc_or_dec_low,[0]EE2_effect_inc_or_dec_low, 1:inc 0:dec
|
||||
|
||||
{0xb3, 0x34}, //44 //ASDE_EE1_effect_slope_low,ASDE_EE2_effect_slope_low
|
||||
{0xb4, 0x44}, //12 //ASDE_EE1_effect_slope_high,ASDE_EE2_effect_slope_high
|
||||
|
||||
{0xb6, 0x38}, //40//40 //ASDE_auto_saturation_dec_slope
|
||||
{0xb7, 0x02}, //04 //ASDE_sub_saturation_slope
|
||||
{0xb9, 0x30}, //[7:0]ASDE_auto_saturation_low_limit
|
||||
{0x3c, 0x08}, //[3:0]auto gray_dec_slope
|
||||
{0x3d, 0x30}, //[7:0]auto gray_dec_th
|
||||
|
||||
|
||||
{0x4b, 0x0d}, //y offset slope
|
||||
{0x4c, 0x20}, //y offset limit
|
||||
|
||||
{0xfe, 0x00},
|
||||
//
|
||||
///////////////////gamma1////////////////////
|
||||
////Gamma
|
||||
{0xfe, 0x02},
|
||||
{0x10, 0x10},
|
||||
{0x11, 0x15},
|
||||
{0x12, 0x1a},
|
||||
{0x13, 0x1f},
|
||||
{0x14, 0x2c},
|
||||
{0x15, 0x39},
|
||||
{0x16, 0x45},
|
||||
{0x17, 0x54},
|
||||
{0x18, 0x69},
|
||||
{0x19, 0x7d},
|
||||
{0x1a, 0x8f},
|
||||
{0x1b, 0x9d},
|
||||
{0x1c, 0xa9},
|
||||
{0x1d, 0xbd},
|
||||
{0x1e, 0xcd},
|
||||
{0x1f, 0xd9},
|
||||
{0x20, 0xe3},
|
||||
{0x21, 0xea},
|
||||
{0x22, 0xef},
|
||||
{0x23, 0xf5},
|
||||
{0x24, 0xf9},
|
||||
{0x25, 0xff},
|
||||
|
||||
/////auto gamma/////
|
||||
{0xfe, 0x02},
|
||||
{0x26, 0x0f},
|
||||
{0x27, 0x14},
|
||||
{0x28, 0x19},
|
||||
{0x29, 0x1e},
|
||||
{0x2a, 0x27},
|
||||
{0x2b, 0x33},
|
||||
{0x2c, 0x3b},
|
||||
{0x2d, 0x45},
|
||||
{0x2e, 0x59},
|
||||
{0x2f, 0x69},
|
||||
{0x30, 0x7c},
|
||||
{0x31, 0x89},
|
||||
{0x32, 0x98},
|
||||
{0x33, 0xae},
|
||||
{0x34, 0xc0},
|
||||
{0x35, 0xcf},
|
||||
{0x36, 0xda},
|
||||
{0x37, 0xe2},
|
||||
{0x38, 0xe9},
|
||||
{0x39, 0xf3},
|
||||
{0x3a, 0xf9},
|
||||
{0x3b, 0xff},
|
||||
|
||||
///////////////////////////////////////////////
|
||||
/////////// YCP ///////////////////////
|
||||
///////////////////////////////////////////////
|
||||
{0xfe, 0x02},
|
||||
{0xd1, 0x30}, //32 //
|
||||
{0xd2, 0x30}, //32 //
|
||||
{0xd3, 0x45},
|
||||
{0xdd, 0x14}, //edge sa
|
||||
{0xde, 0x86}, //asde auto gray
|
||||
{0xed, 0x01}, //
|
||||
{0xee, 0x28},
|
||||
{0xef, 0x30},
|
||||
{0xd8, 0xd8}, //autogray protecy
|
||||
|
||||
////////////////////////////
|
||||
//////// LSC 0.8///////////////
|
||||
////////////////////////////
|
||||
{0xfe, 0x01},
|
||||
{0xa1, 0x80}, // center_row
|
||||
{0xa2, 0x80}, // center_col
|
||||
{0xa4, 0x00}, // sign of b1
|
||||
{0xa5, 0x00}, // sign of b1
|
||||
{0xa6, 0x70}, // sign of b4
|
||||
{0xa7, 0x00}, // sign of b4
|
||||
{0xa8, 0x77}, // sign of b22
|
||||
{0xa9, 0x77}, // sign of b22
|
||||
{0xaa, 0x1f}, // Q1_b1 of R
|
||||
{0xab, 0x0d}, // Q1_b1 of G
|
||||
{0xac, 0x19}, // Q1_b1 of B
|
||||
{0xad, 0x24}, // Q2_b1 of R
|
||||
{0xae, 0x0e}, // Q2_b1 of G
|
||||
{0xaf, 0x1d}, // Q2_b1 of B
|
||||
{0xb0, 0x12}, // Q3_b1 of R
|
||||
{0xb1, 0x0c}, // Q3_b1 of G
|
||||
{0xb2, 0x06}, // Q3_b1 of B
|
||||
{0xb3, 0x13}, // Q4_b1 of R
|
||||
{0xb4, 0x10}, // Q4_b1 of G
|
||||
{0xb5, 0x0c}, // Q4_b1 of B
|
||||
{0xb6, 0x6a}, // right_b2 of R
|
||||
{0xb7, 0x46}, // right_b2 of G
|
||||
{0xb8, 0x40}, // right_b2 of B
|
||||
{0xb9, 0x0b}, // right_b4 of R
|
||||
{0xba, 0x04}, // right_b4 of G
|
||||
{0xbb, 0x00}, // right_b4 of B
|
||||
{0xbc, 0x53}, // left_b2 of R
|
||||
{0xbd, 0x37}, // left_b2 of G
|
||||
{0xbe, 0x2d}, // left_b2 of B
|
||||
{0xbf, 0x0a}, // left_b4 of R
|
||||
{0xc0, 0x0a}, // left_b4 of G
|
||||
{0xc1, 0x14}, // left_b4 of B
|
||||
{0xc2, 0x34}, // up_b2 of R
|
||||
{0xc3, 0x22}, // up_b2 of G
|
||||
{0xc4, 0x18}, // up_b2 of B
|
||||
{0xc5, 0x23}, // up_b4 of R
|
||||
{0xc6, 0x0f}, // up_b4 of G
|
||||
{0xc7, 0x3c}, // up_b4 of B
|
||||
{0xc8, 0x20}, // down_b2 of R
|
||||
{0xc9, 0x1f}, // down_b2 of G
|
||||
{0xca, 0x17}, // down_b2 of B
|
||||
{0xcb, 0x2d}, // down_b4 of R
|
||||
{0xcc, 0x12}, // down_b4 of G
|
||||
{0xcd, 0x20}, // down_b4 of B
|
||||
{0xd0, 0x61}, // right_up_b22 of R
|
||||
{0xd1, 0x2f}, // right_up_b22 of G
|
||||
{0xd2, 0x39}, // right_up_b22 of B
|
||||
{0xd3, 0x45}, // right_down_b22 of R
|
||||
{0xd4, 0x2c}, // right_down_b22 of G
|
||||
{0xd5, 0x21}, // right_down_b22 of B
|
||||
{0xd6, 0x64}, // left_up_b22 of R
|
||||
{0xd7, 0x2d}, // left_up_b22 of G
|
||||
{0xd8, 0x30}, // left_up_b22 of B
|
||||
{0xd9, 0x42}, // left_down_b22 of R
|
||||
{0xda, 0x27}, // left_down_b22 of G
|
||||
{0xdb, 0x13}, // left_down_b22 of B
|
||||
{0xfe, 0x00},
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
///////////// AWB ////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
{0xfe, 0x01},
|
||||
|
||||
{0x4f, 0x00},
|
||||
{0x4f, 0x00},
|
||||
{0x4b, 0x01},
|
||||
{0x4f, 0x00},
|
||||
|
||||
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x6f},
|
||||
{0x4e, 0x02},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x70},
|
||||
|
||||
{0x4e, 0x02},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x8f},
|
||||
{0x4e, 0x02},
|
||||
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x90},
|
||||
{0x4e, 0x02}, //light
|
||||
|
||||
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xed},
|
||||
{0x4e, 0x33}, //light
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xcd},
|
||||
{0x4e, 0x33}, //light
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xec},
|
||||
{0x4e, 0x03}, //light
|
||||
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x6c},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x6d},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x6e},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x8c},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x8d},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0x8e},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xab},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xac},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xad},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xae},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xcb},
|
||||
{0x4e, 0x03},
|
||||
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xcc},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xce},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xeb},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xec},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xee},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0x0c},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0x0d},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xea},
|
||||
{0x4e, 0x03},
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xaf},
|
||||
{0x4e, 0x03}, //dark
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xcf},
|
||||
{0x4e, 0x03}, //dark
|
||||
|
||||
{0x4c, 0x01},
|
||||
{0x4d, 0xca},
|
||||
{0x4e, 0x04}, //light
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0x0b},
|
||||
{0x4e, 0x05}, //light
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0xc8},
|
||||
{0x4e, 0x06}, //light 100lux
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0xa8},
|
||||
|
||||
{0x4e, 0x06}, //light
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0xa9},
|
||||
{0x4e, 0x06}, //light
|
||||
|
||||
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0x89},
|
||||
{0x4e, 0x06}, //400lux
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0x69},
|
||||
{0x4e, 0x06}, //f12
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0x6a},
|
||||
{0x4e, 0x06}, //f12
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0xc7},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0xe7},
|
||||
{0x4e, 0x07}, //100lux
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x07},
|
||||
{0x4e, 0x07}, //light
|
||||
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0xe8},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x02},
|
||||
{0x4d, 0xe9},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x08},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x09},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x27},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x28},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x29},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x47},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x48},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x49},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x67},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x68},
|
||||
{0x4e, 0x07},
|
||||
{0x4c, 0x03},
|
||||
{0x4d, 0x69},
|
||||
{0x4e, 0x07},
|
||||
|
||||
{0x4f, 0x01},
|
||||
{0xfe, 0x01},
|
||||
{0x50, 0x80}, //AWB_PRE_mode
|
||||
{0x51, 0xa8}, //AWB_pre_THD_min[7:0]
|
||||
{0x52, 0x57}, //AWB_pre_THD_min[15:8] Dominiate luma 0.25=639c 0.22=57a8
|
||||
{0x53, 0x38}, //AWB_pre_THD_min_MIX[7:0]
|
||||
{0x54, 0xc7}, //AWB_pre_THD_min_MIX[15:8] Mix luma 0.5
|
||||
|
||||
{0x56, 0x0e}, //AWB_tone mode
|
||||
{0x58, 0x08}, //AWB_C_num_sel,AWB_D_num_sel
|
||||
{0x5b, 0x00}, //AWB_mix_mode
|
||||
|
||||
{0x5c, 0x74}, //green_num0[7:0]
|
||||
{0x5d, 0x8b}, //green_num0[15:8] 0.35
|
||||
|
||||
{0x61, 0xd3}, //R2G_stand0
|
||||
{0x62, 0xb5}, //B2G_stand0
|
||||
{0x63, 0x00}, //88//a4 //AWB gray mode [7]enable
|
||||
{0x65, 0x04}, //AWB margin
|
||||
|
||||
{0x67, 0xb2}, //R2G_stand3[7:0] FF/CWF
|
||||
{0x68, 0xac}, //B2G_stand3[7:0]
|
||||
{0x69, 0x00}, //R2G_stand4[9:8] B2G_stand4[9:8] R2G_stand3[9:8] B2G_stand3[9:8]
|
||||
{0x6a, 0xb2}, //R2G_stand4[7:0] TL84/TL84&CWF
|
||||
{0x6b, 0xac}, //B2G_stand4[7:0]
|
||||
{0x6c, 0xb2}, //R2G_stand5[7:0] A
|
||||
{0x6d, 0xac}, //B2G_stand5[7:0]
|
||||
{0x6e, 0x40}, //AWB_skin_weight R2G_stand5[9:8] B2G_stand5[9:8]
|
||||
{0x6f, 0x18}, //AWB_indoor_THD (0x21=17 caculate)
|
||||
{0x73, 0x00}, //AWB_indoor_mode
|
||||
|
||||
{0x70, 0x10}, //AWB low luma TH
|
||||
{0x71, 0xe8}, //AWB outdoor TH
|
||||
{0x72, 0xc0}, //outdoor mode
|
||||
{0x74, 0x01}, //[2:0]AWB skip mode 2x2,4x4,4x8,8x8
|
||||
{0x75, 0x01}, //[1:0]AWB_every_N
|
||||
{0x7f, 0x08}, //[3]gray world frame start
|
||||
|
||||
{0x76, 0x70}, //R limit
|
||||
{0x77, 0x58}, //G limit
|
||||
{0x78, 0xa0}, //d8 //B limit
|
||||
|
||||
{0xfe, 0x00},
|
||||
//
|
||||
//////////////////////////////////////////
|
||||
/////////// CC ////////////////////////
|
||||
//////////////////////////////////////////
|
||||
{0xfe, 0x02},
|
||||
|
||||
{0xc0, 0x01}, //[5:4] CC mode [0]CCT enable
|
||||
|
||||
{0xC1, 0x50}, //D50/D65
|
||||
{0xc2, 0xF9},
|
||||
{0xc3, 0x00}, //0
|
||||
{0xc4, 0xe8}, //e0
|
||||
{0xc5, 0x48},
|
||||
{0xc6, 0xf0},
|
||||
|
||||
|
||||
{0xC7, 0x50},
|
||||
{0xc8, 0xf2},
|
||||
{0xc9, 0x00},
|
||||
{0xcA, 0xE0},
|
||||
{0xcB, 0x45},
|
||||
{0xcC, 0xec},
|
||||
|
||||
{0xCd, 0x45},
|
||||
{0xce, 0xf0},
|
||||
{0xcf, 0x00},
|
||||
{0xe3, 0xf0},
|
||||
{0xe4, 0x45},
|
||||
{0xe5, 0xe8},
|
||||
|
||||
|
||||
{0xfe, 0x00},
|
||||
|
||||
{0xf2, 0x0f},
|
||||
|
||||
|
||||
//////////////frame rate 50Hz
|
||||
{0xfe, 0x00},
|
||||
|
||||
{0xf7, 0x1d},
|
||||
{0xf8, 0x84},
|
||||
{0xfa, 0x00},
|
||||
|
||||
{0x05, 0x01}, //hb
|
||||
{0x06, 0x3b},
|
||||
{0x07, 0x01}, //Vb
|
||||
{0x08, 0x0b},
|
||||
|
||||
{0xfe, 0x01},
|
||||
{0x25, 0x01},
|
||||
{0x26, 0x32}, //step
|
||||
{0x27, 0x03}, //8.15fps
|
||||
{0x28, 0x96},
|
||||
{0x29, 0x03}, //8.15fps
|
||||
{0x2a, 0x96},
|
||||
{0x2b, 0x03}, //8.15fps
|
||||
{0x2c, 0x96},
|
||||
{0x2d, 0x04}, //8.15fps
|
||||
{0x2e, 0x62},
|
||||
{0x3c, 0x00},
|
||||
{0xfe, 0x00},
|
||||
|
||||
/////////dark sun//////
|
||||
{0xfe, 0x00},
|
||||
{0x18, 0x22},
|
||||
{0xfe, 0x02},
|
||||
{0x40, 0xbf},
|
||||
{0x46, 0xcf},
|
||||
{0xfe, 0x00},
|
||||
|
||||
{0xfe, 0x00},
|
||||
|
||||
{0xf7, 0x1d},
|
||||
{0xf8, 0x84},
|
||||
{0xfa, 0x10},
|
||||
|
||||
{0x05, 0x01}, //hb
|
||||
{0x06, 0x18},
|
||||
{0x07, 0x00}, //Vb
|
||||
{0x08, 0x2e},
|
||||
|
||||
{0xfe, 0x01},
|
||||
{0x25, 0x00},
|
||||
{0x26, 0xa2}, //step
|
||||
{0x27, 0x01},
|
||||
{0x28, 0xe6},
|
||||
{0x29, 0x01},
|
||||
{0x2a, 0xe6},
|
||||
{0x2b, 0x01},
|
||||
{0x2c, 0xe6},
|
||||
{0x2d, 0x04}, // AEC_exp_level4[12:8]
|
||||
{0x2e, 0x62}, // AEC_exp_level4[7:0]
|
||||
{0x3c, 0x00},
|
||||
{0xfe, 0x00},
|
||||
|
||||
{0x09, 0x01}, //row start
|
||||
{0x0a, 0xd0}, //
|
||||
{0x0b, 0x02}, //col start
|
||||
{0x0c, 0x70},
|
||||
{0x0d, 0x01}, //height
|
||||
{0x0e, 0x00},
|
||||
{0x0f, 0x01}, //width
|
||||
{0x10, 0x50},
|
||||
|
||||
{0x90, 0x01}, //crop
|
||||
{0x91, 0x00},
|
||||
{0x92, 0x00},
|
||||
{0x93, 0x00},
|
||||
{0x94, 0x00},
|
||||
{0x95, 0x00},
|
||||
{0x96, 0xf0},
|
||||
{0x97, 0x01},
|
||||
{0x98, 0x40},
|
||||
|
||||
|
||||
{REGLIST_TAIL, 0x00},
|
||||
};
|
||||
|
|
@ -11,24 +11,6 @@
|
|||
|
||||
#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 nt99141_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int nt99141_init(sensor_t *sensor);
|
||||
int NT99141_init(sensor_t *sensor);
|
||||
|
||||
#endif // __NT99141_H__
|
||||
|
|
|
|||
|
|
@ -9,24 +9,5 @@
|
|||
#ifndef __OV2640_H__
|
||||
#define __OV2640_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 ov2640_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int ov2640_init(sensor_t *sensor);
|
||||
|
||||
#endif // __OV2640_H__
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ typedef enum {
|
|||
#define HSTOP 0x18
|
||||
#define VSTART 0x19
|
||||
#define VSTOP 0x1A
|
||||
#define REG_MIDH 0x1C
|
||||
#define REG_MIDL 0x1D
|
||||
#define MIDH 0x1C
|
||||
#define MIDL 0x1D
|
||||
#define AEW 0x24
|
||||
#define AEB 0x25
|
||||
#define VV 0x26
|
||||
|
|
|
|||
|
|
@ -11,24 +11,6 @@
|
|||
|
||||
#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 ov3660_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int ov3660_init(sensor_t *sensor);
|
||||
|
||||
#endif // __OV3660_H__
|
||||
|
|
|
|||
|
|
@ -4,24 +4,6 @@
|
|||
|
||||
#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 ov5640_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int ov5640_init(sensor_t *sensor);
|
||||
|
||||
#endif // __OV5640_H__
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ static const DRAM_ATTR uint16_t sensor_default_regs[][2] = {
|
|||
{ISP_CONTROL_01, 0x83}, // turn color matrix, awb and SDE
|
||||
|
||||
//sys reset
|
||||
{0x3000, 0x20}, // reset MCU
|
||||
{REG_DLY, 10}, // delay 10ms
|
||||
{0x3000, 0x00},
|
||||
{0x3002, 0x1c},
|
||||
|
||||
//clock enable
|
||||
|
|
|
|||
|
|
@ -10,24 +10,5 @@
|
|||
#define __OV7670_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 ov7670_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int ov7670_init(sensor_t *sensor);
|
||||
|
||||
#endif // __OV7670_H__
|
||||
|
|
|
|||
|
|
@ -10,24 +10,5 @@
|
|||
#define __OV7725_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 ov7725_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int ov7725_init(sensor_t *sensor);
|
||||
|
||||
#endif // __OV7725_H__
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* SC030IOT DVP driver.
|
||||
*
|
||||
*/
|
||||
#ifndef __SC030IOT_H__
|
||||
#define __SC030IOT_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 sc030iot_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int sc030iot_init(sensor_t *sensor);
|
||||
|
||||
#endif // __SC030IOT_H__
|
||||
|
|
@ -1,491 +0,0 @@
|
|||
//version: V01P00_20220303
|
||||
//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:3.3V// 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=SC031IOT
|
||||
width=640
|
||||
height=480
|
||||
port=1
|
||||
type=2
|
||||
pin=3
|
||||
SlaveID=0xd0
|
||||
mode=0
|
||||
FlagReg=0xf7
|
||||
FlagMask=0xff
|
||||
FlagData=0xfa
|
||||
FlagReg1=0xf8
|
||||
FlagMask1=0xff
|
||||
FlagData1=0x46
|
||||
outformat=0
|
||||
mclk=20
|
||||
avdd=2.80000
|
||||
dovdd=2.800000
|
||||
dvdd=1.5
|
||||
|
||||
Ext0=0
|
||||
Ext1=0
|
||||
Ext2=0
|
||||
AFVCC=0.0000
|
||||
VPP=0.000000
|
||||
*/
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t sc030iot_default_init_regs[][2] = {
|
||||
{0xf0, 0x30},
|
||||
{0x01, 0xff},
|
||||
{0x02, 0xff},
|
||||
{0x22, 0x07},
|
||||
{0x19, 0xff},
|
||||
{0x3f, 0x82},
|
||||
{0x30, 0x02},
|
||||
{0xf0, 0x01},
|
||||
{0x70, 0x00},
|
||||
{0x71, 0x80},
|
||||
{0x72, 0x20},
|
||||
{0x73, 0x00},
|
||||
{0x74, 0xe0},
|
||||
{0x75, 0x10},
|
||||
{0x76, 0x81},
|
||||
{0x77, 0x88},
|
||||
{0x78, 0xe1},
|
||||
{0x79, 0x01},
|
||||
{0xf5, 0x01},
|
||||
{0xf4, 0x0a},
|
||||
{0xf0, 0x36},
|
||||
{0x37, 0x79},
|
||||
{0x31, 0x82},
|
||||
{0x3e, 0x60},
|
||||
{0x30, 0xf0},
|
||||
{0x33, 0x33},
|
||||
{0xf0, 0x32},
|
||||
{0x48, 0x02},
|
||||
{0xf0, 0x33},
|
||||
{0x02, 0x12},
|
||||
{0x7c, 0x02},
|
||||
{0x7d, 0x0e},
|
||||
{0xa2, 0x04},
|
||||
{0x5e, 0x06},
|
||||
{0x5f, 0x0a},
|
||||
{0x0b, 0x58},
|
||||
{0x06, 0x38},
|
||||
{0xf0, 0x32},
|
||||
{0x48, 0x02},
|
||||
{0xf0, 0x39},
|
||||
{0x02, 0x70},
|
||||
{0xf0, 0x45},
|
||||
{0x09, 0x1c},
|
||||
{0xf0, 0x37},
|
||||
{0x22, 0x0d},
|
||||
{0xf0, 0x33},
|
||||
{0x33, 0x10},
|
||||
{0xb1, 0x80},
|
||||
{0x34, 0x40},
|
||||
{0x0b, 0x54},
|
||||
{0xb2, 0x78},
|
||||
{0xf0, 0x36},
|
||||
{0x11, 0x80},
|
||||
{0xf0, 0x30},
|
||||
{0x38, 0x44},
|
||||
{0xf0, 0x33},
|
||||
{0xb3, 0x51},
|
||||
{0x01, 0x10},
|
||||
{0x0b, 0x6c},
|
||||
{0x06, 0x24},
|
||||
{0xf0, 0x36},
|
||||
{0x31, 0x82},
|
||||
{0x3e, 0x60},
|
||||
{0x30, 0xf0},
|
||||
{0x33, 0x33},
|
||||
{0xf0, 0x34},
|
||||
{0x9f, 0x02},
|
||||
{0xa6, 0x40},
|
||||
{0xa7, 0x47},
|
||||
{0xe8, 0x5f},
|
||||
{0xa8, 0x51},
|
||||
{0xa9, 0x44},
|
||||
{0xe9, 0x36},
|
||||
{0xf0, 0x33},
|
||||
{0xb3, 0x51},
|
||||
{0x64, 0x17},
|
||||
{0x90, 0x01},
|
||||
{0x91, 0x03},
|
||||
{0x92, 0x07},
|
||||
{0x01, 0x10},
|
||||
{0x93, 0x10},
|
||||
{0x94, 0x10},
|
||||
{0x95, 0x10},
|
||||
{0x96, 0x01},
|
||||
{0x97, 0x07},
|
||||
{0x98, 0x1f},
|
||||
{0x99, 0x10},
|
||||
{0x9a, 0x20},
|
||||
{0x9b, 0x28},
|
||||
{0x9c, 0x28},
|
||||
{0xf0, 0x36},
|
||||
{0x70, 0x54},
|
||||
{0xb6, 0x40},
|
||||
{0xb7, 0x41},
|
||||
{0xb8, 0x43},
|
||||
{0xb9, 0x47},
|
||||
{0xba, 0x4f},
|
||||
{0xb0, 0x8b},
|
||||
{0xb1, 0x8b},
|
||||
{0xb2, 0x8b},
|
||||
{0xb3, 0x9b},
|
||||
{0xb4, 0xb8},
|
||||
{0xb5, 0xf0},
|
||||
{0x7e, 0x41},
|
||||
{0x7f, 0x47},
|
||||
{0x77, 0x80},
|
||||
{0x78, 0x84},
|
||||
{0x79, 0x8a},
|
||||
{0xa0, 0x47},
|
||||
{0xa1, 0x5f},
|
||||
{0x96, 0x43},
|
||||
{0x97, 0x44},
|
||||
{0x98, 0x54},
|
||||
{0xf0, 0x00},
|
||||
{0xf0, 0x01},
|
||||
{0x73, 0x00},
|
||||
{0x74, 0xe0},
|
||||
{0x70, 0x00},
|
||||
{0x71, 0x80},
|
||||
{0xf0, 0x36},
|
||||
{0x37, 0x74},
|
||||
{0xf0, 0x3f},
|
||||
{0x03, 0xa1},
|
||||
{0xf0, 0x36},//cvbs_off
|
||||
{0x11, 0x80},
|
||||
{0xf0, 0x01},
|
||||
{0x79, 0xc1},
|
||||
{0xf0, 0x37},
|
||||
{0x24, 0x21},
|
||||
{0xf0, 0x36},
|
||||
{0x41, 0x00},
|
||||
{0xea, 0x09},
|
||||
{0xeb, 0x03},
|
||||
{0xec, 0x19},
|
||||
{0xed, 0x38},
|
||||
{0xe9, 0x30},
|
||||
{0xf0, 0x33},
|
||||
{0x33, 0x00},
|
||||
{0x34, 0x00},
|
||||
{0xb1, 0x00},
|
||||
{0xf0, 0x00},
|
||||
{0xe0, 0x04},
|
||||
{0xf0, 0x01},
|
||||
{0x73, 0x00},
|
||||
{0x74, 0xe0},
|
||||
{0x70, 0x00},
|
||||
{0x71, 0x80},
|
||||
{0xf0, 0x36},
|
||||
{0x32, 0x44},
|
||||
{0xf0, 0x36},
|
||||
{0x3e, 0xe0},
|
||||
{0x70, 0x56},
|
||||
{0x7c, 0x43},
|
||||
{0x7d, 0x47},
|
||||
{0x74, 0x00},
|
||||
{0x75, 0x00},
|
||||
{0x76, 0x00},
|
||||
{0xa0, 0x47},
|
||||
{0xa1, 0x5f},
|
||||
{0x96, 0x22},
|
||||
{0x97, 0x22},
|
||||
{0x98, 0x22},
|
||||
{0xf0, 0x00},
|
||||
{0x72, 0x38},
|
||||
{0x7a, 0x80},
|
||||
{0x85, 0x18},
|
||||
{0x9b, 0x35},
|
||||
{0x9e, 0x20},
|
||||
{0xd0, 0x66},
|
||||
{0xd1, 0x34},
|
||||
{0Xd3, 0x44},
|
||||
{0xd6, 0x44},
|
||||
{0xb0, 0x41},
|
||||
{0xb2, 0x48},
|
||||
{0xb3, 0xf4},
|
||||
{0xb4, 0x0b},
|
||||
{0xb5, 0x78},
|
||||
{0xba, 0xff},
|
||||
{0xbb, 0xc0},
|
||||
{0xbc, 0x90},
|
||||
{0xbd, 0x3a},
|
||||
{0xc1, 0x67},
|
||||
{0xf0, 0x01},
|
||||
{0x20, 0x11},
|
||||
{0x23, 0x90},
|
||||
{0x24, 0x15},
|
||||
{0x25, 0x87},
|
||||
{0xbc, 0x9f},
|
||||
{0xbd, 0x3a},
|
||||
{0x48, 0xe6},
|
||||
{0x49, 0xc0},
|
||||
{0x4a, 0xd0},
|
||||
{0x4b, 0x48},
|
||||
|
||||
// [cvbs_on]
|
||||
{0xf0, 0x36},
|
||||
{0x11, 0x00},
|
||||
{0xf0, 0x01},
|
||||
{0x79, 0xf1},
|
||||
|
||||
// [cvbs_off]
|
||||
{0xf0, 0x36},
|
||||
{0x11, 0x80},
|
||||
{0xf0, 0x01},
|
||||
{0x79, 0xc1},
|
||||
};
|
||||
|
||||
/*
|
||||
[Sensor]
|
||||
SensorName=SC031IOT
|
||||
width=640
|
||||
height=480
|
||||
port=1
|
||||
type=2
|
||||
pin=3
|
||||
SlaveID=0xd0
|
||||
mode=0
|
||||
FlagReg=0xf7
|
||||
FlagMask=0xff
|
||||
FlagData=0xfa
|
||||
FlagReg1=0xf8
|
||||
FlagMask1=0xff
|
||||
FlagData1=0x46
|
||||
outformat=0
|
||||
mclk=27
|
||||
avdd=2.80000
|
||||
dovdd=2.800000
|
||||
dvdd=1.5
|
||||
|
||||
Ext0=0
|
||||
Ext1=0
|
||||
Ext2=0
|
||||
AFVCC=0.0000
|
||||
VPP=0.000000
|
||||
*/
|
||||
/* 27M MCLK, 30fps
|
||||
static const uint8_t sc030iot_default_init_regs[][2] = {
|
||||
{0xf0, 0x30},
|
||||
{0x01, 0xff},
|
||||
{0x02, 0xff},
|
||||
{0x22, 0x07},
|
||||
{0x19, 0xff},
|
||||
{0x3f, 0x82},
|
||||
{0x30, 0x02},
|
||||
{0xf0, 0x01},
|
||||
{0x70, 0x00},
|
||||
{0x71, 0x80},
|
||||
{0x72, 0x20},
|
||||
{0x73, 0x00},
|
||||
{0x74, 0xe0},
|
||||
{0x75, 0x10},
|
||||
{0x76, 0x81},
|
||||
{0x77, 0x88},
|
||||
{0x78, 0xe1},
|
||||
{0x79, 0x01},
|
||||
{0xf5, 0x01},
|
||||
{0xf4, 0x0a},
|
||||
{0xf0, 0x36},
|
||||
{0x37, 0x79},
|
||||
{0x31, 0x82},
|
||||
{0x3e, 0x60},
|
||||
{0x30, 0xf0},
|
||||
{0x33, 0x33},
|
||||
{0xf0, 0x32},
|
||||
{0x48, 0x02},
|
||||
{0xf0, 0x33},
|
||||
{0x02, 0x12},
|
||||
{0x7c, 0x02},
|
||||
{0x7d, 0x0e},
|
||||
{0xa2, 0x04},
|
||||
{0x5e, 0x06},
|
||||
{0x5f, 0x0a},
|
||||
{0x0b, 0x58},
|
||||
{0x06, 0x38},
|
||||
{0xf0, 0x32},
|
||||
{0x48, 0x02},
|
||||
{0xf0, 0x39},
|
||||
{0x02, 0x70},
|
||||
{0xf0, 0x45},
|
||||
{0x09, 0x1c},
|
||||
{0xf0, 0x37},
|
||||
{0x22, 0x0d},
|
||||
{0xf0, 0x33},
|
||||
{0x33, 0x10},
|
||||
{0xb1, 0x80},
|
||||
{0x34, 0x40},
|
||||
{0x0b, 0x54},
|
||||
{0xb2, 0x78},
|
||||
{0xf0, 0x36},
|
||||
{0x11, 0x80},
|
||||
{0xf0, 0x30},
|
||||
{0x38, 0x44},
|
||||
{0xf0, 0x33},
|
||||
{0xb3, 0x51},
|
||||
{0x01, 0x10},
|
||||
{0x0b, 0x6c},
|
||||
{0x06, 0x24},
|
||||
{0xf0, 0x36},
|
||||
{0x31, 0x82},
|
||||
{0x3e, 0x60},
|
||||
{0x30, 0xf0},
|
||||
{0x33, 0x33},
|
||||
{0xf0, 0x34},
|
||||
{0x9f, 0x02},
|
||||
{0xa6, 0x40},
|
||||
{0xa7, 0x47},
|
||||
{0xe8, 0x5f},
|
||||
{0xa8, 0x51},
|
||||
{0xa9, 0x44},
|
||||
{0xe9, 0x36},
|
||||
{0xf0, 0x33},
|
||||
{0xb3, 0x51},
|
||||
{0x64, 0x17},
|
||||
{0x90, 0x01},
|
||||
{0x91, 0x03},
|
||||
{0x92, 0x07},
|
||||
{0x01, 0x10},
|
||||
{0x93, 0x10},
|
||||
{0x94, 0x10},
|
||||
{0x95, 0x10},
|
||||
{0x96, 0x01},
|
||||
{0x97, 0x07},
|
||||
{0x98, 0x1f},
|
||||
{0x99, 0x10},
|
||||
{0x9a, 0x20},
|
||||
{0x9b, 0x28},
|
||||
{0x9c, 0x28},
|
||||
{0xf0, 0x36},
|
||||
{0x70, 0x54},
|
||||
{0xb6, 0x40},
|
||||
{0xb7, 0x41},
|
||||
{0xb8, 0x43},
|
||||
{0xb9, 0x47},
|
||||
{0xba, 0x4f},
|
||||
{0xb0, 0x8b},
|
||||
{0xb1, 0x8b},
|
||||
{0xb2, 0x8b},
|
||||
{0xb3, 0x9b},
|
||||
{0xb4, 0xb8},
|
||||
{0xb5, 0xf0},
|
||||
{0x7e, 0x41},
|
||||
{0x7f, 0x47},
|
||||
{0x77, 0x80},
|
||||
{0x78, 0x84},
|
||||
{0x79, 0x8a},
|
||||
{0xa0, 0x47},
|
||||
{0xa1, 0x5f},
|
||||
{0x96, 0x43},
|
||||
{0x97, 0x44},
|
||||
{0x98, 0x54},
|
||||
{0xf0, 0x00},
|
||||
{0xf0, 0x01},
|
||||
{0x73, 0x00},
|
||||
{0x74, 0xe0},
|
||||
{0x70, 0x00},
|
||||
{0x71, 0x80},
|
||||
{0xf0, 0x36},
|
||||
{0x37, 0x74},
|
||||
{0xf0, 0x3f},
|
||||
{0x03, 0x93},
|
||||
{0xf0, 0x36},//cvbs_off
|
||||
{0x11, 0x80},
|
||||
{0xf0, 0x01},
|
||||
{0x79, 0xc1},
|
||||
{0xf0, 0x37},
|
||||
{0x24, 0x21},
|
||||
{0xf0, 0x36},
|
||||
{0x41, 0x00},
|
||||
{0xe9, 0x2c},
|
||||
{0xf0, 0x33},
|
||||
{0x33, 0x00},
|
||||
{0x34, 0x00},
|
||||
{0xb1, 0x00},
|
||||
{0xf0, 0x00},
|
||||
{0xe0, 0x04},
|
||||
{0xf0, 0x01},
|
||||
{0x73, 0x00},
|
||||
{0x74, 0xe0},
|
||||
{0x70, 0x00},
|
||||
{0x71, 0x80},
|
||||
{0xf0, 0x36},
|
||||
{0x32, 0x44},
|
||||
{0xf0, 0x36},
|
||||
{0x3e, 0xe0},
|
||||
{0x70, 0x56},
|
||||
{0x7c, 0x43},
|
||||
{0x7d, 0x47},
|
||||
{0x74, 0x00},
|
||||
{0x75, 0x00},
|
||||
{0x76, 0x00},
|
||||
{0xa0, 0x47},
|
||||
{0xa1, 0x5f},
|
||||
{0x96, 0x22},
|
||||
{0x97, 0x22},
|
||||
{0x98, 0x22},
|
||||
{0xf0, 0x00},
|
||||
{0x72, 0x38},
|
||||
{0x7a, 0x80},
|
||||
{0x85, 0x18},
|
||||
{0x9b, 0x35},
|
||||
{0x9e, 0x20},
|
||||
{0xd0, 0x66},
|
||||
{0xd1, 0x34},
|
||||
{0Xd3, 0x44},
|
||||
{0xd6, 0x44},
|
||||
{0xb0, 0x41},
|
||||
{0xb2, 0x48},
|
||||
{0xb3, 0xf4},
|
||||
{0xb4, 0x0b},
|
||||
{0xb5, 0x78},
|
||||
{0xba, 0xff},
|
||||
{0xbb, 0xc0},
|
||||
{0xbc, 0x90},
|
||||
{0xbd, 0x3a},
|
||||
{0xc1, 0x67},
|
||||
{0xf0, 0x01},
|
||||
{0x20, 0x11},
|
||||
{0x23, 0x90},
|
||||
{0x24, 0x15},
|
||||
{0x25, 0x87},
|
||||
{0xbc, 0x9f},
|
||||
{0xbd, 0x3a},
|
||||
{0x48, 0xe6},
|
||||
{0x49, 0xc0},
|
||||
{0x4a, 0xd0},
|
||||
{0x4b, 0x48},
|
||||
|
||||
// [cvbs_on]
|
||||
{0xf0, 0x36},
|
||||
{0x11, 0x00},
|
||||
{0xf0, 0x01},
|
||||
{0x79, 0xf1},
|
||||
|
||||
// [cvbs_off]
|
||||
{0xf0, 0x36},
|
||||
{0x11, 0x80},
|
||||
{0xf0, 0x01},
|
||||
{0x79, 0xc1},
|
||||
};
|
||||
|
||||
*/
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* 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__
|
||||
|
|
@ -1,316 +0,0 @@
|
|||
// 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;
|
||||
};
|
||||
|
||||
static const struct sc031gs_regval sc031gs_reset_regs[] = {
|
||||
{0x0103, 0x01}, // soft reset.
|
||||
{REG_DELAY, 10}, // delay.
|
||||
};
|
||||
|
||||
// 200*200, xclk=10M, fps=120fps
|
||||
static const struct sc031gs_regval sc031gs_200x200_init_regs[] = {
|
||||
{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},
|
||||
};
|
||||
|
||||
// 640*480, xclk=20M, fps=50fps, xclk=10M, fps=25fps
|
||||
static const struct sc031gs_regval sc031gs_640x480_50fps_init_regs[] = {
|
||||
{0x0100, 0x00},
|
||||
{0x36e9, 0x80},
|
||||
{0x36f9, 0x80},
|
||||
{0x300f, 0x0f},
|
||||
{0x3018, 0x1f},
|
||||
{0x3019, 0xff},
|
||||
{0x301c, 0xb4},
|
||||
{0x301f, 0x6c},
|
||||
{0x3028, 0x82},
|
||||
{0x3200, 0x00},
|
||||
{0x3201, 0x00},
|
||||
{0x3202, 0x00},
|
||||
{0x3203, 0x08},
|
||||
{0x3204, 0x02},
|
||||
{0x3205, 0x8f},
|
||||
{0x3206, 0x01},
|
||||
{0x3207, 0xf7},
|
||||
{SC031GS_OUTPUT_WINDOW_WIDTH_H_REG, 0x02},
|
||||
{SC031GS_OUTPUT_WINDOW_WIDTH_L_REG, 0x80},
|
||||
{SC031GS_OUTPUT_WINDOW_HIGH_H_REG, 0x01},
|
||||
{SC031GS_OUTPUT_WINDOW_HIGH_L_REG, 0xe0},
|
||||
{0x320c, 0x03},
|
||||
{0x320d, 0x6e},
|
||||
{0x320e, 0x04},
|
||||
{0x320f, 0x72},
|
||||
{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, 0x08},
|
||||
{0x3220, 0x10},
|
||||
{0x3223, 0x50},
|
||||
{0x3250, 0xf0},
|
||||
{0x3251, 0x02},
|
||||
{0x3252, 0x03},
|
||||
{0x3253, 0xb0},
|
||||
{0x3254, 0x02},
|
||||
{0x3255, 0x07},
|
||||
{0x3304, 0x48},
|
||||
{0x3306, 0x38},
|
||||
{0x3309, 0x68},
|
||||
{0x330b, 0xe0},
|
||||
{0x330c, 0x18},
|
||||
{0x330f, 0x20},
|
||||
{0x3310, 0x10},
|
||||
{0x3314, 0x6d},
|
||||
{0x3315, 0x38},
|
||||
{0x3316, 0x68},
|
||||
{0x3317, 0x0f},
|
||||
{0x3329, 0x5c},
|
||||
{0x332d, 0x5c},
|
||||
{0x332f, 0x60},
|
||||
{0x3335, 0x64},
|
||||
{0x3344, 0x64},
|
||||
{0x335b, 0x80},
|
||||
{0x335f, 0x80},
|
||||
{0x3366, 0x06},
|
||||
{0x3385, 0x31},
|
||||
{0x3387, 0x51},
|
||||
{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, 0x36},
|
||||
{0x36eb, 0x1a},
|
||||
{0x36ec, 0x0a},
|
||||
{0x36ed, 0x23},
|
||||
{0x36fa, 0x36},
|
||||
{0x36fb, 0x10},
|
||||
{0x36fc, 0x01},
|
||||
{0x36fd, 0x03},
|
||||
{0x3908, 0x91},
|
||||
{0x3d08, 0x01},
|
||||
{0x3e01, 0x14},
|
||||
{0x3e02, 0x80},
|
||||
{0x3e06, 0x0c},
|
||||
{0x3f04, 0x03},
|
||||
{0x3f05, 0x4e},
|
||||
{0x4500, 0x59},
|
||||
{0x4501, 0xc4},
|
||||
{0x4809, 0x01},
|
||||
{0x4837, 0x1b},
|
||||
{0x5011, 0x00},
|
||||
{0x36e9, 0x20},
|
||||
{0x36f9, 0x24},
|
||||
{0x0100, 0x01}, // must write 0x0100 with 0x01, must delay no less then 7ms
|
||||
//delay 10ms
|
||||
{REG_DELAY, 0X0a},
|
||||
{0x4418, 0x08},
|
||||
{0x4419, 0x80},
|
||||
{0x363d, 0x10},
|
||||
{0x3630, 0x48},
|
||||
{REG_NULL, 0x00},
|
||||
};
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* SC101IOT DVP driver.
|
||||
*
|
||||
*/
|
||||
#ifndef __SC101IOT_H__
|
||||
#define __SC101IOT_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 sc101iot_detect(int slv_addr, sensor_id_t *id);
|
||||
|
||||
/**
|
||||
* @brief initialize sensor function pointers
|
||||
*
|
||||
* @param sensor pointer of sensor
|
||||
* @return
|
||||
* Always 0
|
||||
*/
|
||||
int sc101iot_init(sensor_t *sensor);
|
||||
|
||||
#endif // __SC101IOT_H__
|
||||
|
|
@ -1,257 +0,0 @@
|
|||
//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=DemoSens
|
||||
|
||||
[Vendor]
|
||||
VendorName=SmartSens
|
||||
I2C_CRC=0
|
||||
|
||||
[Sensor]
|
||||
SensorName=SC101AP_raw
|
||||
width=1280
|
||||
height=720
|
||||
port=1
|
||||
type=2
|
||||
pin=3
|
||||
SlaveID=0xd0
|
||||
mode=0
|
||||
FlagReg=0xf7
|
||||
FlagMask=0xff
|
||||
FlagData=0xda
|
||||
FlagReg1=0xf8
|
||||
FlagMask1=0xff
|
||||
FlagData1=0x4a
|
||||
outformat=0
|
||||
mclk=20
|
||||
avdd=2.800000
|
||||
dovdd=2.800000
|
||||
dvdd=1.200000
|
||||
|
||||
Ext0=0
|
||||
Ext1=0
|
||||
Ext2=0
|
||||
AFVCC=0.00
|
||||
VPP=0.000000
|
||||
*/
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t sc101iot_default_init_regs[][2] = {
|
||||
#if CONFIG_SC101IOT_720P_15FPS_ENABLED // 720P+YUV422+15FPS sensor default regs
|
||||
/* Here are some test results:
|
||||
# size xclk fps pic pclk
|
||||
# ------- ------- ------ --------- ------- --- --- --- --- ---
|
||||
# 720p 4 3 err
|
||||
# 720p 8 5 normal 15
|
||||
# 720p 10 7.8 normal 19
|
||||
# 720p 20 15 warning 37.5
|
||||
# VGA 8 6 normal
|
||||
# VGA 20 16 normal
|
||||
|
||||
*/
|
||||
{0xf0, 0x30},
|
||||
{0x01, 0xff},
|
||||
{0x02, 0xe0},
|
||||
{0x30, 0x10},
|
||||
{0x3f, 0x81},
|
||||
{0xf0, 0x00},
|
||||
{0x70, 0x6b},
|
||||
{0x72, 0x30},
|
||||
{0x84, 0xb4},
|
||||
{0x8b, 0x00},
|
||||
{0x8c, 0x20},
|
||||
{0x8d, 0x02},
|
||||
{0x8e, 0xec},
|
||||
{0x9e, 0x10},
|
||||
{0xb0, 0xc1},
|
||||
{0xc8, 0x10},
|
||||
{0xc9, 0x10},
|
||||
{0xc6, 0x00},
|
||||
{0xe0, 0x0f},
|
||||
{0xb5, 0xf0},
|
||||
{0xde, 0x80},
|
||||
{0xb5, 0xf0},
|
||||
{0xde, 0x80},
|
||||
{0xb2, 0x50},
|
||||
{0xb3, 0xfc},
|
||||
{0xb4, 0x40},
|
||||
{0xb5, 0xc0},
|
||||
{0xb6, 0x50},
|
||||
{0xb7, 0xfc},
|
||||
{0xb8, 0x40},
|
||||
{0xb9, 0xc0},
|
||||
{0xba, 0xff},
|
||||
{0xbb, 0xcc},
|
||||
{0xbc, 0xa9},
|
||||
{0xbd, 0x7d},
|
||||
{0xc1, 0x77},
|
||||
{0xf0, 0x01},
|
||||
{0x70, 0x02},
|
||||
{0x71, 0x02},
|
||||
{0x72, 0x50},
|
||||
{0x73, 0x02},
|
||||
{0x74, 0xd2},
|
||||
{0x75, 0x20},
|
||||
{0x76, 0x81},
|
||||
{0x77, 0x8c},
|
||||
{0x78, 0x81},
|
||||
{0xf4, 0x01},
|
||||
{0xf5, 0x00},
|
||||
{0xf6, 0x00},
|
||||
{0xf0, 0x36},
|
||||
{0x40, 0x03},
|
||||
{0x41, 0x01},
|
||||
{0xf0, 0x39},
|
||||
{0x02, 0x70},
|
||||
{0xf0, 0x32},
|
||||
{0x41, 0x00},
|
||||
{0x43, 0x01},
|
||||
{0x48, 0x02},
|
||||
{0xf0, 0x45},
|
||||
{0x09, 0x20},
|
||||
{0xf0, 0x33},
|
||||
{0x33, 0x10},
|
||||
{0xf0, 0x30},
|
||||
{0x38, 0x44},
|
||||
{0xf0, 0x39},
|
||||
{0x07, 0x00},
|
||||
{0x08, 0x19},
|
||||
{0x47, 0x00},
|
||||
{0x48, 0x00},
|
||||
{0xf0, 0x37},
|
||||
{0x24, 0x31},
|
||||
{0xf0, 0x34},
|
||||
{0x9f, 0x02},
|
||||
{0xa6, 0x51},
|
||||
{0xa7, 0x57},
|
||||
{0xe8, 0x5f},
|
||||
{0xa8, 0x50},
|
||||
{0xa9, 0x50},
|
||||
{0xe9, 0x50},
|
||||
{0xf0, 0x33},
|
||||
{0xb3, 0x58},
|
||||
{0xb2, 0x78},
|
||||
{0xf0, 0x34},
|
||||
{0x9f, 0x03},
|
||||
{0xa6, 0x51},
|
||||
{0xa7, 0x57},
|
||||
{0xaa, 0x01},
|
||||
{0xab, 0x28},
|
||||
{0xac, 0x01},
|
||||
{0xad, 0x38},
|
||||
{0xf0, 0x33},
|
||||
{0x0a, 0x01},
|
||||
{0x0b, 0x28},
|
||||
{0xf0, 0x33},
|
||||
{0x64, 0x0f},
|
||||
{0xec, 0x51},
|
||||
{0xed, 0x57},
|
||||
{0x06, 0x58},
|
||||
{0xe9, 0x58},
|
||||
{0xeb, 0x68},
|
||||
{0xf0, 0x33},
|
||||
{0x64, 0x0f},
|
||||
{0xf0, 0x36},
|
||||
{0x70, 0xdf},
|
||||
{0xb6, 0x40},
|
||||
{0xb7, 0x51},
|
||||
{0xb8, 0x53},
|
||||
{0xb9, 0x57},
|
||||
{0xba, 0x5f},
|
||||
{0xb0, 0x84},
|
||||
{0xb1, 0x82},
|
||||
{0xb2, 0x84},
|
||||
{0xb3, 0x88},
|
||||
{0xb4, 0x90},
|
||||
{0xb5, 0x90},
|
||||
{0xf0, 0x36},
|
||||
{0x7e, 0x50},
|
||||
{0x7f, 0x51},
|
||||
{0x77, 0x81},
|
||||
{0x78, 0x86},
|
||||
{0x79, 0x89},
|
||||
{0xf0, 0x36},
|
||||
{0x70, 0xdf},
|
||||
{0x9c, 0x51},
|
||||
{0x9d, 0x57},
|
||||
{0x90, 0x54},
|
||||
{0x91, 0x54},
|
||||
{0x92, 0x56},
|
||||
{0xf0, 0x36},
|
||||
{0xa0, 0x51},
|
||||
{0xa1, 0x57},
|
||||
{0x96, 0x33},
|
||||
{0x97, 0x43},
|
||||
{0x98, 0x43},
|
||||
{0xf0, 0x36},
|
||||
{0x70, 0xdf},
|
||||
{0x7c, 0x40},
|
||||
{0x7d, 0x53},
|
||||
{0x74, 0xd0},
|
||||
{0x75, 0xf0},
|
||||
{0x76, 0xf0},
|
||||
{0xf0, 0x37},
|
||||
{0x0f, 0xd5},
|
||||
{0x7a, 0x40},
|
||||
{0x7b, 0x57},
|
||||
{0x71, 0x09},
|
||||
{0x72, 0x09},
|
||||
{0x73, 0x05},
|
||||
{0xf0, 0x33},
|
||||
{0x01, 0x44},
|
||||
{0xf0, 0x36},
|
||||
{0x37, 0xfb},
|
||||
{0xf0, 0x36},
|
||||
{0x3c, 0x0d},
|
||||
{0xf0, 0x33},
|
||||
{0x14, 0x95},
|
||||
{0xf0, 0x33},
|
||||
{0x8f, 0x80},
|
||||
{0xf0, 0x37},
|
||||
{0x27, 0x14},
|
||||
{0x28, 0x03},
|
||||
{0xf0, 0x36},
|
||||
{0x37, 0xf4},
|
||||
{0xf0, 0x33},
|
||||
{0x01, 0x44},
|
||||
{0xf0, 0x36},
|
||||
{0x79, 0x89},
|
||||
{0xf0, 0x34},
|
||||
{0xac, 0x01},
|
||||
{0xad, 0x40},
|
||||
{0xf0, 0x33},
|
||||
{0xeb, 0x70},
|
||||
{0xf0, 0x34},
|
||||
{0xa8, 0x50},
|
||||
{0xa9, 0x50},
|
||||
{0xf0, 0x33},
|
||||
{0xb3, 0x58},
|
||||
{0xf0, 0x36},
|
||||
{0x11, 0x80},
|
||||
{0xf0, 0x36},
|
||||
{0x41, 0x51},
|
||||
{0xf0, 0x3f},
|
||||
{0x03, 0x09},
|
||||
{0xf0, 0x32},
|
||||
{0x0c, 0x06},
|
||||
{0x0d, 0x82},
|
||||
{0x0e, 0x02},
|
||||
{0x0f, 0xee},
|
||||
{0xf0, 0x36},
|
||||
{0xea, 0x09},
|
||||
{0xeb, 0xf5},
|
||||
{0xec, 0x11},
|
||||
{0xed, 0x27},
|
||||
{0xe9, 0x20},
|
||||
#endif
|
||||
};
|
||||
|
|
@ -1,335 +0,0 @@
|
|||
/*
|
||||
* SC030IOT driver.
|
||||
*
|
||||
* Copyright 2020-2022 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 "sc030iot.h"
|
||||
#include "sc030iot_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 = "sc030";
|
||||
#endif
|
||||
|
||||
#define SC030_SENSOR_ID_HIGH_REG 0XF7
|
||||
#define SC030_SENSOR_ID_LOW_REG 0XF8
|
||||
#define SC030_MAX_FRAME_WIDTH (640)
|
||||
#define SC030_MAX_FRAME_HIGH (480)
|
||||
|
||||
// sc030 use "i2c paging mode", so the high byte of the register needs to be written to the 0xf0 reg.
|
||||
// For more information please refer to the Technical Reference Manual.
|
||||
static int get_reg(sensor_t *sensor, int reg, int reg_value_mask)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t reg_high = (reg>>8) & 0xFF;
|
||||
uint8_t reg_low = reg & 0xFF;
|
||||
|
||||
if(SCCB_Write(sensor->slv_addr, 0xf0, reg_high)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = SCCB_Read(sensor->slv_addr, reg_low);
|
||||
if(ret > 0){
|
||||
ret &= reg_value_mask;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// sc030 use "i2c paging mode", so the high byte of the register needs to be written to the 0xf0 reg.
|
||||
// For more information please refer to the Technical Reference Manual.
|
||||
static int set_reg(sensor_t *sensor, int reg, int mask, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t reg_high = (reg>>8) & 0xFF;
|
||||
uint8_t reg_low = reg & 0xFF;
|
||||
|
||||
if(SCCB_Write(sensor->slv_addr, 0xf0, reg_high)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = SCCB_Write(sensor->slv_addr, reg_low, value & 0xFF);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_regs(sensor_t *sensor, const uint8_t (*regs)[2], uint32_t regs_entry_len)
|
||||
{
|
||||
int i=0, res = 0;
|
||||
while (i<regs_entry_len) {
|
||||
res = SCCB_Write(sensor->slv_addr, regs[i][0], regs[i][1]);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int set_reg_bits(sensor_t *sensor, int reg, uint8_t offset, uint8_t length, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = get_reg(sensor, reg, 0xff);
|
||||
if(ret < 0){
|
||||
return ret;
|
||||
}
|
||||
uint8_t mask = ((1 << length) - 1) << offset;
|
||||
value = (ret & ~mask) | ((value << offset) & mask);
|
||||
ret = set_reg(sensor, reg & 0xFFFF, 0xFFFF, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define WRITE_REGS_OR_RETURN(regs, regs_entry_len) ret = set_regs(sensor, regs, regs_entry_len); 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(0x0100, 7, 1, enable & 0xff); // enable test pattern mode
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_sharpness(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x00e0, 1, 1, 1); // enable edge enhancement
|
||||
WRITE_REG_OR_RETURN(0x00d0, level & 0xFF); // base value
|
||||
WRITE_REG_OR_RETURN(0x00d2, (level >> 8) & 0xFF); // limit
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_agc_gain(sensor_t *sensor, int gain)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x0070, 1, 1, 1); // enable auto agc control
|
||||
WRITE_REG_OR_RETURN(0x0068, gain & 0xFF); // Window weight setting1
|
||||
WRITE_REG_OR_RETURN(0x0069, (gain >> 8) & 0xFF); // Window weight setting2
|
||||
WRITE_REG_OR_RETURN(0x006a, (gain >> 16) & 0xFF); // Window weight setting3
|
||||
WRITE_REG_OR_RETURN(0x006b, (gain >> 24) & 0xFF); // Window weight setting4
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_aec_value(sensor_t *sensor, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x0070, 0, 1, 1); // enable auto aec control
|
||||
WRITE_REG_OR_RETURN(0x0072, value & 0xFF); // AE target
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_awb_gain(sensor_t *sensor, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x00b0, 0, 1, 1); // enable awb control
|
||||
WRITE_REG_OR_RETURN(0x00c8, value & 0xFF); // blue gain
|
||||
WRITE_REG_OR_RETURN(0x00c9, (value>>8) & 0XFF); // red gain
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_saturation(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x00f5, 5, 1, 0); // enable saturation control
|
||||
WRITE_REG_OR_RETURN(0x0149, level & 0xFF); // blue saturation gain (/128)
|
||||
WRITE_REG_OR_RETURN(0x014a, (level>>8) & 0XFF); // red saturation gain (/128)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_contrast(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x00f5, 6, 1, 0); // enable contrast control
|
||||
WRITE_REG_OR_RETURN(0x014b, level); // contrast coefficient(/64)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int reset(sensor_t *sensor)
|
||||
{
|
||||
int ret = set_regs(sensor, sc030iot_default_init_regs, sizeof(sc030iot_default_init_regs)/(sizeof(uint8_t) * 2));
|
||||
|
||||
// Delay
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
|
||||
// ESP_LOGI(TAG, "set_reg=%0x", set_reg(sensor, 0x0100, 0xffff, 0x00)); // write 0x80 to enter test mode if you want to test the sensor
|
||||
// ESP_LOGI(TAG, "0x0100=%0x", get_reg(sensor, 0x0100, 0xffff));
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "reset fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_window(sensor_t *sensor, int offset_x, int offset_y, int w, int h)
|
||||
{
|
||||
int ret = 0;
|
||||
//sc:H_start={0x0172[1:0],0x0170},H_end={0x0172[5:4],0x0171},
|
||||
WRITE_REG_OR_RETURN(0x0170, offset_x & 0xff);
|
||||
WRITE_REG_OR_RETURN(0x0171, (offset_x+w) & 0xff);
|
||||
WRITE_REG_OR_RETURN(0x0172, ((offset_x>>8) & 0x03) | (((offset_x+w)>>4)&0x30));
|
||||
|
||||
//sc:V_start={0x0175[1:0],0x0173},H_end={0x0175[5:4],0x0174},
|
||||
WRITE_REG_OR_RETURN(0x0173, offset_y & 0xff);
|
||||
WRITE_REG_OR_RETURN(0x0174, (offset_y+h) & 0xff);
|
||||
WRITE_REG_OR_RETURN(0x0175, ((offset_y>>8) & 0x03) | (((offset_y+h)>>4)&0x30));
|
||||
|
||||
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>SC030_MAX_FRAME_WIDTH || h > SC030_MAX_FRAME_HIGH) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
uint16_t offset_x = (640-w) /2;
|
||||
uint16_t offset_y = (480-h) /2;
|
||||
|
||||
if(set_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_RGB565:
|
||||
case PIXFORMAT_RAW:
|
||||
case PIXFORMAT_GRAYSCALE:
|
||||
ESP_LOGE(TAG, "Not support");
|
||||
break;
|
||||
case PIXFORMAT_YUV422: // For now, sc030/sc031 sensor only support YUV422.
|
||||
break;
|
||||
default:
|
||||
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 sc030iot_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (SC030IOT_SCCB_ADDR == slv_addr) {
|
||||
uint8_t MIDL = SCCB_Read(slv_addr, SC030_SENSOR_ID_LOW_REG);
|
||||
uint8_t MIDH = SCCB_Read(slv_addr, SC030_SENSOR_ID_HIGH_REG);
|
||||
uint16_t PID = MIDH << 8 | MIDL;
|
||||
if (SC030IOT_PID == PID) {
|
||||
id->PID = PID;
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sc030iot_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_saturation= set_saturation;
|
||||
sensor->set_colorbar = set_colorbar;
|
||||
sensor->set_hmirror = set_hmirror;
|
||||
sensor->set_vflip = set_vflip;
|
||||
sensor->set_sharpness = set_sharpness;
|
||||
sensor->set_agc_gain = set_agc_gain;
|
||||
sensor->set_aec_value = set_aec_value;
|
||||
sensor->set_awb_gain = set_awb_gain;
|
||||
sensor->set_contrast = set_contrast;
|
||||
//not supported
|
||||
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, "sc030iot Attached");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,344 +0,0 @@
|
|||
/*
|
||||
* 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_reset_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},
|
||||
|
||||
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},
|
||||
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;
|
||||
|
||||
struct sc031gs_regval const *framesize_regs = sc031gs_200x200_init_regs;
|
||||
if(framesize > FRAMESIZE_VGA) {
|
||||
goto err;
|
||||
} else if(framesize > FRAMESIZE_QVGA) {
|
||||
framesize_regs = sc031gs_640x480_50fps_init_regs;
|
||||
}
|
||||
|
||||
uint16_t offset_x = (640-w) /2 + 4;
|
||||
uint16_t offset_y = (480-h) /2 + 4;
|
||||
|
||||
int ret = write_regs(sensor->slv_addr, framesize_regs);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "reset fail");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -1,342 +0,0 @@
|
|||
/*
|
||||
* SC101IOT driver.
|
||||
*
|
||||
* Copyright 2020-2022 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 "sc101iot.h"
|
||||
#include "sc101iot_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 = "sc101";
|
||||
#endif
|
||||
|
||||
#define SC101_SENSOR_ID_HIGH_REG 0XF7
|
||||
#define SC101_SENSOR_ID_LOW_REG 0XF8
|
||||
#define SC101_MAX_FRAME_WIDTH (1280)
|
||||
#define SC101_MAX_FRAME_HIGH (720)
|
||||
|
||||
// sc101 use "i2c paging mode", so the high byte of the register needs to be written to the 0xf0 reg.
|
||||
// For more information please refer to the Technical Reference Manual.
|
||||
static int get_reg(sensor_t *sensor, int reg, int mask)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t reg_high = (reg>>8) & 0xFF;
|
||||
uint8_t reg_low = reg & 0xFF;
|
||||
|
||||
if(SCCB_Write(sensor->slv_addr, 0xf0, reg_high)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = SCCB_Read(sensor->slv_addr, reg_low);
|
||||
if(ret > 0){
|
||||
ret &= mask;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// sc101 use "i2c paging mode", so the high byte of the register needs to be written to the 0xf0 reg.
|
||||
// For more information please refer to the Technical Reference Manual.
|
||||
static int set_reg(sensor_t *sensor, int reg, int mask, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t reg_high = (reg>>8) & 0xFF;
|
||||
uint8_t reg_low = reg & 0xFF;
|
||||
|
||||
if(SCCB_Write(sensor->slv_addr, 0xf0, reg_high)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = SCCB_Write(sensor->slv_addr, reg_low, value & 0xFF);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_regs(sensor_t *sensor, const uint8_t (*regs)[2], uint32_t regs_entry_len)
|
||||
{
|
||||
int i=0, res = 0;
|
||||
while (i<regs_entry_len) {
|
||||
res = SCCB_Write(sensor->slv_addr, regs[i][0], regs[i][1]);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int set_reg_bits(sensor_t *sensor, int reg, uint8_t offset, uint8_t length, uint8_t value)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = get_reg(sensor, reg, 0xff);
|
||||
if(ret < 0){
|
||||
return ret;
|
||||
}
|
||||
uint8_t mask = ((1 << length) - 1) << offset;
|
||||
value = (ret & ~mask) | ((value << offset) & mask);
|
||||
ret = set_reg(sensor, reg & 0xFFFF, 0xFFFF, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define WRITE_REGS_OR_RETURN(regs, regs_entry_len) ret = set_regs(sensor, regs, regs_entry_len); 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); // enable mirror
|
||||
} else {
|
||||
SET_REG_BITS_OR_RETURN(0x3221, 1, 2, 0x0); // disable mirror
|
||||
}
|
||||
|
||||
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(0x0100, 7, 1, enable & 0xff); // enable colorbar mode
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_raw_gma(sensor_t *sensor, int enable)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x00f5, 1, 1, enable & 0xff); // enable gamma compensation
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_sharpness(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x00e0, 1, 1, 1); // enable edge enhancement
|
||||
WRITE_REG_OR_RETURN(0x00d0, level & 0xFF); // base value
|
||||
WRITE_REG_OR_RETURN(0x00d2, (level >> 8) & 0xFF); // limit
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_agc_gain(sensor_t *sensor, int gain)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x0070, 1, 1, 1); // enable auto agc control
|
||||
WRITE_REG_OR_RETURN(0x0068, gain & 0xFF); // Window weight setting1
|
||||
WRITE_REG_OR_RETURN(0x0069, (gain >> 8) & 0xFF); // Window weight setting2
|
||||
WRITE_REG_OR_RETURN(0x006a, (gain >> 16) & 0xFF); // Window weight setting3
|
||||
WRITE_REG_OR_RETURN(0x006b, (gain >> 24) & 0xFF); // Window weight setting4
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_aec_value(sensor_t *sensor, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x0070, 0, 1, 1); // enable auto aec control
|
||||
WRITE_REG_OR_RETURN(0x0072, value & 0xFF); // AE target
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_awb_gain(sensor_t *sensor, int value)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x00b0, 0, 1, 1); // enable awb control
|
||||
WRITE_REG_OR_RETURN(0x00c8, value & 0xFF); // blue gain
|
||||
WRITE_REG_OR_RETURN(0x00c9, (value>>8) & 0XFF); // red gain
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_saturation(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x00f5, 5, 1, 0); // enable saturation control
|
||||
WRITE_REG_OR_RETURN(0x0149, level & 0xFF); // blue saturation gain (/128)
|
||||
WRITE_REG_OR_RETURN(0x014a, (level>>8) & 0XFF); // red saturation gain (/128)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_contrast(sensor_t *sensor, int level)
|
||||
{
|
||||
int ret = 0;
|
||||
SET_REG_BITS_OR_RETURN(0x00f5, 6, 1, 0); // enable contrast control
|
||||
WRITE_REG_OR_RETURN(0x014b, level); // contrast coefficient(/64)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int reset(sensor_t *sensor)
|
||||
{
|
||||
int ret = set_regs(sensor, sc101iot_default_init_regs, sizeof(sc101iot_default_init_regs)/(sizeof(uint8_t) * 2));
|
||||
|
||||
// Delay
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
|
||||
// ESP_LOGI(TAG, "set_reg=%0x", set_reg(sensor, 0x0100, 0xffff, 0x00)); // write 0x80 to enter test mode if you want to test the sensor
|
||||
// ESP_LOGI(TAG, "0x0100=%0x", get_reg(sensor, 0x0100, 0xffff));
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "reset fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_window(sensor_t *sensor, int offset_x, int offset_y, int w, int h)
|
||||
{
|
||||
int ret = 0;
|
||||
//sc:H_start={0x0172[3:0],0x0170},H_end={0x0172[7:4],0x0171},
|
||||
WRITE_REG_OR_RETURN(0x0170, offset_x & 0xff);
|
||||
WRITE_REG_OR_RETURN(0x0171, (offset_x+w) & 0xff);
|
||||
WRITE_REG_OR_RETURN(0x0172, ((offset_x>>8) & 0x0f) | (((offset_x+w)>>4)&0xf0));
|
||||
|
||||
//sc:V_start={0x0175[3:0],0x0173},H_end={0x0175[7:4],0x0174},
|
||||
WRITE_REG_OR_RETURN(0x0173, offset_y & 0xff);
|
||||
WRITE_REG_OR_RETURN(0x0174, (offset_y+h) & 0xff);
|
||||
WRITE_REG_OR_RETURN(0x0175, ((offset_y>>8) & 0x0f) | (((offset_y+h)>>4)&0xf0));
|
||||
|
||||
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>SC101_MAX_FRAME_WIDTH || h > SC101_MAX_FRAME_HIGH) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
uint16_t offset_x = (SC101_MAX_FRAME_WIDTH-w) /2;
|
||||
uint16_t offset_y = (SC101_MAX_FRAME_HIGH-h) /2;
|
||||
|
||||
if(set_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_RGB565:
|
||||
case PIXFORMAT_RAW:
|
||||
case PIXFORMAT_GRAYSCALE:
|
||||
ESP_LOGE(TAG, "Not support");
|
||||
break;
|
||||
case PIXFORMAT_YUV422: // For now, sc101 sensor only support YUV422.
|
||||
break;
|
||||
default:
|
||||
ret = -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 sc101iot_detect(int slv_addr, sensor_id_t *id)
|
||||
{
|
||||
if (SC101IOT_SCCB_ADDR == slv_addr) {
|
||||
uint8_t MIDL = SCCB_Read(slv_addr, SC101_SENSOR_ID_LOW_REG);
|
||||
uint8_t MIDH = SCCB_Read(slv_addr, SC101_SENSOR_ID_HIGH_REG);
|
||||
uint16_t PID = MIDH << 8 | MIDL;
|
||||
if (SC101IOT_PID == PID) {
|
||||
id->PID = PID;
|
||||
return PID;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Mismatch PID=0x%x", PID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sc101iot_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_hmirror = set_hmirror;
|
||||
sensor->set_vflip = set_vflip;
|
||||
sensor->set_colorbar = set_colorbar;
|
||||
sensor->set_raw_gma = set_raw_gma;
|
||||
sensor->set_sharpness = set_sharpness;
|
||||
sensor->set_agc_gain = set_agc_gain;
|
||||
sensor->set_aec_value = set_aec_value;
|
||||
sensor->set_awb_gain = set_awb_gain;
|
||||
sensor->set_saturation= set_saturation;
|
||||
sensor->set_contrast = set_contrast;
|
||||
|
||||
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, "sc101iot Attached");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,538 +0,0 @@
|
|||
// Copyright 2010-2020 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include "soc/i2s_struct.h"
|
||||
#include "esp_idf_version.h"
|
||||
#if (ESP_IDF_VERSION_MAJOR >= 4) && (ESP_IDF_VERSION_MINOR > 1)
|
||||
#include "hal/gpio_ll.h"
|
||||
#else
|
||||
#include "soc/gpio_periph.h"
|
||||
#define esp_rom_delay_us ets_delay_us
|
||||
static inline int gpio_ll_get_level(gpio_dev_t *hw, int gpio_num)
|
||||
{
|
||||
if (gpio_num < 32) {
|
||||
return (hw->in >> gpio_num) & 0x1;
|
||||
} else {
|
||||
return (hw->in1.data >> (gpio_num - 32)) & 0x1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#include "ll_cam.h"
|
||||
#include "xclk.h"
|
||||
#include "cam_hal.h"
|
||||
|
||||
#if (ESP_IDF_VERSION_MAJOR >= 4) && (ESP_IDF_VERSION_MINOR >= 3)
|
||||
#include "esp_rom_gpio.h"
|
||||
#endif
|
||||
|
||||
#if (ESP_IDF_VERSION_MAJOR >= 5)
|
||||
#define GPIO_PIN_INTR_POSEDGE GPIO_INTR_POSEDGE
|
||||
#define GPIO_PIN_INTR_NEGEDGE GPIO_INTR_NEGEDGE
|
||||
#define gpio_matrix_in(a,b,c) esp_rom_gpio_connect_in_signal(a,b,c)
|
||||
#endif
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 2)
|
||||
#define ets_delay_us esp_rom_delay_us
|
||||
#endif
|
||||
|
||||
static const char *TAG = "esp32 ll_cam";
|
||||
|
||||
#define I2S_ISR_ENABLE(i) {I2S0.int_clr.i = 1;I2S0.int_ena.i = 1;}
|
||||
#define I2S_ISR_DISABLE(i) {I2S0.int_ena.i = 0;I2S0.int_clr.i = 1;}
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint32_t sample2:8;
|
||||
uint32_t unused2:8;
|
||||
uint32_t sample1:8;
|
||||
uint32_t unused1:8;
|
||||
};
|
||||
uint32_t val;
|
||||
} dma_elem_t;
|
||||
|
||||
typedef enum {
|
||||
/* camera sends byte sequence: s1, s2, s3, s4, ...
|
||||
* fifo receives: 00 s1 00 s2, 00 s2 00 s3, 00 s3 00 s4, ...
|
||||
*/
|
||||
SM_0A0B_0B0C = 0,
|
||||
/* camera sends byte sequence: s1, s2, s3, s4, ...
|
||||
* fifo receives: 00 s1 00 s2, 00 s3 00 s4, ...
|
||||
*/
|
||||
SM_0A0B_0C0D = 1,
|
||||
/* camera sends byte sequence: s1, s2, s3, s4, ...
|
||||
* fifo receives: 00 s1 00 00, 00 s2 00 00, 00 s3 00 00, ...
|
||||
*/
|
||||
SM_0A00_0B00 = 3,
|
||||
} i2s_sampling_mode_t;
|
||||
|
||||
typedef size_t (*dma_filter_t)(uint8_t* dst, const uint8_t* src, size_t len);
|
||||
|
||||
static i2s_sampling_mode_t sampling_mode = SM_0A00_0B00;
|
||||
|
||||
static size_t ll_cam_bytes_per_sample(i2s_sampling_mode_t mode)
|
||||
{
|
||||
switch(mode) {
|
||||
case SM_0A00_0B00:
|
||||
return 4;
|
||||
case SM_0A0B_0B0C:
|
||||
return 4;
|
||||
case SM_0A0B_0C0D:
|
||||
return 2;
|
||||
default:
|
||||
assert(0 && "invalid sampling mode");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t IRAM_ATTR ll_cam_dma_filter_jpeg(uint8_t* dst, const uint8_t* src, size_t len)
|
||||
{
|
||||
const dma_elem_t* dma_el = (const dma_elem_t*)src;
|
||||
size_t elements = len / sizeof(dma_elem_t);
|
||||
size_t end = elements / 4;
|
||||
// manually unrolling 4 iterations of the loop here
|
||||
for (size_t i = 0; i < end; ++i) {
|
||||
dst[0] = dma_el[0].sample1;
|
||||
dst[1] = dma_el[1].sample1;
|
||||
dst[2] = dma_el[2].sample1;
|
||||
dst[3] = dma_el[3].sample1;
|
||||
dma_el += 4;
|
||||
dst += 4;
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
static size_t IRAM_ATTR ll_cam_dma_filter_grayscale(uint8_t* dst, const uint8_t* src, size_t len)
|
||||
{
|
||||
const dma_elem_t* dma_el = (const dma_elem_t*)src;
|
||||
size_t elements = len / sizeof(dma_elem_t);
|
||||
size_t end = elements / 4;
|
||||
for (size_t i = 0; i < end; ++i) {
|
||||
// manually unrolling 4 iterations of the loop here
|
||||
dst[0] = dma_el[0].sample1;
|
||||
dst[1] = dma_el[1].sample1;
|
||||
dst[2] = dma_el[2].sample1;
|
||||
dst[3] = dma_el[3].sample1;
|
||||
dma_el += 4;
|
||||
dst += 4;
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
static size_t IRAM_ATTR ll_cam_dma_filter_grayscale_highspeed(uint8_t* dst, const uint8_t* src, size_t len)
|
||||
{
|
||||
const dma_elem_t* dma_el = (const dma_elem_t*)src;
|
||||
size_t elements = len / sizeof(dma_elem_t);
|
||||
size_t end = elements / 8;
|
||||
for (size_t i = 0; i < end; ++i) {
|
||||
// manually unrolling 4 iterations of the loop here
|
||||
dst[0] = dma_el[0].sample1;
|
||||
dst[1] = dma_el[2].sample1;
|
||||
dst[2] = dma_el[4].sample1;
|
||||
dst[3] = dma_el[6].sample1;
|
||||
dma_el += 8;
|
||||
dst += 4;
|
||||
}
|
||||
// the final sample of a line in SM_0A0B_0B0C sampling mode needs special handling
|
||||
if ((elements & 0x7) != 0) {
|
||||
dst[0] = dma_el[0].sample1;
|
||||
dst[1] = dma_el[2].sample1;
|
||||
elements += 1;
|
||||
}
|
||||
return elements / 2;
|
||||
}
|
||||
|
||||
static size_t IRAM_ATTR ll_cam_dma_filter_yuyv(uint8_t* dst, const uint8_t* src, size_t len)
|
||||
{
|
||||
const dma_elem_t* dma_el = (const dma_elem_t*)src;
|
||||
size_t elements = len / sizeof(dma_elem_t);
|
||||
size_t end = elements / 4;
|
||||
for (size_t i = 0; i < end; ++i) {
|
||||
dst[0] = dma_el[0].sample1;//y0
|
||||
dst[1] = dma_el[0].sample2;//u
|
||||
dst[2] = dma_el[1].sample1;//y1
|
||||
dst[3] = dma_el[1].sample2;//v
|
||||
|
||||
dst[4] = dma_el[2].sample1;//y0
|
||||
dst[5] = dma_el[2].sample2;//u
|
||||
dst[6] = dma_el[3].sample1;//y1
|
||||
dst[7] = dma_el[3].sample2;//v
|
||||
dma_el += 4;
|
||||
dst += 8;
|
||||
}
|
||||
return elements * 2;
|
||||
}
|
||||
|
||||
static size_t IRAM_ATTR ll_cam_dma_filter_yuyv_highspeed(uint8_t* dst, const uint8_t* src, size_t len)
|
||||
{
|
||||
const dma_elem_t* dma_el = (const dma_elem_t*)src;
|
||||
size_t elements = len / sizeof(dma_elem_t);
|
||||
size_t end = elements / 8;
|
||||
for (size_t i = 0; i < end; ++i) {
|
||||
dst[0] = dma_el[0].sample1;//y0
|
||||
dst[1] = dma_el[1].sample1;//u
|
||||
dst[2] = dma_el[2].sample1;//y1
|
||||
dst[3] = dma_el[3].sample1;//v
|
||||
|
||||
dst[4] = dma_el[4].sample1;//y0
|
||||
dst[5] = dma_el[5].sample1;//u
|
||||
dst[6] = dma_el[6].sample1;//y1
|
||||
dst[7] = dma_el[7].sample1;//v
|
||||
dma_el += 8;
|
||||
dst += 8;
|
||||
}
|
||||
if ((elements & 0x7) != 0) {
|
||||
dst[0] = dma_el[0].sample1;//y0
|
||||
dst[1] = dma_el[1].sample1;//u
|
||||
dst[2] = dma_el[2].sample1;//y1
|
||||
dst[3] = dma_el[2].sample2;//v
|
||||
elements += 4;
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
static void IRAM_ATTR ll_cam_vsync_isr(void *arg)
|
||||
{
|
||||
//DBG_PIN_SET(1);
|
||||
cam_obj_t *cam = (cam_obj_t *)arg;
|
||||
BaseType_t HPTaskAwoken = pdFALSE;
|
||||
// filter
|
||||
ets_delay_us(1);
|
||||
if (gpio_ll_get_level(&GPIO, cam->vsync_pin) == !cam->vsync_invert) {
|
||||
ll_cam_send_event(cam, CAM_VSYNC_EVENT, &HPTaskAwoken);
|
||||
if (HPTaskAwoken == pdTRUE) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
//DBG_PIN_SET(0);
|
||||
}
|
||||
|
||||
static void IRAM_ATTR ll_cam_dma_isr(void *arg)
|
||||
{
|
||||
//DBG_PIN_SET(1);
|
||||
cam_obj_t *cam = (cam_obj_t *)arg;
|
||||
BaseType_t HPTaskAwoken = pdFALSE;
|
||||
|
||||
typeof(I2S0.int_st) status = I2S0.int_st;
|
||||
if (status.val == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
I2S0.int_clr.val = status.val;
|
||||
|
||||
if (status.in_suc_eof) {
|
||||
ll_cam_send_event(cam, CAM_IN_SUC_EOF_EVENT, &HPTaskAwoken);
|
||||
}
|
||||
if (HPTaskAwoken == pdTRUE) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
//DBG_PIN_SET(0);
|
||||
}
|
||||
|
||||
bool IRAM_ATTR ll_cam_stop(cam_obj_t *cam)
|
||||
{
|
||||
I2S0.conf.rx_start = 0;
|
||||
I2S_ISR_DISABLE(in_suc_eof);
|
||||
I2S0.in_link.stop = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_deinit(cam_obj_t *cam)
|
||||
{
|
||||
gpio_isr_handler_remove(cam->vsync_pin);
|
||||
|
||||
if (cam->cam_intr_handle) {
|
||||
esp_intr_free(cam->cam_intr_handle);
|
||||
cam->cam_intr_handle = NULL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool ll_cam_start(cam_obj_t *cam, int frame_pos)
|
||||
{
|
||||
I2S0.conf.rx_start = 0;
|
||||
|
||||
I2S_ISR_ENABLE(in_suc_eof);
|
||||
|
||||
I2S0.conf.rx_reset = 1;
|
||||
I2S0.conf.rx_reset = 0;
|
||||
I2S0.conf.rx_fifo_reset = 1;
|
||||
I2S0.conf.rx_fifo_reset = 0;
|
||||
I2S0.lc_conf.in_rst = 1;
|
||||
I2S0.lc_conf.in_rst = 0;
|
||||
I2S0.lc_conf.ahbm_fifo_rst = 1;
|
||||
I2S0.lc_conf.ahbm_fifo_rst = 0;
|
||||
I2S0.lc_conf.ahbm_rst = 1;
|
||||
I2S0.lc_conf.ahbm_rst = 0;
|
||||
|
||||
I2S0.rx_eof_num = cam->dma_half_buffer_size / sizeof(dma_elem_t);
|
||||
I2S0.in_link.addr = ((uint32_t)&cam->dma[0]) & 0xfffff;
|
||||
|
||||
I2S0.in_link.start = 1;
|
||||
I2S0.conf.rx_start = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_config(cam_obj_t *cam, const camera_config_t *config)
|
||||
{
|
||||
// Enable and configure I2S peripheral
|
||||
periph_module_enable(PERIPH_I2S0_MODULE);
|
||||
|
||||
I2S0.conf.rx_reset = 1;
|
||||
I2S0.conf.rx_reset = 0;
|
||||
I2S0.conf.rx_fifo_reset = 1;
|
||||
I2S0.conf.rx_fifo_reset = 0;
|
||||
I2S0.lc_conf.in_rst = 1;
|
||||
I2S0.lc_conf.in_rst = 0;
|
||||
I2S0.lc_conf.ahbm_fifo_rst = 1;
|
||||
I2S0.lc_conf.ahbm_fifo_rst = 0;
|
||||
I2S0.lc_conf.ahbm_rst = 1;
|
||||
I2S0.lc_conf.ahbm_rst = 0;
|
||||
|
||||
I2S0.conf.rx_slave_mod = 1;
|
||||
I2S0.conf.rx_right_first = 0;
|
||||
I2S0.conf.rx_msb_right = 0;
|
||||
I2S0.conf.rx_msb_shift = 0;
|
||||
I2S0.conf.rx_mono = 0;
|
||||
I2S0.conf.rx_short_sync = 0;
|
||||
|
||||
I2S0.conf2.lcd_en = 1;
|
||||
I2S0.conf2.camera_en = 1;
|
||||
|
||||
// Configure clock divider
|
||||
I2S0.clkm_conf.clkm_div_a = 0;
|
||||
I2S0.clkm_conf.clkm_div_b = 0;
|
||||
I2S0.clkm_conf.clkm_div_num = 2;
|
||||
|
||||
I2S0.fifo_conf.dscr_en = 1;
|
||||
I2S0.fifo_conf.rx_fifo_mod = sampling_mode;
|
||||
I2S0.fifo_conf.rx_fifo_mod_force_en = 1;
|
||||
|
||||
I2S0.conf_chan.rx_chan_mod = 1;
|
||||
I2S0.sample_rate_conf.rx_bits_mod = 0;
|
||||
I2S0.timing.val = 0;
|
||||
I2S0.timing.rx_dsync_sw = 1;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void ll_cam_vsync_intr_enable(cam_obj_t *cam, bool en)
|
||||
{
|
||||
if (en) {
|
||||
gpio_intr_enable(cam->vsync_pin);
|
||||
} else {
|
||||
gpio_intr_disable(cam->vsync_pin);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_set_pin(cam_obj_t *cam, const camera_config_t *config)
|
||||
{
|
||||
gpio_config_t io_conf = {0};
|
||||
io_conf.intr_type = cam->vsync_invert ? GPIO_PIN_INTR_NEGEDGE : GPIO_PIN_INTR_POSEDGE;
|
||||
io_conf.pin_bit_mask = 1ULL << config->pin_vsync;
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = 1;
|
||||
io_conf.pull_down_en = 0;
|
||||
gpio_config(&io_conf);
|
||||
gpio_install_isr_service(ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM);
|
||||
gpio_isr_handler_add(config->pin_vsync, ll_cam_vsync_isr, cam);
|
||||
gpio_intr_disable(config->pin_vsync);
|
||||
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_pclk], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_pclk, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(config->pin_pclk, GPIO_FLOATING);
|
||||
gpio_matrix_in(config->pin_pclk, I2S0I_WS_IN_IDX, false);
|
||||
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_vsync], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_vsync, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(config->pin_vsync, GPIO_FLOATING);
|
||||
gpio_matrix_in(config->pin_vsync, I2S0I_V_SYNC_IDX, false);
|
||||
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_href], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_href, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(config->pin_href, GPIO_FLOATING);
|
||||
gpio_matrix_in(config->pin_href, I2S0I_H_SYNC_IDX, false);
|
||||
|
||||
int data_pins[8] = {
|
||||
config->pin_d0, config->pin_d1, config->pin_d2, config->pin_d3, config->pin_d4, config->pin_d5, config->pin_d6, config->pin_d7,
|
||||
};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[data_pins[i]], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(data_pins[i], GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(data_pins[i], GPIO_FLOATING);
|
||||
gpio_matrix_in(data_pins[i], I2S0I_DATA_IN0_IDX + i, false);
|
||||
}
|
||||
|
||||
gpio_matrix_in(0x38, I2S0I_H_ENABLE_IDX, false);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_init_isr(cam_obj_t *cam)
|
||||
{
|
||||
return esp_intr_alloc(ETS_I2S0_INTR_SOURCE, ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM, ll_cam_dma_isr, cam, &cam->cam_intr_handle);
|
||||
}
|
||||
|
||||
void ll_cam_do_vsync(cam_obj_t *cam)
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t ll_cam_get_dma_align(cam_obj_t *cam)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool ll_cam_calc_rgb_dma(cam_obj_t *cam){
|
||||
size_t dma_half_buffer_max = CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX / 2 / cam->dma_bytes_per_item;
|
||||
size_t dma_buffer_max = 2 * dma_half_buffer_max;
|
||||
size_t node_max = LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE / cam->dma_bytes_per_item;
|
||||
|
||||
size_t line_width = cam->width * cam->in_bytes_per_pixel;
|
||||
size_t image_size = cam->height * line_width;
|
||||
if (image_size > (4 * 1024 * 1024) || (line_width > dma_half_buffer_max)) {
|
||||
ESP_LOGE(TAG, "Resolution too high");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t node_size = node_max;
|
||||
size_t nodes_per_line = 1;
|
||||
size_t lines_per_node = 1;
|
||||
size_t lines_per_half_buffer = 1;
|
||||
size_t dma_half_buffer_min = node_max;
|
||||
size_t dma_half_buffer = dma_half_buffer_max;
|
||||
size_t dma_buffer_size = dma_buffer_max;
|
||||
|
||||
// Calculate DMA Node Size so that it's divisable by or divisor of the line width
|
||||
if(line_width >= node_max){
|
||||
// One or more nodes will be requied for one line
|
||||
for(size_t i = node_max; i > 0; i=i-1){
|
||||
if ((line_width % i) == 0) {
|
||||
node_size = i;
|
||||
nodes_per_line = line_width / node_size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// One or more lines can fit into one node
|
||||
for(size_t i = node_max; i > 0; i=i-1){
|
||||
if ((i % line_width) == 0) {
|
||||
node_size = i;
|
||||
lines_per_node = node_size / line_width;
|
||||
while((cam->height % lines_per_node) != 0){
|
||||
lines_per_node = lines_per_node - 1;
|
||||
node_size = lines_per_node * line_width;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Calculate minimum EOF size = max(mode_size, line_size)
|
||||
dma_half_buffer_min = node_size * nodes_per_line;
|
||||
// Calculate max EOF size divisable by node size
|
||||
dma_half_buffer = (dma_half_buffer_max / dma_half_buffer_min) * dma_half_buffer_min;
|
||||
// Adjust EOF size so that height will be divisable by the number of lines in each EOF
|
||||
lines_per_half_buffer = dma_half_buffer / line_width;
|
||||
while((cam->height % lines_per_half_buffer) != 0){
|
||||
dma_half_buffer = dma_half_buffer - dma_half_buffer_min;
|
||||
lines_per_half_buffer = dma_half_buffer / line_width;
|
||||
}
|
||||
// Calculate DMA size
|
||||
dma_buffer_size =(dma_buffer_max / dma_half_buffer) * dma_half_buffer;
|
||||
|
||||
ESP_LOGI(TAG, "node_size: %4u, nodes_per_line: %u, lines_per_node: %u, dma_half_buffer_min: %5u, dma_half_buffer: %5u,"
|
||||
"lines_per_half_buffer: %2u, dma_buffer_size: %5u, image_size: %u",
|
||||
(unsigned) (node_size * cam->dma_bytes_per_item), (unsigned) nodes_per_line, (unsigned) lines_per_node,
|
||||
(unsigned) (dma_half_buffer_min * cam->dma_bytes_per_item), (unsigned) (dma_half_buffer * cam->dma_bytes_per_item),
|
||||
(unsigned) (lines_per_half_buffer), (unsigned) (dma_buffer_size * cam->dma_bytes_per_item), (unsigned) image_size);
|
||||
|
||||
cam->dma_buffer_size = dma_buffer_size * cam->dma_bytes_per_item;
|
||||
cam->dma_half_buffer_size = dma_half_buffer * cam->dma_bytes_per_item;
|
||||
cam->dma_node_buffer_size = node_size * cam->dma_bytes_per_item;
|
||||
cam->dma_half_buffer_cnt = cam->dma_buffer_size / cam->dma_half_buffer_size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool ll_cam_dma_sizes(cam_obj_t *cam)
|
||||
{
|
||||
cam->dma_bytes_per_item = ll_cam_bytes_per_sample(sampling_mode);
|
||||
if (cam->jpeg_mode) {
|
||||
cam->dma_half_buffer_cnt = 8;
|
||||
cam->dma_node_buffer_size = 2048;
|
||||
cam->dma_half_buffer_size = cam->dma_node_buffer_size * 2;
|
||||
cam->dma_buffer_size = cam->dma_half_buffer_cnt * cam->dma_half_buffer_size;
|
||||
} else {
|
||||
return ll_cam_calc_rgb_dma(cam);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static dma_filter_t dma_filter = ll_cam_dma_filter_jpeg;
|
||||
|
||||
size_t IRAM_ATTR ll_cam_memcpy(cam_obj_t *cam, uint8_t *out, const uint8_t *in, size_t len)
|
||||
{
|
||||
//DBG_PIN_SET(1);
|
||||
size_t r = dma_filter(out, in, len);
|
||||
//DBG_PIN_SET(0);
|
||||
return r;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_set_sample_mode(cam_obj_t *cam, pixformat_t pix_format, uint32_t xclk_freq_hz, uint16_t sensor_pid)
|
||||
{
|
||||
if (pix_format == PIXFORMAT_GRAYSCALE) {
|
||||
if (sensor_pid == OV3660_PID || sensor_pid == OV5640_PID || sensor_pid == NT99141_PID || sensor_pid == SC031GS_PID || sensor_pid == BF20A6_PID || sensor_pid == GC0308_PID) {
|
||||
if (xclk_freq_hz > 10000000) {
|
||||
sampling_mode = SM_0A00_0B00;
|
||||
dma_filter = ll_cam_dma_filter_yuyv_highspeed;
|
||||
} else {
|
||||
sampling_mode = SM_0A0B_0C0D;
|
||||
dma_filter = ll_cam_dma_filter_yuyv;
|
||||
}
|
||||
cam->in_bytes_per_pixel = 1; // camera sends Y8
|
||||
} else {
|
||||
if (xclk_freq_hz > 10000000 && sensor_pid != OV7725_PID) {
|
||||
sampling_mode = SM_0A00_0B00;
|
||||
dma_filter = ll_cam_dma_filter_grayscale_highspeed;
|
||||
} else {
|
||||
sampling_mode = SM_0A0B_0C0D;
|
||||
dma_filter = ll_cam_dma_filter_grayscale;
|
||||
}
|
||||
cam->in_bytes_per_pixel = 2; // camera sends YU/YV
|
||||
}
|
||||
cam->fb_bytes_per_pixel = 1; // frame buffer stores Y8
|
||||
} else if (pix_format == PIXFORMAT_YUV422 || pix_format == PIXFORMAT_RGB565) {
|
||||
if (xclk_freq_hz > 10000000 && sensor_pid != OV7725_PID) {
|
||||
if (sensor_pid == OV7670_PID) {
|
||||
sampling_mode = SM_0A0B_0B0C;
|
||||
} else {
|
||||
sampling_mode = SM_0A00_0B00;
|
||||
}
|
||||
dma_filter = ll_cam_dma_filter_yuyv_highspeed;
|
||||
} else {
|
||||
sampling_mode = SM_0A0B_0C0D;
|
||||
dma_filter = ll_cam_dma_filter_yuyv;
|
||||
}
|
||||
cam->in_bytes_per_pixel = 2; // camera sends YU/YV
|
||||
cam->fb_bytes_per_pixel = 2; // frame buffer stores YU/YV/RGB565
|
||||
} else if (pix_format == PIXFORMAT_JPEG) {
|
||||
cam->in_bytes_per_pixel = 1;
|
||||
cam->fb_bytes_per_pixel = 1;
|
||||
dma_filter = ll_cam_dma_filter_jpeg;
|
||||
sampling_mode = SM_0A00_0B00;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Requested format is not supported");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
I2S0.fifo_conf.rx_fifo_mod = sampling_mode;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
|
@ -1,411 +0,0 @@
|
|||
// Copyright 2010-2020 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include "soc/system_reg.h"
|
||||
#include "soc/i2s_struct.h"
|
||||
#include "hal/gpio_ll.h"
|
||||
#include "ll_cam.h"
|
||||
#include "xclk.h"
|
||||
#include "cam_hal.h"
|
||||
|
||||
#if (ESP_IDF_VERSION_MAJOR >= 4) && (ESP_IDF_VERSION_MINOR >= 3)
|
||||
#include "esp_rom_gpio.h"
|
||||
#endif
|
||||
|
||||
#if (ESP_IDF_VERSION_MAJOR >= 5)
|
||||
#define GPIO_PIN_INTR_POSEDGE GPIO_INTR_POSEDGE
|
||||
#define GPIO_PIN_INTR_NEGEDGE GPIO_INTR_NEGEDGE
|
||||
#define gpio_matrix_in(a,b,c) esp_rom_gpio_connect_in_signal(a,b,c)
|
||||
#define ets_delay_us(a) esp_rom_delay_us(a)
|
||||
#endif
|
||||
|
||||
static const char *TAG = "s2 ll_cam";
|
||||
|
||||
#define I2S_ISR_ENABLE(i) {I2S0.int_clr.i = 1;I2S0.int_ena.i = 1;}
|
||||
#define I2S_ISR_DISABLE(i) {I2S0.int_ena.i = 0;I2S0.int_clr.i = 1;}
|
||||
|
||||
static void CAMERA_ISR_IRAM_ATTR ll_cam_vsync_isr(void *arg)
|
||||
{
|
||||
//DBG_PIN_SET(1);
|
||||
cam_obj_t *cam = (cam_obj_t *)arg;
|
||||
BaseType_t HPTaskAwoken = pdFALSE;
|
||||
// filter
|
||||
ets_delay_us(1);
|
||||
if (gpio_ll_get_level(&GPIO, cam->vsync_pin) == !cam->vsync_invert) {
|
||||
ll_cam_send_event(cam, CAM_VSYNC_EVENT, &HPTaskAwoken);
|
||||
}
|
||||
|
||||
if (HPTaskAwoken == pdTRUE) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
//DBG_PIN_SET(0);
|
||||
}
|
||||
|
||||
static void CAMERA_ISR_IRAM_ATTR ll_cam_dma_isr(void *arg)
|
||||
{
|
||||
cam_obj_t *cam = (cam_obj_t *)arg;
|
||||
BaseType_t HPTaskAwoken = pdFALSE;
|
||||
|
||||
typeof(I2S0.int_st) status = I2S0.int_st;
|
||||
if (status.val == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
I2S0.int_clr.val = status.val;
|
||||
|
||||
if (status.in_suc_eof) {
|
||||
ll_cam_send_event(cam, CAM_IN_SUC_EOF_EVENT, &HPTaskAwoken);
|
||||
}
|
||||
|
||||
if (HPTaskAwoken == pdTRUE) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
bool IRAM_ATTR ll_cam_stop(cam_obj_t *cam)
|
||||
{
|
||||
I2S0.conf.rx_start = 0;
|
||||
|
||||
if (cam->jpeg_mode || !cam->psram_mode) {
|
||||
I2S_ISR_DISABLE(in_suc_eof);
|
||||
}
|
||||
|
||||
I2S0.in_link.stop = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_deinit(cam_obj_t *cam)
|
||||
{
|
||||
gpio_isr_handler_remove(cam->vsync_pin);
|
||||
|
||||
if (cam->cam_intr_handle) {
|
||||
esp_intr_free(cam->cam_intr_handle);
|
||||
cam->cam_intr_handle = NULL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool ll_cam_start(cam_obj_t *cam, int frame_pos)
|
||||
{
|
||||
I2S0.conf.rx_start = 0;
|
||||
|
||||
if (cam->jpeg_mode || !cam->psram_mode) {
|
||||
I2S_ISR_ENABLE(in_suc_eof);
|
||||
}
|
||||
|
||||
I2S0.conf.rx_reset = 1;
|
||||
I2S0.conf.rx_reset = 0;
|
||||
I2S0.conf.rx_fifo_reset = 1;
|
||||
I2S0.conf.rx_fifo_reset = 0;
|
||||
I2S0.lc_conf.in_rst = 1;
|
||||
I2S0.lc_conf.in_rst = 0;
|
||||
I2S0.lc_conf.ahbm_fifo_rst = 1;
|
||||
I2S0.lc_conf.ahbm_fifo_rst = 0;
|
||||
I2S0.lc_conf.ahbm_rst = 1;
|
||||
I2S0.lc_conf.ahbm_rst = 0;
|
||||
|
||||
I2S0.rx_eof_num = cam->dma_half_buffer_size; // Ping pong operation
|
||||
if (!cam->psram_mode) {
|
||||
I2S0.in_link.addr = ((uint32_t)&cam->dma[0]) & 0xfffff;
|
||||
} else {
|
||||
I2S0.in_link.addr = ((uint32_t)&cam->frames[frame_pos].dma[0]) & 0xfffff;
|
||||
}
|
||||
|
||||
I2S0.in_link.start = 1;
|
||||
I2S0.conf.rx_start = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_config(cam_obj_t *cam, const camera_config_t *config)
|
||||
{
|
||||
esp_err_t err = camera_enable_out_clock(config);
|
||||
if(err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
periph_module_enable(PERIPH_I2S0_MODULE);
|
||||
// Configure the clock
|
||||
I2S0.clkm_conf.clkm_div_num = 2; // 160MHz / 2 = 80MHz
|
||||
I2S0.clkm_conf.clkm_div_b = 0;
|
||||
I2S0.clkm_conf.clkm_div_a = 0;
|
||||
I2S0.clkm_conf.clk_sel = 2;
|
||||
I2S0.clkm_conf.clk_en = 1;
|
||||
|
||||
|
||||
I2S0.conf.val = 0;
|
||||
I2S0.fifo_conf.val = 0;
|
||||
I2S0.fifo_conf.dscr_en = 1;
|
||||
|
||||
I2S0.lc_conf.ahbm_fifo_rst = 1;
|
||||
I2S0.lc_conf.ahbm_fifo_rst = 0;
|
||||
I2S0.lc_conf.ahbm_rst = 1;
|
||||
I2S0.lc_conf.ahbm_rst = 0;
|
||||
I2S0.lc_conf.check_owner = 0;
|
||||
//I2S0.lc_conf.indscr_burst_en = 1;
|
||||
//I2S0.lc_conf.ext_mem_bk_size = 0; // DMA access external memory block size. 0: 16 bytes, 1: 32 bytes, 2:64 bytes, 3:reserved
|
||||
|
||||
I2S0.timing.val = 0;
|
||||
|
||||
I2S0.int_ena.val = 0;
|
||||
I2S0.int_clr.val = ~0;
|
||||
|
||||
I2S0.conf2.lcd_en = 1;
|
||||
I2S0.conf2.camera_en = 1;
|
||||
|
||||
// Configuration data format
|
||||
I2S0.conf.rx_slave_mod = 1;
|
||||
I2S0.conf.rx_right_first = 0;
|
||||
I2S0.conf.rx_msb_right = cam->swap_data;
|
||||
I2S0.conf.rx_short_sync = 0;
|
||||
I2S0.conf.rx_mono = 0;
|
||||
I2S0.conf.rx_msb_shift = 0;
|
||||
I2S0.conf.rx_dma_equal = 1;
|
||||
|
||||
// Configure sampling rate
|
||||
I2S0.sample_rate_conf.rx_bck_div_num = 1;
|
||||
I2S0.sample_rate_conf.rx_bits_mod = 8;
|
||||
|
||||
I2S0.conf2.i_v_sync_filter_en = 1;
|
||||
I2S0.conf2.i_v_sync_filter_thres = 4;
|
||||
I2S0.conf2.cam_sync_fifo_reset = 1;
|
||||
I2S0.conf2.cam_sync_fifo_reset = 0;
|
||||
|
||||
I2S0.conf_chan.rx_chan_mod = 1;
|
||||
|
||||
I2S0.fifo_conf.rx_fifo_mod_force_en = 1;
|
||||
I2S0.fifo_conf.rx_data_num = 32;
|
||||
I2S0.fifo_conf.rx_fifo_mod = 2;
|
||||
|
||||
I2S0.lc_conf.in_rst = 1;
|
||||
I2S0.lc_conf.in_rst = 0;
|
||||
|
||||
I2S0.conf.rx_start = 1;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void ll_cam_vsync_intr_enable(cam_obj_t *cam, bool en)
|
||||
{
|
||||
if (en) {
|
||||
gpio_intr_enable(cam->vsync_pin);
|
||||
} else {
|
||||
gpio_intr_disable(cam->vsync_pin);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_set_pin(cam_obj_t *cam, const camera_config_t *config)
|
||||
{
|
||||
gpio_config_t io_conf = {0};
|
||||
io_conf.intr_type = cam->vsync_invert ? GPIO_PIN_INTR_NEGEDGE : GPIO_PIN_INTR_POSEDGE;
|
||||
io_conf.pin_bit_mask = 1ULL << config->pin_vsync;
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = 1;
|
||||
io_conf.pull_down_en = 0;
|
||||
gpio_config(&io_conf);
|
||||
gpio_install_isr_service(ESP_INTR_FLAG_LOWMED | CAMERA_ISR_IRAM_FLAG);
|
||||
gpio_isr_handler_add(config->pin_vsync, ll_cam_vsync_isr, cam);
|
||||
gpio_intr_disable(config->pin_vsync);
|
||||
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_pclk], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_pclk, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(config->pin_pclk, GPIO_FLOATING);
|
||||
gpio_matrix_in(config->pin_pclk, I2S0I_WS_IN_IDX, false);
|
||||
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_vsync], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_vsync, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(config->pin_vsync, GPIO_FLOATING);
|
||||
gpio_matrix_in(config->pin_vsync, I2S0I_V_SYNC_IDX, cam->vsync_invert);
|
||||
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_href], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_href, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(config->pin_href, GPIO_FLOATING);
|
||||
gpio_matrix_in(config->pin_href, I2S0I_H_SYNC_IDX, false);
|
||||
|
||||
int data_pins[8] = {
|
||||
config->pin_d0, config->pin_d1, config->pin_d2, config->pin_d3, config->pin_d4, config->pin_d5, config->pin_d6, config->pin_d7,
|
||||
};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[data_pins[i]], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(data_pins[i], GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(data_pins[i], GPIO_FLOATING);
|
||||
// High bit alignment, IN16 is always the highest bit
|
||||
// fifo accesses data by bit, when rx_bits_mod is 8, the data needs to be aligned by 8 bits
|
||||
gpio_matrix_in(data_pins[i], I2S0I_DATA_IN0_IDX + 8 + i, false);
|
||||
}
|
||||
|
||||
gpio_matrix_in(0x38, I2S0I_H_ENABLE_IDX, false);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_init_isr(cam_obj_t *cam)
|
||||
{
|
||||
return esp_intr_alloc(ETS_I2S0_INTR_SOURCE, ESP_INTR_FLAG_LOWMED | CAMERA_ISR_IRAM_FLAG, ll_cam_dma_isr, cam, &cam->cam_intr_handle);
|
||||
}
|
||||
|
||||
void ll_cam_do_vsync(cam_obj_t *cam)
|
||||
{
|
||||
ll_cam_vsync_intr_enable(cam, false);
|
||||
gpio_matrix_in(cam->vsync_pin, I2S0I_V_SYNC_IDX, !cam->vsync_invert);
|
||||
ets_delay_us(10);
|
||||
gpio_matrix_in(cam->vsync_pin, I2S0I_V_SYNC_IDX, cam->vsync_invert);
|
||||
ll_cam_vsync_intr_enable(cam, true);
|
||||
}
|
||||
|
||||
uint8_t ll_cam_get_dma_align(cam_obj_t *cam)
|
||||
{
|
||||
return 64;//16 << I2S0.lc_conf.ext_mem_bk_size;
|
||||
}
|
||||
|
||||
static bool ll_cam_calc_rgb_dma(cam_obj_t *cam){
|
||||
size_t node_max = LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE / cam->dma_bytes_per_item;
|
||||
size_t line_width = cam->width * cam->in_bytes_per_pixel;
|
||||
size_t node_size = node_max;
|
||||
size_t nodes_per_line = 1;
|
||||
size_t lines_per_node = 1;
|
||||
|
||||
// Calculate DMA Node Size so that it's divisable by or divisor of the line width
|
||||
if(line_width >= node_max){
|
||||
// One or more nodes will be requied for one line
|
||||
for(size_t i = node_max; i > 0; i=i-1){
|
||||
if ((line_width % i) == 0) {
|
||||
node_size = i;
|
||||
nodes_per_line = line_width / node_size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// One or more lines can fit into one node
|
||||
for(size_t i = node_max; i > 0; i=i-1){
|
||||
if ((i % line_width) == 0) {
|
||||
node_size = i;
|
||||
lines_per_node = node_size / line_width;
|
||||
while((cam->height % lines_per_node) != 0){
|
||||
lines_per_node = lines_per_node - 1;
|
||||
node_size = lines_per_node * line_width;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "node_size: %4u, nodes_per_line: %u, lines_per_node: %u",
|
||||
(unsigned) (node_size * cam->dma_bytes_per_item), nodes_per_line, lines_per_node);
|
||||
|
||||
cam->dma_node_buffer_size = node_size * cam->dma_bytes_per_item;
|
||||
|
||||
if (cam->psram_mode) {
|
||||
cam->dma_buffer_size = cam->recv_size * cam->dma_bytes_per_item;
|
||||
cam->dma_half_buffer_cnt = 2;
|
||||
cam->dma_half_buffer_size = cam->dma_buffer_size / cam->dma_half_buffer_cnt;
|
||||
} else {
|
||||
size_t dma_half_buffer_max = CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX / 2 / cam->dma_bytes_per_item;
|
||||
if (line_width > dma_half_buffer_max) {
|
||||
ESP_LOGE(TAG, "Resolution too high");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Calculate minimum EOF size = max(mode_size, line_size)
|
||||
size_t dma_half_buffer_min = node_size * nodes_per_line;
|
||||
|
||||
// Calculate max EOF size divisable by node size
|
||||
size_t dma_half_buffer = (dma_half_buffer_max / dma_half_buffer_min) * dma_half_buffer_min;
|
||||
|
||||
// Adjust EOF size so that height will be divisable by the number of lines in each EOF
|
||||
size_t lines_per_half_buffer = dma_half_buffer / line_width;
|
||||
while((cam->height % lines_per_half_buffer) != 0){
|
||||
dma_half_buffer = dma_half_buffer - dma_half_buffer_min;
|
||||
lines_per_half_buffer = dma_half_buffer / line_width;
|
||||
}
|
||||
|
||||
// Calculate DMA size
|
||||
size_t dma_buffer_max = 2 * dma_half_buffer_max;
|
||||
size_t dma_buffer_size = dma_buffer_max;
|
||||
dma_buffer_size =(dma_buffer_max / dma_half_buffer) * dma_half_buffer;
|
||||
|
||||
ESP_LOGI(TAG, "dma_half_buffer_min: %5u, dma_half_buffer: %5u, lines_per_half_buffer: %2u, dma_buffer_size: %5u",
|
||||
(unsigned) (dma_half_buffer_min * cam->dma_bytes_per_item), (unsigned) (dma_half_buffer * cam->dma_bytes_per_item),
|
||||
(unsigned) lines_per_half_buffer, (unsigned) (dma_buffer_size * cam->dma_bytes_per_item));
|
||||
|
||||
cam->dma_buffer_size = dma_buffer_size * cam->dma_bytes_per_item;
|
||||
cam->dma_half_buffer_size = dma_half_buffer * cam->dma_bytes_per_item;
|
||||
cam->dma_half_buffer_cnt = cam->dma_buffer_size / cam->dma_half_buffer_size;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool ll_cam_dma_sizes(cam_obj_t *cam)
|
||||
{
|
||||
cam->dma_bytes_per_item = 1;
|
||||
if (cam->jpeg_mode) {
|
||||
if (cam->psram_mode) {
|
||||
cam->dma_buffer_size = cam->recv_size;
|
||||
cam->dma_half_buffer_size = 1024;
|
||||
cam->dma_half_buffer_cnt = cam->dma_buffer_size / cam->dma_half_buffer_size;
|
||||
cam->dma_node_buffer_size = cam->dma_half_buffer_size;
|
||||
} else {
|
||||
cam->dma_half_buffer_cnt = 16;
|
||||
cam->dma_buffer_size = cam->dma_half_buffer_cnt * 1024;
|
||||
cam->dma_half_buffer_size = cam->dma_buffer_size / cam->dma_half_buffer_cnt;
|
||||
cam->dma_node_buffer_size = cam->dma_half_buffer_size;
|
||||
}
|
||||
} else {
|
||||
return ll_cam_calc_rgb_dma(cam);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t IRAM_ATTR ll_cam_memcpy(cam_obj_t *cam, uint8_t *out, const uint8_t *in, size_t len)
|
||||
{
|
||||
// YUV to Grayscale
|
||||
if (cam->in_bytes_per_pixel == 2 && cam->fb_bytes_per_pixel == 1) {
|
||||
size_t end = len / 8;
|
||||
for (size_t i = 0; i < end; ++i) {
|
||||
out[0] = in[0];
|
||||
out[1] = in[2];
|
||||
out[2] = in[4];
|
||||
out[3] = in[6];
|
||||
out += 4;
|
||||
in += 8;
|
||||
}
|
||||
return len / 2;
|
||||
}
|
||||
|
||||
// just memcpy
|
||||
memcpy(out, in, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_set_sample_mode(cam_obj_t *cam, pixformat_t pix_format, uint32_t xclk_freq_hz, uint16_t sensor_pid)
|
||||
{
|
||||
if (pix_format == PIXFORMAT_GRAYSCALE) {
|
||||
if (sensor_pid == OV3660_PID || sensor_pid == OV5640_PID || sensor_pid == NT99141_PID || sensor_pid == SC031GS_PID || sensor_pid == BF20A6_PID || sensor_pid == GC0308_PID) {
|
||||
cam->in_bytes_per_pixel = 1; // camera sends Y8
|
||||
} else {
|
||||
cam->in_bytes_per_pixel = 2; // camera sends YU/YV
|
||||
}
|
||||
cam->fb_bytes_per_pixel = 1; // frame buffer stores Y8
|
||||
} else if (pix_format == PIXFORMAT_YUV422 || pix_format == PIXFORMAT_RGB565) {
|
||||
cam->in_bytes_per_pixel = 2; // camera sends YU/YV
|
||||
cam->fb_bytes_per_pixel = 2; // frame buffer stores YU/YV/RGB565
|
||||
} else if (pix_format == PIXFORMAT_JPEG) {
|
||||
cam->in_bytes_per_pixel = 1;
|
||||
cam->fb_bytes_per_pixel = 1;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Requested format is not supported");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/*----------------------------------------------------------------------------/
|
||||
/ TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2012
|
||||
/----------------------------------------------------------------------------*/
|
||||
#ifndef _TJPGDEC
|
||||
#define _TJPGDEC
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* System Configurations */
|
||||
|
||||
#define JD_SZBUF 512 /* Size of stream input buffer */
|
||||
#define JD_FORMAT 0 /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */
|
||||
#define JD_USE_SCALE 1 /* Use descaling feature for output */
|
||||
#define JD_TBLCLIP 1 /* Use table for saturation (might be a bit faster but increases 1K bytes of code size) */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* These types must be 16-bit, 32-bit or larger integer */
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* These types must be 8-bit integer */
|
||||
typedef char CHAR;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
/* These types must be 16-bit integer */
|
||||
typedef short SHORT;
|
||||
typedef unsigned short USHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned short WCHAR;
|
||||
|
||||
/* These types must be 32-bit integer */
|
||||
typedef long LONG;
|
||||
typedef unsigned long ULONG;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
|
||||
/* Error code */
|
||||
typedef enum {
|
||||
JDR_OK = 0, /* 0: Succeeded */
|
||||
JDR_INTR, /* 1: Interrupted by output function */
|
||||
JDR_INP, /* 2: Device error or wrong termination of input stream */
|
||||
JDR_MEM1, /* 3: Insufficient memory pool for the image */
|
||||
JDR_MEM2, /* 4: Insufficient stream input buffer */
|
||||
JDR_PAR, /* 5: Parameter error */
|
||||
JDR_FMT1, /* 6: Data format error (may be damaged data) */
|
||||
JDR_FMT2, /* 7: Right format but not supported */
|
||||
JDR_FMT3 /* 8: Not supported JPEG standard */
|
||||
} JRESULT;
|
||||
|
||||
|
||||
|
||||
/* Rectangular structure */
|
||||
typedef struct {
|
||||
WORD left, right, top, bottom;
|
||||
} JRECT;
|
||||
|
||||
|
||||
|
||||
/* Decompressor object structure */
|
||||
typedef struct JDEC JDEC;
|
||||
struct JDEC {
|
||||
UINT dctr; /* Number of bytes available in the input buffer */
|
||||
BYTE* dptr; /* Current data read ptr */
|
||||
BYTE* inbuf; /* Bit stream input buffer */
|
||||
BYTE dmsk; /* Current bit in the current read byte */
|
||||
BYTE scale; /* Output scaling ratio */
|
||||
BYTE msx, msy; /* MCU size in unit of block (width, height) */
|
||||
BYTE qtid[3]; /* Quantization table ID of each component */
|
||||
SHORT dcv[3]; /* Previous DC element of each component */
|
||||
WORD nrst; /* Restart inverval */
|
||||
UINT width, height; /* Size of the input image (pixel) */
|
||||
BYTE* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
|
||||
WORD* huffcode[2][2]; /* Huffman code word tables [id][dcac] */
|
||||
BYTE* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
|
||||
LONG* qttbl[4]; /* Dequaitizer tables [id] */
|
||||
void* workbuf; /* Working buffer for IDCT and RGB output */
|
||||
BYTE* mcubuf; /* Working buffer for the MCU */
|
||||
void* pool; /* Pointer to available memory pool */
|
||||
UINT sz_pool; /* Size of momory pool (bytes available) */
|
||||
UINT (*infunc)(JDEC*, BYTE*, UINT);/* Pointer to jpeg stream input function */
|
||||
void* device; /* Pointer to I/O device identifiler for the session */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* TJpgDec API functions */
|
||||
JRESULT jd_prepare (JDEC*, UINT(*)(JDEC*,BYTE*,UINT), void*, UINT, void*);
|
||||
JRESULT jd_decomp (JDEC*, UINT(*)(JDEC*,void*,JRECT*), BYTE);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TJPGDEC */
|
||||
|
|
@ -1,602 +0,0 @@
|
|||
// Copyright 2010-2020 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include "soc/system_reg.h"
|
||||
#include "soc/lcd_cam_struct.h"
|
||||
#include "soc/lcd_cam_reg.h"
|
||||
#include "soc/gdma_struct.h"
|
||||
#include "soc/gdma_periph.h"
|
||||
#include "soc/gdma_reg.h"
|
||||
#include "hal/clk_gate_ll.h"
|
||||
#include "esp_private/gdma.h"
|
||||
#include "ll_cam.h"
|
||||
#include "cam_hal.h"
|
||||
#include "esp_rom_gpio.h"
|
||||
|
||||
#if (ESP_IDF_VERSION_MAJOR >= 5)
|
||||
#include "soc/gpio_sig_map.h"
|
||||
#include "soc/gpio_periph.h"
|
||||
#include "soc/io_mux_reg.h"
|
||||
#define gpio_matrix_in(a,b,c) esp_rom_gpio_connect_in_signal(a,b,c)
|
||||
#define gpio_matrix_out(a,b,c,d) esp_rom_gpio_connect_out_signal(a,b,c,d)
|
||||
#define ets_delay_us(a) esp_rom_delay_us(a)
|
||||
#endif
|
||||
|
||||
#if !defined(SOC_GDMA_PAIRS_PER_GROUP) && defined(SOC_GDMA_PAIRS_PER_GROUP_MAX)
|
||||
#define SOC_GDMA_PAIRS_PER_GROUP SOC_GDMA_PAIRS_PER_GROUP_MAX
|
||||
#endif
|
||||
|
||||
static const char *TAG = "s3 ll_cam";
|
||||
|
||||
void ll_cam_dma_print_state(cam_obj_t *cam)
|
||||
{
|
||||
esp_rom_printf("dma_infifo_status[%u] :\n", cam->dma_num);
|
||||
esp_rom_printf(" infifo_full_l1 : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.infifo_full_l1);
|
||||
esp_rom_printf(" infifo_empty_l1 : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.infifo_empty_l1);
|
||||
esp_rom_printf(" infifo_full_l2 : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.infifo_full_l2);
|
||||
esp_rom_printf(" infifo_empty_l2 : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.infifo_empty_l2);
|
||||
esp_rom_printf(" infifo_full_l3 : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.infifo_full_l3);
|
||||
esp_rom_printf(" infifo_empty_l3 : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.infifo_empty_l3);
|
||||
esp_rom_printf(" infifo_cnt_l1 : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.infifo_cnt_l1);
|
||||
esp_rom_printf(" infifo_cnt_l2 : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.infifo_cnt_l2);
|
||||
esp_rom_printf(" infifo_cnt_l3 : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.infifo_cnt_l3);
|
||||
esp_rom_printf(" in_remain_under_1b_l3: %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.in_remain_under_1b_l3);
|
||||
esp_rom_printf(" in_remain_under_2b_l3: %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.in_remain_under_2b_l3);
|
||||
esp_rom_printf(" in_remain_under_3b_l3: %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.in_remain_under_3b_l3);
|
||||
esp_rom_printf(" in_remain_under_4b_l3: %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.in_remain_under_4b_l3);
|
||||
esp_rom_printf(" in_buf_hungry : %lu\n", GDMA.channel[cam->dma_num].in.infifo_status.in_buf_hungry);
|
||||
esp_rom_printf("dma_state[%u] :\n", cam->dma_num);
|
||||
esp_rom_printf(" dscr_addr : 0x%lx\n", GDMA.channel[cam->dma_num].in.state.dscr_addr);
|
||||
esp_rom_printf(" in_dscr_state : %lu\n", GDMA.channel[cam->dma_num].in.state.in_dscr_state);
|
||||
esp_rom_printf(" in_state : %lu\n", GDMA.channel[cam->dma_num].in.state.in_state);
|
||||
}
|
||||
|
||||
void ll_cam_dma_reset(cam_obj_t *cam)
|
||||
{
|
||||
|
||||
GDMA.channel[cam->dma_num].in.int_clr.val = ~0;
|
||||
GDMA.channel[cam->dma_num].in.int_ena.val = 0;
|
||||
|
||||
GDMA.channel[cam->dma_num].in.conf0.val = 0;
|
||||
GDMA.channel[cam->dma_num].in.conf0.in_rst = 1;
|
||||
GDMA.channel[cam->dma_num].in.conf0.in_rst = 0;
|
||||
|
||||
//internal SRAM only
|
||||
if (!cam->psram_mode) {
|
||||
GDMA.channel[cam->dma_num].in.conf0.indscr_burst_en = 1;
|
||||
GDMA.channel[cam->dma_num].in.conf0.in_data_burst_en = 1;
|
||||
}
|
||||
|
||||
GDMA.channel[cam->dma_num].in.conf1.in_check_owner = 0;
|
||||
// GDMA.channel[cam->dma_num].in.conf1.in_ext_mem_bk_size = 2;
|
||||
|
||||
GDMA.channel[cam->dma_num].in.peri_sel.sel = 5;
|
||||
//GDMA.channel[cam->dma_num].in.pri.rx_pri = 1;//rx prio 0-15
|
||||
//GDMA.channel[cam->dma_num].in.sram_size.in_size = 6;//This register is used to configure the size of L2 Tx FIFO for Rx channel. 0:16 bytes, 1:24 bytes, 2:32 bytes, 3: 40 bytes, 4: 48 bytes, 5:56 bytes, 6: 64 bytes, 7: 72 bytes, 8: 80 bytes.
|
||||
//GDMA.channel[cam->dma_num].in.wight.rx_weight = 7;//The weight of Rx channel 0-15
|
||||
}
|
||||
|
||||
static void CAMERA_ISR_IRAM_ATTR ll_cam_vsync_isr(void *arg)
|
||||
{
|
||||
//DBG_PIN_SET(1);
|
||||
cam_obj_t *cam = (cam_obj_t *)arg;
|
||||
BaseType_t HPTaskAwoken = pdFALSE;
|
||||
|
||||
typeof(LCD_CAM.lc_dma_int_st) status = LCD_CAM.lc_dma_int_st;
|
||||
if (status.val == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
LCD_CAM.lc_dma_int_clr.val = status.val;
|
||||
|
||||
if (status.cam_vsync_int_st) {
|
||||
ll_cam_send_event(cam, CAM_VSYNC_EVENT, &HPTaskAwoken);
|
||||
}
|
||||
|
||||
if (HPTaskAwoken == pdTRUE) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
//DBG_PIN_SET(0);
|
||||
}
|
||||
|
||||
static void CAMERA_ISR_IRAM_ATTR ll_cam_dma_isr(void *arg)
|
||||
{
|
||||
cam_obj_t *cam = (cam_obj_t *)arg;
|
||||
BaseType_t HPTaskAwoken = pdFALSE;
|
||||
|
||||
typeof(GDMA.channel[cam->dma_num].in.int_st) status = GDMA.channel[cam->dma_num].in.int_st;
|
||||
if (status.val == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
GDMA.channel[cam->dma_num].in.int_clr.val = status.val;
|
||||
|
||||
if (status.in_suc_eof) {
|
||||
ll_cam_send_event(cam, CAM_IN_SUC_EOF_EVENT, &HPTaskAwoken);
|
||||
}
|
||||
|
||||
if (HPTaskAwoken == pdTRUE) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
bool IRAM_ATTR ll_cam_stop(cam_obj_t *cam)
|
||||
{
|
||||
if (cam->jpeg_mode || !cam->psram_mode) {
|
||||
GDMA.channel[cam->dma_num].in.int_ena.in_suc_eof = 0;
|
||||
GDMA.channel[cam->dma_num].in.int_clr.in_suc_eof = 1;
|
||||
}
|
||||
GDMA.channel[cam->dma_num].in.link.stop = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ll_cam_start(cam_obj_t *cam, int frame_pos)
|
||||
{
|
||||
LCD_CAM.cam_ctrl1.cam_start = 0;
|
||||
|
||||
if (cam->jpeg_mode || !cam->psram_mode) {
|
||||
GDMA.channel[cam->dma_num].in.int_clr.in_suc_eof = 1;
|
||||
GDMA.channel[cam->dma_num].in.int_ena.in_suc_eof = 1;
|
||||
}
|
||||
|
||||
LCD_CAM.cam_ctrl1.cam_reset = 1;
|
||||
LCD_CAM.cam_ctrl1.cam_reset = 0;
|
||||
LCD_CAM.cam_ctrl1.cam_afifo_reset = 1;
|
||||
LCD_CAM.cam_ctrl1.cam_afifo_reset = 0;
|
||||
GDMA.channel[cam->dma_num].in.conf0.in_rst = 1;
|
||||
GDMA.channel[cam->dma_num].in.conf0.in_rst = 0;
|
||||
|
||||
LCD_CAM.cam_ctrl1.cam_rec_data_bytelen = cam->dma_half_buffer_size - 1; // Ping pong operation
|
||||
|
||||
if (!cam->psram_mode) {
|
||||
GDMA.channel[cam->dma_num].in.link.addr = ((uint32_t)&cam->dma[0]) & 0xfffff;
|
||||
} else {
|
||||
GDMA.channel[cam->dma_num].in.link.addr = ((uint32_t)&cam->frames[frame_pos].dma[0]) & 0xfffff;
|
||||
}
|
||||
|
||||
GDMA.channel[cam->dma_num].in.link.start = 1;
|
||||
|
||||
LCD_CAM.cam_ctrl.cam_update = 1;
|
||||
LCD_CAM.cam_ctrl1.cam_start = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_deinit(cam_obj_t *cam)
|
||||
{
|
||||
if (cam->cam_intr_handle) {
|
||||
esp_intr_free(cam->cam_intr_handle);
|
||||
cam->cam_intr_handle = NULL;
|
||||
}
|
||||
|
||||
if (cam->dma_intr_handle) {
|
||||
esp_intr_free(cam->dma_intr_handle);
|
||||
cam->dma_intr_handle = NULL;
|
||||
}
|
||||
gdma_disconnect(cam->dma_channel_handle);
|
||||
gdma_del_channel(cam->dma_channel_handle);
|
||||
cam->dma_channel_handle = NULL;
|
||||
// GDMA.channel[cam->dma_num].in.link.addr = 0x0;
|
||||
|
||||
LCD_CAM.cam_ctrl1.cam_start = 0;
|
||||
LCD_CAM.cam_ctrl1.cam_reset = 1;
|
||||
LCD_CAM.cam_ctrl1.cam_reset = 0;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t ll_cam_dma_init(cam_obj_t *cam)
|
||||
{
|
||||
//alloc rx gdma channel
|
||||
gdma_channel_alloc_config_t rx_alloc_config = {
|
||||
.direction = GDMA_CHANNEL_DIRECTION_RX,
|
||||
};
|
||||
#if ((ESP_IDF_VERSION_MAJOR == 5 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 5)
|
||||
esp_err_t ret = gdma_new_ahb_channel(&rx_alloc_config, &cam->dma_channel_handle);
|
||||
#else
|
||||
esp_err_t ret = gdma_new_channel(&rx_alloc_config, &cam->dma_channel_handle);
|
||||
#endif
|
||||
if (ret != ESP_OK) {
|
||||
cam_deinit();
|
||||
ESP_LOGE(TAG, "Can't find available GDMA channel");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
int chan_id = -1;
|
||||
ret = gdma_get_channel_id(cam->dma_channel_handle, &chan_id);
|
||||
if (ret != ESP_OK) {
|
||||
cam_deinit();
|
||||
ESP_LOGE(TAG, "Can't get GDMA channel number");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
cam->dma_num = chan_id;
|
||||
ESP_LOGI(TAG, "DMA Channel=%d", cam->dma_num);
|
||||
// for (int x = (SOC_GDMA_PAIRS_PER_GROUP - 1); x >= 0; x--) {
|
||||
// if (GDMA.channel[x].in.link.addr == 0x0) {
|
||||
// cam->dma_num = x;
|
||||
// ESP_LOGI(TAG, "DMA Channel=%d", cam->dma_num);
|
||||
// break;
|
||||
// }
|
||||
// if (x == 0) {
|
||||
// cam_deinit();
|
||||
// ESP_LOGE(TAG, "Can't found available GDMA channel");
|
||||
// return ESP_FAIL;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!periph_ll_periph_enabled(PERIPH_GDMA_MODULE)) {
|
||||
periph_ll_disable_clk_set_rst(PERIPH_GDMA_MODULE);
|
||||
periph_ll_enable_clk_clear_rst(PERIPH_GDMA_MODULE);
|
||||
}
|
||||
// if (REG_GET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_DMA_CLK_EN) == 0) {
|
||||
// REG_CLR_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_DMA_CLK_EN);
|
||||
// REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_DMA_CLK_EN);
|
||||
// REG_SET_BIT(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_DMA_RST);
|
||||
// REG_CLR_BIT(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_DMA_RST);
|
||||
// }
|
||||
ll_cam_dma_reset(cam);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#if CONFIG_CAMERA_CONVERTER_ENABLED
|
||||
static esp_err_t ll_cam_converter_config(cam_obj_t *cam, const camera_config_t *config)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
switch (config->conv_mode) {
|
||||
case YUV422_TO_YUV420:
|
||||
if (config->pixel_format != PIXFORMAT_YUV422) {
|
||||
ret = ESP_FAIL;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "YUV422 to YUV420 mode");
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_yuv2yuv_mode = 1;
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_yuv_mode = 0;
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_trans_mode = 1;
|
||||
}
|
||||
break;
|
||||
case YUV422_TO_RGB565:
|
||||
if (config->pixel_format != PIXFORMAT_YUV422) {
|
||||
ret = ESP_FAIL;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "YUV422 to RGB565 mode");
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_yuv2yuv_mode = 3;
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_yuv_mode = 0;
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_trans_mode = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#if CONFIG_LCD_CAM_CONV_BT709_ENABLED
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_protocol_mode = 1;
|
||||
#else
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_protocol_mode = 0;
|
||||
#endif
|
||||
#if CONFIG_LCD_CAM_CONV_FULL_RANGE_ENABLED
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_data_out_mode = 1;
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_data_in_mode = 1;
|
||||
#else
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_data_out_mode = 0;
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_data_in_mode = 0;
|
||||
#endif
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_mode_8bits_on = 1;
|
||||
LCD_CAM.cam_rgb_yuv.cam_conv_bypass = 1;
|
||||
cam->conv_mode = config->conv_mode;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
esp_err_t ll_cam_config(cam_obj_t *cam, const camera_config_t *config)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
if (!periph_ll_periph_enabled(PERIPH_LCD_CAM_MODULE)) {
|
||||
periph_ll_disable_clk_set_rst(PERIPH_LCD_CAM_MODULE);
|
||||
periph_ll_enable_clk_clear_rst(PERIPH_LCD_CAM_MODULE);
|
||||
}
|
||||
// if (REG_GET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_LCD_CAM_CLK_EN) == 0) {
|
||||
// REG_CLR_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_LCD_CAM_CLK_EN);
|
||||
// REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_LCD_CAM_CLK_EN);
|
||||
// REG_SET_BIT(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_LCD_CAM_RST);
|
||||
// REG_CLR_BIT(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_LCD_CAM_RST);
|
||||
// }
|
||||
|
||||
LCD_CAM.cam_ctrl.val = 0;
|
||||
|
||||
LCD_CAM.cam_ctrl.cam_clkm_div_b = 0;
|
||||
LCD_CAM.cam_ctrl.cam_clkm_div_a = 0;
|
||||
LCD_CAM.cam_ctrl.cam_clkm_div_num = 160000000 / config->xclk_freq_hz;
|
||||
LCD_CAM.cam_ctrl.cam_clk_sel = 3;//Select Camera module source clock. 0: no clock. 1: APLL. 2: CLK160. 3: no clock.
|
||||
|
||||
LCD_CAM.cam_ctrl.cam_stop_en = 0;
|
||||
LCD_CAM.cam_ctrl.cam_vsync_filter_thres = 4; // Filter by LCD_CAM clock
|
||||
LCD_CAM.cam_ctrl.cam_update = 0;
|
||||
LCD_CAM.cam_ctrl.cam_byte_order = cam->swap_data;
|
||||
LCD_CAM.cam_ctrl.cam_bit_order = 0;
|
||||
LCD_CAM.cam_ctrl.cam_line_int_en = 0;
|
||||
LCD_CAM.cam_ctrl.cam_vs_eof_en = 0; //1: CAM_VSYNC to generate in_suc_eof. 0: in_suc_eof is controlled by reg_cam_rec_data_cyclelen
|
||||
|
||||
LCD_CAM.cam_ctrl1.val = 0;
|
||||
LCD_CAM.cam_ctrl1.cam_rec_data_bytelen = LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE - 1; // Cannot be assigned to 0, and it is easy to overflow
|
||||
LCD_CAM.cam_ctrl1.cam_line_int_num = 0; // The number of hsyncs that generate hs interrupts
|
||||
LCD_CAM.cam_ctrl1.cam_clk_inv = 0;
|
||||
LCD_CAM.cam_ctrl1.cam_vsync_filter_en = 1;
|
||||
LCD_CAM.cam_ctrl1.cam_2byte_en = 0;
|
||||
LCD_CAM.cam_ctrl1.cam_de_inv = 0;
|
||||
LCD_CAM.cam_ctrl1.cam_hsync_inv = 0;
|
||||
LCD_CAM.cam_ctrl1.cam_vsync_inv = 0;
|
||||
LCD_CAM.cam_ctrl1.cam_vh_de_mode_en = 0;
|
||||
|
||||
LCD_CAM.cam_rgb_yuv.val = 0;
|
||||
|
||||
#if CONFIG_CAMERA_CONVERTER_ENABLED
|
||||
if (config->conv_mode) {
|
||||
ret = ll_cam_converter_config(cam, config);
|
||||
if(ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
LCD_CAM.cam_ctrl.cam_update = 1;
|
||||
LCD_CAM.cam_ctrl1.cam_start = 1;
|
||||
|
||||
ret = ll_cam_dma_init(cam);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ll_cam_vsync_intr_enable(cam_obj_t *cam, bool en)
|
||||
{
|
||||
LCD_CAM.lc_dma_int_clr.cam_vsync_int_clr = 1;
|
||||
if (en) {
|
||||
LCD_CAM.lc_dma_int_ena.cam_vsync_int_ena = 1;
|
||||
} else {
|
||||
LCD_CAM.lc_dma_int_ena.cam_vsync_int_ena = 0;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_set_pin(cam_obj_t *cam, const camera_config_t *config)
|
||||
{
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_pclk], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_pclk, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(config->pin_pclk, GPIO_FLOATING);
|
||||
gpio_matrix_in(config->pin_pclk, CAM_PCLK_IDX, false);
|
||||
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_vsync], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_vsync, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(config->pin_vsync, GPIO_FLOATING);
|
||||
gpio_matrix_in(config->pin_vsync, CAM_V_SYNC_IDX, cam->vsync_invert);
|
||||
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_href], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_href, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(config->pin_href, GPIO_FLOATING);
|
||||
gpio_matrix_in(config->pin_href, CAM_H_ENABLE_IDX, false);
|
||||
|
||||
int data_pins[8] = {
|
||||
config->pin_d0, config->pin_d1, config->pin_d2, config->pin_d3, config->pin_d4, config->pin_d5, config->pin_d6, config->pin_d7,
|
||||
};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[data_pins[i]], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(data_pins[i], GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(data_pins[i], GPIO_FLOATING);
|
||||
gpio_matrix_in(data_pins[i], CAM_DATA_IN0_IDX + i, false);
|
||||
}
|
||||
if (config->pin_xclk >= 0) {
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_xclk], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(config->pin_xclk, GPIO_MODE_OUTPUT);
|
||||
gpio_set_pull_mode(config->pin_xclk, GPIO_FLOATING);
|
||||
gpio_matrix_out(config->pin_xclk, CAM_CLK_IDX, false, false);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_init_isr(cam_obj_t *cam)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret = esp_intr_alloc_intrstatus(gdma_periph_signals.groups[0].pairs[cam->dma_num].rx_irq_id,
|
||||
ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED | CAMERA_ISR_IRAM_FLAG,
|
||||
(uint32_t)&GDMA.channel[cam->dma_num].in.int_st, GDMA_IN_SUC_EOF_CH0_INT_ST_M,
|
||||
ll_cam_dma_isr, cam, &cam->dma_intr_handle);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "DMA interrupt allocation of camera failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_intr_alloc_intrstatus(ETS_LCD_CAM_INTR_SOURCE,
|
||||
ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED | CAMERA_ISR_IRAM_FLAG,
|
||||
(uint32_t)&LCD_CAM.lc_dma_int_st.val, LCD_CAM_CAM_VSYNC_INT_ST_M,
|
||||
ll_cam_vsync_isr, cam, &cam->cam_intr_handle);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "LCD_CAM interrupt allocation of camera failed");
|
||||
return ret;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void ll_cam_do_vsync(cam_obj_t *cam)
|
||||
{
|
||||
gpio_matrix_in(cam->vsync_pin, CAM_V_SYNC_IDX, !cam->vsync_invert);
|
||||
ets_delay_us(10);
|
||||
gpio_matrix_in(cam->vsync_pin, CAM_V_SYNC_IDX, cam->vsync_invert);
|
||||
}
|
||||
|
||||
uint8_t ll_cam_get_dma_align(cam_obj_t *cam)
|
||||
{
|
||||
return 16 << GDMA.channel[cam->dma_num].in.conf1.in_ext_mem_bk_size;
|
||||
}
|
||||
|
||||
static bool ll_cam_calc_rgb_dma(cam_obj_t *cam){
|
||||
size_t node_max = LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE / cam->dma_bytes_per_item;
|
||||
size_t line_width = cam->width * cam->in_bytes_per_pixel;
|
||||
size_t node_size = node_max;
|
||||
size_t nodes_per_line = 1;
|
||||
size_t lines_per_node = 1;
|
||||
|
||||
// Calculate DMA Node Size so that it's divisable by or divisor of the line width
|
||||
if(line_width >= node_max){
|
||||
// One or more nodes will be requied for one line
|
||||
for(size_t i = node_max; i > 0; i=i-1){
|
||||
if ((line_width % i) == 0) {
|
||||
node_size = i;
|
||||
nodes_per_line = line_width / node_size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// One or more lines can fit into one node
|
||||
for(size_t i = node_max; i > 0; i=i-1){
|
||||
if ((i % line_width) == 0) {
|
||||
node_size = i;
|
||||
lines_per_node = node_size / line_width;
|
||||
while((cam->height % lines_per_node) != 0){
|
||||
lines_per_node = lines_per_node - 1;
|
||||
node_size = lines_per_node * line_width;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "node_size: %4u, nodes_per_line: %u, lines_per_node: %u",
|
||||
(unsigned) (node_size * cam->dma_bytes_per_item), (unsigned) nodes_per_line, (unsigned) lines_per_node);
|
||||
|
||||
cam->dma_node_buffer_size = node_size * cam->dma_bytes_per_item;
|
||||
|
||||
size_t dma_half_buffer_max = CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX / 2 / cam->dma_bytes_per_item;
|
||||
if (line_width > dma_half_buffer_max) {
|
||||
ESP_LOGE(TAG, "Resolution too high");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Calculate minimum EOF size = max(mode_size, line_size)
|
||||
size_t dma_half_buffer_min = node_size * nodes_per_line;
|
||||
|
||||
// Calculate max EOF size divisable by node size
|
||||
size_t dma_half_buffer = (dma_half_buffer_max / dma_half_buffer_min) * dma_half_buffer_min;
|
||||
|
||||
// Adjust EOF size so that height will be divisable by the number of lines in each EOF
|
||||
size_t lines_per_half_buffer = dma_half_buffer / line_width;
|
||||
while((cam->height % lines_per_half_buffer) != 0){
|
||||
dma_half_buffer = dma_half_buffer - dma_half_buffer_min;
|
||||
lines_per_half_buffer = dma_half_buffer / line_width;
|
||||
}
|
||||
|
||||
// Calculate DMA size
|
||||
size_t dma_buffer_max = 2 * dma_half_buffer_max;
|
||||
if (cam->psram_mode) {
|
||||
dma_buffer_max = cam->recv_size / cam->dma_bytes_per_item;
|
||||
}
|
||||
size_t dma_buffer_size = dma_buffer_max;
|
||||
if (!cam->psram_mode) {
|
||||
dma_buffer_size =(dma_buffer_max / dma_half_buffer) * dma_half_buffer;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "dma_half_buffer_min: %5u, dma_half_buffer: %5u, lines_per_half_buffer: %2u, dma_buffer_size: %5u",
|
||||
(unsigned) (dma_half_buffer_min * cam->dma_bytes_per_item), (unsigned) (dma_half_buffer * cam->dma_bytes_per_item),
|
||||
(unsigned) lines_per_half_buffer, (unsigned) (dma_buffer_size * cam->dma_bytes_per_item));
|
||||
|
||||
cam->dma_buffer_size = dma_buffer_size * cam->dma_bytes_per_item;
|
||||
cam->dma_half_buffer_size = dma_half_buffer * cam->dma_bytes_per_item;
|
||||
cam->dma_half_buffer_cnt = cam->dma_buffer_size / cam->dma_half_buffer_size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool ll_cam_dma_sizes(cam_obj_t *cam)
|
||||
{
|
||||
cam->dma_bytes_per_item = 1;
|
||||
if (cam->jpeg_mode) {
|
||||
if (cam->psram_mode) {
|
||||
cam->dma_buffer_size = cam->recv_size;
|
||||
cam->dma_half_buffer_size = 1024;
|
||||
cam->dma_half_buffer_cnt = cam->dma_buffer_size / cam->dma_half_buffer_size;
|
||||
cam->dma_node_buffer_size = cam->dma_half_buffer_size;
|
||||
} else {
|
||||
cam->dma_half_buffer_cnt = 16;
|
||||
cam->dma_buffer_size = cam->dma_half_buffer_cnt * 1024;
|
||||
cam->dma_half_buffer_size = cam->dma_buffer_size / cam->dma_half_buffer_cnt;
|
||||
cam->dma_node_buffer_size = cam->dma_half_buffer_size;
|
||||
}
|
||||
} else {
|
||||
return ll_cam_calc_rgb_dma(cam);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t IRAM_ATTR ll_cam_memcpy(cam_obj_t *cam, uint8_t *out, const uint8_t *in, size_t len)
|
||||
{
|
||||
// YUV to Grayscale
|
||||
if (cam->in_bytes_per_pixel == 2 && cam->fb_bytes_per_pixel == 1) {
|
||||
size_t end = len / 8;
|
||||
for (size_t i = 0; i < end; ++i) {
|
||||
out[0] = in[0];
|
||||
out[1] = in[2];
|
||||
out[2] = in[4];
|
||||
out[3] = in[6];
|
||||
out += 4;
|
||||
in += 8;
|
||||
}
|
||||
return len / 2;
|
||||
}
|
||||
|
||||
// just memcpy
|
||||
memcpy(out, in, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
esp_err_t ll_cam_set_sample_mode(cam_obj_t *cam, pixformat_t pix_format, uint32_t xclk_freq_hz, uint16_t sensor_pid)
|
||||
{
|
||||
if (pix_format == PIXFORMAT_GRAYSCALE) {
|
||||
if (sensor_pid == OV3660_PID || sensor_pid == OV5640_PID || sensor_pid == NT99141_PID || sensor_pid == SC031GS_PID || sensor_pid == BF20A6_PID || sensor_pid == GC0308_PID) {
|
||||
cam->in_bytes_per_pixel = 1; // camera sends Y8
|
||||
} else {
|
||||
cam->in_bytes_per_pixel = 2; // camera sends YU/YV
|
||||
}
|
||||
cam->fb_bytes_per_pixel = 1; // frame buffer stores Y8
|
||||
} else if (pix_format == PIXFORMAT_YUV422 || pix_format == PIXFORMAT_RGB565) {
|
||||
#if CONFIG_CAMERA_CONVERTER_ENABLED
|
||||
switch (cam->conv_mode) {
|
||||
case YUV422_TO_YUV420:
|
||||
cam->in_bytes_per_pixel = 1.5; // for DMA receive
|
||||
cam->fb_bytes_per_pixel = 1.5; // frame buffer stores YUV420
|
||||
break;
|
||||
case YUV422_TO_RGB565:
|
||||
default:
|
||||
cam->in_bytes_per_pixel = 2; // for DMA receive
|
||||
cam->fb_bytes_per_pixel = 2; // frame buffer stores YU/YV/RGB565
|
||||
break;
|
||||
}
|
||||
#else
|
||||
cam->in_bytes_per_pixel = 2; // for DMA receive
|
||||
cam->fb_bytes_per_pixel = 2; // frame buffer stores YU/YV/RGB565
|
||||
#endif
|
||||
} else if (pix_format == PIXFORMAT_JPEG) {
|
||||
cam->in_bytes_per_pixel = 1;
|
||||
cam->fb_bytes_per_pixel = 1;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Requested format is not supported");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// implements function from xclk.c to allow dynamic XCLK change
|
||||
esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz)
|
||||
{
|
||||
LCD_CAM.cam_ctrl.cam_clkm_div_b = 0;
|
||||
LCD_CAM.cam_ctrl.cam_clkm_div_a = 0;
|
||||
LCD_CAM.cam_ctrl.cam_clkm_div_num = 160000000 / xclk_freq_hz;
|
||||
LCD_CAM.cam_ctrl.cam_clk_sel = 3;//Select Camera module source clock. 0: no clock. 1: APLL. 2: CLK160. 3: no clock.
|
||||
LCD_CAM.cam_ctrl.cam_update = 1;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/*----------------------------------------------------------------------------/
|
||||
/ TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2012
|
||||
/----------------------------------------------------------------------------*/
|
||||
#ifndef _TJPGDEC
|
||||
#define _TJPGDEC
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* System Configurations */
|
||||
|
||||
#define JD_SZBUF 512 /* Size of stream input buffer */
|
||||
#define JD_FORMAT 0 /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */
|
||||
#define JD_USE_SCALE 1 /* Use descaling feature for output */
|
||||
#define JD_TBLCLIP 1 /* Use table for saturation (might be a bit faster but increases 1K bytes of code size) */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* These types must be 16-bit, 32-bit or larger integer */
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* These types must be 8-bit integer */
|
||||
typedef char CHAR;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
/* These types must be 16-bit integer */
|
||||
typedef short SHORT;
|
||||
typedef unsigned short USHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned short WCHAR;
|
||||
|
||||
/* These types must be 32-bit integer */
|
||||
typedef long LONG;
|
||||
typedef unsigned long ULONG;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
|
||||
/* Error code */
|
||||
typedef enum {
|
||||
JDR_OK = 0, /* 0: Succeeded */
|
||||
JDR_INTR, /* 1: Interrupted by output function */
|
||||
JDR_INP, /* 2: Device error or wrong termination of input stream */
|
||||
JDR_MEM1, /* 3: Insufficient memory pool for the image */
|
||||
JDR_MEM2, /* 4: Insufficient stream input buffer */
|
||||
JDR_PAR, /* 5: Parameter error */
|
||||
JDR_FMT1, /* 6: Data format error (may be damaged data) */
|
||||
JDR_FMT2, /* 7: Right format but not supported */
|
||||
JDR_FMT3 /* 8: Not supported JPEG standard */
|
||||
} JRESULT;
|
||||
|
||||
|
||||
|
||||
/* Rectangular structure */
|
||||
typedef struct {
|
||||
WORD left, right, top, bottom;
|
||||
} JRECT;
|
||||
|
||||
|
||||
|
||||
/* Decompressor object structure */
|
||||
typedef struct JDEC JDEC;
|
||||
struct JDEC {
|
||||
UINT dctr; /* Number of bytes available in the input buffer */
|
||||
BYTE* dptr; /* Current data read ptr */
|
||||
BYTE* inbuf; /* Bit stream input buffer */
|
||||
BYTE dmsk; /* Current bit in the current read byte */
|
||||
BYTE scale; /* Output scaling ratio */
|
||||
BYTE msx, msy; /* MCU size in unit of block (width, height) */
|
||||
BYTE qtid[3]; /* Quantization table ID of each component */
|
||||
SHORT dcv[3]; /* Previous DC element of each component */
|
||||
WORD nrst; /* Restart inverval */
|
||||
UINT width, height; /* Size of the input image (pixel) */
|
||||
BYTE* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
|
||||
WORD* huffcode[2][2]; /* Huffman code word tables [id][dcac] */
|
||||
BYTE* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
|
||||
LONG* qttbl[4]; /* Dequaitizer tables [id] */
|
||||
void* workbuf; /* Working buffer for IDCT and RGB output */
|
||||
BYTE* mcubuf; /* Working buffer for the MCU */
|
||||
void* pool; /* Pointer to available memory pool */
|
||||
UINT sz_pool; /* Size of momory pool (bytes available) */
|
||||
UINT (*infunc)(JDEC*, BYTE*, UINT);/* Pointer to jpeg stream input function */
|
||||
void* device; /* Pointer to I/O device identifiler for the session */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* TJpgDec API functions */
|
||||
JRESULT jd_prepare (JDEC*, UINT(*)(JDEC*,BYTE*,UINT), void*, UINT, void*);
|
||||
JRESULT jd_decomp (JDEC*, UINT(*)(JDEC*,void*,JRECT*), BYTE);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TJPGDEC */
|
||||
|
|
@ -1,165 +0,0 @@
|
|||
// Copyright 2010-2020 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_idf_version.h"
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
#include "esp32/rom/lldesc.h"
|
||||
#else
|
||||
#include "rom/lldesc.h"
|
||||
#endif
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/rom/lldesc.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/rom/lldesc.h"
|
||||
#endif
|
||||
#include "esp_log.h"
|
||||
#include "esp_camera.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#if __has_include("esp_private/periph_ctrl.h")
|
||||
# include "esp_private/periph_ctrl.h"
|
||||
#endif
|
||||
#if __has_include("esp_private/gdma.h")
|
||||
# include "esp_private/gdma.h"
|
||||
#endif
|
||||
|
||||
#if CONFIG_LCD_CAM_ISR_IRAM_SAFE
|
||||
#define CAMERA_ISR_IRAM_FLAG ESP_INTR_FLAG_IRAM
|
||||
#define CAMERA_ISR_IRAM_ATTR IRAM_ATTR
|
||||
#else
|
||||
#define CAMERA_ISR_IRAM_FLAG 0
|
||||
#define CAMERA_ISR_IRAM_ATTR
|
||||
#endif
|
||||
|
||||
#define CAMERA_DBG_PIN_ENABLE 0
|
||||
#if CAMERA_DBG_PIN_ENABLE
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#define DBG_PIN_NUM 26
|
||||
#else
|
||||
#define DBG_PIN_NUM 7
|
||||
#endif
|
||||
#include "hal/gpio_ll.h"
|
||||
#define DBG_PIN_SET(v) gpio_ll_set_level(&GPIO, DBG_PIN_NUM, v)
|
||||
#else
|
||||
#define DBG_PIN_SET(v)
|
||||
#endif
|
||||
|
||||
#define CAM_CHECK(a, str, ret) if (!(a)) { \
|
||||
ESP_LOGE(TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
|
||||
return (ret); \
|
||||
}
|
||||
|
||||
#define CAM_CHECK_GOTO(a, str, lab) if (!(a)) { \
|
||||
ESP_LOGE(TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
|
||||
goto lab; \
|
||||
}
|
||||
|
||||
#define LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE (4092)
|
||||
|
||||
typedef enum {
|
||||
CAM_IN_SUC_EOF_EVENT = 0,
|
||||
CAM_VSYNC_EVENT
|
||||
} cam_event_t;
|
||||
|
||||
typedef enum {
|
||||
CAM_STATE_IDLE = 0,
|
||||
CAM_STATE_READ_BUF = 1,
|
||||
} cam_state_t;
|
||||
|
||||
typedef struct {
|
||||
camera_fb_t fb;
|
||||
uint8_t en;
|
||||
//for RGB/YUV modes
|
||||
lldesc_t *dma;
|
||||
size_t fb_offset;
|
||||
} cam_frame_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t dma_bytes_per_item;
|
||||
uint32_t dma_buffer_size;
|
||||
uint32_t dma_half_buffer_size;
|
||||
uint32_t dma_half_buffer_cnt;
|
||||
uint32_t dma_node_buffer_size;
|
||||
uint32_t dma_node_cnt;
|
||||
uint32_t frame_copy_cnt;
|
||||
|
||||
//for JPEG mode
|
||||
lldesc_t *dma;
|
||||
uint8_t *dma_buffer;
|
||||
|
||||
cam_frame_t *frames;
|
||||
|
||||
QueueHandle_t event_queue;
|
||||
QueueHandle_t frame_buffer_queue;
|
||||
TaskHandle_t task_handle;
|
||||
intr_handle_t cam_intr_handle;
|
||||
|
||||
uint8_t dma_num;//ESP32-S3
|
||||
intr_handle_t dma_intr_handle;//ESP32-S3
|
||||
#if SOC_GDMA_SUPPORTED
|
||||
gdma_channel_handle_t dma_channel_handle;//ESP32-S3
|
||||
#endif
|
||||
|
||||
uint8_t jpeg_mode;
|
||||
uint8_t vsync_pin;
|
||||
uint8_t vsync_invert;
|
||||
uint32_t frame_cnt;
|
||||
uint32_t recv_size;
|
||||
bool swap_data;
|
||||
bool psram_mode;
|
||||
|
||||
//for RGB/YUV modes
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
#if CONFIG_CAMERA_CONVERTER_ENABLED
|
||||
float in_bytes_per_pixel;
|
||||
float fb_bytes_per_pixel;
|
||||
camera_conv_mode_t conv_mode;
|
||||
#else
|
||||
uint8_t in_bytes_per_pixel;
|
||||
uint8_t fb_bytes_per_pixel;
|
||||
#endif
|
||||
uint32_t fb_size;
|
||||
|
||||
cam_state_t state;
|
||||
} cam_obj_t;
|
||||
|
||||
|
||||
bool ll_cam_stop(cam_obj_t *cam);
|
||||
bool ll_cam_start(cam_obj_t *cam, int frame_pos);
|
||||
esp_err_t ll_cam_config(cam_obj_t *cam, const camera_config_t *config);
|
||||
esp_err_t ll_cam_deinit(cam_obj_t *cam);
|
||||
void ll_cam_vsync_intr_enable(cam_obj_t *cam, bool en);
|
||||
esp_err_t ll_cam_set_pin(cam_obj_t *cam, const camera_config_t *config);
|
||||
esp_err_t ll_cam_init_isr(cam_obj_t *cam);
|
||||
void ll_cam_do_vsync(cam_obj_t *cam);
|
||||
uint8_t ll_cam_get_dma_align(cam_obj_t *cam);
|
||||
bool ll_cam_dma_sizes(cam_obj_t *cam);
|
||||
size_t ll_cam_memcpy(cam_obj_t *cam, uint8_t *out, const uint8_t *in, size_t len);
|
||||
esp_err_t ll_cam_set_sample_mode(cam_obj_t *cam, pixformat_t pix_format, uint32_t xclk_freq_hz, uint16_t sensor_pid);
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
void ll_cam_dma_print_state(cam_obj_t *cam);
|
||||
void ll_cam_dma_reset(cam_obj_t *cam);
|
||||
#endif
|
||||
|
||||
// implemented in cam_hal
|
||||
void ll_cam_send_event(cam_obj_t *cam, cam_event_t cam_event, BaseType_t * HPTaskAwoken);
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
#include "driver/gpio.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "xclk.h"
|
||||
#include "esp_camera.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 = "camera_xclk";
|
||||
#endif
|
||||
|
||||
#define NO_CAMERA_LEDC_CHANNEL 0xFF
|
||||
static ledc_channel_t g_ledc_channel = NO_CAMERA_LEDC_CHANNEL;
|
||||
|
||||
esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz)
|
||||
{
|
||||
ledc_timer_config_t timer_conf;
|
||||
timer_conf.duty_resolution = LEDC_TIMER_1_BIT;
|
||||
timer_conf.freq_hz = xclk_freq_hz;
|
||||
timer_conf.speed_mode = LEDC_LOW_SPEED_MODE;
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
timer_conf.deconfigure = false;
|
||||
#endif
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
timer_conf.clk_cfg = LEDC_AUTO_CLK;
|
||||
#endif
|
||||
timer_conf.timer_num = (ledc_timer_t)ledc_timer;
|
||||
esp_err_t err = ledc_timer_config(&timer_conf);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "ledc_timer_config failed for freq %d, rc=%x", xclk_freq_hz, err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t camera_enable_out_clock(const camera_config_t* config)
|
||||
{
|
||||
esp_err_t err = xclk_timer_conf(config->ledc_timer, config->xclk_freq_hz);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "ledc_timer_config failed, rc=%x", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
g_ledc_channel = config->ledc_channel;
|
||||
ledc_channel_config_t ch_conf;
|
||||
ch_conf.gpio_num = config->pin_xclk;
|
||||
ch_conf.speed_mode = LEDC_LOW_SPEED_MODE;
|
||||
ch_conf.channel = config->ledc_channel;
|
||||
ch_conf.intr_type = LEDC_INTR_DISABLE;
|
||||
ch_conf.timer_sel = config->ledc_timer;
|
||||
ch_conf.duty = 1;
|
||||
ch_conf.hpoint = 0;
|
||||
err = ledc_channel_config(&ch_conf);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "ledc_channel_config failed, rc=%x", err);
|
||||
return err;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void camera_disable_out_clock()
|
||||
{
|
||||
if (g_ledc_channel != NO_CAMERA_LEDC_CHANNEL) {
|
||||
ledc_stop(LEDC_LOW_SPEED_MODE, g_ledc_channel, 0);
|
||||
g_ledc_channel = NO_CAMERA_LEDC_CHANNEL;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
idf_component_register(SRC_DIRS .
|
||||
PRIV_INCLUDE_DIRS .
|
||||
PRIV_REQUIRES test_utils esp32-camera nvs_flash
|
||||
EMBED_TXTFILES pictures/testimg.jpeg pictures/test_outside.jpeg pictures/test_inside.jpeg)
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#
|
||||
#Component Makefile
|
||||
#
|
||||
|
||||
COMPONENT_SRCDIRS += ./
|
||||
COMPONENT_PRIV_INCLUDEDIRS += ./
|
||||
|
||||
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 80 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.6 KiB |
|
|
@ -1,535 +0,0 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "unity.h"
|
||||
#include <mbedtls/base64.h>
|
||||
#include "esp_log.h"
|
||||
#include "driver/i2c.h"
|
||||
|
||||
#include "esp_camera.h"
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
#define BOARD_WROVER_KIT 1
|
||||
#elif defined CONFIG_IDF_TARGET_ESP32S2
|
||||
#define BOARD_CAMERA_MODEL_ESP32S2 1
|
||||
#elif defined CONFIG_IDF_TARGET_ESP32S3
|
||||
#define BOARD_CAMERA_MODEL_ESP32_S3_EYE 1
|
||||
#endif
|
||||
|
||||
// WROVER-KIT PIN Map
|
||||
#if BOARD_WROVER_KIT
|
||||
|
||||
#define PWDN_GPIO_NUM -1 //power down is not used
|
||||
#define RESET_GPIO_NUM -1 //software reset will be performed
|
||||
#define XCLK_GPIO_NUM 21
|
||||
#define SIOD_GPIO_NUM 26
|
||||
#define SIOC_GPIO_NUM 27
|
||||
|
||||
#define Y9_GPIO_NUM 35
|
||||
#define Y8_GPIO_NUM 34
|
||||
#define Y7_GPIO_NUM 39
|
||||
#define Y6_GPIO_NUM 36
|
||||
#define Y5_GPIO_NUM 19
|
||||
#define Y4_GPIO_NUM 18
|
||||
#define Y3_GPIO_NUM 5
|
||||
#define Y2_GPIO_NUM 4
|
||||
#define VSYNC_GPIO_NUM 25
|
||||
#define HREF_GPIO_NUM 23
|
||||
#define PCLK_GPIO_NUM 22
|
||||
|
||||
// ESP32Cam (AiThinker) PIN Map
|
||||
#elif BOARD_ESP32CAM_AITHINKER
|
||||
|
||||
#define PWDN_GPIO_NUM 32
|
||||
#define RESET_GPIO_NUM -1 //software reset will be performed
|
||||
#define XCLK_GPIO_NUM 0
|
||||
#define SIOD_GPIO_NUM 26
|
||||
#define SIOC_GPIO_NUM 27
|
||||
|
||||
#define Y9_GPIO_NUM 35
|
||||
#define Y8_GPIO_NUM 34
|
||||
#define Y7_GPIO_NUM 39
|
||||
#define Y6_GPIO_NUM 36
|
||||
#define Y5_GPIO_NUM 21
|
||||
#define Y4_GPIO_NUM 19
|
||||
#define Y3_GPIO_NUM 18
|
||||
#define Y2_GPIO_NUM 5
|
||||
#define VSYNC_GPIO_NUM 25
|
||||
#define HREF_GPIO_NUM 23
|
||||
#define PCLK_GPIO_NUM 22
|
||||
|
||||
#elif BOARD_CAMERA_MODEL_ESP32S2
|
||||
|
||||
#define PWDN_GPIO_NUM -1
|
||||
#define RESET_GPIO_NUM -1
|
||||
|
||||
#define VSYNC_GPIO_NUM 21
|
||||
#define HREF_GPIO_NUM 38
|
||||
#define PCLK_GPIO_NUM 11
|
||||
#define XCLK_GPIO_NUM 40
|
||||
|
||||
#define SIOD_GPIO_NUM 17
|
||||
#define SIOC_GPIO_NUM 18
|
||||
|
||||
#define Y9_GPIO_NUM 39
|
||||
#define Y8_GPIO_NUM 41
|
||||
#define Y7_GPIO_NUM 42
|
||||
#define Y6_GPIO_NUM 12
|
||||
#define Y5_GPIO_NUM 3
|
||||
#define Y4_GPIO_NUM 14
|
||||
#define Y3_GPIO_NUM 37
|
||||
#define Y2_GPIO_NUM 13
|
||||
|
||||
#elif BOARD_CAMERA_MODEL_ESP32_S3_EYE
|
||||
|
||||
#define PWDN_GPIO_NUM 43
|
||||
#define RESET_GPIO_NUM 44
|
||||
|
||||
#define VSYNC_GPIO_NUM 6
|
||||
#define HREF_GPIO_NUM 7
|
||||
#define PCLK_GPIO_NUM 13
|
||||
#define XCLK_GPIO_NUM 15
|
||||
|
||||
#define SIOD_GPIO_NUM 4
|
||||
#define SIOC_GPIO_NUM 5
|
||||
|
||||
#define Y9_GPIO_NUM 16
|
||||
#define Y8_GPIO_NUM 17
|
||||
#define Y7_GPIO_NUM 18
|
||||
#define Y6_GPIO_NUM 12
|
||||
#define Y5_GPIO_NUM 11
|
||||
#define Y4_GPIO_NUM 10
|
||||
#define Y3_GPIO_NUM 9
|
||||
#define Y2_GPIO_NUM 8
|
||||
|
||||
#endif
|
||||
|
||||
#define I2C_MASTER_SCL_IO 4 /*!< GPIO number used for I2C master clock */
|
||||
#define I2C_MASTER_SDA_IO 5 /*!< GPIO number used for I2C master data */
|
||||
#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
|
||||
#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */
|
||||
|
||||
static const char *TAG = "test camera";
|
||||
|
||||
typedef void (*decode_func_t)(uint8_t *jpegbuffer, uint32_t size, uint8_t *outbuffer);
|
||||
|
||||
static esp_err_t init_camera(uint32_t xclk_freq_hz, pixformat_t pixel_format, framesize_t frame_size, uint8_t fb_count, int sccb_sda_gpio_num, int sccb_port)
|
||||
{
|
||||
framesize_t size_bak = frame_size;
|
||||
if (PIXFORMAT_JPEG == pixel_format && FRAMESIZE_SVGA > frame_size) {
|
||||
frame_size = FRAMESIZE_HD;
|
||||
}
|
||||
camera_config_t camera_config = {
|
||||
.pin_pwdn = PWDN_GPIO_NUM,
|
||||
.pin_reset = RESET_GPIO_NUM,
|
||||
.pin_xclk = XCLK_GPIO_NUM,
|
||||
.pin_sccb_sda = sccb_sda_gpio_num, // If pin_sccb_sda is -1, sccb will use the already initialized i2c port specified by `sccb_i2c_port`.
|
||||
.pin_sccb_scl = SIOC_GPIO_NUM,
|
||||
.sccb_i2c_port = sccb_port,
|
||||
|
||||
.pin_d7 = Y9_GPIO_NUM,
|
||||
.pin_d6 = Y8_GPIO_NUM,
|
||||
.pin_d5 = Y7_GPIO_NUM,
|
||||
.pin_d4 = Y6_GPIO_NUM,
|
||||
.pin_d3 = Y5_GPIO_NUM,
|
||||
.pin_d2 = Y4_GPIO_NUM,
|
||||
.pin_d1 = Y3_GPIO_NUM,
|
||||
.pin_d0 = Y2_GPIO_NUM,
|
||||
.pin_vsync = VSYNC_GPIO_NUM,
|
||||
.pin_href = HREF_GPIO_NUM,
|
||||
.pin_pclk = PCLK_GPIO_NUM,
|
||||
|
||||
//EXPERIMENTAL: Set to 16MHz on ESP32-S2 or ESP32-S3 to enable EDMA mode
|
||||
.xclk_freq_hz = xclk_freq_hz,
|
||||
.ledc_timer = LEDC_TIMER_0,
|
||||
.ledc_channel = LEDC_CHANNEL_0,
|
||||
|
||||
.pixel_format = pixel_format, //YUV422,GRAYSCALE,RGB565,JPEG
|
||||
.frame_size = frame_size, //QQVGA-UXGAQQVGA-UXGA, For ESP32, do not use sizes above QVGA when not JPEG. The performance of the ESP32-S series has improved a lot, but JPEG mode always gives better frame rates.
|
||||
|
||||
.jpeg_quality = 12, //0-63, for OV series camera sensors, lower number means higher quality
|
||||
.fb_count = fb_count, //When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
|
||||
.grab_mode = CAMERA_GRAB_WHEN_EMPTY
|
||||
};
|
||||
|
||||
//initialize the camera
|
||||
esp_err_t ret = esp_camera_init(&camera_config);
|
||||
|
||||
if (ESP_OK == ret && PIXFORMAT_JPEG == pixel_format && FRAMESIZE_SVGA > size_bak) {
|
||||
sensor_t *s = esp_camera_sensor_get();
|
||||
s->set_framesize(s, size_bak);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool camera_test_fps(uint16_t times, float *fps, uint32_t *size)
|
||||
{
|
||||
*fps = 0.0f;
|
||||
*size = 0;
|
||||
uint32_t s = 0;
|
||||
uint32_t num = 0;
|
||||
uint64_t total_time = esp_timer_get_time();
|
||||
for (size_t i = 0; i < times; i++) {
|
||||
camera_fb_t *pic = esp_camera_fb_get();
|
||||
if (NULL == pic) {
|
||||
ESP_LOGW(TAG, "fb get failed");
|
||||
return 0;
|
||||
} else {
|
||||
s += pic->len;
|
||||
num++;
|
||||
}
|
||||
esp_camera_fb_return(pic);
|
||||
}
|
||||
total_time = esp_timer_get_time() - total_time;
|
||||
if (num) {
|
||||
*fps = num * 1000000.0f / total_time ;
|
||||
*size = s / num;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *get_cam_format_name(pixformat_t pixel_format)
|
||||
{
|
||||
switch (pixel_format) {
|
||||
case PIXFORMAT_JPEG: return "JPEG";
|
||||
case PIXFORMAT_RGB565: return "RGB565";
|
||||
case PIXFORMAT_RGB888: return "RGB888";
|
||||
case PIXFORMAT_YUV422: return "YUV422";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "UNKNOW";
|
||||
}
|
||||
|
||||
static void printf_img_base64(const camera_fb_t *pic)
|
||||
{
|
||||
uint8_t *outbuffer = NULL;
|
||||
size_t outsize = 0;
|
||||
if (PIXFORMAT_JPEG != pic->format) {
|
||||
fmt2jpg(pic->buf, pic->width * pic->height * 2, pic->width, pic->height, pic->format, 50, &outbuffer, &outsize);
|
||||
} else {
|
||||
outbuffer = pic->buf;
|
||||
outsize = pic->len;
|
||||
}
|
||||
|
||||
uint8_t *base64_buf = calloc(1, outsize * 4);
|
||||
if (NULL != base64_buf) {
|
||||
size_t out_len = 0;
|
||||
mbedtls_base64_encode(base64_buf, outsize * 4, &out_len, outbuffer, outsize);
|
||||
printf("%s\n", base64_buf);
|
||||
free(base64_buf);
|
||||
if (PIXFORMAT_JPEG != pic->format) {
|
||||
free(outbuffer);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGE(TAG, "malloc for base64 buffer failed");
|
||||
}
|
||||
}
|
||||
|
||||
static void camera_performance_test(uint32_t xclk_freq, uint32_t pic_num)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
//detect sensor information
|
||||
TEST_ESP_OK(init_camera(20000000, PIXFORMAT_RGB565, FRAMESIZE_QVGA, 2, SIOD_GPIO_NUM, -1));
|
||||
sensor_t *s = esp_camera_sensor_get();
|
||||
camera_sensor_info_t *info = esp_camera_sensor_get_info(&s->id);
|
||||
TEST_ASSERT_NOT_NULL(info);
|
||||
TEST_ESP_OK(esp_camera_deinit());
|
||||
vTaskDelay(500 / portTICK_RATE_MS);
|
||||
framesize_t max_size = info->max_size;
|
||||
pixformat_t all_format[] = {PIXFORMAT_JPEG, PIXFORMAT_RGB565, PIXFORMAT_YUV422, };
|
||||
pixformat_t *format_s = &all_format[0];
|
||||
pixformat_t *format_e = &all_format[2];
|
||||
if (false == info->support_jpeg) {
|
||||
format_s++; // skip jpeg
|
||||
}
|
||||
|
||||
struct fps_result {
|
||||
float fps[FRAMESIZE_INVALID];
|
||||
uint32_t size[FRAMESIZE_INVALID];
|
||||
};
|
||||
struct fps_result results[3] = {0};
|
||||
|
||||
for (; format_s <= format_e; format_s++) {
|
||||
for (size_t i = 0; i <= max_size; i++) {
|
||||
ESP_LOGI(TAG, "\n\n===> Testing format:%s resolution: %d x %d <===", get_cam_format_name(*format_s), resolution[i].width, resolution[i].height);
|
||||
ret = init_camera(xclk_freq, *format_s, i, 2, SIOD_GPIO_NUM, -1);
|
||||
vTaskDelay(100 / portTICK_RATE_MS);
|
||||
if (ESP_OK != ret) {
|
||||
ESP_LOGW(TAG, "Testing init failed :-(, skip this item");
|
||||
vTaskDelay(500 / portTICK_RATE_MS);
|
||||
continue;
|
||||
}
|
||||
camera_test_fps(pic_num, &results[format_s - all_format].fps[i], &results[format_s - all_format].size[i]);
|
||||
TEST_ESP_OK(esp_camera_deinit());
|
||||
}
|
||||
}
|
||||
|
||||
printf("FPS Result\n");
|
||||
printf("resolution , JPEG fps, JPEG size, RGB565 fps, RGB565 size, YUV422 fps, YUV422 size \n");
|
||||
for (size_t i = 0; i <= max_size; i++) {
|
||||
printf("%4d x %4d , %5.2f, %6d, %5.2f, %7d, %5.2f, %7d \n",
|
||||
resolution[i].width, resolution[i].height,
|
||||
results[0].fps[i], results[0].size[i],
|
||||
results[1].fps[i], results[1].size[i],
|
||||
results[2].fps[i], results[2].size[i]);
|
||||
}
|
||||
printf("----------------------------------------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
TEST_CASE("Camera driver init, deinit test", "[camera]")
|
||||
{
|
||||
uint64_t t1 = esp_timer_get_time();
|
||||
TEST_ESP_OK(init_camera(20000000, PIXFORMAT_RGB565, FRAMESIZE_QVGA, 2, SIOD_GPIO_NUM, -1));
|
||||
uint64_t t2 = esp_timer_get_time();
|
||||
ESP_LOGI(TAG, "Camera init time %llu ms", (t2 - t1) / 1000);
|
||||
|
||||
TEST_ESP_OK(esp_camera_deinit());
|
||||
}
|
||||
|
||||
TEST_CASE("Camera driver take RGB565 picture test", "[camera]")
|
||||
{
|
||||
TEST_ESP_OK(init_camera(10000000, PIXFORMAT_RGB565, FRAMESIZE_QVGA, 2, SIOD_GPIO_NUM, -1));
|
||||
vTaskDelay(500 / portTICK_RATE_MS);
|
||||
ESP_LOGI(TAG, "Taking picture...");
|
||||
camera_fb_t *pic = esp_camera_fb_get();
|
||||
if (pic) {
|
||||
ESP_LOGI(TAG, "picture: %d x %d, size: %u", pic->width, pic->height, pic->len);
|
||||
printf_img_base64(pic);
|
||||
esp_camera_fb_return(pic);
|
||||
}
|
||||
|
||||
TEST_ESP_OK(esp_camera_deinit());
|
||||
TEST_ASSERT_NOT_NULL(pic);
|
||||
}
|
||||
|
||||
TEST_CASE("Camera driver take YUV422 picture test", "[camera]")
|
||||
{
|
||||
TEST_ESP_OK(init_camera(10000000, PIXFORMAT_YUV422, FRAMESIZE_QVGA, 2, SIOD_GPIO_NUM, -1));
|
||||
vTaskDelay(500 / portTICK_RATE_MS);
|
||||
ESP_LOGI(TAG, "Taking picture...");
|
||||
camera_fb_t *pic = esp_camera_fb_get();
|
||||
if (pic) {
|
||||
ESP_LOGI(TAG, "picture: %d x %d, size: %u", pic->width, pic->height, pic->len);
|
||||
printf_img_base64(pic);
|
||||
esp_camera_fb_return(pic);
|
||||
}
|
||||
|
||||
TEST_ESP_OK(esp_camera_deinit());
|
||||
TEST_ASSERT_NOT_NULL(pic);
|
||||
}
|
||||
|
||||
TEST_CASE("Camera driver take JPEG picture test", "[camera]")
|
||||
{
|
||||
TEST_ESP_OK(init_camera(20000000, PIXFORMAT_JPEG, FRAMESIZE_QVGA, 2, SIOD_GPIO_NUM, -1));
|
||||
vTaskDelay(500 / portTICK_RATE_MS);
|
||||
ESP_LOGI(TAG, "Taking picture...");
|
||||
camera_fb_t *pic = esp_camera_fb_get();
|
||||
if (pic) {
|
||||
ESP_LOGI(TAG, "picture: %d x %d, size: %u", pic->width, pic->height, pic->len);
|
||||
printf_img_base64(pic);
|
||||
esp_camera_fb_return(pic);
|
||||
}
|
||||
|
||||
TEST_ESP_OK(esp_camera_deinit());
|
||||
TEST_ASSERT_NOT_NULL(pic);
|
||||
}
|
||||
|
||||
TEST_CASE("Camera driver performance test", "[camera]")
|
||||
{
|
||||
camera_performance_test(20 * 1000000, 16);
|
||||
}
|
||||
|
||||
|
||||
static void print_rgb565_img(uint8_t *img, int width, int height)
|
||||
{
|
||||
uint16_t *p = (uint16_t *)img;
|
||||
const char temp2char[17] = "@MNHQ&#UJ*x7^i;.";
|
||||
for (size_t j = 0; j < height; j++) {
|
||||
for (size_t i = 0; i < width; i++) {
|
||||
uint32_t c = p[j * width + i];
|
||||
uint8_t r = c >> 11;
|
||||
uint8_t g = (c >> 6) & 0x1f;
|
||||
uint8_t b = c & 0x1f;
|
||||
c = (r + g + b) / 3;
|
||||
c >>= 1;
|
||||
printf("%c", temp2char[15 - c]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void print_rgb888_img(uint8_t *img, int width, int height)
|
||||
{
|
||||
uint8_t *p = (uint8_t *)img;
|
||||
const char temp2char[17] = "@MNHQ&#UJ*x7^i;.";
|
||||
for (size_t j = 0; j < height; j++) {
|
||||
for (size_t i = 0; i < width; i++) {
|
||||
uint8_t *c = p + 3 * (j * width + i);
|
||||
uint8_t r = *c++;
|
||||
uint8_t g = *c++;
|
||||
uint8_t b = *c;
|
||||
uint32_t v = (r + g + b) / 3;
|
||||
v >>= 4;
|
||||
printf("%c", temp2char[15 - v]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void tjpgd_decode_rgb565(uint8_t *mjpegbuffer, uint32_t size, uint8_t *outbuffer)
|
||||
{
|
||||
jpg2rgb565(mjpegbuffer, size, outbuffer, JPG_SCALE_NONE);
|
||||
}
|
||||
|
||||
static void tjpgd_decode_rgb888(uint8_t *mjpegbuffer, uint32_t size, uint8_t *outbuffer)
|
||||
{
|
||||
fmt2rgb888(mjpegbuffer, size, PIXFORMAT_JPEG, outbuffer);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
DECODE_RGB565,
|
||||
DECODE_RGB888,
|
||||
} decode_type_t;
|
||||
|
||||
static const decode_func_t g_decode_func[2][2] = {
|
||||
{tjpgd_decode_rgb565,},
|
||||
{tjpgd_decode_rgb888,},
|
||||
};
|
||||
|
||||
|
||||
static float jpg_decode_test(uint8_t decoder_index, decode_type_t type, const uint8_t *jpg, uint32_t length, uint32_t img_w, uint32_t img_h, uint32_t times)
|
||||
{
|
||||
uint8_t *jpg_buf = malloc(length);
|
||||
if (NULL == jpg_buf) {
|
||||
ESP_LOGE(TAG, "malloc for jpg buffer failed");
|
||||
return 0;
|
||||
}
|
||||
memcpy(jpg_buf, jpg, length);
|
||||
|
||||
uint8_t *rgb_buf = heap_caps_malloc(img_w * img_h * 3, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if (NULL == rgb_buf) {
|
||||
free(jpg_buf);
|
||||
ESP_LOGE(TAG, "malloc for rgb buffer failed");
|
||||
return 0;
|
||||
}
|
||||
decode_func_t decode = g_decode_func[type][decoder_index];
|
||||
decode(jpg_buf, length, rgb_buf);
|
||||
if (DECODE_RGB565 == type) {
|
||||
ESP_LOGI(TAG, "jpeg decode to rgb565");
|
||||
print_rgb565_img(rgb_buf, img_w, img_h);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "jpeg decode to rgb888");
|
||||
print_rgb888_img(rgb_buf, img_w, img_h);
|
||||
}
|
||||
|
||||
uint64_t t_decode[times];
|
||||
for (size_t i = 0; i < times; i++) {
|
||||
uint64_t t1 = esp_timer_get_time();
|
||||
decode(jpg_buf, length, rgb_buf);
|
||||
t_decode[i] = esp_timer_get_time() - t1;
|
||||
}
|
||||
|
||||
printf("resolution , t \n");
|
||||
uint64_t t_total = 0;
|
||||
for (size_t i = 0; i < times; i++) {
|
||||
t_total += t_decode[i];
|
||||
float t = t_decode[i] / 1000.0f;
|
||||
printf("%4d x %4d , %5.2f ms \n", img_w, img_h, t);
|
||||
}
|
||||
|
||||
float fps = times / (t_total / 1000000.0f);
|
||||
printf("Decode FPS Result\n");
|
||||
printf("resolution , fps \n");
|
||||
printf("%4d x %4d , %5.2f \n", img_w, img_h, fps);
|
||||
|
||||
free(jpg_buf);
|
||||
heap_caps_free(rgb_buf);
|
||||
return fps;
|
||||
}
|
||||
|
||||
static void img_jpeg_decode_test(uint16_t pic_index, uint16_t lib_index)
|
||||
{
|
||||
extern const uint8_t img1_start[] asm("_binary_testimg_jpeg_start");
|
||||
extern const uint8_t img1_end[] asm("_binary_testimg_jpeg_end");
|
||||
extern const uint8_t img2_start[] asm("_binary_test_inside_jpeg_start");
|
||||
extern const uint8_t img2_end[] asm("_binary_test_inside_jpeg_end");
|
||||
extern const uint8_t img3_start[] asm("_binary_test_outside_jpeg_start");
|
||||
extern const uint8_t img3_end[] asm("_binary_test_outside_jpeg_end");
|
||||
|
||||
struct img_t {
|
||||
const uint8_t *buf;
|
||||
uint32_t length;
|
||||
uint16_t w, h;
|
||||
};
|
||||
struct img_t imgs[3] = {
|
||||
{
|
||||
.buf = img1_start,
|
||||
.length = img1_end - img1_start,
|
||||
.w = 227,
|
||||
.h = 149,
|
||||
},
|
||||
{
|
||||
.buf = img2_start,
|
||||
.length = img2_end - img2_start,
|
||||
.w = 320,
|
||||
.h = 240,
|
||||
},
|
||||
{
|
||||
.buf = img3_start,
|
||||
.length = img3_end - img3_start,
|
||||
.w = 480,
|
||||
.h = 320,
|
||||
},
|
||||
};
|
||||
|
||||
ESP_LOGI(TAG, "pic_index:%d", pic_index);
|
||||
ESP_LOGI(TAG, "lib_index:%d", lib_index);
|
||||
jpg_decode_test(lib_index, DECODE_RGB565, imgs[pic_index].buf, imgs[pic_index].length, imgs[pic_index].w, imgs[pic_index].h, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief i2c master initialization
|
||||
*/
|
||||
static esp_err_t i2c_master_init(int i2c_port)
|
||||
{
|
||||
i2c_config_t conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = I2C_MASTER_SDA_IO,
|
||||
.scl_io_num = I2C_MASTER_SCL_IO,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = I2C_MASTER_FREQ_HZ,
|
||||
};
|
||||
|
||||
i2c_param_config(i2c_port, &conf);
|
||||
|
||||
return i2c_driver_install(i2c_port, conf.mode, 0, 0, 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Conversions image 227x149 jpeg decode test", "[camera]")
|
||||
{
|
||||
img_jpeg_decode_test(0, 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Conversions image 320x240 jpeg decode test", "[camera]")
|
||||
{
|
||||
img_jpeg_decode_test(1, 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Conversions image 480x320 jpeg decode test", "[camera]")
|
||||
{
|
||||
img_jpeg_decode_test(2, 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Camera driver uses an i2c port initialized by other devices test", "[camera]")
|
||||
{
|
||||
TEST_ESP_OK(i2c_master_init(I2C_MASTER_NUM));
|
||||
TEST_ESP_OK(init_camera(20000000, PIXFORMAT_JPEG, FRAMESIZE_QVGA, 2, -1, I2C_MASTER_NUM));
|
||||
vTaskDelay(500 / portTICK_RATE_MS);
|
||||
TEST_ESP_OK(esp_camera_deinit());
|
||||
TEST_ESP_OK(i2c_driver_delete(I2C_MASTER_NUM));
|
||||
}
|
||||
Loading…
Reference in a new issue