├── CMakeLists.txt
├── LICENSE
├── README.md
├── components
├── cli_console
│ ├── CMakeLists.txt
│ ├── component.mk
│ ├── include
│ │ └── console.h
│ └── src
│ │ └── console.c
├── esp32-camera
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── Kconfig
│ ├── LICENSE
│ ├── README.md
│ ├── component.mk
│ ├── conversions
│ │ ├── esp_jpg_decode.c
│ │ ├── include
│ │ │ ├── esp_jpg_decode.h
│ │ │ └── img_converters.h
│ │ ├── jpge.cpp
│ │ ├── private_include
│ │ │ ├── jpge.h
│ │ │ └── yuv.h
│ │ ├── to_bmp.c
│ │ ├── to_jpg.cpp
│ │ └── yuv.c
│ ├── driver
│ │ ├── cam_hal.c
│ │ ├── esp_camera.c
│ │ ├── include
│ │ │ ├── esp_camera.h
│ │ │ └── sensor.h
│ │ ├── private_include
│ │ │ ├── cam_hal.h
│ │ │ ├── sccb.h
│ │ │ └── xclk.h
│ │ ├── sccb.c
│ │ └── sensor.c
│ ├── examples
│ │ ├── CMakeLists.txt
│ │ ├── Makefile
│ │ ├── main
│ │ │ ├── CMakeLists.txt
│ │ │ ├── component.mk
│ │ │ └── take_picture.c
│ │ └── sdkconfig.defaults
│ ├── idf_component.yml
│ ├── library.json
│ ├── sensors
│ │ ├── bf20a6.c
│ │ ├── bf3005.c
│ │ ├── gc0308.c
│ │ ├── gc032a.c
│ │ ├── gc2145.c
│ │ ├── nt99141.c
│ │ ├── ov2640.c
│ │ ├── ov3660.c
│ │ ├── ov5640.c
│ │ ├── ov7670.c
│ │ ├── ov7725.c
│ │ └── private_include
│ │ │ ├── bf20a6.h
│ │ │ ├── bf20a6_regs.h
│ │ │ ├── bf20a6_settings.h
│ │ │ ├── bf3005.h
│ │ │ ├── bf3005_regs.h
│ │ │ ├── gc0308.h
│ │ │ ├── gc0308_regs.h
│ │ │ ├── gc0308_settings.h
│ │ │ ├── gc032a.h
│ │ │ ├── gc032a_regs.h
│ │ │ ├── gc032a_settings.h
│ │ │ ├── gc2145.h
│ │ │ ├── gc2145_regs.h
│ │ │ ├── gc2145_settings.h
│ │ │ ├── nt99141.h
│ │ │ ├── nt99141_regs.h
│ │ │ ├── nt99141_settings.h
│ │ │ ├── ov2640.h
│ │ │ ├── ov2640_regs.h
│ │ │ ├── ov2640_settings.h
│ │ │ ├── ov3660.h
│ │ │ ├── ov3660_regs.h
│ │ │ ├── ov3660_settings.h
│ │ │ ├── ov5640.h
│ │ │ ├── ov5640_regs.h
│ │ │ ├── ov5640_settings.h
│ │ │ ├── ov7670.h
│ │ │ ├── ov7670_regs.h
│ │ │ ├── ov7725.h
│ │ │ └── ov7725_regs.h
│ ├── target
│ │ ├── esp32
│ │ │ └── ll_cam.c
│ │ ├── esp32s2
│ │ │ ├── ll_cam.c
│ │ │ ├── private_include
│ │ │ │ └── tjpgd.h
│ │ │ └── tjpgd.c
│ │ ├── esp32s3
│ │ │ └── ll_cam.c
│ │ ├── private_include
│ │ │ └── ll_cam.h
│ │ └── xclk.c
│ └── test
│ │ ├── CMakeLists.txt
│ │ ├── component.mk
│ │ ├── pictures
│ │ ├── test_inside.jpeg
│ │ ├── test_outside.jpeg
│ │ └── testimg.jpeg
│ │ └── test_camera.c
└── esp_rtc
│ ├── CMakeLists.txt
│ ├── include
│ └── esp_rtc.h
│ └── lib
│ └── libesp_rtc.a
├── main
├── CMakeLists.txt
├── calling.jpg
├── component.mk
├── espressif.jpg
├── incoming.jpg
├── keyboard.jpg
├── main.c
├── main_rtc_media.c
└── main_rtc_media.h
├── partitions_esp_rtc_demo.csv
└── sdkconfig
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # The following lines of boilerplate have to be in your project's
2 | # CMakeLists in this exact order for cmake to work correctly
3 | cmake_minimum_required(VERSION 3.5)
4 |
5 | set(EXTRA_COMPONENT_DIRS ./components)
6 |
7 | include($ENV{ADF_PATH}/CMakeLists.txt)
8 | include($ENV{IDF_PATH}/tools/cmake/project.cmake)
9 |
10 | project(esp-rtc)
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ESP-RTC example
2 |
3 |
4 | ## 例程简介
5 |
6 | ESP RTC 是一个基于标准 SIP 协议的视频通话客户端,可以用于点对点音频/视频通话等场景。
7 |
8 | ## 环境配置
9 |
10 | ### 硬件要求
11 |
12 | 本例程目前仅支持`ESP32-S3-Korvo-2`开发板。
13 |
14 | ### 其他要求
15 |
16 | - 您可以使用 Example 乐鑫自建的服务器来测试,具体测试账号可以联系乐鑫来获取。
17 |
18 | - 或者您也可以搭建如下 SIP PBX 服务器中的一个:
19 |
20 | - [Asterisk FreePBX](https://www.freepbx.org/downloads/)
21 |
22 | - [Asterisk for Raspberry Pi](http://www.raspberry-asterisk.org/)
23 |
24 | - [Freeswitch](https://freeswitch.org/confluence/display/FREESWITCH/Installation)
25 | - 建议关闭服务器事件通知 `NOTIFY`,可以通过在 `conf/sip_profiles/internal.xml` 中设置 `` 关闭通知。
26 |
27 | - 建议关闭服务器 timer,可以通过在 `conf/sip_profiles/internal.xml` 中设置 `` 来关闭。
28 |
29 | - 建议在 `conf/vars.xml` 中打开 PCMA、PCMU、VP8。
30 |
31 | - 我们建议搭建 Freeswitch 服务器来测试。
32 |
33 | ## 编译和下载
34 |
35 | ### IDF 默认分支
36 |
37 | 本例程默认 IDF 为 https://github.com/espressif/esp-idf/tree/release/v4.4
38 |
39 | 本例程默认 ADF 为 https://github.com/espressif/esp-adf/tree/master
40 |
41 | 本例程还需给 IDF 合入1个patch ,合入命令如下:
42 |
43 | ```
44 | cd $IDF_PATH
45 | git apply $ADF_PATH/idf_patches/idf_v4.4_freertos.patch
46 | ```
47 |
48 | ### 编译和下载
49 |
50 | 请先编译版本并烧录到开发板上,然后运行 monitor 工具来查看串口输出 (替换 PORT 为端口名称):
51 |
52 | ```
53 | idf.py -p PORT flash monitor
54 | ```
55 |
56 | 退出调试界面使用 ``Ctrl-]``
57 |
58 | 有关配置和使用 ESP-IDF 生成项目的完整步骤,请参阅 [《ESP-IDF 编程指南》](https://docs.espressif.com/projects/esp-idf/zh_CN/release-v4.4/get-started/index.html)。
59 |
60 | ## 如何使用例程
61 |
62 | ### 功能和用法
63 |
64 | - 例程开始运行后,连接默认Wifi网络或者串口输入 "join" 来配置网络。
65 | - 设备开机联网完成并成功连接服务器后,串口输入 "call " 拨打对方号码 如 1010/1011
66 | - 或者按下 "PLAY" 键来进行拨号
67 | - 串口输入 "bye" 或者 按下 "MUTE" 键来进行挂断或者拒接
68 | - 串口输入 "answer" 或者 按下 "REC" 键来接听
69 | - 串口输入 "tasks" "stat" "mem" 查看系统状态
70 | - "Vol+" 和 "Vol-" 键可以调节开发板通话音量
71 | - 如果使用自建服务器,可以在 `LOGIN_URL` 中配置服务器域名和用户账号及密码 (Transport://user:password@server:port)
72 | - 例如:tcp://100:100@192.168.1.123:5060
73 |
74 | ## 技术支持
75 | 请按照下面的链接获取技术支持:
76 |
77 | - 技术支持参见 [esp32.com](https://esp32.com/viewforum.php?f=20) 论坛
78 | - 故障和新功能需求,请创建 [GitHub issue](https://github.com/espressif/esp-adf/issues)
79 |
80 | 我们会尽快回复。
81 |
--------------------------------------------------------------------------------
/components/cli_console/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(COMPONENT_ADD_INCLUDEDIRS include)
2 | set(COMPONENT_SRCS src/console.c)
3 |
4 | set(COMPONENT_REQUIRES console audio_sal)
5 |
6 | register_component()
--------------------------------------------------------------------------------
/components/cli_console/component.mk:
--------------------------------------------------------------------------------
1 | COMPONENT_ADD_INCLUDEDIRS := include
2 |
3 | COMPONENT_SRCDIRS := src
4 |
--------------------------------------------------------------------------------
/components/cli_console/include/console.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef _CONSOLE_H
3 | #define _CONSOLE_H
4 |
5 | #ifdef __cplusplus
6 | extern "C" {
7 | #endif
8 |
9 | #include "esp_console.h"
10 | #include "driver/uart.h"
11 | #include "linenoise/linenoise.h"
12 | #include "argtable3/argtable3.h"
13 | void console_init();
14 |
15 | #ifdef __cplusplus
16 | }
17 | #endif
18 |
19 | #endif
--------------------------------------------------------------------------------
/components/cli_console/src/console.c:
--------------------------------------------------------------------------------
1 | #include "freertos/FreeRTOS.h"
2 | #include "freertos/task.h"
3 | #include "freertos/event_groups.h"
4 | #include "esp_system.h"
5 | #include "esp_log.h"
6 | #include "esp_wifi.h"
7 | #include "esp_vfs_dev.h"
8 | #include "audio_mem.h"
9 | #include "audio_sys.h"
10 | #include "console.h"
11 |
12 | static const char *TAG = "VOIP_CONSOLE";
13 |
14 | #define PROMPT_STR CONFIG_IDF_TARGET
15 |
16 | #define CONSOLE_TASK_STACK_SIZE 3*1024
17 |
18 | static void initialize_console(void)
19 | {
20 | /* Drain stdout before reconfiguring it */
21 | fflush(stdout);
22 | fsync(fileno(stdout));
23 |
24 | /* Disable buffering on stdin */
25 | setvbuf(stdin, NULL, _IONBF, 0);
26 |
27 | /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
28 | esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
29 | /* Move the caret to the beginning of the next line on '\n' */
30 | esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
31 |
32 | /* Configure UART. Note that REF_TICK is used so that the baud rate remains
33 | * correct while APB frequency is changing in light sleep mode.
34 | */
35 | const uart_config_t uart_config = {
36 | .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE,
37 | .data_bits = UART_DATA_8_BITS,
38 | .parity = UART_PARITY_DISABLE,
39 | .stop_bits = UART_STOP_BITS_1,
40 | #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
41 | .source_clk = UART_SCLK_REF_TICK,
42 | #else
43 | .source_clk = UART_SCLK_XTAL,
44 | #endif
45 | };
46 | /* Install UART driver for interrupt-driven reads and writes */
47 | uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM,
48 | 256, 0, 0, NULL, 0);
49 | ESP_ERROR_CHECK( uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config) );
50 |
51 | /* Tell VFS to use UART driver */
52 | esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
53 |
54 | /* Initialize the console */
55 | esp_console_config_t console_config = {
56 | .max_cmdline_args = 8,
57 | .max_cmdline_length = 256,
58 | #if CONFIG_LOG_COLORS
59 | .hint_color = atoi(LOG_COLOR_CYAN)
60 | #endif
61 | };
62 | ESP_ERROR_CHECK(esp_console_init(&console_config));
63 |
64 | /* Configure linenoise line completion library */
65 | /* Enable multiline editing. If not set, long commands will scroll within
66 | * single line.
67 | */
68 | linenoiseSetMultiLine(1);
69 |
70 | /* Tell linenoise where to get command completions and hints */
71 | linenoiseSetCompletionCallback(&esp_console_get_completion);
72 | linenoiseSetHintsCallback((linenoiseHintsCallback *) &esp_console_get_hint);
73 |
74 | /* Set command history size */
75 | linenoiseHistorySetMaxLen(100);
76 |
77 | /* Don't return empty lines */
78 | linenoiseAllowEmpty(false);
79 |
80 | #if CONFIG_STORE_HISTORY
81 | /* Load command history from filesystem */
82 | linenoiseHistoryLoad(HISTORY_PATH);
83 | #endif
84 | }
85 |
86 | static void console_task(void *pv)
87 | {
88 | vTaskDelay(1 * 1000 / portTICK_PERIOD_MS);
89 | /* Prompt to be printed before each line.
90 | * This can be customized, made dynamic, etc.
91 | */
92 | const char* prompt = LOG_COLOR_I PROMPT_STR "> " LOG_RESET_COLOR;
93 |
94 | printf("\n"
95 | "This is an example of ESP-IDF console component.\n"
96 | "Type 'help' to get the list of commands.\n"
97 | "Use UP/DOWN arrows to navigate through command history.\n"
98 | "Press TAB when typing command name to auto-complete.\n"
99 | "Press Enter or Ctrl+C will terminate the console environment.\n");
100 |
101 | /* Figure out if the terminal supports escape sequences */
102 | int probe_status = linenoiseProbe();
103 | if (probe_status) { /* zero indicates success */
104 | printf("\n"
105 | "Your terminal application does not support escape sequences.\n"
106 | "Line editing and history features are disabled.\n"
107 | "On Windows, try using Putty instead.\n");
108 | linenoiseSetDumbMode(1);
109 | #if CONFIG_LOG_COLORS
110 | /* Since the terminal doesn't support escape sequences,
111 | * don't use color codes in the prompt.
112 | */
113 | prompt = PROMPT_STR "> ";
114 | #endif //CONFIG_LOG_COLORS
115 | }
116 |
117 | while (1) {
118 | /* Get a line using linenoise.
119 | * The line is returned when ENTER is pressed.
120 | */
121 | char *line = linenoise(prompt);
122 | if (line == NULL) { /* Ignore empty lines */
123 | continue;
124 | }
125 |
126 | /* Try to run the command */
127 | int ret;
128 | esp_err_t err = esp_console_run(line, &ret);
129 | if (err == ESP_ERR_NOT_FOUND) {
130 | printf("Unrecognized command\n");
131 | } else if (err == ESP_ERR_INVALID_ARG) {
132 | // command was empty
133 | } else if (err == ESP_OK && ret != ESP_OK) {
134 | //printf("Command returned non-zero error code: 0x%x (%s)\n", ret, esp_err_to_name(err));
135 | } else if (err != ESP_OK) {
136 | //printf("Internal error: %s\n", esp_err_to_name(err));
137 | }
138 | /* linenoise allocates line buffer on the heap, so need to free it */
139 | linenoiseFree(line);
140 | }
141 | vTaskDelete(NULL);
142 | }
143 |
144 | static int free_mem(int argc, char **argv)
145 | {
146 | #ifdef CONFIG_SPIRAM_BOOT_INIT
147 | printf("Func:%s, Line:%d, MEM Total:%d Bytes, Inter:%d Bytes, Dram:%d Bytes\r\n", __FUNCTION__, __LINE__, esp_get_free_heap_size(),
148 | heap_caps_get_free_size(MALLOC_CAP_INTERNAL), heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
149 | #else
150 | printf("Func:%s, Line:%d, MEM Total:%d Bytes\r\n", __FUNCTION__, __LINE__, esp_get_free_heap_size());
151 | #endif
152 | return 0;
153 | }
154 |
155 | static int reboot(int argc, char **argv)
156 | {
157 | esp_restart();
158 | return 0;
159 | }
160 |
161 | #ifdef CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
162 | static int run_time_stats(int argc, char **argv)
163 | {
164 | audio_sys_get_real_time_stats();
165 | return 0;
166 | }
167 | #endif
168 |
169 | static int tasks_info(int argc, char **argv)
170 | {
171 | const size_t bytes_per_task = 40; /* see vTaskList description */
172 | char *task_list_buffer = malloc(uxTaskGetNumberOfTasks() * bytes_per_task);
173 | if (task_list_buffer == NULL) {
174 | ESP_LOGE(TAG, "failed to allocate buffer for vTaskList output");
175 | return 1;
176 | }
177 | fputs("Task Name\tStatus\tPrio\tHWM\tTask#", stdout);
178 | #ifdef CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
179 | fputs("\tAffinity", stdout);
180 | #endif
181 | fputs("\n", stdout);
182 | vTaskList(task_list_buffer);
183 | fputs(task_list_buffer, stdout);
184 | free(task_list_buffer);
185 | return 0;
186 | }
187 |
188 | static bool wifi_join(const char *ssid, const char *pass)
189 | {
190 | wifi_config_t wifi_config = { 0 };
191 | if (ssid) {
192 | memcpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
193 | }
194 | if (pass) {
195 | memcpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
196 | }
197 |
198 | ESP_ERROR_CHECK( esp_wifi_disconnect() );
199 | ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
200 | ESP_ERROR_CHECK( esp_wifi_connect() );
201 |
202 | return 0;
203 | }
204 |
205 | /** Arguments used by 'join' function */
206 | static struct {
207 | struct arg_str *ssid;
208 | struct arg_str *password;
209 | struct arg_end *end;
210 | } join_args;
211 |
212 | static int connect(int argc, char **argv)
213 | {
214 | int nerrors = arg_parse(argc, argv, (void **) &join_args);
215 | if (nerrors != 0) {
216 | arg_print_errors(stderr, join_args.end, argv[0]);
217 | return 1;
218 | }
219 | ESP_LOGI(__func__, "Connecting to '%s'",
220 | join_args.ssid->sval[0]);
221 |
222 | wifi_join(join_args.ssid->sval[0],
223 | join_args.password->sval[0]);
224 | return 0;
225 | }
226 |
227 | static void register_system_commond()
228 | {
229 | const esp_console_cmd_t cmd_tasks = {
230 | .command = "tasks",
231 | .help = "Get information about running tasks",
232 | .hint = NULL,
233 | .func = &tasks_info,
234 | };
235 | ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_tasks) );
236 |
237 | const esp_console_cmd_t cmd_free = {
238 | .command = "mem",
239 | .help = "Get the current size of free heap memory",
240 | .hint = NULL,
241 | .func = &free_mem,
242 | };
243 | ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_free) );
244 |
245 | const esp_console_cmd_t cmd_reboot = {
246 | .command = "reboot",
247 | .help = "reboot",
248 | .hint = NULL,
249 | .func = &reboot,
250 | };
251 | ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_reboot) );
252 |
253 | #ifdef CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
254 | const esp_console_cmd_t cmd_stat = {
255 | .command = "stat",
256 | .help = "Get Run Time Stats",
257 | .hint = NULL,
258 | .func = &run_time_stats,
259 | };
260 | ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_stat) );
261 | #endif
262 |
263 | join_args.ssid = arg_str1(NULL, NULL, "", "SSID of AP");
264 | join_args.password = arg_str0(NULL, NULL, "", "PSK of AP");
265 | join_args.end = arg_end(2);
266 |
267 | const esp_console_cmd_t join_cmd = {
268 | .command = "join",
269 | .help = "Join WiFi AP as a station",
270 | .hint = NULL,
271 | .func = &connect,
272 | .argtable = &join_args
273 | };
274 |
275 | ESP_ERROR_CHECK( esp_console_cmd_register(&join_cmd) );
276 | }
277 |
278 | void console_init()
279 | {
280 | initialize_console();
281 | esp_console_register_help_command();
282 | register_system_commond();
283 | xTaskCreatePinnedToCore(console_task, "console_task", CONSOLE_TASK_STACK_SIZE, NULL, 10, NULL, 1);
284 | }
285 |
--------------------------------------------------------------------------------
/components/esp32-camera/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 | .vscode
3 | **/build
4 | **/sdkconfig
5 | **/sdkconfig.old
--------------------------------------------------------------------------------
/components/esp32-camera/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET STREQUAL "esp32s3")
2 | set(COMPONENT_SRCS
3 | driver/esp_camera.c
4 | driver/cam_hal.c
5 | driver/sccb.c
6 | driver/sensor.c
7 | sensors/ov2640.c
8 | sensors/ov3660.c
9 | sensors/ov5640.c
10 | sensors/ov7725.c
11 | sensors/ov7670.c
12 | sensors/nt99141.c
13 | sensors/gc0308.c
14 | sensors/gc2145.c
15 | sensors/gc032a.c
16 | sensors/bf3005.c
17 | sensors/bf20a6.c
18 | conversions/yuv.c
19 | conversions/to_jpg.cpp
20 | conversions/to_bmp.c
21 | conversions/jpge.cpp
22 | conversions/esp_jpg_decode.c
23 | )
24 |
25 | set(COMPONENT_ADD_INCLUDEDIRS
26 | driver/include
27 | conversions/include
28 | )
29 |
30 | set(COMPONENT_PRIV_INCLUDEDIRS
31 | driver/private_include
32 | sensors/private_include
33 | conversions/private_include
34 | target/private_include
35 | )
36 |
37 | if(IDF_TARGET STREQUAL "esp32")
38 | list(APPEND COMPONENT_SRCS
39 | target/xclk.c
40 | target/esp32/ll_cam.c
41 | )
42 | endif()
43 |
44 | if(IDF_TARGET STREQUAL "esp32s2")
45 | list(APPEND COMPONENT_SRCS
46 | target/xclk.c
47 | target/esp32s2/ll_cam.c
48 | target/esp32s2/tjpgd.c
49 | )
50 |
51 | list(APPEND COMPONENT_PRIV_INCLUDEDIRS
52 | target/esp32s2/private_include
53 | )
54 | endif()
55 |
56 | if(IDF_TARGET STREQUAL "esp32s3")
57 | list(APPEND COMPONENT_SRCS
58 | target/esp32s3/ll_cam.c
59 | )
60 | endif()
61 |
62 | set(COMPONENT_REQUIRES driver)
63 | set(COMPONENT_PRIV_REQUIRES freertos nvs_flash)
64 |
65 | register_component()
66 | endif()
67 |
--------------------------------------------------------------------------------
/components/esp32-camera/Kconfig:
--------------------------------------------------------------------------------
1 | menu "Camera configuration"
2 |
3 | config OV7670_SUPPORT
4 | bool "Support OV7670 VGA"
5 | default y
6 | help
7 | Enable this option if you want to use the OV7670.
8 | Disable this option to save memory.
9 |
10 | config OV7725_SUPPORT
11 | bool "Support OV7725 VGA"
12 | default y
13 | help
14 | Enable this option if you want to use the OV7725.
15 | Disable this option to save memory.
16 |
17 | config NT99141_SUPPORT
18 | bool "Support NT99141 HD"
19 | default y
20 | help
21 | Enable this option if you want to use the NT99141.
22 | Disable this option to save memory.
23 |
24 | config OV2640_SUPPORT
25 | bool "Support OV2640 2MP"
26 | default y
27 | help
28 | Enable this option if you want to use the OV2640.
29 | Disable this option to save memory.
30 |
31 | config OV3660_SUPPORT
32 | bool "Support OV3660 3MP"
33 | default y
34 | help
35 | Enable this option if you want to use the OV3360.
36 | Disable this option to save memory.
37 |
38 | config OV5640_SUPPORT
39 | bool "Support OV5640 5MP"
40 | default y
41 | help
42 | Enable this option if you want to use the OV5640.
43 | Disable this option to save memory.
44 |
45 | config GC2145_SUPPORT
46 | bool "Support GC2145 2MP"
47 | default y
48 | help
49 | Enable this option if you want to use the GC2145.
50 | Disable this option to save memory.
51 |
52 | config GC032A_SUPPORT
53 | bool "Support GC032A VGA"
54 | default y
55 | help
56 | Enable this option if you want to use the GC032A.
57 | Disable this option to save memory.
58 |
59 | config GC0308_SUPPORT
60 | bool "Support GC0308 VGA"
61 | default y
62 | help
63 | Enable this option if you want to use the GC0308.
64 | Disable this option to save memory.
65 |
66 | config BF3005_SUPPORT
67 | bool "Support BF3005(BYD3005) VGA"
68 | default y
69 | help
70 | Enable this option if you want to use the BF3005.
71 | Disable this option to save memory.
72 |
73 | config BF20A6_SUPPORT
74 | bool "Support BF20A6(BYD20A6) VGA"
75 | default y
76 | help
77 | Enable this option if you want to use the BF20A6.
78 | Disable this option to save memory.
79 |
80 | choice SCCB_HARDWARE_I2C_PORT
81 | bool "I2C peripheral to use for SCCB"
82 | default SCCB_HARDWARE_I2C_PORT1
83 |
84 | config SCCB_HARDWARE_I2C_PORT0
85 | bool "I2C0"
86 | config SCCB_HARDWARE_I2C_PORT1
87 | bool "I2C1"
88 |
89 | endchoice
90 |
91 | config SCCB_CLK_FREQ
92 | int "SCCB clk frequency"
93 | default 100000
94 | range 100000 400000
95 | help
96 | Increasing this value can reduce the initialization time of the sensor.
97 | Please refer to the relevant instructions of the sensor to adjust the value.
98 |
99 | choice GC_SENSOR_WINDOW_MODE
100 | bool "GalaxyCore Sensor Window Mode"
101 | depends on (GC2145_SUPPORT || GC032A_SUPPORT || GC0308_SUPPORT)
102 | default GC_SENSOR_SUBSAMPLE_MODE
103 | help
104 | This option determines how to reduce the output size when the resolution you set is less than the maximum resolution.
105 | SUBSAMPLE_MODE has a bigger perspective and WINDOWING_MODE has a higher frame rate.
106 |
107 | config GC_SENSOR_WINDOWING_MODE
108 | bool "Windowing Mode"
109 | config GC_SENSOR_SUBSAMPLE_MODE
110 | bool "Subsample Mode"
111 | endchoice
112 |
113 | choice CAMERA_TASK_PINNED_TO_CORE
114 | bool "Camera task pinned to core"
115 | default CAMERA_CORE0
116 | help
117 | Pin the camera handle task to a certain core(0/1). It can also be done automatically choosing NO_AFFINITY.
118 |
119 | config CAMERA_CORE0
120 | bool "CORE0"
121 | config CAMERA_CORE1
122 | bool "CORE1"
123 | config CAMERA_NO_AFFINITY
124 | bool "NO_AFFINITY"
125 |
126 | endchoice
127 |
128 | config CAMERA_DMA_BUFFER_SIZE_MAX
129 | int "DMA buffer size"
130 | range 8192 32768
131 | default 32768
132 | help
133 | Maximum value of DMA buffer
134 | Larger values may fail to allocate due to insufficient contiguous memory blocks, and smaller value may cause DMA interrupt to be too frequent
135 |
136 | endmenu
137 |
--------------------------------------------------------------------------------
/components/esp32-camera/component.mk:
--------------------------------------------------------------------------------
1 | COMPONENT_ADD_INCLUDEDIRS := driver/include conversions/include
2 | COMPONENT_PRIV_INCLUDEDIRS := driver/private_include conversions/private_include sensors/private_include target/private_include
3 | COMPONENT_SRCDIRS := driver conversions sensors target target/esp32
4 | CXXFLAGS += -fno-rtti
5 |
--------------------------------------------------------------------------------
/components/esp32-camera/conversions/esp_jpg_decode.c:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #include "esp_jpg_decode.h"
15 |
16 | #include "esp_system.h"
17 | #if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
18 | #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
19 | #include "esp32/rom/tjpgd.h"
20 | #elif CONFIG_IDF_TARGET_ESP32S2
21 | #include "tjpgd.h"
22 | #elif CONFIG_IDF_TARGET_ESP32S3
23 | #include "esp32s3/rom/tjpgd.h"
24 | #else
25 | #error Target CONFIG_IDF_TARGET is not supported
26 | #endif
27 | #else // ESP32 Before IDF 4.0
28 | #include "rom/tjpgd.h"
29 | #endif
30 |
31 | #if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
32 | #include "esp32-hal-log.h"
33 | #define TAG ""
34 | #else
35 | #include "esp_log.h"
36 | static const char* TAG = "esp_jpg_decode";
37 | #endif
38 |
39 | typedef struct {
40 | jpg_scale_t scale;
41 | jpg_reader_cb reader;
42 | jpg_writer_cb writer;
43 | void * arg;
44 | size_t len;
45 | size_t index;
46 | } esp_jpg_decoder_t;
47 |
48 | static const char * jd_errors[] = {
49 | "Succeeded",
50 | "Interrupted by output function",
51 | "Device error or wrong termination of input stream",
52 | "Insufficient memory pool for the image",
53 | "Insufficient stream input buffer",
54 | "Parameter error",
55 | "Data format error",
56 | "Right format but not supported",
57 | "Not supported JPEG standard"
58 | };
59 |
60 | static uint32_t _jpg_write(JDEC *decoder, void *bitmap, JRECT *rect)
61 | {
62 | uint16_t x = rect->left;
63 | uint16_t y = rect->top;
64 | uint16_t w = rect->right + 1 - x;
65 | uint16_t h = rect->bottom + 1 - y;
66 | uint8_t *data = (uint8_t *)bitmap;
67 |
68 | esp_jpg_decoder_t * jpeg = (esp_jpg_decoder_t *)decoder->device;
69 |
70 | if (jpeg->writer) {
71 | return jpeg->writer(jpeg->arg, x, y, w, h, data);
72 | }
73 | return 0;
74 | }
75 |
76 | static uint32_t _jpg_read(JDEC *decoder, uint8_t *buf, uint32_t len)
77 | {
78 | esp_jpg_decoder_t * jpeg = (esp_jpg_decoder_t *)decoder->device;
79 | if (jpeg->len && len > (jpeg->len - jpeg->index)) {
80 | len = jpeg->len - jpeg->index;
81 | }
82 | if (len) {
83 | len = jpeg->reader(jpeg->arg, jpeg->index, buf, len);
84 | if (!len) {
85 | ESP_LOGE(TAG, "Read Fail at %u/%u", jpeg->index, jpeg->len);
86 | }
87 | jpeg->index += len;
88 | }
89 | return len;
90 | }
91 |
92 | esp_err_t esp_jpg_decode(size_t len, jpg_scale_t scale, jpg_reader_cb reader, jpg_writer_cb writer, void * arg)
93 | {
94 | static uint8_t work[3100];
95 | JDEC decoder;
96 | esp_jpg_decoder_t jpeg;
97 |
98 | jpeg.len = len;
99 | jpeg.reader = reader;
100 | jpeg.writer = writer;
101 | jpeg.arg = arg;
102 | jpeg.scale = scale;
103 | jpeg.index = 0;
104 |
105 | JRESULT jres = jd_prepare(&decoder, _jpg_read, work, 3100, &jpeg);
106 | if(jres != JDR_OK){
107 | ESP_LOGE(TAG, "JPG Header Parse Failed! %s", jd_errors[jres]);
108 | return ESP_FAIL;
109 | }
110 |
111 | uint16_t output_width = decoder.width / (1 << (uint8_t)(jpeg.scale));
112 | uint16_t output_height = decoder.height / (1 << (uint8_t)(jpeg.scale));
113 |
114 | //output start
115 | writer(arg, 0, 0, output_width, output_height, NULL);
116 | //output write
117 | jres = jd_decomp(&decoder, _jpg_write, (uint8_t)jpeg.scale);
118 | //output end
119 | writer(arg, output_width, output_height, output_width, output_height, NULL);
120 |
121 | if (jres != JDR_OK) {
122 | ESP_LOGE(TAG, "JPG Decompression Failed! %s", jd_errors[jres]);
123 | return ESP_FAIL;
124 | }
125 | //check if all data has been consumed.
126 | if (len && jpeg.index < len) {
127 | _jpg_read(&decoder, NULL, len - jpeg.index);
128 | }
129 |
130 | return ESP_OK;
131 | }
132 |
133 |
--------------------------------------------------------------------------------
/components/esp32-camera/conversions/include/esp_jpg_decode.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #ifndef _ESP_JPG_DECODE_H_
15 | #define _ESP_JPG_DECODE_H_
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | #include
22 | #include
23 | #include
24 | #include "esp_err.h"
25 |
26 | typedef enum {
27 | JPG_SCALE_NONE,
28 | JPG_SCALE_2X,
29 | JPG_SCALE_4X,
30 | JPG_SCALE_8X,
31 | JPG_SCALE_MAX = JPG_SCALE_8X
32 | } jpg_scale_t;
33 |
34 | typedef size_t (* jpg_reader_cb)(void * arg, size_t index, uint8_t *buf, size_t len);
35 | typedef bool (* jpg_writer_cb)(void * arg, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t *data);
36 |
37 | esp_err_t esp_jpg_decode(size_t len, jpg_scale_t scale, jpg_reader_cb reader, jpg_writer_cb writer, void * arg);
38 |
39 | #ifdef __cplusplus
40 | }
41 | #endif
42 |
43 | #endif /* _ESP_JPG_DECODE_H_ */
44 |
--------------------------------------------------------------------------------
/components/esp32-camera/conversions/include/img_converters.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #ifndef _IMG_CONVERTERS_H_
15 | #define _IMG_CONVERTERS_H_
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | #include
22 | #include
23 | #include
24 | #include "esp_camera.h"
25 | #include "esp_jpg_decode.h"
26 |
27 | typedef size_t (* jpg_out_cb)(void * arg, size_t index, const void* data, size_t len);
28 |
29 | /**
30 | * @brief Convert image buffer to JPEG
31 | *
32 | * @param src Source buffer in RGB565, RGB888, YUYV or GRAYSCALE format
33 | * @param src_len Length in bytes of the source buffer
34 | * @param width Width in pixels of the source image
35 | * @param height Height in pixels of the source image
36 | * @param format Format of the source image
37 | * @param quality JPEG quality of the resulting image
38 | * @param cp Callback to be called to write the bytes of the output JPEG
39 | * @param arg Pointer to be passed to the callback
40 | *
41 | * @return true on success
42 | */
43 | bool fmt2jpg_cb(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixformat_t format, uint8_t quality, jpg_out_cb cb, void * arg);
44 |
45 | /**
46 | * @brief Convert camera frame buffer to JPEG
47 | *
48 | * @param fb Source camera frame buffer
49 | * @param quality JPEG quality of the resulting image
50 | * @param cp Callback to be called to write the bytes of the output JPEG
51 | * @param arg Pointer to be passed to the callback
52 | *
53 | * @return true on success
54 | */
55 | bool frame2jpg_cb(camera_fb_t * fb, uint8_t quality, jpg_out_cb cb, void * arg);
56 |
57 | /**
58 | * @brief Convert image buffer to JPEG buffer
59 | *
60 | * @param src Source buffer in RGB565, RGB888, YUYV or GRAYSCALE format
61 | * @param src_len Length in bytes of the source buffer
62 | * @param width Width in pixels of the source image
63 | * @param height Height in pixels of the source image
64 | * @param format Format of the source image
65 | * @param quality JPEG quality of the resulting image
66 | * @param out Pointer to be populated with the address of the resulting buffer.
67 | * You MUST free the pointer once you are done with it.
68 | * @param out_len Pointer to be populated with the length of the output buffer
69 | *
70 | * @return true on success
71 | */
72 | bool fmt2jpg(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixformat_t format, uint8_t quality, uint8_t ** out, size_t * out_len);
73 |
74 | /**
75 | * @brief Convert camera frame buffer to JPEG buffer
76 | *
77 | * @param fb Source camera frame buffer
78 | * @param quality JPEG quality of the resulting image
79 | * @param out Pointer to be populated with the address of the resulting buffer
80 | * @param out_len Pointer to be populated with the length of the output buffer
81 | *
82 | * @return true on success
83 | */
84 | bool frame2jpg(camera_fb_t * fb, uint8_t quality, uint8_t ** out, size_t * out_len);
85 |
86 | /**
87 | * @brief Convert image buffer to BMP buffer
88 | *
89 | * @param src Source buffer in JPEG, RGB565, RGB888, YUYV or GRAYSCALE format
90 | * @param src_len Length in bytes of the source buffer
91 | * @param width Width in pixels of the source image
92 | * @param height Height in pixels of the source image
93 | * @param format Format of the source image
94 | * @param out Pointer to be populated with the address of the resulting buffer
95 | * @param out_len Pointer to be populated with the length of the output buffer
96 | *
97 | * @return true on success
98 | */
99 | bool fmt2bmp(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixformat_t format, uint8_t ** out, size_t * out_len);
100 |
101 | /**
102 | * @brief Convert camera frame buffer to BMP buffer
103 | *
104 | * @param fb Source camera frame buffer
105 | * @param out Pointer to be populated with the address of the resulting buffer
106 | * @param out_len Pointer to be populated with the length of the output buffer
107 | *
108 | * @return true on success
109 | */
110 | bool frame2bmp(camera_fb_t * fb, uint8_t ** out, size_t * out_len);
111 |
112 | /**
113 | * @brief Convert image buffer to RGB888 buffer (used for face detection)
114 | *
115 | * @param src Source buffer in JPEG, RGB565, RGB888, YUYV or GRAYSCALE format
116 | * @param src_len Length in bytes of the source buffer
117 | * @param format Format of the source image
118 | * @param rgb_buf Pointer to the output buffer (width * height * 3)
119 | *
120 | * @return true on success
121 | */
122 | bool fmt2rgb888(const uint8_t *src_buf, size_t src_len, pixformat_t format, uint8_t * rgb_buf);
123 |
124 | bool jpg2rgb565(const uint8_t *src, size_t src_len, uint8_t * out, jpg_scale_t scale);
125 |
126 | #ifdef __cplusplus
127 | }
128 | #endif
129 |
130 | #endif /* _IMG_CONVERTERS_H_ */
131 |
--------------------------------------------------------------------------------
/components/esp32-camera/conversions/private_include/jpge.h:
--------------------------------------------------------------------------------
1 | // jpge.h - C++ class for JPEG compression.
2 | // Public domain, Rich Geldreich
3 | // Alex Evans: Added RGBA support, linear memory allocator.
4 | #ifndef JPEG_ENCODER_H
5 | #define JPEG_ENCODER_H
6 |
7 | namespace jpge
8 | {
9 | typedef unsigned char uint8;
10 | typedef signed short int16;
11 | typedef signed int int32;
12 | typedef unsigned short uint16;
13 | typedef unsigned int uint32;
14 | typedef unsigned int uint;
15 |
16 | // JPEG chroma subsampling factors. Y_ONLY (grayscale images) and H2V2 (color images) are the most common.
17 | enum subsampling_t { Y_ONLY = 0, H1V1 = 1, H2V1 = 2, H2V2 = 3 };
18 |
19 | // JPEG compression parameters structure.
20 | struct params {
21 | inline params() : m_quality(85), m_subsampling(H2V2) { }
22 |
23 | inline bool check() const {
24 | if ((m_quality < 1) || (m_quality > 100)) {
25 | return false;
26 | }
27 | if ((uint)m_subsampling > (uint)H2V2) {
28 | return false;
29 | }
30 | return true;
31 | }
32 |
33 | // Quality: 1-100, higher is better. Typical values are around 50-95.
34 | int m_quality;
35 |
36 | // m_subsampling:
37 | // 0 = Y (grayscale) only
38 | // 1 = H1V1 subsampling (YCbCr 1x1x1, 3 blocks per MCU)
39 | // 2 = H2V1 subsampling (YCbCr 2x1x1, 4 blocks per MCU)
40 | // 3 = H2V2 subsampling (YCbCr 4x1x1, 6 blocks per MCU-- very common)
41 | subsampling_t m_subsampling;
42 | };
43 |
44 | // Output stream abstract class - used by the jpeg_encoder class to write to the output stream.
45 | // put_buf() is generally called with len==JPGE_OUT_BUF_SIZE bytes, but for headers it'll be called with smaller amounts.
46 | class output_stream {
47 | public:
48 | virtual ~output_stream() { };
49 | virtual bool put_buf(const void* Pbuf, int len) = 0;
50 | virtual uint get_size() const = 0;
51 | };
52 |
53 | // Lower level jpeg_encoder class - useful if more control is needed than the above helper functions.
54 | class jpeg_encoder {
55 | public:
56 | jpeg_encoder();
57 | ~jpeg_encoder();
58 |
59 | // Initializes the compressor.
60 | // pStream: The stream object to use for writing compressed data.
61 | // params - Compression parameters structure, defined above.
62 | // width, height - Image dimensions.
63 | // channels - May be 1, or 3. 1 indicates grayscale, 3 indicates RGB source data.
64 | // Returns false on out of memory or if a stream write fails.
65 | bool init(output_stream *pStream, int width, int height, int src_channels, const params &comp_params = params());
66 |
67 | // Call this method with each source scanline.
68 | // width * src_channels bytes per scanline is expected (RGB or Y format).
69 | // You must call with NULL after all scanlines are processed to finish compression.
70 | // Returns false on out of memory or if a stream write fails.
71 | bool process_scanline(const void* pScanline);
72 |
73 | // Deinitializes the compressor, freeing any allocated memory. May be called at any time.
74 | void deinit();
75 |
76 | private:
77 | jpeg_encoder(const jpeg_encoder &);
78 | jpeg_encoder &operator =(const jpeg_encoder &);
79 |
80 | typedef int32 sample_array_t;
81 | enum { JPGE_OUT_BUF_SIZE = 512 };
82 |
83 | output_stream *m_pStream;
84 | params m_params;
85 | uint8 m_num_components;
86 | uint8 m_comp_h_samp[3], m_comp_v_samp[3];
87 | int m_image_x, m_image_y, m_image_bpp, m_image_bpl;
88 | int m_image_x_mcu, m_image_y_mcu;
89 | int m_image_bpl_xlt, m_image_bpl_mcu;
90 | int m_mcus_per_row;
91 | int m_mcu_x, m_mcu_y;
92 | uint8 *m_mcu_lines[16];
93 | uint8 m_mcu_y_ofs;
94 | sample_array_t m_sample_array[64];
95 | int16 m_coefficient_array[64];
96 |
97 | int m_last_dc_val[3];
98 | uint8 m_out_buf[JPGE_OUT_BUF_SIZE];
99 | uint8 *m_pOut_buf;
100 | uint m_out_buf_left;
101 | uint32 m_bit_buffer;
102 | uint m_bits_in;
103 | uint8 m_pass_num;
104 | bool m_all_stream_writes_succeeded;
105 |
106 | bool jpg_open(int p_x_res, int p_y_res, int src_channels);
107 |
108 | void flush_output_buffer();
109 | void put_bits(uint bits, uint len);
110 |
111 | void emit_byte(uint8 i);
112 | void emit_word(uint i);
113 | void emit_marker(int marker);
114 |
115 | void emit_jfif_app0();
116 | void emit_dqt();
117 | void emit_sof();
118 | void emit_dht(uint8 *bits, uint8 *val, int index, bool ac_flag);
119 | void emit_dhts();
120 | void emit_sos();
121 |
122 | void compute_quant_table(int32 *dst, const int16 *src);
123 | void load_quantized_coefficients(int component_num);
124 |
125 | void load_block_8_8_grey(int x);
126 | void load_block_8_8(int x, int y, int c);
127 | void load_block_16_8(int x, int c);
128 | void load_block_16_8_8(int x, int c);
129 |
130 | void code_coefficients_pass_two(int component_num);
131 | void code_block(int component_num);
132 |
133 | void process_mcu_row();
134 | bool process_end_of_image();
135 | void load_mcu(const void* src);
136 | void clear();
137 | void init();
138 | };
139 |
140 | } // namespace jpge
141 |
142 | #endif // JPEG_ENCODER
143 |
--------------------------------------------------------------------------------
/components/esp32-camera/conversions/private_include/yuv.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #ifndef _CONVERSIONS_YUV_H_
15 | #define _CONVERSIONS_YUV_H_
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | #include
22 |
23 | void yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b);
24 |
25 | #ifdef __cplusplus
26 | }
27 | #endif
28 |
29 | #endif /* _CONVERSIONS_YUV_H_ */
30 |
--------------------------------------------------------------------------------
/components/esp32-camera/conversions/to_jpg.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #include
15 | #include
16 | #include "esp_attr.h"
17 | #include "soc/efuse_reg.h"
18 | #include "esp_heap_caps.h"
19 | #include "esp_camera.h"
20 | #include "img_converters.h"
21 | #include "jpge.h"
22 | #include "yuv.h"
23 |
24 | #include "esp_system.h"
25 | #if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
26 | #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
27 | #include "esp32/spiram.h"
28 | #elif CONFIG_IDF_TARGET_ESP32S2
29 | #include "esp32s2/spiram.h"
30 | #elif CONFIG_IDF_TARGET_ESP32S3
31 | #include "esp32s3/spiram.h"
32 | #else
33 | #error Target CONFIG_IDF_TARGET is not supported
34 | #endif
35 | #else // ESP32 Before IDF 4.0
36 | #include "esp_spiram.h"
37 | #endif
38 |
39 | #if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
40 | #include "esp32-hal-log.h"
41 | #define TAG ""
42 | #else
43 | #include "esp_log.h"
44 | static const char* TAG = "to_jpg";
45 | #endif
46 |
47 | static void *_malloc(size_t size)
48 | {
49 | void * res = malloc(size);
50 | if(res) {
51 | return res;
52 | }
53 | return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
54 | }
55 |
56 | 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)
57 | {
58 | int i=0, o=0, l=0;
59 | if(format == PIXFORMAT_GRAYSCALE) {
60 | memcpy(dst, src + line * width, width);
61 | } else if(format == PIXFORMAT_RGB888) {
62 | l = width * 3;
63 | src += l * line;
64 | for(i=0; i> 3;
75 | dst[o++] = (src[i+1] & 0x1F) << 3;
76 | }
77 | } else if(format == PIXFORMAT_YUV422) {
78 | uint8_t y0, y1, u, v;
79 | uint8_t r, g, b;
80 | l = width * 2;
81 | src += l * line;
82 | for(i=0; i 100) {
114 | quality = 100;
115 | }
116 |
117 | jpge::params comp_params = jpge::params();
118 | comp_params.m_subsampling = subsampling;
119 | comp_params.m_quality = quality;
120 |
121 | jpge::jpeg_encoder dst_image;
122 |
123 | if (!dst_image.init(dst_stream, width, height, num_channels, comp_params)) {
124 | ESP_LOGE(TAG, "JPG encoder init failed");
125 | return false;
126 | }
127 |
128 | uint8_t* line = (uint8_t*)_malloc(width * num_channels);
129 | if(!line) {
130 | ESP_LOGE(TAG, "Scan line malloc failed");
131 | return false;
132 | }
133 |
134 | for (int i = 0; i < height; i++) {
135 | convert_line_format(src, format, line, width, num_channels, i);
136 | if (!dst_image.process_scanline(line)) {
137 | ESP_LOGE(TAG, "JPG process line %u failed", i);
138 | free(line);
139 | return false;
140 | }
141 | }
142 | free(line);
143 |
144 | if (!dst_image.process_scanline(NULL)) {
145 | ESP_LOGE(TAG, "JPG image finish failed");
146 | return false;
147 | }
148 | dst_image.deinit();
149 | return true;
150 | }
151 |
152 | class callback_stream : public jpge::output_stream {
153 | protected:
154 | jpg_out_cb ocb;
155 | void * oarg;
156 | size_t index;
157 |
158 | public:
159 | callback_stream(jpg_out_cb cb, void * arg) : ocb(cb), oarg(arg), index(0) { }
160 | virtual ~callback_stream() { }
161 | virtual bool put_buf(const void* data, int len)
162 | {
163 | index += ocb(oarg, index, data, len);
164 | return true;
165 | }
166 | virtual size_t get_size() const
167 | {
168 | return index;
169 | }
170 | };
171 |
172 | bool fmt2jpg_cb(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixformat_t format, uint8_t quality, jpg_out_cb cb, void * arg)
173 | {
174 | callback_stream dst_stream(cb, arg);
175 | return convert_image(src, width, height, format, quality, &dst_stream);
176 | }
177 |
178 | bool frame2jpg_cb(camera_fb_t * fb, uint8_t quality, jpg_out_cb cb, void * arg)
179 | {
180 | return fmt2jpg_cb(fb->buf, fb->len, fb->width, fb->height, fb->format, quality, cb, arg);
181 | }
182 |
183 |
184 |
185 | class memory_stream : public jpge::output_stream {
186 | protected:
187 | uint8_t *out_buf;
188 | size_t max_len, index;
189 |
190 | public:
191 | memory_stream(void *pBuf, uint buf_size) : out_buf(static_cast(pBuf)), max_len(buf_size), index(0) { }
192 |
193 | virtual ~memory_stream() { }
194 |
195 | virtual bool put_buf(const void* pBuf, int len)
196 | {
197 | if (!pBuf) {
198 | //end of image
199 | return true;
200 | }
201 | if ((size_t)len > (max_len - index)) {
202 | //ESP_LOGW(TAG, "JPG output overflow: %d bytes (%d,%d,%d)", len - (max_len - index), len, index, max_len);
203 | len = max_len - index;
204 | }
205 | if (len) {
206 | memcpy(out_buf + index, pBuf, len);
207 | index += len;
208 | }
209 | return true;
210 | }
211 |
212 | virtual size_t get_size() const
213 | {
214 | return index;
215 | }
216 | };
217 |
218 | bool fmt2jpg(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixformat_t format, uint8_t quality, uint8_t ** out, size_t * out_len)
219 | {
220 | //todo: allocate proper buffer for holding JPEG data
221 | //this should be enough for CIF frame size
222 | int jpg_buf_len = 128*1024;
223 |
224 |
225 | uint8_t * jpg_buf = (uint8_t *)_malloc(jpg_buf_len);
226 | if(jpg_buf == NULL) {
227 | ESP_LOGE(TAG, "JPG buffer malloc failed");
228 | return false;
229 | }
230 | memory_stream dst_stream(jpg_buf, jpg_buf_len);
231 |
232 | if(!convert_image(src, width, height, format, quality, &dst_stream)) {
233 | free(jpg_buf);
234 | return false;
235 | }
236 |
237 | *out = jpg_buf;
238 | *out_len = dst_stream.get_size();
239 | return true;
240 | }
241 |
242 | bool frame2jpg(camera_fb_t * fb, uint8_t quality, uint8_t ** out, size_t * out_len)
243 | {
244 | return fmt2jpg(fb->buf, fb->len, fb->width, fb->height, fb->format, quality, out, out_len);
245 | }
246 |
--------------------------------------------------------------------------------
/components/esp32-camera/driver/include/esp_camera.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | /*
15 | * Example Use
16 | *
17 | static camera_config_t camera_example_config = {
18 | .pin_pwdn = PIN_PWDN,
19 | .pin_reset = PIN_RESET,
20 | .pin_xclk = PIN_XCLK,
21 | .pin_sscb_sda = PIN_SIOD,
22 | .pin_sscb_scl = PIN_SIOC,
23 | .pin_d7 = PIN_D7,
24 | .pin_d6 = PIN_D6,
25 | .pin_d5 = PIN_D5,
26 | .pin_d4 = PIN_D4,
27 | .pin_d3 = PIN_D3,
28 | .pin_d2 = PIN_D2,
29 | .pin_d1 = PIN_D1,
30 | .pin_d0 = PIN_D0,
31 | .pin_vsync = PIN_VSYNC,
32 | .pin_href = PIN_HREF,
33 | .pin_pclk = PIN_PCLK,
34 |
35 | .xclk_freq_hz = 20000000,
36 | .ledc_timer = LEDC_TIMER_0,
37 | .ledc_channel = LEDC_CHANNEL_0,
38 | .pixel_format = PIXFORMAT_JPEG,
39 | .frame_size = FRAMESIZE_SVGA,
40 | .jpeg_quality = 10,
41 | .fb_count = 2,
42 | .grab_mode = CAMERA_GRAB_WHEN_EMPTY
43 | };
44 |
45 | esp_err_t camera_example_init(){
46 | return esp_camera_init(&camera_example_config);
47 | }
48 |
49 | esp_err_t camera_example_capture(){
50 | //capture a frame
51 | camera_fb_t * fb = esp_camera_fb_get();
52 | if (!fb) {
53 | ESP_LOGE(TAG, "Frame buffer could not be acquired");
54 | return ESP_FAIL;
55 | }
56 |
57 | //replace this with your own function
58 | display_image(fb->width, fb->height, fb->pixformat, fb->buf, fb->len);
59 |
60 | //return the frame buffer back to be reused
61 | esp_camera_fb_return(fb);
62 |
63 | return ESP_OK;
64 | }
65 | */
66 |
67 | #pragma once
68 |
69 | #include "esp_err.h"
70 | #include "driver/ledc.h"
71 | #include "sensor.h"
72 | #include "sys/time.h"
73 |
74 | #ifdef __cplusplus
75 | extern "C" {
76 | #endif
77 |
78 | /**
79 | * @brief Configuration structure for camera initialization
80 | */
81 | typedef enum {
82 | CAMERA_GRAB_WHEN_EMPTY, /*!< Fills buffers when they are empty. Less resources but first 'fb_count' frames might be old */
83 | CAMERA_GRAB_LATEST /*!< Except when 1 frame buffer is used, queue will always contain the last 'fb_count' frames */
84 | } camera_grab_mode_t;
85 |
86 | /**
87 | * @brief Camera frame buffer location
88 | */
89 | typedef enum {
90 | CAMERA_FB_IN_PSRAM, /*!< Frame buffer is placed in external PSRAM */
91 | CAMERA_FB_IN_DRAM /*!< Frame buffer is placed in internal DRAM */
92 | } camera_fb_location_t;
93 |
94 | /**
95 | * @brief Configuration structure for camera initialization
96 | */
97 | typedef struct {
98 | int pin_pwdn; /*!< GPIO pin for camera power down line */
99 | int pin_reset; /*!< GPIO pin for camera reset line */
100 | int pin_xclk; /*!< GPIO pin for camera XCLK line */
101 | int pin_sscb_sda; /*!< GPIO pin for camera SDA line */
102 | int pin_sscb_scl; /*!< GPIO pin for camera SCL line */
103 | int pin_d7; /*!< GPIO pin for camera D7 line */
104 | int pin_d6; /*!< GPIO pin for camera D6 line */
105 | int pin_d5; /*!< GPIO pin for camera D5 line */
106 | int pin_d4; /*!< GPIO pin for camera D4 line */
107 | int pin_d3; /*!< GPIO pin for camera D3 line */
108 | int pin_d2; /*!< GPIO pin for camera D2 line */
109 | int pin_d1; /*!< GPIO pin for camera D1 line */
110 | int pin_d0; /*!< GPIO pin for camera D0 line */
111 | int pin_vsync; /*!< GPIO pin for camera VSYNC line */
112 | int pin_href; /*!< GPIO pin for camera HREF line */
113 | int pin_pclk; /*!< GPIO pin for camera PCLK line */
114 |
115 | int xclk_freq_hz; /*!< Frequency of XCLK signal, in Hz. EXPERIMENTAL: Set to 16MHz on ESP32-S2 or ESP32-S3 to enable EDMA mode */
116 |
117 | ledc_timer_t ledc_timer; /*!< LEDC timer to be used for generating XCLK */
118 | ledc_channel_t ledc_channel; /*!< LEDC channel to be used for generating XCLK */
119 |
120 | pixformat_t pixel_format; /*!< Format of the pixel data: PIXFORMAT_ + YUV422|GRAYSCALE|RGB565|JPEG */
121 | framesize_t frame_size; /*!< Size of the output image: FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA */
122 |
123 | int jpeg_quality; /*!< Quality of JPEG output. 0-63 lower means higher quality */
124 | size_t fb_count; /*!< Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed) */
125 | camera_fb_location_t fb_location; /*!< The location where the frame buffer will be allocated */
126 | camera_grab_mode_t grab_mode; /*!< When buffers should be filled */
127 | } camera_config_t;
128 |
129 | /**
130 | * @brief Data structure of camera frame buffer
131 | */
132 | typedef struct {
133 | uint8_t * buf; /*!< Pointer to the pixel data */
134 | size_t len; /*!< Length of the buffer in bytes */
135 | size_t width; /*!< Width of the buffer in pixels */
136 | size_t height; /*!< Height of the buffer in pixels */
137 | pixformat_t format; /*!< Format of the pixel data */
138 | struct timeval timestamp; /*!< Timestamp since boot of the first DMA buffer of the frame */
139 | } camera_fb_t;
140 |
141 | #define ESP_ERR_CAMERA_BASE 0x20000
142 | #define ESP_ERR_CAMERA_NOT_DETECTED (ESP_ERR_CAMERA_BASE + 1)
143 | #define ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE (ESP_ERR_CAMERA_BASE + 2)
144 | #define ESP_ERR_CAMERA_FAILED_TO_SET_OUT_FORMAT (ESP_ERR_CAMERA_BASE + 3)
145 | #define ESP_ERR_CAMERA_NOT_SUPPORTED (ESP_ERR_CAMERA_BASE + 4)
146 |
147 | /**
148 | * @brief Initialize the camera driver
149 | *
150 | * @note call camera_probe before calling this function
151 | *
152 | * This function detects and configures camera over I2C interface,
153 | * allocates framebuffer and DMA buffers,
154 | * initializes parallel I2S input, and sets up DMA descriptors.
155 | *
156 | * Currently this function can only be called once and there is
157 | * no way to de-initialize this module.
158 | *
159 | * @param config Camera configuration parameters
160 | *
161 | * @return ESP_OK on success
162 | */
163 | esp_err_t esp_camera_init(const camera_config_t* config);
164 |
165 | /**
166 | * @brief Deinitialize the camera driver
167 | *
168 | * @return
169 | * - ESP_OK on success
170 | * - ESP_ERR_INVALID_STATE if the driver hasn't been initialized yet
171 | */
172 | esp_err_t esp_camera_deinit();
173 |
174 | /**
175 | * @brief Obtain pointer to a frame buffer.
176 | *
177 | * @return pointer to the frame buffer
178 | */
179 | camera_fb_t* esp_camera_fb_get();
180 |
181 | /**
182 | * @brief Return the frame buffer to be reused again.
183 | *
184 | * @param fb Pointer to the frame buffer
185 | */
186 | void esp_camera_fb_return(camera_fb_t * fb);
187 |
188 | /**
189 | * @brief Get a pointer to the image sensor control structure
190 | *
191 | * @return pointer to the sensor
192 | */
193 | sensor_t * esp_camera_sensor_get();
194 |
195 | /**
196 | * @brief Save camera settings to non-volatile-storage (NVS)
197 | *
198 | * @param key A unique nvs key name for the camera settings
199 | */
200 | esp_err_t esp_camera_save_to_nvs(const char *key);
201 |
202 | /**
203 | * @brief Load camera settings from non-volatile-storage (NVS)
204 | *
205 | * @param key A unique nvs key name for the camera settings
206 | */
207 | esp_err_t esp_camera_load_from_nvs(const char *key);
208 |
209 | #ifdef __cplusplus
210 | }
211 | #endif
212 |
213 | #include "img_converters.h"
214 |
215 |
--------------------------------------------------------------------------------
/components/esp32-camera/driver/include/sensor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * Sensor abstraction layer.
7 | *
8 | */
9 | #ifndef __SENSOR_H__
10 | #define __SENSOR_H__
11 | #include
12 | #include
13 |
14 | #ifdef __cplusplus
15 | extern "C" {
16 | #endif
17 |
18 | typedef enum {
19 | OV9650_PID = 0x96,
20 | OV7725_PID = 0x77,
21 | OV2640_PID = 0x26,
22 | OV3660_PID = 0x3660,
23 | OV5640_PID = 0x5640,
24 | OV7670_PID = 0x76,
25 | NT99141_PID = 0x1410,
26 | GC2145_PID = 0x2145,
27 | GC032A_PID = 0x232a,
28 | GC0308_PID = 0x9b,
29 | BF3005_PID = 0x30,
30 | BF20A6_PID = 0x20a6,
31 | } camera_pid_t;
32 |
33 | typedef enum {
34 | CAMERA_OV7725,
35 | CAMERA_OV2640,
36 | CAMERA_OV3660,
37 | CAMERA_OV5640,
38 | CAMERA_OV7670,
39 | CAMERA_NT99141,
40 | CAMERA_GC2145,
41 | CAMERA_GC032A,
42 | CAMERA_GC0308,
43 | CAMERA_BF3005,
44 | CAMERA_BF20A6,
45 | CAMERA_MODEL_MAX,
46 | CAMERA_NONE,
47 | } camera_model_t;
48 |
49 | typedef enum {
50 | OV2640_SCCB_ADDR = 0x30,// 0x60 >> 1
51 | OV5640_SCCB_ADDR = 0x3C,// 0x78 >> 1
52 | OV3660_SCCB_ADDR = 0x3C,// 0x78 >> 1
53 | OV7725_SCCB_ADDR = 0x21,// 0x42 >> 1
54 | OV7670_SCCB_ADDR = 0x21,// 0x42 >> 1
55 | NT99141_SCCB_ADDR = 0x2A,// 0x54 >> 1
56 | GC2145_SCCB_ADDR = 0x3C,// 0x78 >> 1
57 | GC032A_SCCB_ADDR = 0x21,// 0x42 >> 1
58 | GC0308_SCCB_ADDR = 0x21,// 0x42 >> 1
59 | BF3005_SCCB_ADDR = 0x6E,
60 | BF20A6_SCCB_ADDR = 0x6E,
61 | } camera_sccb_addr_t;
62 |
63 | typedef enum {
64 | PIXFORMAT_RGB565, // 2BPP/RGB565
65 | PIXFORMAT_YUV422, // 2BPP/YUV422
66 | PIXFORMAT_GRAYSCALE, // 1BPP/GRAYSCALE
67 | PIXFORMAT_JPEG, // JPEG/COMPRESSED
68 | PIXFORMAT_RGB888, // 3BPP/RGB888
69 | PIXFORMAT_RAW, // RAW
70 | PIXFORMAT_RGB444, // 3BP2P/RGB444
71 | PIXFORMAT_RGB555, // 3BP2P/RGB555
72 | } pixformat_t;
73 |
74 | typedef enum {
75 | FRAMESIZE_96X96, // 96x96
76 | FRAMESIZE_QQVGA, // 160x120
77 | FRAMESIZE_QCIF, // 176x144
78 | FRAMESIZE_HQVGA, // 240x176
79 | FRAMESIZE_240X240, // 240x240
80 | FRAMESIZE_QVGA, // 320x240
81 | FRAMESIZE_CIF, // 400x296
82 | FRAMESIZE_HVGA, // 480x320
83 | FRAMESIZE_VGA, // 640x480
84 | FRAMESIZE_SVGA, // 800x600
85 | FRAMESIZE_XGA, // 1024x768
86 | FRAMESIZE_HD, // 1280x720
87 | FRAMESIZE_SXGA, // 1280x1024
88 | FRAMESIZE_UXGA, // 1600x1200
89 | // 3MP Sensors
90 | FRAMESIZE_FHD, // 1920x1080
91 | FRAMESIZE_P_HD, // 720x1280
92 | FRAMESIZE_P_3MP, // 864x1536
93 | FRAMESIZE_QXGA, // 2048x1536
94 | // 5MP Sensors
95 | FRAMESIZE_QHD, // 2560x1440
96 | FRAMESIZE_WQXGA, // 2560x1600
97 | FRAMESIZE_P_FHD, // 1080x1920
98 | FRAMESIZE_QSXGA, // 2560x1920
99 | FRAMESIZE_INVALID
100 | } framesize_t;
101 |
102 | typedef struct {
103 | const camera_model_t model;
104 | const char *name;
105 | const camera_sccb_addr_t sccb_addr;
106 | const camera_pid_t pid;
107 | const framesize_t max_size;
108 | const bool support_jpeg;
109 | } camera_sensor_info_t;
110 |
111 | typedef enum {
112 | ASPECT_RATIO_4X3,
113 | ASPECT_RATIO_3X2,
114 | ASPECT_RATIO_16X10,
115 | ASPECT_RATIO_5X3,
116 | ASPECT_RATIO_16X9,
117 | ASPECT_RATIO_21X9,
118 | ASPECT_RATIO_5X4,
119 | ASPECT_RATIO_1X1,
120 | ASPECT_RATIO_9X16
121 | } aspect_ratio_t;
122 |
123 | typedef enum {
124 | GAINCEILING_2X,
125 | GAINCEILING_4X,
126 | GAINCEILING_8X,
127 | GAINCEILING_16X,
128 | GAINCEILING_32X,
129 | GAINCEILING_64X,
130 | GAINCEILING_128X,
131 | } gainceiling_t;
132 |
133 | typedef struct {
134 | uint16_t max_width;
135 | uint16_t max_height;
136 | uint16_t start_x;
137 | uint16_t start_y;
138 | uint16_t end_x;
139 | uint16_t end_y;
140 | uint16_t offset_x;
141 | uint16_t offset_y;
142 | uint16_t total_x;
143 | uint16_t total_y;
144 | } ratio_settings_t;
145 |
146 | typedef struct {
147 | const uint16_t width;
148 | const uint16_t height;
149 | const aspect_ratio_t aspect_ratio;
150 | } resolution_info_t;
151 |
152 | // Resolution table (in sensor.c)
153 | extern const resolution_info_t resolution[];
154 | // camera sensor table (in sensor.c)
155 | extern const camera_sensor_info_t camera_sensor[];
156 |
157 | typedef struct {
158 | uint8_t MIDH;
159 | uint8_t MIDL;
160 | uint16_t PID;
161 | uint8_t VER;
162 | } sensor_id_t;
163 |
164 | typedef struct {
165 | framesize_t framesize;//0 - 10
166 | bool scale;
167 | bool binning;
168 | uint8_t quality;//0 - 63
169 | int8_t brightness;//-2 - 2
170 | int8_t contrast;//-2 - 2
171 | int8_t saturation;//-2 - 2
172 | int8_t sharpness;//-2 - 2
173 | uint8_t denoise;
174 | uint8_t special_effect;//0 - 6
175 | uint8_t wb_mode;//0 - 4
176 | uint8_t awb;
177 | uint8_t awb_gain;
178 | uint8_t aec;
179 | uint8_t aec2;
180 | int8_t ae_level;//-2 - 2
181 | uint16_t aec_value;//0 - 1200
182 | uint8_t agc;
183 | uint8_t agc_gain;//0 - 30
184 | uint8_t gainceiling;//0 - 6
185 | uint8_t bpc;
186 | uint8_t wpc;
187 | uint8_t raw_gma;
188 | uint8_t lenc;
189 | uint8_t hmirror;
190 | uint8_t vflip;
191 | uint8_t dcw;
192 | uint8_t colorbar;
193 | } camera_status_t;
194 |
195 | typedef struct _sensor sensor_t;
196 | typedef struct _sensor {
197 | sensor_id_t id; // Sensor ID.
198 | uint8_t slv_addr; // Sensor I2C slave address.
199 | pixformat_t pixformat;
200 | camera_status_t status;
201 | int xclk_freq_hz;
202 |
203 | // Sensor function pointers
204 | int (*init_status) (sensor_t *sensor);
205 | int (*reset) (sensor_t *sensor);
206 | int (*set_pixformat) (sensor_t *sensor, pixformat_t pixformat);
207 | int (*set_framesize) (sensor_t *sensor, framesize_t framesize);
208 | int (*set_contrast) (sensor_t *sensor, int level);
209 | int (*set_brightness) (sensor_t *sensor, int level);
210 | int (*set_saturation) (sensor_t *sensor, int level);
211 | int (*set_sharpness) (sensor_t *sensor, int level);
212 | int (*set_denoise) (sensor_t *sensor, int level);
213 | int (*set_gainceiling) (sensor_t *sensor, gainceiling_t gainceiling);
214 | int (*set_quality) (sensor_t *sensor, int quality);
215 | int (*set_colorbar) (sensor_t *sensor, int enable);
216 | int (*set_whitebal) (sensor_t *sensor, int enable);
217 | int (*set_gain_ctrl) (sensor_t *sensor, int enable);
218 | int (*set_exposure_ctrl) (sensor_t *sensor, int enable);
219 | int (*set_hmirror) (sensor_t *sensor, int enable);
220 | int (*set_vflip) (sensor_t *sensor, int enable);
221 |
222 | int (*set_aec2) (sensor_t *sensor, int enable);
223 | int (*set_awb_gain) (sensor_t *sensor, int enable);
224 | int (*set_agc_gain) (sensor_t *sensor, int gain);
225 | int (*set_aec_value) (sensor_t *sensor, int gain);
226 |
227 | int (*set_special_effect) (sensor_t *sensor, int effect);
228 | int (*set_wb_mode) (sensor_t *sensor, int mode);
229 | int (*set_ae_level) (sensor_t *sensor, int level);
230 |
231 | int (*set_dcw) (sensor_t *sensor, int enable);
232 | int (*set_bpc) (sensor_t *sensor, int enable);
233 | int (*set_wpc) (sensor_t *sensor, int enable);
234 |
235 | int (*set_raw_gma) (sensor_t *sensor, int enable);
236 | int (*set_lenc) (sensor_t *sensor, int enable);
237 |
238 | int (*get_reg) (sensor_t *sensor, int reg, int mask);
239 | int (*set_reg) (sensor_t *sensor, int reg, int mask, int value);
240 | 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);
241 | int (*set_pll) (sensor_t *sensor, int bypass, int mul, int sys, int root, int pre, int seld5, int pclken, int pclk);
242 | int (*set_xclk) (sensor_t *sensor, int timer, int xclk);
243 | } sensor_t;
244 |
245 | camera_sensor_info_t *esp_camera_sensor_get_info(sensor_id_t *id);
246 |
247 | #ifdef __cplusplus
248 | }
249 | #endif
250 |
251 | #endif /* __SENSOR_H__ */
252 |
--------------------------------------------------------------------------------
/components/esp32-camera/driver/private_include/cam_hal.h:
--------------------------------------------------------------------------------
1 | // Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #pragma once
16 |
17 | #include "esp_camera.h"
18 |
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | /**
25 | * @brief Uninitialize the lcd_cam module
26 | *
27 | * @param handle Provide handle pointer to release resources
28 | *
29 | * @return
30 | * - ESP_OK Success
31 | * - ESP_FAIL Uninitialize fail
32 | */
33 | esp_err_t cam_deinit(void);
34 |
35 | /**
36 | * @brief Initialize the lcd_cam module
37 | *
38 | * @param config Configurations - see lcd_cam_config_t struct
39 | *
40 | * @return
41 | * - ESP_OK Success
42 | * - ESP_ERR_INVALID_ARG Parameter error
43 | * - ESP_ERR_NO_MEM No memory to initialize lcd_cam
44 | * - ESP_FAIL Initialize fail
45 | */
46 | esp_err_t cam_init(const camera_config_t *config);
47 |
48 | esp_err_t cam_config(const camera_config_t *config, framesize_t frame_size, uint16_t sensor_pid);
49 |
50 | void cam_stop(void);
51 |
52 | void cam_start(void);
53 |
54 | camera_fb_t *cam_take(TickType_t timeout);
55 |
56 | void cam_give(camera_fb_t *dma_buffer);
57 |
58 | #ifdef __cplusplus
59 | }
60 | #endif
61 |
--------------------------------------------------------------------------------
/components/esp32-camera/driver/private_include/sccb.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * SCCB (I2C like) driver.
7 | *
8 | */
9 | #ifndef __SCCB_H__
10 | #define __SCCB_H__
11 | #include
12 | int SCCB_Init(int pin_sda, int pin_scl);
13 | int SCCB_Deinit(void);
14 | uint8_t SCCB_Probe();
15 | uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg);
16 | uint8_t SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data);
17 | uint8_t SCCB_Read16(uint8_t slv_addr, uint16_t reg);
18 | uint8_t SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data);
19 | #endif // __SCCB_H__
20 |
--------------------------------------------------------------------------------
/components/esp32-camera/driver/private_include/xclk.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "esp_system.h"
4 |
5 | esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz);
6 |
7 | esp_err_t camera_enable_out_clock();
8 |
9 | void camera_disable_out_clock();
10 |
--------------------------------------------------------------------------------
/components/esp32-camera/driver/sccb.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * SCCB (I2C like) driver.
7 | *
8 | */
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include "sccb.h"
14 | #include "sensor.h"
15 | #include
16 | #include "sdkconfig.h"
17 | #if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
18 | #include "esp32-hal-log.h"
19 | #else
20 | #include "esp_log.h"
21 | static const char* TAG = "sccb";
22 | #endif
23 |
24 | #define LITTLETOBIG(x) ((x<<8)|(x>>8))
25 |
26 | #include "driver/i2c.h"
27 |
28 | // support IDF 5.x
29 | #ifndef portTICK_RATE_MS
30 | #define portTICK_RATE_MS portTICK_PERIOD_MS
31 | #endif
32 |
33 | #define SCCB_FREQ CONFIG_SCCB_CLK_FREQ /*!< I2C master frequency*/
34 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
35 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */
36 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
37 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
38 | #define ACK_VAL 0x0 /*!< I2C ack value */
39 | #define NACK_VAL 0x1 /*!< I2C nack value */
40 | #if CONFIG_SCCB_HARDWARE_I2C_PORT1
41 | const int SCCB_I2C_PORT = 1;
42 | #else
43 | const int SCCB_I2C_PORT = 0;
44 | #endif
45 |
46 | int SCCB_Init(int pin_sda, int pin_scl)
47 | {
48 | ESP_LOGI(TAG, "pin_sda %d pin_scl %d", pin_sda, pin_scl);
49 | // i2c_config_t conf;
50 | // memset(&conf, 0, sizeof(i2c_config_t));
51 | // conf.mode = I2C_MODE_MASTER;
52 | // conf.sda_io_num = pin_sda;
53 | // conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
54 | // conf.scl_io_num = pin_scl;
55 | // conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
56 | // conf.master.clk_speed = SCCB_FREQ;
57 |
58 | // i2c_param_config(SCCB_I2C_PORT, &conf);
59 | // i2c_driver_install(SCCB_I2C_PORT, conf.mode, 0, 0, 0);
60 | return 0;
61 | }
62 |
63 | int SCCB_Deinit(void)
64 | {
65 | return 0; //i2c_driver_delete(SCCB_I2C_PORT);
66 | }
67 |
68 | uint8_t SCCB_Probe(void)
69 | {
70 | uint8_t slave_addr = 0x0;
71 | // for (size_t i = 1; i < 0x80; i++) {
72 | // i2c_cmd_handle_t cmd = i2c_cmd_link_create();
73 | // i2c_master_start(cmd);
74 | // i2c_master_write_byte(cmd, ( i << 1 ) | WRITE_BIT, ACK_CHECK_EN);
75 | // i2c_master_stop(cmd);
76 | // esp_err_t ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
77 | // i2c_cmd_link_delete(cmd);
78 | // if( ret == ESP_OK) {
79 | // ESP_LOGW(TAG, "Found I2C Device at 0x%02X", i);
80 | // }
81 | // }
82 | for (size_t i = 0; i < CAMERA_MODEL_MAX; i++) {
83 | if (slave_addr == camera_sensor[i].sccb_addr) {
84 | continue;
85 | }
86 | slave_addr = camera_sensor[i].sccb_addr;
87 | i2c_cmd_handle_t cmd = i2c_cmd_link_create();
88 | i2c_master_start(cmd);
89 | i2c_master_write_byte(cmd, ( slave_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
90 | i2c_master_stop(cmd);
91 | esp_err_t ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
92 | i2c_cmd_link_delete(cmd);
93 | if( ret == ESP_OK) {
94 | return slave_addr;
95 | }
96 | }
97 | return 0;
98 | }
99 |
100 | uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
101 | {
102 | uint8_t data=0;
103 | esp_err_t ret = ESP_FAIL;
104 | i2c_cmd_handle_t cmd = i2c_cmd_link_create();
105 | i2c_master_start(cmd);
106 | i2c_master_write_byte(cmd, ( slv_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
107 | i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);
108 | i2c_master_stop(cmd);
109 | ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
110 | i2c_cmd_link_delete(cmd);
111 | if(ret != ESP_OK) return -1;
112 | cmd = i2c_cmd_link_create();
113 | i2c_master_start(cmd);
114 | i2c_master_write_byte(cmd, ( slv_addr << 1 ) | READ_BIT, ACK_CHECK_EN);
115 | i2c_master_read_byte(cmd, &data, NACK_VAL);
116 | i2c_master_stop(cmd);
117 | ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
118 | i2c_cmd_link_delete(cmd);
119 | if(ret != ESP_OK) {
120 | ESP_LOGE(TAG, "SCCB_Read Failed addr:0x%02x, reg:0x%02x, data:0x%02x, ret:%d", slv_addr, reg, data, ret);
121 | }
122 | return data;
123 | }
124 |
125 | uint8_t SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data)
126 | {
127 | esp_err_t ret = ESP_FAIL;
128 | i2c_cmd_handle_t cmd = i2c_cmd_link_create();
129 | i2c_master_start(cmd);
130 | i2c_master_write_byte(cmd, ( slv_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
131 | i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);
132 | i2c_master_write_byte(cmd, data, ACK_CHECK_EN);
133 | i2c_master_stop(cmd);
134 | ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
135 | i2c_cmd_link_delete(cmd);
136 | if(ret != ESP_OK) {
137 | ESP_LOGE(TAG, "SCCB_Write Failed addr:0x%02x, reg:0x%02x, data:0x%02x, ret:%d", slv_addr, reg, data, ret);
138 | }
139 | return ret == ESP_OK ? 0 : -1;
140 | }
141 |
142 | uint8_t SCCB_Read16(uint8_t slv_addr, uint16_t reg)
143 | {
144 | uint8_t data=0;
145 | esp_err_t ret = ESP_FAIL;
146 | uint16_t reg_htons = LITTLETOBIG(reg);
147 | uint8_t *reg_u8 = (uint8_t *)®_htons;
148 | i2c_cmd_handle_t cmd = i2c_cmd_link_create();
149 | i2c_master_start(cmd);
150 | i2c_master_write_byte(cmd, ( slv_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
151 | i2c_master_write_byte(cmd, reg_u8[0], ACK_CHECK_EN);
152 | i2c_master_write_byte(cmd, reg_u8[1], ACK_CHECK_EN);
153 | i2c_master_stop(cmd);
154 | ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
155 | i2c_cmd_link_delete(cmd);
156 | if(ret != ESP_OK) return -1;
157 | cmd = i2c_cmd_link_create();
158 | i2c_master_start(cmd);
159 | i2c_master_write_byte(cmd, ( slv_addr << 1 ) | READ_BIT, ACK_CHECK_EN);
160 | i2c_master_read_byte(cmd, &data, NACK_VAL);
161 | i2c_master_stop(cmd);
162 | ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
163 | i2c_cmd_link_delete(cmd);
164 | if(ret != ESP_OK) {
165 | ESP_LOGE(TAG, "W [%04x]=%02x fail\n", reg, data);
166 | }
167 | return data;
168 | }
169 |
170 | uint8_t SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data)
171 | {
172 | static uint16_t i = 0;
173 | esp_err_t ret = ESP_FAIL;
174 | uint16_t reg_htons = LITTLETOBIG(reg);
175 | uint8_t *reg_u8 = (uint8_t *)®_htons;
176 | i2c_cmd_handle_t cmd = i2c_cmd_link_create();
177 | i2c_master_start(cmd);
178 | i2c_master_write_byte(cmd, ( slv_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
179 | i2c_master_write_byte(cmd, reg_u8[0], ACK_CHECK_EN);
180 | i2c_master_write_byte(cmd, reg_u8[1], ACK_CHECK_EN);
181 | i2c_master_write_byte(cmd, data, ACK_CHECK_EN);
182 | i2c_master_stop(cmd);
183 | ret = i2c_master_cmd_begin(SCCB_I2C_PORT, cmd, 1000 / portTICK_RATE_MS);
184 | i2c_cmd_link_delete(cmd);
185 | if(ret != ESP_OK) {
186 | ESP_LOGE(TAG, "W [%04x]=%02x %d fail\n", reg, data, i++);
187 | }
188 | return ret == ESP_OK ? 0 : -1;
189 | }
190 |
--------------------------------------------------------------------------------
/components/esp32-camera/driver/sensor.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "sensor.h"
3 |
4 | const camera_sensor_info_t camera_sensor[CAMERA_MODEL_MAX] = {
5 | // The sequence must be consistent with camera_model_t
6 | {CAMERA_OV7725, "OV7725", OV7725_SCCB_ADDR, OV7725_PID, FRAMESIZE_VGA, false},
7 | {CAMERA_OV2640, "OV2640", OV2640_SCCB_ADDR, OV2640_PID, FRAMESIZE_UXGA, true},
8 | {CAMERA_OV3660, "OV3660", OV3660_SCCB_ADDR, OV3660_PID, FRAMESIZE_QXGA, true},
9 | {CAMERA_OV5640, "OV5640", OV5640_SCCB_ADDR, OV5640_PID, FRAMESIZE_QSXGA, true},
10 | {CAMERA_OV7670, "OV7670", OV7670_SCCB_ADDR, OV7670_PID, FRAMESIZE_VGA, false},
11 | {CAMERA_NT99141, "NT99141", NT99141_SCCB_ADDR, NT99141_PID, FRAMESIZE_HD, true},
12 | {CAMERA_GC2145, "GC2145", GC2145_SCCB_ADDR, GC2145_PID, FRAMESIZE_UXGA, false},
13 | {CAMERA_GC032A, "GC032A", GC032A_SCCB_ADDR, GC032A_PID, FRAMESIZE_VGA, false},
14 | {CAMERA_GC0308, "GC0308", GC0308_SCCB_ADDR, GC0308_PID, FRAMESIZE_VGA, false},
15 | {CAMERA_BF3005, "BF3005", BF3005_SCCB_ADDR, BF3005_PID, FRAMESIZE_VGA, false},
16 | {CAMERA_BF20A6, "BF20A6", BF20A6_SCCB_ADDR, BF20A6_PID, FRAMESIZE_VGA, false},
17 | };
18 |
19 | const resolution_info_t resolution[FRAMESIZE_INVALID] = {
20 | { 96, 96, ASPECT_RATIO_1X1 }, /* 96x96 */
21 | { 160, 120, ASPECT_RATIO_4X3 }, /* QQVGA */
22 | { 176, 144, ASPECT_RATIO_5X4 }, /* QCIF */
23 | { 240, 176, ASPECT_RATIO_4X3 }, /* HQVGA */
24 | { 240, 240, ASPECT_RATIO_1X1 }, /* 240x240 */
25 | { 320, 240, ASPECT_RATIO_4X3 }, /* QVGA */
26 | { 400, 296, ASPECT_RATIO_4X3 }, /* CIF */
27 | { 480, 320, ASPECT_RATIO_3X2 }, /* HVGA */
28 | { 640, 480, ASPECT_RATIO_4X3 }, /* VGA */
29 | { 800, 600, ASPECT_RATIO_4X3 }, /* SVGA */
30 | { 1024, 768, ASPECT_RATIO_4X3 }, /* XGA */
31 | { 1280, 720, ASPECT_RATIO_16X9 }, /* HD */
32 | { 1280, 1024, ASPECT_RATIO_5X4 }, /* SXGA */
33 | { 1600, 1200, ASPECT_RATIO_4X3 }, /* UXGA */
34 | // 3MP Sensors
35 | { 1920, 1080, ASPECT_RATIO_16X9 }, /* FHD */
36 | { 720, 1280, ASPECT_RATIO_9X16 }, /* Portrait HD */
37 | { 864, 1536, ASPECT_RATIO_9X16 }, /* Portrait 3MP */
38 | { 2048, 1536, ASPECT_RATIO_4X3 }, /* QXGA */
39 | // 5MP Sensors
40 | { 2560, 1440, ASPECT_RATIO_16X9 }, /* QHD */
41 | { 2560, 1600, ASPECT_RATIO_16X10 }, /* WQXGA */
42 | { 1088, 1920, ASPECT_RATIO_9X16 }, /* Portrait FHD */
43 | { 2560, 1920, ASPECT_RATIO_4X3 }, /* QSXGA */
44 | };
45 |
46 | camera_sensor_info_t *esp_camera_sensor_get_info(sensor_id_t *id)
47 | {
48 | for (int i = 0; i < CAMERA_MODEL_MAX; i++) {
49 | if (id->PID == camera_sensor[i].pid) {
50 | return (camera_sensor_info_t *)&camera_sensor[i];
51 | }
52 | }
53 | return NULL;
54 | }
55 |
--------------------------------------------------------------------------------
/components/esp32-camera/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # The following lines of boilerplate have to be in your project's
2 | # CMakeLists in this exact order for cmake to work correctly
3 | cmake_minimum_required(VERSION 3.5)
4 |
5 | set(EXTRA_COMPONENT_DIRS "../")
6 |
7 | add_compile_options(-fdiagnostics-color=always)
8 | include($ENV{IDF_PATH}/tools/cmake/project.cmake)
9 | project(camera_example)
--------------------------------------------------------------------------------
/components/esp32-camera/examples/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a
3 | # project subdirectory.
4 | #
5 |
6 | PROJECT_NAME := camera_example
7 |
8 | EXTRA_COMPONENT_DIRS := ../
9 |
10 | include $(IDF_PATH)/make/project.mk
11 |
12 |
--------------------------------------------------------------------------------
/components/esp32-camera/examples/main/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(COMPONENT_SRCS take_picture.c)
2 | set(COMPONENT_ADD_INCLUDEDIRS .)
3 | register_component()
--------------------------------------------------------------------------------
/components/esp32-camera/examples/main/component.mk:
--------------------------------------------------------------------------------
1 | #
2 | # "main" pseudo-component makefile.
3 | #
4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
5 |
6 |
--------------------------------------------------------------------------------
/components/esp32-camera/examples/main/take_picture.c:
--------------------------------------------------------------------------------
1 | /**
2 | * This example takes a picture every 5s and print its size on serial monitor.
3 | */
4 |
5 | // =============================== SETUP ======================================
6 |
7 | // 1. Board setup (Uncomment):
8 | // #define BOARD_WROVER_KIT
9 | // #define BOARD_ESP32CAM_AITHINKER
10 |
11 | /**
12 | * 2. Kconfig setup
13 | *
14 | * If you have a Kconfig file, copy the content from
15 | * https://github.com/espressif/esp32-camera/blob/master/Kconfig into it.
16 | * In case you haven't, copy and paste this Kconfig file inside the src directory.
17 | * This Kconfig file has definitions that allows more control over the camera and
18 | * how it will be initialized.
19 | */
20 |
21 | /**
22 | * 3. Enable PSRAM on sdkconfig:
23 | *
24 | * CONFIG_ESP32_SPIRAM_SUPPORT=y
25 | *
26 | * More info on
27 | * https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/kconfig.html#config-esp32-spiram-support
28 | */
29 |
30 | // ================================ CODE ======================================
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 |
38 | #include "freertos/FreeRTOS.h"
39 | #include "freertos/task.h"
40 |
41 | // support IDF 5.x
42 | #ifndef portTICK_RATE_MS
43 | #define portTICK_RATE_MS portTICK_PERIOD_MS
44 | #endif
45 |
46 | #include "esp_camera.h"
47 |
48 | #define BOARD_WROVER_KIT 1
49 |
50 | // WROVER-KIT PIN Map
51 | #ifdef BOARD_WROVER_KIT
52 |
53 | #define CAM_PIN_PWDN -1 //power down is not used
54 | #define CAM_PIN_RESET -1 //software reset will be performed
55 | #define CAM_PIN_XCLK 21
56 | #define CAM_PIN_SIOD 26
57 | #define CAM_PIN_SIOC 27
58 |
59 | #define CAM_PIN_D7 35
60 | #define CAM_PIN_D6 34
61 | #define CAM_PIN_D5 39
62 | #define CAM_PIN_D4 36
63 | #define CAM_PIN_D3 19
64 | #define CAM_PIN_D2 18
65 | #define CAM_PIN_D1 5
66 | #define CAM_PIN_D0 4
67 | #define CAM_PIN_VSYNC 25
68 | #define CAM_PIN_HREF 23
69 | #define CAM_PIN_PCLK 22
70 |
71 | #endif
72 |
73 | // ESP32Cam (AiThinker) PIN Map
74 | #ifdef BOARD_ESP32CAM_AITHINKER
75 |
76 | #define CAM_PIN_PWDN 32
77 | #define CAM_PIN_RESET -1 //software reset will be performed
78 | #define CAM_PIN_XCLK 0
79 | #define CAM_PIN_SIOD 26
80 | #define CAM_PIN_SIOC 27
81 |
82 | #define CAM_PIN_D7 35
83 | #define CAM_PIN_D6 34
84 | #define CAM_PIN_D5 39
85 | #define CAM_PIN_D4 36
86 | #define CAM_PIN_D3 21
87 | #define CAM_PIN_D2 19
88 | #define CAM_PIN_D1 18
89 | #define CAM_PIN_D0 5
90 | #define CAM_PIN_VSYNC 25
91 | #define CAM_PIN_HREF 23
92 | #define CAM_PIN_PCLK 22
93 |
94 | #endif
95 |
96 | static const char *TAG = "example:take_picture";
97 |
98 | static camera_config_t camera_config = {
99 | .pin_pwdn = CAM_PIN_PWDN,
100 | .pin_reset = CAM_PIN_RESET,
101 | .pin_xclk = CAM_PIN_XCLK,
102 | .pin_sscb_sda = CAM_PIN_SIOD,
103 | .pin_sscb_scl = CAM_PIN_SIOC,
104 |
105 | .pin_d7 = CAM_PIN_D7,
106 | .pin_d6 = CAM_PIN_D6,
107 | .pin_d5 = CAM_PIN_D5,
108 | .pin_d4 = CAM_PIN_D4,
109 | .pin_d3 = CAM_PIN_D3,
110 | .pin_d2 = CAM_PIN_D2,
111 | .pin_d1 = CAM_PIN_D1,
112 | .pin_d0 = CAM_PIN_D0,
113 | .pin_vsync = CAM_PIN_VSYNC,
114 | .pin_href = CAM_PIN_HREF,
115 | .pin_pclk = CAM_PIN_PCLK,
116 |
117 | //XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
118 | .xclk_freq_hz = 20000000,
119 | .ledc_timer = LEDC_TIMER_0,
120 | .ledc_channel = LEDC_CHANNEL_0,
121 |
122 | .pixel_format = PIXFORMAT_RGB565, //YUV422,GRAYSCALE,RGB565,JPEG
123 | .frame_size = FRAMESIZE_QVGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG
124 |
125 | .jpeg_quality = 12, //0-63 lower number means higher quality
126 | .fb_count = 1, //if more than one, i2s runs in continuous mode. Use only with JPEG
127 | .grab_mode = CAMERA_GRAB_WHEN_EMPTY,
128 | };
129 |
130 | static esp_err_t init_camera()
131 | {
132 | //initialize the camera
133 | esp_err_t err = esp_camera_init(&camera_config);
134 | if (err != ESP_OK)
135 | {
136 | ESP_LOGE(TAG, "Camera Init Failed");
137 | return err;
138 | }
139 |
140 | return ESP_OK;
141 | }
142 |
143 | void app_main()
144 | {
145 | if(ESP_OK != init_camera()) {
146 | return;
147 | }
148 |
149 | while (1)
150 | {
151 | ESP_LOGI(TAG, "Taking picture...");
152 | camera_fb_t *pic = esp_camera_fb_get();
153 |
154 | // use pic->buf to access the image
155 | ESP_LOGI(TAG, "Picture taken! Its size was: %zu bytes", pic->len);
156 | esp_camera_fb_return(pic);
157 |
158 | vTaskDelay(5000 / portTICK_RATE_MS);
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/components/esp32-camera/examples/sdkconfig.defaults:
--------------------------------------------------------------------------------
1 | CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
2 | CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
3 | CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
4 |
5 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
6 | CONFIG_PARTITION_TABLE_OFFSET=0x10000
7 |
8 | CONFIG_FREERTOS_HZ=1000
9 | CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
10 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
11 |
12 | CONFIG_SPIRAM_SUPPORT=y
13 | CONFIG_ESP32_SPIRAM_SUPPORT=y
14 | CONFIG_ESP32S2_SPIRAM_SUPPORT=y
15 | CONFIG_ESP32S3_SPIRAM_SUPPORT=y
16 | CONFIG_SPIRAM_SPEED_80M=y
17 |
18 |
--------------------------------------------------------------------------------
/components/esp32-camera/idf_component.yml:
--------------------------------------------------------------------------------
1 | description: ESP32 compatible driver for OV2640, OV3660, OV5640, OV7670 and OV7725 image sensors.
2 | targets:
3 | - esp32
4 | - esp32s2
5 | - esp32s3
6 |
--------------------------------------------------------------------------------
/components/esp32-camera/library.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "esp32-camera",
3 | "version": "2.0.0",
4 | "keywords": "esp32, camera, espressif, esp32-cam",
5 | "description": "ESP32 compatible driver for OV2640, OV3660, OV5640, OV7670 and OV7725 image sensors.",
6 | "repository": {
7 | "type": "git",
8 | "url": "https://github.com/espressif/esp32-camera"
9 | },
10 | "frameworks": "espidf",
11 | "platforms": "*",
12 | "build": {
13 | "flags": [
14 | "-Idriver/include",
15 | "-Iconversions/include",
16 | "-Idriver/private_include",
17 | "-Iconversions/private_include",
18 | "-Isensors/private_include",
19 | "-Itarget/private_include",
20 | "-fno-rtti"
21 | ],
22 | "includeDir": ".",
23 | "srcDir": ".",
24 | "srcFilter": ["-<*>", "+", "+", "+"]
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/bf20a6.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __BF20A6_H__
3 | #define __BF20A6_H__
4 |
5 | #include "sensor.h"
6 |
7 | /**
8 | * @brief Detect sensor pid
9 | *
10 | * @param slv_addr SCCB address
11 | * @param id Detection result
12 | * @return
13 | * 0: Can't detect this sensor
14 | * Nonzero: This sensor has been detected
15 | */
16 | int bf20a6_detect(int slv_addr, sensor_id_t *id);
17 |
18 | /**
19 | * @brief initialize sensor function pointers
20 | *
21 | * @param sensor pointer of sensor
22 | * @return
23 | * Always 0
24 | */
25 | int bf20a6_init(sensor_t *sensor);
26 |
27 | #endif // __BF20A6_H__
28 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/bf20a6_regs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * BF20A6 register definitions.
3 | */
4 | #ifndef __BF20A6_REG_REGS_H__
5 | #define __BF20A6_REG_REGS_H__
6 |
7 | #define SENSOR_ID_HIGH 0XFC
8 | #define SENSOR_ID_LOW 0XFD
9 | #define RESET_RELATED 0XF2
10 |
11 |
12 | #endif //__BF20A6_REG_REGS_H__
13 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/bf20a6_settings.h:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | #define REG_DLY 0xffff
5 | #define REGLIST_TAIL 0xffff /* Array end token */
6 |
7 | static const uint16_t bf20a6_default_init_regs[][2] = {
8 | {0xf2,0x01},
9 | {0x12,0x20},
10 | {0x3a,0x00},
11 | {0xe1,0x92},
12 | {0xe3,0x12},// PLL Control, important for framerate(choice: 0x02\0x12\0x22\0x32\0x82)
13 | {0xe0,0x00},
14 | {0x2a,0x98},
15 | {0xcd,0x17},
16 | {0xc0,0x10},
17 | {0xc6,0x1d},
18 | {0x10,0x35},
19 | {0xe2,0x09},
20 | {0xe4,0x72},
21 | {0xe5,0x22},
22 | {0xe6,0x24},
23 | {0xe7,0x64},
24 | {0xe8,0xa2}, // DVP:a2}, SPI:f2 VDDIO=1.8V,E8[2]=1},VDDIO=2.8V,E8[2]=0},
25 | {0x4a,0x00},
26 | {0x00,0x03},
27 | {0x1f,0x02},
28 | {0x22,0x02},
29 | {0x0c,0x31},
30 |
31 | {0x00,0x00},
32 | {0x60,0x81},
33 | {0x61,0x81},
34 |
35 | {0xa0,0x08},
36 | {0x01,0x1a},
37 | // {0x01,0x1a},
38 | // {0x01,0x1a},
39 | // {0x02,0x15},
40 | // {0x02,0x15},
41 | {0x02,0x15},
42 | {0x13,0x08},
43 | {0x8a,0x96},
44 | {0x8b,0x06},
45 | {0x87,0x18},
46 |
47 |
48 | {0x34,0x48}, // lens
49 | {0x35,0x40},
50 | {0x36,0x40},
51 |
52 | {0x71,0x44},
53 | {0x72,0x48},
54 | {0x74,0xa2},
55 | {0x75,0xa9},
56 | {0x78,0x12},
57 | {0x79,0xa0},
58 | {0x7a,0x94},
59 | {0x7c,0x97},
60 | {0x40,0x30},
61 | {0x41,0x30},
62 | {0x42,0x28},
63 | {0x43,0x1f},
64 | {0x44,0x1c},
65 | {0x45,0x16},
66 | {0x46,0x13},
67 | {0x47,0x10},
68 | {0x48,0x0D},
69 | {0x49,0x0C},
70 | {0x4B,0x0A},
71 | {0x4C,0x0B},
72 | {0x4E,0x09},
73 | {0x4F,0x08},
74 | {0x50,0x08},
75 |
76 |
77 | {0x5f,0x29},
78 | {0x23,0x33},
79 | {0xa1,0x10}, // AWB
80 | {0xa2,0x0d},
81 | {0xa3,0x30},
82 | {0xa4,0x06},
83 | {0xa5,0x22},
84 | {0xa6,0x56},
85 | {0xa7,0x18},
86 | {0xa8,0x1a},
87 | {0xa9,0x12},
88 | {0xaa,0x12},
89 | {0xab,0x16},
90 | {0xac,0xb1},
91 | {0xba,0x12},
92 | {0xbb,0x12},
93 | {0xad,0x12},
94 | {0xae,0x56},
95 | {0xaf,0x0a},
96 | {0x3b,0x30},
97 | {0x3c,0x12},
98 | {0x3d,0x22},
99 | {0x3e,0x3f},
100 | {0x3f,0x28},
101 | {0xb8,0xc3},
102 | {0xb9,0xa3},
103 | {0x39,0x47}, // pure color threshold
104 | {0x26,0x13},
105 | {0x27,0x16},
106 | {0x28,0x14},
107 | {0x29,0x18},
108 | {0xee,0x0d},
109 |
110 |
111 | {0x13,0x05},
112 | {0x24,0x3C},
113 | {0x81,0x20},
114 | {0x82,0x40},
115 | {0x83,0x30},
116 | {0x84,0x58},
117 | {0x85,0x30},
118 | {0x92,0x08},
119 | {0x86,0x80},
120 | {0x8a,0x96},
121 | {0x91,0xff},
122 | {0x94,0x62},
123 | {0x9a,0x18}, // outdoor threshold
124 | {0xf0,0x45}, // integral time control, important for framerate(choice: 0x46\0x45\0x44..)
125 | {0x51,0x17}, // color normal
126 | {0x52,0x03},
127 | {0x53,0x5F},
128 | {0x54,0x47},
129 | {0x55,0x66},
130 | {0x56,0x0F},
131 | {0x7e,0x14},
132 | {0x57,0x36}, // color
133 | {0x58,0x2A},
134 | {0x59,0xAA},
135 | {0x5a,0xA8},
136 | {0x5b,0x43},
137 | {0x5c,0x10},
138 | {0x5d,0x00},
139 | {0x7d,0x36},
140 | {0x5e,0x10},
141 |
142 | {0xd6,0x88}, // contrast
143 | {0xd5,0x20}, // bright
144 | {0xb0,0x84}, // low light ctrl in gray section
145 | {0xb5,0x08}, // the threshold of GLB_GAIN
146 | {0xb1,0xc8}, // saturation
147 | {0xb2,0xc0},
148 | {0xb3,0xd0},
149 | {0xb4,0xB0},
150 |
151 | {0x32,0x10},
152 | // {0x8a,0x00},
153 | // {0x8b,0x10},
154 | {0xa0,0x09},
155 | {0x00,0x03},
156 | {0x0b,0x02},
157 | {REGLIST_TAIL, 0x00},
158 | };
159 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/bf3005.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * BF3005 driver.
7 | *
8 | */
9 | #ifndef __BF3005_H__
10 | #define __BF3005_H__
11 | #include "sensor.h"
12 |
13 | /**
14 | * @brief Detect sensor pid
15 | *
16 | * @param slv_addr SCCB address
17 | * @param id Detection result
18 | * @return
19 | * 0: Can't detect this sensor
20 | * Nonzero: This sensor has been detected
21 | */
22 | int bf3005_detect(int slv_addr, sensor_id_t *id);
23 |
24 | /**
25 | * @brief initialize sensor function pointers
26 | *
27 | * @param sensor pointer of sensor
28 | * @return
29 | * Always 0
30 | */
31 | int bf3005_init(sensor_t *sensor);
32 |
33 | #endif // __BF3005_H__
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/bf3005_regs.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahhfzhang/esp-rtc/62a0d980807cbf309894e75130697784dc901339/components/esp32-camera/sensors/private_include/bf3005_regs.h
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/gc0308.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "sensor.h"
4 |
5 | #ifdef __cplusplus
6 | extern "C" {
7 | #endif
8 |
9 | /**
10 | * @brief Detect sensor pid
11 | *
12 | * @param slv_addr SCCB address
13 | * @param id Detection result
14 | * @return
15 | * 0: Can't detect this sensor
16 | * Nonzero: This sensor has been detected
17 | */
18 | int gc0308_detect(int slv_addr, sensor_id_t *id);
19 |
20 | /**
21 | * @brief initialize sensor function pointers
22 | *
23 | * @param sensor pointer of sensor
24 | * @return
25 | * Always 0
26 | */
27 | int gc0308_init(sensor_t *sensor);
28 |
29 | #ifdef __cplusplus
30 | }
31 | #endif
32 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/gc0308_regs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GC0308 register definitions.
3 | */
4 | #ifndef __GC0308_REG_REGS_H__
5 | #define __GC0308_REG_REGS_H__
6 |
7 | #define RESET_RELATED 0xfe // Bit[7]: Software reset
8 | // Bit[6:5]: NA
9 | // Bit[4]: CISCTL_restart_n
10 | // Bit[3:1]: NA
11 | // Bit[0]: page select
12 | // 0:page0
13 | // 1:page1
14 |
15 |
16 | // page0:
17 |
18 |
19 |
20 | /**
21 | * @brief register value
22 | */
23 |
24 |
25 | #endif // __GC0308_REG_REGS_H__
26 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/gc0308_settings.h:
--------------------------------------------------------------------------------
1 | #ifndef _GC0308_SETTINGS_H_
2 | #define _GC0308_SETTINGS_H_
3 |
4 | #include
5 |
6 | #define REG_DLY 0xffff
7 | #define REGLIST_TAIL 0x0000 /* Array end token */
8 |
9 | static const uint16_t gc0308_sensor_default_regs[][2] = {
10 | {0xfe, 0x00},
11 | {0xec, 0x20},
12 | {0x05, 0x00},
13 | {0x06, 0x00},
14 | {0x07, 0x00},
15 | {0x08, 0x00},
16 | {0x09, 0x01},
17 | {0x0a, 0xe8},
18 | {0x0b, 0x02},
19 | {0x0c, 0x88},
20 | {0x0d, 0x02},
21 | {0x0e, 0x02},
22 | {0x10, 0x26},
23 | {0x11, 0x0d},
24 | {0x12, 0x2a},
25 | {0x13, 0x00},
26 | {0x14, 0x11},
27 | {0x15, 0x0a},
28 | {0x16, 0x05},
29 | {0x17, 0x01},
30 | {0x18, 0x44},
31 | {0x19, 0x44},
32 | {0x1a, 0x2a},
33 | {0x1b, 0x00},
34 | {0x1c, 0x49},
35 | {0x1d, 0x9a},
36 | {0x1e, 0x61},
37 | {0x1f, 0x00}, //pad drv <=24MHz, use 0x00 is ok
38 | {0x20, 0x7f},
39 | {0x21, 0xfa},
40 | {0x22, 0x57},
41 | {0x24, 0xa2}, //YCbYCr
42 | {0x25, 0x0f},
43 | {0x26, 0x03}, // 0x01
44 | {0x28, 0x00},
45 | {0x2d, 0x0a},
46 | {0x2f, 0x01},
47 | {0x30, 0xf7},
48 | {0x31, 0x50},
49 | {0x32, 0x00},
50 | {0x33, 0x28},
51 | {0x34, 0x2a},
52 | {0x35, 0x28},
53 | {0x39, 0x04},
54 | {0x3a, 0x20},
55 | {0x3b, 0x20},
56 | {0x3c, 0x00},
57 | {0x3d, 0x00},
58 | {0x3e, 0x00},
59 | {0x3f, 0x00},
60 | {0x50, 0x14}, // 0x14
61 | {0x52, 0x41},
62 | {0x53, 0x80},
63 | {0x54, 0x80},
64 | {0x55, 0x80},
65 | {0x56, 0x80},
66 | {0x8b, 0x20},
67 | {0x8c, 0x20},
68 | {0x8d, 0x20},
69 | {0x8e, 0x14},
70 | {0x8f, 0x10},
71 | {0x90, 0x14},
72 | {0x91, 0x3c},
73 | {0x92, 0x50},
74 | //{0x8b,0x10},
75 | //{0x8c,0x10},
76 | //{0x8d,0x10},
77 | //{0x8e,0x10},
78 | //{0x8f,0x10},
79 | //{0x90,0x10},
80 | //{0x91,0x3c},
81 | //{0x92,0x50},
82 | {0x5d, 0x12},
83 | {0x5e, 0x1a},
84 | {0x5f, 0x24},
85 | {0x60, 0x07},
86 | {0x61, 0x15},
87 | {0x62, 0x08}, // 0x08
88 | {0x64, 0x03}, // 0x03
89 | {0x66, 0xe8},
90 | {0x67, 0x86},
91 | {0x68, 0x82},
92 | {0x69, 0x18},
93 | {0x6a, 0x0f},
94 | {0x6b, 0x00},
95 | {0x6c, 0x5f},
96 | {0x6d, 0x8f},
97 | {0x6e, 0x55},
98 | {0x6f, 0x38},
99 | {0x70, 0x15},
100 | {0x71, 0x33},
101 | {0x72, 0xdc},
102 | {0x73, 0x00},
103 | {0x74, 0x02},
104 | {0x75, 0x3f},
105 | {0x76, 0x02},
106 | {0x77, 0x38}, // 0x47
107 | {0x78, 0x88},
108 | {0x79, 0x81},
109 | {0x7a, 0x81},
110 | {0x7b, 0x22},
111 | {0x7c, 0xff},
112 | {0x93, 0x48}, //color matrix default
113 | {0x94, 0x02},
114 | {0x95, 0x07},
115 | {0x96, 0xe0},
116 | {0x97, 0x40},
117 | {0x98, 0xf0},
118 | {0xb1, 0x40},
119 | {0xb2, 0x40},
120 | {0xb3, 0x40}, //0x40
121 | {0xb6, 0xe0},
122 | {0xbd, 0x38},
123 | {0xbe, 0x36},
124 | {0xd0, 0xCB},
125 | {0xd1, 0x10},
126 | {0xd2, 0x90},
127 | {0xd3, 0x48},
128 | {0xd5, 0xF2},
129 | {0xd6, 0x16},
130 | {0xdb, 0x92},
131 | {0xdc, 0xA5},
132 | {0xdf, 0x23},
133 | {0xd9, 0x00},
134 | {0xda, 0x00},
135 | {0xe0, 0x09},
136 | {0xed, 0x04},
137 | {0xee, 0xa0},
138 | {0xef, 0x40},
139 | {0x80, 0x03},
140 |
141 | {0x9F, 0x10},
142 | {0xA0, 0x20},
143 | {0xA1, 0x38},
144 | {0xA2, 0x4e},
145 | {0xA3, 0x63},
146 | {0xA4, 0x76},
147 | {0xA5, 0x87},
148 | {0xA6, 0xa2},
149 | {0xA7, 0xb8},
150 | {0xA8, 0xca},
151 | {0xA9, 0xd8},
152 | {0xAA, 0xe3},
153 | {0xAB, 0xeb},
154 | {0xAC, 0xf0},
155 | {0xAD, 0xF8},
156 | {0xAE, 0xFd},
157 | {0xAF, 0xFF},
158 |
159 | {0xc0, 0x00},
160 | {0xc1, 0x10},
161 | {0xc2, 0x1c},
162 | {0xc3, 0x30},
163 | {0xc4, 0x43},
164 | {0xc5, 0x54},
165 | {0xc6, 0x65},
166 | {0xc7, 0x75},
167 | {0xc8, 0x93},
168 | {0xc9, 0xB0},
169 | {0xca, 0xCB},
170 | {0xcb, 0xE6},
171 | {0xcc, 0xFF},
172 | {0xf0, 0x02},
173 | {0xf1, 0x01},
174 | {0xf2, 0x02},
175 | {0xf3, 0x30},
176 | {0xf7, 0x04},
177 | {0xf8, 0x02},
178 | {0xf9, 0x9f},
179 | {0xfa, 0x78},
180 | {0xfe, 0x01},
181 | {0x00, 0xf5},
182 | {0x02, 0x20},
183 | {0x04, 0x10},
184 | {0x05, 0x08},
185 | {0x06, 0x20},
186 | {0x08, 0x0a},
187 | {0x0a, 0xa0},
188 | {0x0b, 0x60},
189 | {0x0c, 0x08},
190 | {0x0e, 0x44},
191 | {0x0f, 0x32},
192 | {0x10, 0x41},
193 | {0x11, 0x37},
194 | {0x12, 0x22},
195 | {0x13, 0x19},
196 | {0x14, 0x44},
197 | {0x15, 0x44},
198 | {0x16, 0xc2},
199 | {0x17, 0xA8},
200 | {0x18, 0x18},
201 | {0x19, 0x50},
202 | {0x1a, 0xd8},
203 | {0x1b, 0xf5},
204 | {0x70, 0x40},
205 | {0x71, 0x58},
206 | {0x72, 0x30},
207 | {0x73, 0x48},
208 | {0x74, 0x20},
209 | {0x75, 0x60},
210 | {0x77, 0x20},
211 | {0x78, 0x32},
212 | {0x30, 0x03},
213 | {0x31, 0x40},
214 | {0x32, 0x10},
215 | {0x33, 0xe0},
216 | {0x34, 0xe0},
217 | {0x35, 0x00},
218 | {0x36, 0x80},
219 | {0x37, 0x00},
220 | {0x38, 0x04},
221 | {0x39, 0x09},
222 | {0x3a, 0x12},
223 | {0x3b, 0x1C},
224 | {0x3c, 0x28},
225 | {0x3d, 0x31},
226 | {0x3e, 0x44},
227 | {0x3f, 0x57},
228 | {0x40, 0x6C},
229 | {0x41, 0x81},
230 | {0x42, 0x94},
231 | {0x43, 0xA7},
232 | {0x44, 0xB8},
233 | {0x45, 0xD6},
234 | {0x46, 0xEE},
235 | {0x47, 0x0d},
236 | {0x62, 0xf7},
237 | {0x63, 0x68},
238 | {0x64, 0xd3},
239 | {0x65, 0xd3},
240 | {0x66, 0x60},
241 | {0xfe, 0x00},
242 | {REGLIST_TAIL, 0x00},
243 | };
244 |
245 | #endif
246 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/gc032a.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * GC032A driver.
4 | *
5 | */
6 | #ifndef __GC032A_H__
7 | #define __GC032A_H__
8 |
9 | #include "sensor.h"
10 |
11 | /**
12 | * @brief Detect sensor pid
13 | *
14 | * @param slv_addr SCCB address
15 | * @param id Detection result
16 | * @return
17 | * 0: Can't detect this sensor
18 | * Nonzero: This sensor has been detected
19 | */
20 | int gc032a_detect(int slv_addr, sensor_id_t *id);
21 |
22 | /**
23 | * @brief initialize sensor function pointers
24 | *
25 | * @param sensor pointer of sensor
26 | * @return
27 | * Always 0
28 | */
29 | int gc032a_init(sensor_t *sensor);
30 |
31 | #endif // __GC032A_H__
32 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/gc032a_regs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GC032A register definitions.
3 | */
4 | #ifndef __GC032A_REG_REGS_H__
5 | #define __GC032A_REG_REGS_H__
6 |
7 | #define SENSOR_ID_HIGH 0XF0
8 | #define SENSOR_ID_LOW 0XF1
9 | #define PAD_VB_HIZ_MODE 0XF2
10 | #define SYNC_OUTPUT 0XF3
11 | #define I2C_CONFIG 0XF4
12 | #define PLL_MODE1 0XF7
13 | #define PLL_MODE2 0XF8
14 | #define CM_MODE 0XF9
15 | #define ISP_DIV_MODE 0XFA
16 | #define I2C_DEVICE_ID 0XFB
17 | #define ANALOG_PWC 0XFC
18 | #define ISP_DIV_MODE2 0XFD
19 | #define RESET_RELATED 0XFE // Bit[7]: Software reset
20 | // Bit[6]: cm reset
21 | // Bit[5]: spi reset
22 | // Bit[4]: CISCTL_restart_n
23 | // Bit[3]: PLL_rst
24 | // Bit[2:0]: page select
25 | // 000:page0
26 | // 001:page1
27 | // 010:page2
28 | // 011:page3
29 |
30 | //----page0-----------------------------
31 | #define P0_EXPOSURE_HIGH 0X03
32 | #define P0_EXPOSURE_LOW 0X04
33 | #define P0_HB_HIGH 0X05
34 | #define P0_HB_LOW 0X06
35 | #define P0_VB_HIGH 0X07
36 | #define P0_VB_LOW 0X08
37 | #define P0_ROW_START_HIGH 0X09
38 | #define P0_ROW_START_LOW 0X0A
39 | #define P0_COLUMN_START_HIGH 0X0B
40 | #define P0_COLUMN_START_LOW 0X0C
41 | #define P0_WINDOW_HEIGHT_HIGH 0X0D
42 | #define P0_WINDOW_HEIGHT_LOW 0X0E
43 | #define P0_WINDOW_WIDTH_HIGH 0X0F
44 | #define P0_WINDOW_WIDTH_LOW 0X10
45 | #define P0_SH_DELAY 0X11
46 | #define P0_VS_ST 0X12
47 | #define P0_VS_ET 0X13
48 | #define P0_CISCTL_MODE1 0X17
49 |
50 | #define P0_BLOCK_ENABLE_1 0X40
51 | #define P0_AAAA_ENABLE 0X42
52 | #define P0_SPECIAL_EFFECT 0X43
53 | #define P0_SYNC_MODE 0X46
54 | #define P0_GAIN_CODE 0X48
55 | #define P0_DEBUG_MODE2 0X4C
56 | #define P0_WIN_MODE 0X50
57 | #define P0_OUT_WIN_Y1_HIGH 0X51
58 | #define P0_OUT_WIN_Y1_LOW 0X52
59 | #define P0_OUT_WIN_X1_HIGH 0X53
60 | #define P0_OUT_WIN_X1_LOW 0X54
61 | #define P0_OUT_WIN_HEIGHT_HIGH 0X55
62 | #define P0_OUT_WIN_HEIGHT_LOW 0X56
63 | #define P0_OUT_WIN_WIDTH_HIGH 0X57
64 | #define P0_OUT_WIN_WIDTH_LOW 0X58
65 |
66 | #define P0_GLOBAL_SATURATION 0XD0
67 | #define P0_SATURATION_CB 0XD1
68 | #define P0_SATURATION_CR 0XD2
69 | #define P0_LUMA_CONTRAST 0XD3
70 | #define P0_CONTRAST_CENTER 0XD4
71 | #define P0_LUMA_OFFSET 0XD5
72 | #define P0_FIXED_CB 0XDA
73 | #define P0_FIXED_CR 0XDB
74 |
75 | //----page3-----------------------------
76 | #define P3_IMAGE_WIDTH_LOW 0X5B
77 | #define P3_IMAGE_WIDTH_HIGH 0X5C
78 | #define P3_IMAGE_HEIGHT_LOW 0X5D
79 | #define P3_IMAGE_HEIGHT_HIGH 0X5E
80 |
81 |
82 | #endif //__GC032A_REG_REGS_H__
83 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/gc032a_settings.h:
--------------------------------------------------------------------------------
1 | #ifndef _GC032A_SETTINGS_H_
2 | #define _GC032A_SETTINGS_H_
3 |
4 | #include
5 | #include
6 | #include "esp_attr.h"
7 | #include "gc032a_regs.h"
8 |
9 |
10 | #define REG_DLY 0xffff
11 | #define REGLIST_TAIL 0x0000
12 |
13 |
14 | /*
15 | * The default register settings, as obtained from OmniVision. There
16 | * is really no making sense of most of these - lots of "reserved" values
17 | * and such.
18 | *
19 | */
20 | static const uint16_t gc032a_default_regs[][2] = {
21 | /*System*/
22 | {0xf3, 0xff},
23 | {0xf5, 0x06},
24 | {0xf7, 0x01},
25 | {0xf8, 0x03},
26 | {0xf9, 0xce},
27 | {0xfa, 0x00},
28 | {0xfc, 0x02},
29 | {0xfe, 0x02},
30 | {0x81, 0x03},
31 |
32 | {0xfe, 0x00},
33 | {0x77, 0x64},
34 | {0x78, 0x40},
35 | {0x79, 0x60},
36 | /*ANALOG & CISCTL*/
37 | {0xfe, 0x00},
38 | {0x03, 0x01},
39 | {0x04, 0xce},
40 | {0x05, 0x01},
41 | {0x06, 0xad},
42 | {0x07, 0x00},
43 | {0x08, 0x10},
44 | {0x0a, 0x00},
45 | {0x0c, 0x00},
46 | {0x0d, 0x01},
47 | {0x0e, 0xe8}, // height 488
48 | {0x0f, 0x02},
49 | {0x10, 0x88}, // width 648
50 | {0x17, 0x54},
51 | {0x19, 0x08},
52 | {0x1a, 0x0a},
53 | {0x1f, 0x40},
54 | {0x20, 0x30},
55 | {0x2e, 0x80},
56 | {0x2f, 0x2b},
57 | {0x30, 0x1a},
58 | {0xfe, 0x02},
59 | {0x03, 0x02},
60 | {0x05, 0xd7},
61 | {0x06, 0x60},
62 | {0x08, 0x80},
63 | {0x12, 0x89},
64 |
65 | /*blk*/
66 | {0xfe, 0x00},
67 | {0x18, 0x02},
68 | {0xfe, 0x02},
69 | {0x40, 0x22},
70 | {0x45, 0x00},
71 | {0x46, 0x00},
72 | {0x49, 0x20},
73 | {0x4b, 0x3c},
74 | {0x50, 0x20},
75 | {0x42, 0x10},
76 |
77 | /*isp*/
78 | {0xfe, 0x01},
79 | {0x0a, 0xc5},
80 | {0x45, 0x00},
81 | {0xfe, 0x00},
82 | {0x40, 0xff},
83 | {0x41, 0x25},
84 | {0x42, 0xcf},
85 | {0x43, 0x10},
86 | {0x44, 0x83},
87 | {0x46, 0x23},
88 | {0x49, 0x03},
89 | {0x52, 0x02},
90 | {0x54, 0x00},
91 | {0xfe, 0x02},
92 | {0x22, 0xf6},
93 |
94 | /*Shading*/
95 | {0xfe, 0x01},
96 | {0xc1, 0x38},
97 | {0xc2, 0x4c},
98 | {0xc3, 0x00},
99 | {0xc4, 0x32},
100 | {0xc5, 0x24},
101 | {0xc6, 0x16},
102 | {0xc7, 0x08},
103 | {0xc8, 0x08},
104 | {0xc9, 0x00},
105 | {0xca, 0x20},
106 | {0xdc, 0x8a},
107 | {0xdd, 0xa0},
108 | {0xde, 0xa6},
109 | {0xdf, 0x75},
110 |
111 | /*AWB*/
112 | {0xfe, 0x01},
113 | {0x7c, 0x09},
114 | {0x65, 0x06},
115 | {0x7c, 0x08},
116 | {0x56, 0xf4},
117 | {0x66, 0x0f},
118 | {0x67, 0x84},
119 | {0x6b, 0x80},
120 | {0x6d, 0x12},
121 | {0x6e, 0xb0},
122 | {0x86, 0x00},
123 | {0x87, 0x00},
124 | {0x88, 0x00},
125 | {0x89, 0x00},
126 | {0x8a, 0x00},
127 | {0x8b, 0x00},
128 | {0x8c, 0x00},
129 | {0x8d, 0x00},
130 | {0x8e, 0x00},
131 | {0x8f, 0x00},
132 | {0x90, 0x00},
133 | {0x91, 0x00},
134 | {0x92, 0xf4},
135 | {0x93, 0xd5},
136 | {0x94, 0x50},
137 | {0x95, 0x0f},
138 | {0x96, 0xf4},
139 | {0x97, 0x2d},
140 | {0x98, 0x0f},
141 | {0x99, 0xa6},
142 | {0x9a, 0x2d},
143 | {0x9b, 0x0f},
144 | {0x9c, 0x59},
145 | {0x9d, 0x2d},
146 | {0x9e, 0xaa},
147 | {0x9f, 0x67},
148 | {0xa0, 0x59},
149 | {0xa1, 0x00},
150 | {0xa2, 0x00},
151 | {0xa3, 0x0a},
152 | {0xa4, 0x00},
153 | {0xa5, 0x00},
154 | {0xa6, 0xd4},
155 | {0xa7, 0x9f},
156 | {0xa8, 0x55},
157 | {0xa9, 0xd4},
158 | {0xaa, 0x9f},
159 | {0xab, 0xac},
160 | {0xac, 0x9f},
161 | {0xad, 0x55},
162 | {0xae, 0xd4},
163 | {0xaf, 0xac},
164 | {0xb0, 0xd4},
165 | {0xb1, 0xa3},
166 | {0xb2, 0x55},
167 | {0xb3, 0xd4},
168 | {0xb4, 0xac},
169 | {0xb5, 0x00},
170 | {0xb6, 0x00},
171 | {0xb7, 0x05},
172 | {0xb8, 0xd6},
173 | {0xb9, 0x8c},
174 |
175 | /*CC*/
176 | {0xfe, 0x01},
177 | {0xd0, 0x40},
178 | {0xd1, 0xf8},
179 | {0xd2, 0x00},
180 | {0xd3, 0xfa},
181 | {0xd4, 0x45},
182 | {0xd5, 0x02},
183 |
184 | {0xd6, 0x30},
185 | {0xd7, 0xfa},
186 | {0xd8, 0x08},
187 | {0xd9, 0x08},
188 | {0xda, 0x58},
189 | {0xdb, 0x02},
190 | {0xfe, 0x00},
191 |
192 | /*Gamma*/
193 | {0xfe, 0x00},
194 | {0xba, 0x00},
195 | {0xbb, 0x04},
196 | {0xbc, 0x0a},
197 | {0xbd, 0x0e},
198 | {0xbe, 0x22},
199 | {0xbf, 0x30},
200 | {0xc0, 0x3d},
201 | {0xc1, 0x4a},
202 | {0xc2, 0x5d},
203 | {0xc3, 0x6b},
204 | {0xc4, 0x7a},
205 | {0xc5, 0x85},
206 | {0xc6, 0x90},
207 | {0xc7, 0xa5},
208 | {0xc8, 0xb5},
209 | {0xc9, 0xc2},
210 | {0xca, 0xcc},
211 | {0xcb, 0xd5},
212 | {0xcc, 0xde},
213 | {0xcd, 0xea},
214 | {0xce, 0xf5},
215 | {0xcf, 0xff},
216 |
217 | /*Auto Gamma*/
218 | {0xfe, 0x00},
219 | {0x5a, 0x08},
220 | {0x5b, 0x0f},
221 | {0x5c, 0x15},
222 | {0x5d, 0x1c},
223 | {0x5e, 0x28},
224 | {0x5f, 0x36},
225 | {0x60, 0x45},
226 | {0x61, 0x51},
227 | {0x62, 0x6a},
228 | {0x63, 0x7d},
229 | {0x64, 0x8d},
230 | {0x65, 0x98},
231 | {0x66, 0xa2},
232 | {0x67, 0xb5},
233 | {0x68, 0xc3},
234 | {0x69, 0xcd},
235 | {0x6a, 0xd4},
236 | {0x6b, 0xdc},
237 | {0x6c, 0xe3},
238 | {0x6d, 0xf0},
239 | {0x6e, 0xf9},
240 | {0x6f, 0xff},
241 |
242 | /*Gain*/
243 | {0xfe, 0x00},
244 | {0x70, 0x50},
245 |
246 | /*AEC*/
247 | {0xfe, 0x00},
248 | {0x4f, 0x01},
249 | {0xfe, 0x01},
250 | {0x0d, 0x00},
251 | {0x12, 0xa0},
252 | {0x13, 0x3a},
253 | {0x44, 0x04},
254 | {0x1f, 0x30},
255 | {0x20, 0x40},
256 | {0x26, 0x9a},
257 | {0x3e, 0x20},
258 | {0x3f, 0x2d},
259 | {0x40, 0x40},
260 | {0x41, 0x5b},
261 | {0x42, 0x82},
262 | {0x43, 0xb7},
263 | {0x04, 0x0a},
264 | {0x02, 0x79},
265 | {0x03, 0xc0},
266 |
267 | /*measure window*/
268 | {0xfe, 0x01},
269 | {0xcc, 0x08},
270 | {0xcd, 0x08},
271 | {0xce, 0xa4},
272 | {0xcf, 0xec},
273 |
274 | /*DNDD*/
275 | {0xfe, 0x00},
276 | {0x81, 0xb8},
277 | {0x82, 0x12},
278 | {0x83, 0x0a},
279 | {0x84, 0x01},
280 | {0x86, 0x50},
281 | {0x87, 0x18},
282 | {0x88, 0x10},
283 | {0x89, 0x70},
284 | {0x8a, 0x20},
285 | {0x8b, 0x10},
286 | {0x8c, 0x08},
287 | {0x8d, 0x0a},
288 |
289 | /*Intpee*/
290 | {0xfe, 0x00},
291 | {0x8f, 0xaa},
292 | {0x90, 0x9c},
293 | {0x91, 0x52},
294 | {0x92, 0x03},
295 | {0x93, 0x03},
296 | {0x94, 0x08},
297 | {0x95, 0x44},
298 | {0x97, 0x00},
299 | {0x98, 0x00},
300 |
301 | /*ASDE*/
302 | {0xfe, 0x00},
303 | {0xa1, 0x30},
304 | {0xa2, 0x41},
305 | {0xa4, 0x30},
306 | {0xa5, 0x20},
307 | {0xaa, 0x30},
308 | {0xac, 0x32},
309 |
310 | /*YCP*/
311 | {0xfe, 0x00},
312 | {0xd1, 0x3c},
313 | {0xd2, 0x3c},
314 | {0xd3, 0x38},
315 | {0xd6, 0xf4},
316 | {0xd7, 0x1d},
317 | {0xdd, 0x73},
318 | {0xde, 0x84},
319 |
320 | /*Banding*/
321 | {0xfe, 0x00},
322 | {0x05, 0x01},
323 | {0x06, 0xad},
324 | {0x07, 0x00},
325 | {0x08, 0x10},
326 |
327 | {0xfe, 0x01},
328 | {0x25, 0x00},
329 | {0x26, 0x9a},
330 |
331 | {0x27, 0x01},
332 | {0x28, 0xce},
333 | {0x29, 0x02},
334 | {0x2a, 0x68},
335 | {0x2b, 0x02},
336 | {0x2c, 0x68},
337 | {0x2d, 0x07},
338 | {0x2e, 0xd2},
339 | {0x2f, 0x0b},
340 | {0x30, 0x6e},
341 | {0x31, 0x0e},
342 | {0x32, 0x70},
343 | {0x33, 0x12},
344 | {0x34, 0x0c},
345 | {0x3c, 0x30},
346 |
347 | /*Analog&Cisctl*/
348 | {0xfe, 0x00},
349 | {0x05, 0x01},
350 | {0x06, 0xa0},
351 | {0x07, 0x00},
352 | {0x08, 0x20},
353 | {0x0a, 0x78},
354 | {0x0c, 0xa0},
355 | {0x0d, 0x00}, //window_height [8]
356 | {0x0e, 0xf8}, //window_height [7:0] 248
357 | {0x0f, 0x01}, //window_width [9:8]
358 | {0x10, 0x48}, //window_width [7:0] 328
359 |
360 | {0x55, 0x00},
361 | {0x56, 0xf0}, // 240
362 | {0x57, 0x01},
363 | {0x58, 0x40}, // 320
364 |
365 | /*SPI*/
366 | {0xfe, 0x03},
367 | {0x5b, 0x40},
368 | {0x5c, 0x01},
369 | {0x5d, 0xf0},
370 | {0x5e, 0x00},
371 |
372 | /*AEC*/
373 | {0xfe, 0x01},
374 | {0x25, 0x00}, //step
375 | {0x26, 0x63},
376 | {0x27, 0x01},
377 | {0x28, 0x29},
378 | {0x29, 0x01},
379 | {0x2a, 0x29},
380 | {0x2b, 0x01},
381 | {0x2c, 0x29},
382 | {0x2d, 0x01},
383 | {0x2e, 0x29},
384 | {0x2f, 0x01},
385 | {0x30, 0x29},
386 | {0x31, 0x01},
387 | {0x32, 0x29},
388 | {0x33, 0x01},
389 | {0x34, 0x29},
390 | {0x3c, 0x00},
391 |
392 | /*measure window*/
393 | {0xfe, 0x01},
394 | {0xcc, 0x04},
395 | {0xcd, 0x04},
396 | {0xce, 0x72},
397 | {0xcf, 0x52},
398 | {REGLIST_TAIL, 0x00},
399 | };
400 |
401 | #endif
402 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/gc2145.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __GC2145_H__
3 | #define __GC2145_H__
4 |
5 | #include "sensor.h"
6 |
7 | /**
8 | * @brief Detect sensor pid
9 | *
10 | * @param slv_addr SCCB address
11 | * @param id Detection result
12 | * @return
13 | * 0: Can't detect this sensor
14 | * Nonzero: This sensor has been detected
15 | */
16 | int gc2145_detect(int slv_addr, sensor_id_t *id);
17 |
18 | /**
19 | * @brief initialize sensor function pointers
20 | *
21 | * @param sensor pointer of sensor
22 | * @return
23 | * Always 0
24 | */
25 | int gc2145_init(sensor_t *sensor);
26 |
27 | #endif // __GC2145_H__
28 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/gc2145_regs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GC2145 register definitions.
3 | */
4 | #ifndef __GC2145_REG_REGS_H__
5 | #define __GC2145_REG_REGS_H__
6 |
7 | #define CHIP_ID_HIGH 0XF0
8 | #define CHIP_ID_LOW 0XF1
9 | #define PLL_MODE1 0XF7
10 | #define PLL_MODE2 0XF8
11 | #define CM_MODE 0XF9
12 | #define CLK_DIV_MODE 0XFA
13 | #define RESET_RELATED 0xfe // Bit[7]: Software reset
14 | // Bit[6]: cm reset
15 | // Bit[5]: mipi reset
16 | // Bit[4]: CISCTL_restart_n
17 | // Bit[3]: NA
18 | // Bit[2:0]: page select
19 | // 000:page0
20 | // 001:page1
21 | // 010:page2
22 | // 011:page3
23 |
24 | //-page0----------------
25 |
26 | #define P0_EXPOSURE_HIGH 0X03
27 | #define P0_EXPOSURE_LOW 0X04
28 | #define P0_HB_HIGH 0X05
29 | #define P0_HB_LOW 0X06
30 | #define P0_VB_HIGH 0X07
31 | #define P0_VB_LOW 0X08
32 | #define P0_ROW_START_HIGH 0X09
33 | #define P0_ROW_START_LOW 0X0A
34 | #define P0_COL_START_HIGH 0X0B
35 | #define P0_COL_START_LOW 0X0C
36 |
37 | #define P0_WIN_HEIGHT_HIGH 0X0D
38 | #define P0_WIN_HEIGHT_LOW 0X0E
39 | #define P0_WIN_WIDTH_HIGH 0X0F
40 | #define P0_WIN_WIDTH_LOW 0X10
41 | #define P0_ANALOG_MODE1 0X17
42 | #define P0_ANALOG_MODE2 0X18
43 |
44 | #define P0_SPECIAL_EFFECT 0X83
45 | #define P0_OUTPUT_FORMAT 0x84 // Format select
46 | // Bit[7]:YUV420 row switch
47 | // Bit[6]:YUV420 col switch
48 | // Bit[7]:YUV420_legacy
49 | // Bit[4:0]:output data mode
50 | // 5’h00 Cb Y Cr Y
51 | // 5’h01 Cr Y Cb Y
52 | // 5’h02 Y Cb Y Cr
53 | // 5’h03 Y Cr Y Cb
54 | // 5’h04 LSC bypass, C/Y
55 | // 5’h05 LSC bypass, Y/C
56 | // 5’h06 RGB 565
57 | // 5’h0f bypass 10bits
58 | // 5’h17 switch odd/even column /row to controls output Bayer pattern
59 | // 00 RGBG
60 | // 01 RGGB
61 | // 10 BGGR
62 | // 11 GBRG
63 | // 5'h18 DNDD out mode
64 | // 5'h19 LSC out mode
65 | // 5;h1b EEINTP out mode
66 | #define P0_FRAME_START 0X85
67 | #define P0_SYNC_MODE 0X86
68 | #define P0_MODULE_GATING 0X88
69 | #define P0_BYPASS_MODE 0X89
70 | #define P0_DEBUG_MODE2 0X8C
71 | #define P0_DEBUG_MODE3 0X8D
72 | #define P0_CROP_ENABLE 0X90
73 | #define P0_OUT_WIN_Y1_HIGH 0X91
74 | #define P0_OUT_WIN_Y1_LOW 0X92
75 | #define P0_OUT_WIN_X1_HIGH 0X93
76 | #define P0_OUT_WIN_X1_LOW 0X94
77 | #define P0_OUT_WIN_HEIGHT_HIGH 0X95
78 | #define P0_OUT_WIN_HEIGHT_LOW 0X96
79 | #define P0_OUT_WIN_WIDTH_HIGH 0X97
80 | #define P0_OUT_WIN_WIDTH_LOW 0X98
81 | #define P0_SUBSAMPLE 0X99
82 | #define P0_SUBSAMPLE_MODE 0X9A
83 |
84 |
85 | #endif // __GC2145_REG_REGS_H__
86 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/nt99141.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * NT99141 driver.
7 | *
8 | */
9 | #ifndef __NT99141_H__
10 | #define __NT99141_H__
11 |
12 | #include "sensor.h"
13 |
14 | /**
15 | * @brief Detect sensor pid
16 | *
17 | * @param slv_addr SCCB address
18 | * @param id Detection result
19 | * @return
20 | * 0: Can't detect this sensor
21 | * Nonzero: This sensor has been detected
22 | */
23 | int nt99141_detect(int slv_addr, sensor_id_t *id);
24 |
25 | /**
26 | * @brief initialize sensor function pointers
27 | *
28 | * @param sensor pointer of sensor
29 | * @return
30 | * Always 0
31 | */
32 | int nt99141_init(sensor_t *sensor);
33 |
34 | #endif // __NT99141_H__
35 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/nt99141_regs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * NT99141 register definitions.
3 | */
4 | #ifndef __NT99141_REG_REGS_H__
5 | #define __NT99141_REG_REGS_H__
6 |
7 | /* system control registers */
8 | #define SYSTEM_CTROL0 0x3021 // Bit[7]: Software reset
9 | // Bit[6]: Software power down
10 | // Bit[5]: Reserved
11 | // Bit[4]: SRB clock SYNC enable
12 | // Bit[3]: Isolation suspend select
13 | // Bit[2:0]: Not used
14 |
15 | /* output format control registers */
16 | #define FORMAT_CTRL 0x501F // Format select
17 | // Bit[2:0]:
18 | // 000: YUV422
19 | // 001: RGB
20 | // 010: Dither
21 | // 011: RAW after DPC
22 | // 101: RAW after CIP
23 |
24 | /* format control registers */
25 | #define FORMAT_CTRL00 0x4300
26 |
27 | /* frame control registers */
28 | #define FRAME_CTRL01 0x4201 // Control Passed Frame Number When both ON and OFF number set to 0x00,frame control is in bypass mode
29 | // Bit[7:4]: Not used
30 | // Bit[3:0]: Frame ON number
31 | #define FRAME_CTRL02 0x4202 // Control Masked Frame Number When both ON and OFF number set to 0x00,frame control is in bypass mode
32 | // Bit[7:4]: Not used
33 | // BIT[3:0]: Frame OFF number
34 |
35 | /* ISP top control registers */
36 | #define PRE_ISP_TEST_SETTING_1 0x3025 // Bit[7]: Test enable
37 | // 0: Test disable
38 | // 1: Color bar enable
39 | // Bit[6]: Rolling
40 | // Bit[5]: Transparent
41 | // Bit[4]: Square black and white
42 | // Bit[3:2]: Color bar style
43 | // 00: Standard 8 color bar
44 | // 01: Gradual change at vertical mode 1
45 | // 10: Gradual change at horizontal
46 | // 11: Gradual change at vertical mode 2
47 | // Bit[1:0]: Test select
48 | // 00: Color bar
49 | // 01: Random data
50 | // 10: Square data
51 | // 11: Black image
52 |
53 | //exposure = {0x3500[3:0], 0x3501[7:0], 0x3502[7:0]} / 16 × tROW
54 |
55 | /* AEC/AGC control functions */
56 | #define AEC_PK_MANUAL 0x3201 // AEC Manual Mode Control
57 | // Bit[7:6]: Reserved
58 | // Bit[5]: Gain delay option
59 | // Valid when 0x3503[4]=1’b0
60 | // 0: Delay one frame latch
61 | // 1: One frame latch
62 | // Bit[4:2]: Reserved
63 | // Bit[1]: AGC manual
64 | // 0: Auto enable
65 | // 1: Manual enable
66 | // Bit[0]: AEC manual
67 | // 0: Auto enable
68 | // 1: Manual enable
69 |
70 | //gain = {0x350A[1:0], 0x350B[7:0]} / 16
71 |
72 | /* mirror and flip registers */
73 | #define TIMING_TC_REG20 0x3022 // Timing Control Register
74 | // Bit[2:1]: Vertical flip enable
75 | // 00: Normal
76 | // 11: Vertical flip
77 | // Bit[0]: Vertical binning enable
78 | #define TIMING_TC_REG21 0x3022 // Timing Control Register
79 | // Bit[5]: Compression Enable
80 | // Bit[2:1]: Horizontal mirror enable
81 | // 00: Normal
82 | // 11: Horizontal mirror
83 | // Bit[0]: Horizontal binning enable
84 |
85 | #define CLOCK_POL_CONTROL 0x3024// Bit[5]: PCLK polarity 0: active low
86 | // 1: active high
87 | // Bit[3]: Gate PCLK under VSYNC
88 | // Bit[2]: Gate PCLK under HREF
89 | // Bit[1]: HREF polarity
90 | // 0: active low
91 | // 1: active high
92 | // Bit[0] VSYNC polarity
93 | // 0: active low
94 | // 1: active high
95 | #define DRIVE_CAPABILITY 0x306a // Bit[7:6]:
96 | // 00: 1x
97 | // 01: 2x
98 | // 10: 3x
99 | // 11: 4x
100 |
101 |
102 | #define X_ADDR_ST_H 0x3800 //Bit[3:0]: X address start[11:8]
103 | #define X_ADDR_ST_L 0x3801 //Bit[7:0]: X address start[7:0]
104 | #define Y_ADDR_ST_H 0x3802 //Bit[2:0]: Y address start[10:8]
105 | #define Y_ADDR_ST_L 0x3803 //Bit[7:0]: Y address start[7:0]
106 | #define X_ADDR_END_H 0x3804 //Bit[3:0]: X address end[11:8]
107 | #define X_ADDR_END_L 0x3805 //Bit[7:0]:
108 | #define Y_ADDR_END_H 0x3806 //Bit[2:0]: Y address end[10:8]
109 | #define Y_ADDR_END_L 0x3807 //Bit[7:0]:
110 | // Size after scaling
111 | #define X_OUTPUT_SIZE_H 0x3808 //Bit[3:0]: DVP output horizontal width[11:8]
112 | #define X_OUTPUT_SIZE_L 0x3809 //Bit[7:0]:
113 | #define Y_OUTPUT_SIZE_H 0x380a //Bit[2:0]: DVP output vertical height[10:8]
114 | #define Y_OUTPUT_SIZE_L 0x380b //Bit[7:0]:
115 | #define X_TOTAL_SIZE_H 0x380c //Bit[3:0]: Total horizontal size[11:8]
116 | #define X_TOTAL_SIZE_L 0x380d //Bit[7:0]:
117 | #define Y_TOTAL_SIZE_H 0x380e //Bit[7:0]: Total vertical size[15:8]
118 | #define Y_TOTAL_SIZE_L 0x380f //Bit[7:0]:
119 | #define X_OFFSET_H 0x3810 //Bit[3:0]: ISP horizontal offset[11:8]
120 | #define X_OFFSET_L 0x3811 //Bit[7:0]:
121 | #define Y_OFFSET_H 0x3812 //Bit[2:0]: ISP vertical offset[10:8]
122 | #define Y_OFFSET_L 0x3813 //Bit[7:0]:
123 | #define X_INCREMENT 0x3814 //Bit[7:4]: Horizontal odd subsample increment
124 | //Bit[3:0]: Horizontal even subsample increment
125 | #define Y_INCREMENT 0x3815 //Bit[7:4]: Vertical odd subsample increment
126 | //Bit[3:0]: Vertical even subsample increment
127 | // Size before scaling
128 | //#define X_INPUT_SIZE (X_ADDR_END - X_ADDR_ST + 1 - (2 * X_OFFSET))
129 | //#define Y_INPUT_SIZE (Y_ADDR_END - Y_ADDR_ST + 1 - (2 * Y_OFFSET))
130 |
131 | #define ISP_CONTROL_01 0x3021 // Bit[5]: Scale enable
132 | // 0: Disable
133 | // 1: Enable
134 |
135 | #define SCALE_CTRL_1 0x5601 // Bit[6:4]: HDIV RW
136 | // DCW scale times
137 | // 000: DCW 1 time
138 | // 001: DCW 2 times
139 | // 010: DCW 4 times
140 | // 100: DCW 8 times
141 | // 101: DCW 16 times
142 | // Others: DCW 16 times
143 | // Bit[2:0]: VDIV RW
144 | // DCW scale times
145 | // 000: DCW 1 time
146 | // 001: DCW 2 times
147 | // 010: DCW 4 times
148 | // 100: DCW 8 times
149 | // 101: DCW 16 times
150 | // Others: DCW 16 times
151 |
152 | #define SCALE_CTRL_2 0x5602 // X_SCALE High Bits
153 | #define SCALE_CTRL_3 0x5603 // X_SCALE Low Bits
154 | #define SCALE_CTRL_4 0x5604 // Y_SCALE High Bits
155 | #define SCALE_CTRL_5 0x5605 // Y_SCALE Low Bits
156 | #define SCALE_CTRL_6 0x5606 // Bit[3:0]: V Offset
157 |
158 | #define PCLK_RATIO 0x3824 // Bit[4:0]: PCLK ratio manual
159 | #define VFIFO_CTRL0C 0x460C // Bit[1]: PCLK manual enable
160 | // 0: Auto
161 | // 1: Manual by PCLK_RATIO
162 |
163 | #define VFIFO_X_SIZE_H 0x4602
164 | #define VFIFO_X_SIZE_L 0x4603
165 | #define VFIFO_Y_SIZE_H 0x4604
166 | #define VFIFO_Y_SIZE_L 0x4605
167 |
168 | #define SC_PLLS_CTRL0 0x303a // Bit[7]: PLLS bypass
169 | #define SC_PLLS_CTRL1 0x303b // Bit[4:0]: PLLS multiplier
170 | #define SC_PLLS_CTRL2 0x303c // Bit[6:4]: PLLS charge pump control
171 | // Bit[3:0]: PLLS system divider
172 | #define SC_PLLS_CTRL3 0x303d // Bit[5:4]: PLLS pre-divider
173 | // 00: 1
174 | // 01: 1.5
175 | // 10: 2
176 | // 11: 3
177 | // Bit[2]: PLLS root-divider - 1
178 | // Bit[1:0]: PLLS seld5
179 | // 00: 1
180 | // 01: 1
181 | // 10: 2
182 | // 11: 2.5
183 |
184 | #define COMPRESSION_CTRL00 0x4400 //
185 | #define COMPRESSION_CTRL01 0x4401 //
186 | #define COMPRESSION_CTRL02 0x4402 //
187 | #define COMPRESSION_CTRL03 0x4403 //
188 | #define COMPRESSION_CTRL04 0x4404 //
189 | #define COMPRESSION_CTRL05 0x4405 //
190 | #define COMPRESSION_CTRL06 0x4406 //
191 | #define COMPRESSION_CTRL07 0x3401 // Bit[5:0]: QS
192 | #define COMPRESSION_ISI_CTRL 0x4408 //
193 | #define COMPRESSION_CTRL09 0x4409 //
194 | #define COMPRESSION_CTRL0a 0x440a //
195 | #define COMPRESSION_CTRL0b 0x440b //
196 | #define COMPRESSION_CTRL0c 0x440c //
197 | #define COMPRESSION_CTRL0d 0x440d //
198 | #define COMPRESSION_CTRL0E 0x440e //
199 |
200 | /**
201 | * @brief register value
202 | */
203 | #define TEST_COLOR_BAR 0x02 /* Enable Color Bar roling Test */
204 |
205 | #define AEC_PK_MANUAL_AGC_MANUALEN 0x02 /* Enable AGC Manual enable */
206 | #define AEC_PK_MANUAL_AEC_MANUALEN 0x01 /* Enable AEC Manual enable */
207 |
208 | #define TIMING_TC_REG20_VFLIP 0x01 /* Vertical flip enable */
209 | #define TIMING_TC_REG21_HMIRROR 0x02 /* Horizontal mirror enable */
210 |
211 | #endif // __NT99141_REG_REGS_H__
212 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov2640.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * OV2640 driver.
7 | *
8 | */
9 | #ifndef __OV2640_H__
10 | #define __OV2640_H__
11 | #include "sensor.h"
12 | /**
13 | * @brief Detect sensor pid
14 | *
15 | * @param slv_addr SCCB address
16 | * @param id Detection result
17 | * @return
18 | * 0: Can't detect this sensor
19 | * Nonzero: This sensor has been detected
20 | */
21 | int ov2640_detect(int slv_addr, sensor_id_t *id);
22 |
23 | /**
24 | * @brief initialize sensor function pointers
25 | *
26 | * @param sensor pointer of sensor
27 | * @return
28 | * Always 0
29 | */
30 | int ov2640_init(sensor_t *sensor);
31 |
32 | #endif // __OV2640_H__
33 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov2640_regs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * OV2640 register definitions.
7 | */
8 | #ifndef __REG_REGS_H__
9 | #define __REG_REGS_H__
10 | /* DSP register bank FF=0x00*/
11 | #define R_BYPASS 0x05
12 | #define QS 0x44
13 | #define CTRLI 0x50
14 | #define HSIZE 0x51
15 | #define VSIZE 0x52
16 | #define XOFFL 0x53
17 | #define YOFFL 0x54
18 | #define VHYX 0x55
19 | #define DPRP 0x56
20 | #define TEST 0x57
21 | #define ZMOW 0x5A
22 | #define ZMOH 0x5B
23 | #define ZMHH 0x5C
24 | #define BPADDR 0x7C
25 | #define BPDATA 0x7D
26 | #define CTRL2 0x86
27 | #define CTRL3 0x87
28 | #define SIZEL 0x8C
29 | #define HSIZE8 0xC0
30 | #define VSIZE8 0xC1
31 | #define CTRL0 0xC2
32 | #define CTRL1 0xC3
33 | #define R_DVP_SP 0xD3
34 | #define IMAGE_MODE 0xDA
35 | #define RESET 0xE0
36 | #define MS_SP 0xF0
37 | #define SS_ID 0xF7
38 | #define SS_CTRL 0xF7
39 | #define MC_BIST 0xF9
40 | #define MC_AL 0xFA
41 | #define MC_AH 0xFB
42 | #define MC_D 0xFC
43 | #define P_CMD 0xFD
44 | #define P_STATUS 0xFE
45 | #define BANK_SEL 0xFF
46 |
47 | #define CTRLI_LP_DP 0x80
48 | #define CTRLI_ROUND 0x40
49 |
50 | #define CTRL0_AEC_EN 0x80
51 | #define CTRL0_AEC_SEL 0x40
52 | #define CTRL0_STAT_SEL 0x20
53 | #define CTRL0_VFIRST 0x10
54 | #define CTRL0_YUV422 0x08
55 | #define CTRL0_YUV_EN 0x04
56 | #define CTRL0_RGB_EN 0x02
57 | #define CTRL0_RAW_EN 0x01
58 |
59 | #define CTRL2_DCW_EN 0x20
60 | #define CTRL2_SDE_EN 0x10
61 | #define CTRL2_UV_ADJ_EN 0x08
62 | #define CTRL2_UV_AVG_EN 0x04
63 | #define CTRL2_CMX_EN 0x01
64 |
65 | #define CTRL3_BPC_EN 0x80
66 | #define CTRL3_WPC_EN 0x40
67 |
68 | #define R_DVP_SP_AUTO_MODE 0x80
69 |
70 | #define R_BYPASS_DSP_EN 0x00
71 | #define R_BYPASS_DSP_BYPAS 0x01
72 |
73 | #define IMAGE_MODE_Y8_DVP_EN 0x40
74 | #define IMAGE_MODE_JPEG_EN 0x10
75 | #define IMAGE_MODE_YUV422 0x00
76 | #define IMAGE_MODE_RAW10 0x04
77 | #define IMAGE_MODE_RGB565 0x08
78 | #define IMAGE_MODE_HREF_VSYNC 0x02
79 | #define IMAGE_MODE_LBYTE_FIRST 0x01
80 |
81 | #define RESET_MICROC 0x40
82 | #define RESET_SCCB 0x20
83 | #define RESET_JPEG 0x10
84 | #define RESET_DVP 0x04
85 | #define RESET_IPU 0x02
86 | #define RESET_CIF 0x01
87 |
88 | #define MC_BIST_RESET 0x80
89 | #define MC_BIST_BOOT_ROM_SEL 0x40
90 | #define MC_BIST_12KB_SEL 0x20
91 | #define MC_BIST_12KB_MASK 0x30
92 | #define MC_BIST_512KB_SEL 0x08
93 | #define MC_BIST_512KB_MASK 0x0C
94 | #define MC_BIST_BUSY_BIT_R 0x02
95 | #define MC_BIST_MC_RES_ONE_SH_W 0x02
96 | #define MC_BIST_LAUNCH 0x01
97 |
98 |
99 | typedef enum {
100 | BANK_DSP, BANK_SENSOR, BANK_MAX
101 | } ov2640_bank_t;
102 |
103 | /* Sensor register bank FF=0x01*/
104 | #define GAIN 0x00
105 | #define COM1 0x03
106 | #define REG04 0x04
107 | #define REG08 0x08
108 | #define COM2 0x09
109 | #define REG_PID 0x0A
110 | #define REG_VER 0x0B
111 | #define COM3 0x0C
112 | #define COM4 0x0D
113 | #define AEC 0x10
114 | #define CLKRC 0x11
115 | #define COM7 0x12
116 | #define COM8 0x13
117 | #define COM9 0x14 /* AGC gain ceiling */
118 | #define COM10 0x15
119 | #define HSTART 0x17
120 | #define HSTOP 0x18
121 | #define VSTART 0x19
122 | #define VSTOP 0x1A
123 | #define REG_MIDH 0x1C
124 | #define REG_MIDL 0x1D
125 | #define AEW 0x24
126 | #define AEB 0x25
127 | #define VV 0x26
128 | #define REG2A 0x2A
129 | #define FRARL 0x2B
130 | #define ADDVSL 0x2D
131 | #define ADDVSH 0x2E
132 | #define YAVG 0x2F
133 | #define HSDY 0x30
134 | #define HEDY 0x31
135 | #define REG32 0x32
136 | #define ARCOM2 0x34
137 | #define REG45 0x45
138 | #define FLL 0x46
139 | #define FLH 0x47
140 | #define COM19 0x48
141 | #define ZOOMS 0x49
142 | #define COM22 0x4B
143 | #define COM25 0x4E
144 | #define BD50 0x4F
145 | #define BD60 0x50
146 | #define REG5D 0x5D
147 | #define REG5E 0x5E
148 | #define REG5F 0x5F
149 | #define REG60 0x60
150 | #define HISTO_LOW 0x61
151 | #define HISTO_HIGH 0x62
152 |
153 | #define REG04_DEFAULT 0x28
154 | #define REG04_HFLIP_IMG 0x80
155 | #define REG04_VFLIP_IMG 0x40
156 | #define REG04_VREF_EN 0x10
157 | #define REG04_HREF_EN 0x08
158 | #define REG04_SET(x) (REG04_DEFAULT|x)
159 |
160 | #define COM2_STDBY 0x10
161 | #define COM2_OUT_DRIVE_1x 0x00
162 | #define COM2_OUT_DRIVE_2x 0x01
163 | #define COM2_OUT_DRIVE_3x 0x02
164 | #define COM2_OUT_DRIVE_4x 0x03
165 |
166 | #define COM3_DEFAULT 0x38
167 | #define COM3_BAND_50Hz 0x04
168 | #define COM3_BAND_60Hz 0x00
169 | #define COM3_BAND_AUTO 0x02
170 | #define COM3_BAND_SET(x) (COM3_DEFAULT|x)
171 |
172 | #define COM7_SRST 0x80
173 | #define COM7_RES_UXGA 0x00 /* UXGA */
174 | #define COM7_RES_SVGA 0x40 /* SVGA */
175 | #define COM7_RES_CIF 0x20 /* CIF */
176 | #define COM7_ZOOM_EN 0x04 /* Enable Zoom */
177 | #define COM7_COLOR_BAR 0x02 /* Enable Color Bar Test */
178 |
179 | #define COM8_DEFAULT 0xC0
180 | #define COM8_BNDF_EN 0x20 /* Enable Banding filter */
181 | #define COM8_AGC_EN 0x04 /* AGC Auto/Manual control selection */
182 | #define COM8_AEC_EN 0x01 /* Auto/Manual Exposure control */
183 | #define COM8_SET(x) (COM8_DEFAULT|x)
184 |
185 | #define COM9_DEFAULT 0x08
186 | #define COM9_AGC_GAIN_2x 0x00 /* AGC: 2x */
187 | #define COM9_AGC_GAIN_4x 0x01 /* AGC: 4x */
188 | #define COM9_AGC_GAIN_8x 0x02 /* AGC: 8x */
189 | #define COM9_AGC_GAIN_16x 0x03 /* AGC: 16x */
190 | #define COM9_AGC_GAIN_32x 0x04 /* AGC: 32x */
191 | #define COM9_AGC_GAIN_64x 0x05 /* AGC: 64x */
192 | #define COM9_AGC_GAIN_128x 0x06 /* AGC: 128x */
193 | #define COM9_AGC_SET(x) (COM9_DEFAULT|(x<<5))
194 |
195 | #define COM10_HREF_EN 0x80 /* HSYNC changes to HREF */
196 | #define COM10_HSYNC_EN 0x40 /* HREF changes to HSYNC */
197 | #define COM10_PCLK_FREE 0x20 /* PCLK output option: free running PCLK */
198 | #define COM10_PCLK_EDGE 0x10 /* Data is updated at the rising edge of PCLK */
199 | #define COM10_HREF_NEG 0x08 /* HREF negative */
200 | #define COM10_VSYNC_NEG 0x02 /* VSYNC negative */
201 | #define COM10_HSYNC_NEG 0x01 /* HSYNC negative */
202 |
203 | #define CTRL1_AWB 0x08 /* Enable AWB */
204 |
205 | #define VV_AGC_TH_SET(h,l) ((h<<4)|(l&0x0F))
206 |
207 | #define REG32_UXGA 0x36
208 | #define REG32_SVGA 0x09
209 | #define REG32_CIF 0x89
210 |
211 | #define CLKRC_2X 0x80
212 | #define CLKRC_2X_UXGA (0x01 | CLKRC_2X)
213 | #define CLKRC_2X_SVGA CLKRC_2X
214 | #define CLKRC_2X_CIF CLKRC_2X
215 |
216 | #endif //__REG_REGS_H__
217 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov3660.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * OV3660 driver.
7 | *
8 | */
9 | #ifndef __OV3660_H__
10 | #define __OV3660_H__
11 |
12 | #include "sensor.h"
13 |
14 | /**
15 | * @brief Detect sensor pid
16 | *
17 | * @param slv_addr SCCB address
18 | * @param id Detection result
19 | * @return
20 | * 0: Can't detect this sensor
21 | * Nonzero: This sensor has been detected
22 | */
23 | int ov3660_detect(int slv_addr, sensor_id_t *id);
24 |
25 | /**
26 | * @brief initialize sensor function pointers
27 | *
28 | * @param sensor pointer of sensor
29 | * @return
30 | * Always 0
31 | */
32 | int ov3660_init(sensor_t *sensor);
33 |
34 | #endif // __OV3660_H__
35 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov3660_regs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * OV3660 register definitions.
3 | */
4 | #ifndef __OV3660_REG_REGS_H__
5 | #define __OV3660_REG_REGS_H__
6 |
7 | /* system control registers */
8 | #define SYSTEM_CTROL0 0x3008 // Bit[7]: Software reset
9 | // Bit[6]: Software power down
10 | // Bit[5]: Reserved
11 | // Bit[4]: SRB clock SYNC enable
12 | // Bit[3]: Isolation suspend select
13 | // Bit[2:0]: Not used
14 |
15 | /* output format control registers */
16 | #define FORMAT_CTRL 0x501F // Format select
17 | // Bit[2:0]:
18 | // 000: YUV422
19 | // 001: RGB
20 | // 010: Dither
21 | // 011: RAW after DPC
22 | // 101: RAW after CIP
23 |
24 | /* format control registers */
25 | #define FORMAT_CTRL00 0x4300
26 |
27 | /* frame control registers */
28 | #define FRAME_CTRL01 0x4201 // Control Passed Frame Number When both ON and OFF number set to 0x00,frame control is in bypass mode
29 | // Bit[7:4]: Not used
30 | // Bit[3:0]: Frame ON number
31 | #define FRAME_CTRL02 0x4202 // Control Masked Frame Number When both ON and OFF number set to 0x00,frame control is in bypass mode
32 | // Bit[7:4]: Not used
33 | // BIT[3:0]: Frame OFF number
34 |
35 | /* ISP top control registers */
36 | #define PRE_ISP_TEST_SETTING_1 0x503D // Bit[7]: Test enable
37 | // 0: Test disable
38 | // 1: Color bar enable
39 | // Bit[6]: Rolling
40 | // Bit[5]: Transparent
41 | // Bit[4]: Square black and white
42 | // Bit[3:2]: Color bar style
43 | // 00: Standard 8 color bar
44 | // 01: Gradual change at vertical mode 1
45 | // 10: Gradual change at horizontal
46 | // 11: Gradual change at vertical mode 2
47 | // Bit[1:0]: Test select
48 | // 00: Color bar
49 | // 01: Random data
50 | // 10: Square data
51 | // 11: Black image
52 |
53 | //exposure = {0x3500[3:0], 0x3501[7:0], 0x3502[7:0]} / 16 × tROW
54 |
55 | /* AEC/AGC control functions */
56 | #define AEC_PK_MANUAL 0x3503 // AEC Manual Mode Control
57 | // Bit[7:6]: Reserved
58 | // Bit[5]: Gain delay option
59 | // Valid when 0x3503[4]=1’b0
60 | // 0: Delay one frame latch
61 | // 1: One frame latch
62 | // Bit[4:2]: Reserved
63 | // Bit[1]: AGC manual
64 | // 0: Auto enable
65 | // 1: Manual enable
66 | // Bit[0]: AEC manual
67 | // 0: Auto enable
68 | // 1: Manual enable
69 |
70 | //gain = {0x350A[1:0], 0x350B[7:0]} / 16
71 |
72 | /* mirror and flip registers */
73 | #define TIMING_TC_REG20 0x3820 // Timing Control Register
74 | // Bit[2:1]: Vertical flip enable
75 | // 00: Normal
76 | // 11: Vertical flip
77 | // Bit[0]: Vertical binning enable
78 | #define TIMING_TC_REG21 0x3821 // Timing Control Register
79 | // Bit[5]: Compression Enable
80 | // Bit[2:1]: Horizontal mirror enable
81 | // 00: Normal
82 | // 11: Horizontal mirror
83 | // Bit[0]: Horizontal binning enable
84 |
85 | #define CLOCK_POL_CONTROL 0x4740// Bit[5]: PCLK polarity 0: active low
86 | // 1: active high
87 | // Bit[3]: Gate PCLK under VSYNC
88 | // Bit[2]: Gate PCLK under HREF
89 | // Bit[1]: HREF polarity
90 | // 0: active low
91 | // 1: active high
92 | // Bit[0] VSYNC polarity
93 | // 0: active low
94 | // 1: active high
95 | #define DRIVE_CAPABILITY 0x302c // Bit[7:6]:
96 | // 00: 1x
97 | // 01: 2x
98 | // 10: 3x
99 | // 11: 4x
100 |
101 |
102 | #define X_ADDR_ST_H 0x3800 //Bit[3:0]: X address start[11:8]
103 | #define X_ADDR_ST_L 0x3801 //Bit[7:0]: X address start[7:0]
104 | #define Y_ADDR_ST_H 0x3802 //Bit[2:0]: Y address start[10:8]
105 | #define Y_ADDR_ST_L 0x3803 //Bit[7:0]: Y address start[7:0]
106 | #define X_ADDR_END_H 0x3804 //Bit[3:0]: X address end[11:8]
107 | #define X_ADDR_END_L 0x3805 //Bit[7:0]:
108 | #define Y_ADDR_END_H 0x3806 //Bit[2:0]: Y address end[10:8]
109 | #define Y_ADDR_END_L 0x3807 //Bit[7:0]:
110 | // Size after scaling
111 | #define X_OUTPUT_SIZE_H 0x3808 //Bit[3:0]: DVP output horizontal width[11:8]
112 | #define X_OUTPUT_SIZE_L 0x3809 //Bit[7:0]:
113 | #define Y_OUTPUT_SIZE_H 0x380a //Bit[2:0]: DVP output vertical height[10:8]
114 | #define Y_OUTPUT_SIZE_L 0x380b //Bit[7:0]:
115 | #define X_TOTAL_SIZE_H 0x380c //Bit[3:0]: Total horizontal size[11:8]
116 | #define X_TOTAL_SIZE_L 0x380d //Bit[7:0]:
117 | #define Y_TOTAL_SIZE_H 0x380e //Bit[7:0]: Total vertical size[15:8]
118 | #define Y_TOTAL_SIZE_L 0x380f //Bit[7:0]:
119 | #define X_OFFSET_H 0x3810 //Bit[3:0]: ISP horizontal offset[11:8]
120 | #define X_OFFSET_L 0x3811 //Bit[7:0]:
121 | #define Y_OFFSET_H 0x3812 //Bit[2:0]: ISP vertical offset[10:8]
122 | #define Y_OFFSET_L 0x3813 //Bit[7:0]:
123 | #define X_INCREMENT 0x3814 //Bit[7:4]: Horizontal odd subsample increment
124 | //Bit[3:0]: Horizontal even subsample increment
125 | #define Y_INCREMENT 0x3815 //Bit[7:4]: Vertical odd subsample increment
126 | //Bit[3:0]: Vertical even subsample increment
127 | // Size before scaling
128 | //#define X_INPUT_SIZE (X_ADDR_END - X_ADDR_ST + 1 - (2 * X_OFFSET))
129 | //#define Y_INPUT_SIZE (Y_ADDR_END - Y_ADDR_ST + 1 - (2 * Y_OFFSET))
130 |
131 | #define ISP_CONTROL_01 0x5001 // Bit[5]: Scale enable
132 | // 0: Disable
133 | // 1: Enable
134 |
135 | #define SCALE_CTRL_1 0x5601 // Bit[6:4]: HDIV RW
136 | // DCW scale times
137 | // 000: DCW 1 time
138 | // 001: DCW 2 times
139 | // 010: DCW 4 times
140 | // 100: DCW 8 times
141 | // 101: DCW 16 times
142 | // Others: DCW 16 times
143 | // Bit[2:0]: VDIV RW
144 | // DCW scale times
145 | // 000: DCW 1 time
146 | // 001: DCW 2 times
147 | // 010: DCW 4 times
148 | // 100: DCW 8 times
149 | // 101: DCW 16 times
150 | // Others: DCW 16 times
151 |
152 | #define SCALE_CTRL_2 0x5602 // X_SCALE High Bits
153 | #define SCALE_CTRL_3 0x5603 // X_SCALE Low Bits
154 | #define SCALE_CTRL_4 0x5604 // Y_SCALE High Bits
155 | #define SCALE_CTRL_5 0x5605 // Y_SCALE Low Bits
156 | #define SCALE_CTRL_6 0x5606 // Bit[3:0]: V Offset
157 |
158 | #define PCLK_RATIO 0x3824 // Bit[4:0]: PCLK ratio manual
159 | #define VFIFO_CTRL0C 0x460C // Bit[1]: PCLK manual enable
160 | // 0: Auto
161 | // 1: Manual by PCLK_RATIO
162 |
163 | #define VFIFO_X_SIZE_H 0x4602
164 | #define VFIFO_X_SIZE_L 0x4603
165 | #define VFIFO_Y_SIZE_H 0x4604
166 | #define VFIFO_Y_SIZE_L 0x4605
167 |
168 | #define SC_PLLS_CTRL0 0x303a // Bit[7]: PLLS bypass
169 | #define SC_PLLS_CTRL1 0x303b // Bit[4:0]: PLLS multiplier
170 | #define SC_PLLS_CTRL2 0x303c // Bit[6:4]: PLLS charge pump control
171 | // Bit[3:0]: PLLS system divider
172 | #define SC_PLLS_CTRL3 0x303d // Bit[5:4]: PLLS pre-divider
173 | // 00: 1
174 | // 01: 1.5
175 | // 10: 2
176 | // 11: 3
177 | // Bit[2]: PLLS root-divider - 1
178 | // Bit[1:0]: PLLS seld5
179 | // 00: 1
180 | // 01: 1
181 | // 10: 2
182 | // 11: 2.5
183 |
184 | #define COMPRESSION_CTRL00 0x4400 //
185 | #define COMPRESSION_CTRL01 0x4401 //
186 | #define COMPRESSION_CTRL02 0x4402 //
187 | #define COMPRESSION_CTRL03 0x4403 //
188 | #define COMPRESSION_CTRL04 0x4404 //
189 | #define COMPRESSION_CTRL05 0x4405 //
190 | #define COMPRESSION_CTRL06 0x4406 //
191 | #define COMPRESSION_CTRL07 0x4407 // Bit[5:0]: QS
192 | #define COMPRESSION_ISI_CTRL 0x4408 //
193 | #define COMPRESSION_CTRL09 0x4409 //
194 | #define COMPRESSION_CTRL0a 0x440a //
195 | #define COMPRESSION_CTRL0b 0x440b //
196 | #define COMPRESSION_CTRL0c 0x440c //
197 | #define COMPRESSION_CTRL0d 0x440d //
198 | #define COMPRESSION_CTRL0E 0x440e //
199 |
200 | /**
201 | * @brief register value
202 | */
203 | #define TEST_COLOR_BAR 0xC0 /* Enable Color Bar roling Test */
204 |
205 | #define AEC_PK_MANUAL_AGC_MANUALEN 0x02 /* Enable AGC Manual enable */
206 | #define AEC_PK_MANUAL_AEC_MANUALEN 0x01 /* Enable AEC Manual enable */
207 |
208 | #define TIMING_TC_REG20_VFLIP 0x06 /* Vertical flip enable */
209 | #define TIMING_TC_REG21_HMIRROR 0x06 /* Horizontal mirror enable */
210 |
211 | #endif // __OV3660_REG_REGS_H__
212 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov3660_settings.h:
--------------------------------------------------------------------------------
1 | #ifndef _OV3660_SETTINGS_H_
2 | #define _OV3660_SETTINGS_H_
3 |
4 | #include
5 | #include
6 | #include "esp_attr.h"
7 | #include "ov3660_regs.h"
8 |
9 | static const ratio_settings_t ratio_table[] = {
10 | // mw, mh, sx, sy, ex, ey, ox, oy, tx, ty
11 | { 2048, 1536, 0, 0, 2079, 1547, 16, 6, 2300, 1564 }, //4x3
12 | { 1920, 1280, 64, 128, 2015, 1419, 16, 6, 2172, 1436 }, //3x2
13 | { 2048, 1280, 0, 128, 2079, 1419, 16, 6, 2300, 1436 }, //16x10
14 | { 1920, 1152, 64, 192, 2015, 1355, 16, 6, 2172, 1372 }, //5x3
15 | { 1920, 1080, 64, 242, 2015, 1333, 16, 6, 2172, 1322 }, //16x9
16 | { 2048, 880, 0, 328, 2079, 1219, 16, 6, 2300, 1236 }, //21x9
17 | { 1920, 1536, 64, 0, 2015, 1547, 16, 6, 2172, 1564 }, //5x4
18 | { 1536, 1536, 256, 0, 1823, 1547, 16, 6, 2044, 1564 }, //1x1
19 | { 864, 1536, 592, 0, 1487, 1547, 16, 6, 2044, 1564 } //9x16
20 | };
21 |
22 | #define REG_DLY 0xffff
23 | #define REGLIST_TAIL 0x0000
24 |
25 | static const DRAM_ATTR uint16_t sensor_default_regs[][2] = {
26 | {SYSTEM_CTROL0, 0x82}, // software reset
27 | {REG_DLY, 10}, // delay 10ms
28 |
29 | {0x3103, 0x13},
30 | {SYSTEM_CTROL0, 0x42},
31 | {0x3017, 0xff},
32 | {0x3018, 0xff},
33 | {DRIVE_CAPABILITY, 0xc3},
34 | {CLOCK_POL_CONTROL, 0x21},
35 |
36 | {0x3611, 0x01},
37 | {0x3612, 0x2d},
38 |
39 | {0x3032, 0x00},
40 | {0x3614, 0x80},
41 | {0x3618, 0x00},
42 | {0x3619, 0x75},
43 | {0x3622, 0x80},
44 | {0x3623, 0x00},
45 | {0x3624, 0x03},
46 | {0x3630, 0x52},
47 | {0x3632, 0x07},
48 | {0x3633, 0xd2},
49 | {0x3704, 0x80},
50 | {0x3708, 0x66},
51 | {0x3709, 0x12},
52 | {0x370b, 0x12},
53 | {0x3717, 0x00},
54 | {0x371b, 0x60},
55 | {0x371c, 0x00},
56 | {0x3901, 0x13},
57 |
58 | {0x3600, 0x08},
59 | {0x3620, 0x43},
60 | {0x3702, 0x20},
61 | {0x3739, 0x48},
62 | {0x3730, 0x20},
63 | {0x370c, 0x0c},
64 |
65 | {0x3a18, 0x00},
66 | {0x3a19, 0xf8},
67 |
68 | {0x3000, 0x10},
69 | {0x3004, 0xef},
70 |
71 | {0x6700, 0x05},
72 | {0x6701, 0x19},
73 | {0x6702, 0xfd},
74 | {0x6703, 0xd1},
75 | {0x6704, 0xff},
76 | {0x6705, 0xff},
77 |
78 | {0x3c01, 0x80},
79 | {0x3c00, 0x04},
80 | {0x3a08, 0x00}, {0x3a09, 0x62}, //50Hz Band Width Step (10bit)
81 | {0x3a0e, 0x08}, //50Hz Max Bands in One Frame (6 bit)
82 | {0x3a0a, 0x00}, {0x3a0b, 0x52}, //60Hz Band Width Step (10bit)
83 | {0x3a0d, 0x09}, //60Hz Max Bands in One Frame (6 bit)
84 |
85 | {0x3a00, 0x3a},//night mode off
86 | {0x3a14, 0x09},
87 | {0x3a15, 0x30},
88 | {0x3a02, 0x09},
89 | {0x3a03, 0x30},
90 |
91 | {COMPRESSION_CTRL0E, 0x08},
92 | {0x4520, 0x0b},
93 | {0x460b, 0x37},
94 | {0x4713, 0x02},
95 | {0x471c, 0xd0},
96 | {0x5086, 0x00},
97 |
98 | {0x5002, 0x00},
99 | {0x501f, 0x00},
100 |
101 | {SYSTEM_CTROL0, 0x02},
102 |
103 | {0x5180, 0xff},
104 | {0x5181, 0xf2},
105 | {0x5182, 0x00},
106 | {0x5183, 0x14},
107 | {0x5184, 0x25},
108 | {0x5185, 0x24},
109 | {0x5186, 0x16},
110 | {0x5187, 0x16},
111 | {0x5188, 0x16},
112 | {0x5189, 0x68},
113 | {0x518a, 0x60},
114 | {0x518b, 0xe0},
115 | {0x518c, 0xb2},
116 | {0x518d, 0x42},
117 | {0x518e, 0x35},
118 | {0x518f, 0x56},
119 | {0x5190, 0x56},
120 | {0x5191, 0xf8},
121 | {0x5192, 0x04},
122 | {0x5193, 0x70},
123 | {0x5194, 0xf0},
124 | {0x5195, 0xf0},
125 | {0x5196, 0x03},
126 | {0x5197, 0x01},
127 | {0x5198, 0x04},
128 | {0x5199, 0x12},
129 | {0x519a, 0x04},
130 | {0x519b, 0x00},
131 | {0x519c, 0x06},
132 | {0x519d, 0x82},
133 | {0x519e, 0x38},
134 |
135 | {0x5381, 0x1d},
136 | {0x5382, 0x60},
137 | {0x5383, 0x03},
138 | {0x5384, 0x0c},
139 | {0x5385, 0x78},
140 | {0x5386, 0x84},
141 | {0x5387, 0x7d},
142 | {0x5388, 0x6b},
143 | {0x5389, 0x12},
144 | {0x538a, 0x01},
145 | {0x538b, 0x98},
146 |
147 | {0x5480, 0x01},
148 | // {0x5481, 0x05},
149 | // {0x5482, 0x09},
150 | // {0x5483, 0x10},
151 | // {0x5484, 0x3a},
152 | // {0x5485, 0x4c},
153 | // {0x5486, 0x5a},
154 | // {0x5487, 0x68},
155 | // {0x5488, 0x74},
156 | // {0x5489, 0x80},
157 | // {0x548a, 0x8e},
158 | // {0x548b, 0xa4},
159 | // {0x548c, 0xb4},
160 | // {0x548d, 0xc8},
161 | // {0x548e, 0xde},
162 | // {0x548f, 0xf0},
163 | // {0x5490, 0x15},
164 |
165 | {0x5000, 0xa7},
166 | {0x5800, 0x0C},
167 | {0x5801, 0x09},
168 | {0x5802, 0x0C},
169 | {0x5803, 0x0C},
170 | {0x5804, 0x0D},
171 | {0x5805, 0x17},
172 | {0x5806, 0x06},
173 | {0x5807, 0x05},
174 | {0x5808, 0x04},
175 | {0x5809, 0x06},
176 | {0x580a, 0x09},
177 | {0x580b, 0x0E},
178 | {0x580c, 0x05},
179 | {0x580d, 0x01},
180 | {0x580e, 0x01},
181 | {0x580f, 0x01},
182 | {0x5810, 0x05},
183 | {0x5811, 0x0D},
184 | {0x5812, 0x05},
185 | {0x5813, 0x01},
186 | {0x5814, 0x01},
187 | {0x5815, 0x01},
188 | {0x5816, 0x05},
189 | {0x5817, 0x0D},
190 | {0x5818, 0x08},
191 | {0x5819, 0x06},
192 | {0x581a, 0x05},
193 | {0x581b, 0x07},
194 | {0x581c, 0x0B},
195 | {0x581d, 0x0D},
196 | {0x581e, 0x12},
197 | {0x581f, 0x0D},
198 | {0x5820, 0x0E},
199 | {0x5821, 0x10},
200 | {0x5822, 0x10},
201 | {0x5823, 0x1E},
202 | {0x5824, 0x53},
203 | {0x5825, 0x15},
204 | {0x5826, 0x05},
205 | {0x5827, 0x14},
206 | {0x5828, 0x54},
207 | {0x5829, 0x25},
208 | {0x582a, 0x33},
209 | {0x582b, 0x33},
210 | {0x582c, 0x34},
211 | {0x582d, 0x16},
212 | {0x582e, 0x24},
213 | {0x582f, 0x41},
214 | {0x5830, 0x50},
215 | {0x5831, 0x42},
216 | {0x5832, 0x15},
217 | {0x5833, 0x25},
218 | {0x5834, 0x34},
219 | {0x5835, 0x33},
220 | {0x5836, 0x24},
221 | {0x5837, 0x26},
222 | {0x5838, 0x54},
223 | {0x5839, 0x25},
224 | {0x583a, 0x15},
225 | {0x583b, 0x25},
226 | {0x583c, 0x53},
227 | {0x583d, 0xCF},
228 |
229 | {0x3a0f, 0x30},
230 | {0x3a10, 0x28},
231 | {0x3a1b, 0x30},
232 | {0x3a1e, 0x28},
233 | {0x3a11, 0x60},
234 | {0x3a1f, 0x14},
235 |
236 | {0x5302, 0x28},
237 | {0x5303, 0x20},
238 |
239 | {0x5306, 0x1c}, //de-noise offset 1
240 | {0x5307, 0x28}, //de-noise offset 2
241 |
242 | {0x4002, 0xc5},
243 | {0x4003, 0x81},
244 | {0x4005, 0x12},
245 |
246 | {0x5688, 0x11},
247 | {0x5689, 0x11},
248 | {0x568a, 0x11},
249 | {0x568b, 0x11},
250 | {0x568c, 0x11},
251 | {0x568d, 0x11},
252 | {0x568e, 0x11},
253 | {0x568f, 0x11},
254 |
255 | {0x5580, 0x06},
256 | {0x5588, 0x00},
257 | {0x5583, 0x40},
258 | {0x5584, 0x2c},
259 |
260 | {ISP_CONTROL_01, 0x83}, // turn color matrix, awb and SDE
261 | {REGLIST_TAIL, 0x00}, // tail
262 | };
263 |
264 | static const DRAM_ATTR uint16_t sensor_fmt_jpeg[][2] = {
265 | {FORMAT_CTRL, 0x00}, // YUV422
266 | {FORMAT_CTRL00, 0x30}, // YUYV
267 | {0x3002, 0x00},//0x1c to 0x00 !!!
268 | {0x3006, 0xff},//0xc3 to 0xff !!!
269 | {0x471c, 0x50},//0xd0 to 0x50 !!!
270 | {REGLIST_TAIL, 0x00}, // tail
271 | };
272 |
273 | static const DRAM_ATTR uint16_t sensor_fmt_raw[][2] = {
274 | {FORMAT_CTRL00, 0x00}, // RAW
275 | {REGLIST_TAIL, 0x00}
276 | };
277 |
278 | static const DRAM_ATTR uint16_t sensor_fmt_grayscale[][2] = {
279 | {FORMAT_CTRL, 0x00}, // YUV422
280 | {FORMAT_CTRL00, 0x10}, // Y8
281 | {REGLIST_TAIL, 0x00}
282 | };
283 |
284 | static const DRAM_ATTR uint16_t sensor_fmt_yuv422[][2] = {
285 | {FORMAT_CTRL, 0x00}, // YUV422
286 | {FORMAT_CTRL00, 0x30}, // YUYV
287 | {REGLIST_TAIL, 0x00}
288 | };
289 |
290 | static const DRAM_ATTR uint16_t sensor_fmt_rgb565[][2] = {
291 | {FORMAT_CTRL, 0x01}, // RGB
292 | {FORMAT_CTRL00, 0x61}, // RGB565 (BGR)
293 | {REGLIST_TAIL, 0x00}
294 | };
295 |
296 | static const DRAM_ATTR uint8_t sensor_saturation_levels[9][11] = {
297 | {0x1d, 0x60, 0x03, 0x07, 0x48, 0x4f, 0x4b, 0x40, 0x0b, 0x01, 0x98},//-4
298 | {0x1d, 0x60, 0x03, 0x08, 0x54, 0x5c, 0x58, 0x4b, 0x0d, 0x01, 0x98},//-3
299 | {0x1d, 0x60, 0x03, 0x0a, 0x60, 0x6a, 0x64, 0x56, 0x0e, 0x01, 0x98},//-2
300 | {0x1d, 0x60, 0x03, 0x0b, 0x6c, 0x77, 0x70, 0x60, 0x10, 0x01, 0x98},//-1
301 | {0x1d, 0x60, 0x03, 0x0c, 0x78, 0x84, 0x7d, 0x6b, 0x12, 0x01, 0x98},//0
302 | {0x1d, 0x60, 0x03, 0x0d, 0x84, 0x91, 0x8a, 0x76, 0x14, 0x01, 0x98},//+1
303 | {0x1d, 0x60, 0x03, 0x0e, 0x90, 0x9e, 0x96, 0x80, 0x16, 0x01, 0x98},//+2
304 | {0x1d, 0x60, 0x03, 0x10, 0x9c, 0xac, 0xa2, 0x8b, 0x17, 0x01, 0x98},//+3
305 | {0x1d, 0x60, 0x03, 0x11, 0xa8, 0xb9, 0xaf, 0x96, 0x19, 0x01, 0x98},//+4
306 | };
307 |
308 | static const DRAM_ATTR uint8_t sensor_special_effects[7][4] = {
309 | {0x06, 0x40, 0x2c, 0x08},//Normal
310 | {0x46, 0x40, 0x28, 0x08},//Negative
311 | {0x1e, 0x80, 0x80, 0x08},//Grayscale
312 | {0x1e, 0x80, 0xc0, 0x08},//Red Tint
313 | {0x1e, 0x60, 0x60, 0x08},//Green Tint
314 | {0x1e, 0xa0, 0x40, 0x08},//Blue Tint
315 | {0x1e, 0x40, 0xa0, 0x08},//Sepia
316 | };
317 |
318 | #endif
319 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov5640.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __OV5640_H__
3 | #define __OV5640_H__
4 |
5 | #include "sensor.h"
6 |
7 | /**
8 | * @brief Detect sensor pid
9 | *
10 | * @param slv_addr SCCB address
11 | * @param id Detection result
12 | * @return
13 | * 0: Can't detect this sensor
14 | * Nonzero: This sensor has been detected
15 | */
16 | int ov5640_detect(int slv_addr, sensor_id_t *id);
17 |
18 | /**
19 | * @brief initialize sensor function pointers
20 | *
21 | * @param sensor pointer of sensor
22 | * @return
23 | * Always 0
24 | */
25 | int ov5640_init(sensor_t *sensor);
26 |
27 | #endif // __OV5640_H__
28 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov5640_regs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * OV5640 register definitions.
3 | */
4 | #ifndef __OV5640_REG_REGS_H__
5 | #define __OV5640_REG_REGS_H__
6 |
7 | /* system control registers */
8 | #define SYSTEM_CTROL0 0x3008 // Bit[7]: Software reset
9 | // Bit[6]: Software power down
10 | // Bit[5]: Reserved
11 | // Bit[4]: SRB clock SYNC enable
12 | // Bit[3]: Isolation suspend select
13 | // Bit[2:0]: Not used
14 |
15 | #define DRIVE_CAPABILITY 0x302c // Bit[7:6]:
16 | // 00: 1x
17 | // 01: 2x
18 | // 10: 3x
19 | // 11: 4x
20 |
21 | #define SC_PLLS_CTRL0 0x303a // Bit[7]: PLLS bypass
22 | #define SC_PLLS_CTRL1 0x303b // Bit[4:0]: PLLS multiplier
23 | #define SC_PLLS_CTRL2 0x303c // Bit[6:4]: PLLS charge pump control
24 | // Bit[3:0]: PLLS system divider
25 | #define SC_PLLS_CTRL3 0x303d // Bit[5:4]: PLLS pre-divider
26 | // 00: 1
27 | // 01: 1.5
28 | // 10: 2
29 | // 11: 3
30 | // Bit[2]: PLLS root-divider - 1
31 | // Bit[1:0]: PLLS seld5
32 | // 00: 1
33 | // 01: 1
34 | // 10: 2
35 | // 11: 2.5
36 |
37 | /* AEC/AGC control functions */
38 | #define AEC_PK_MANUAL 0x3503 // AEC Manual Mode Control
39 | // Bit[7:6]: Reserved
40 | // Bit[5]: Gain delay option
41 | // Valid when 0x3503[4]=1’b0
42 | // 0: Delay one frame latch
43 | // 1: One frame latch
44 | // Bit[4:2]: Reserved
45 | // Bit[1]: AGC manual
46 | // 0: Auto enable
47 | // 1: Manual enable
48 | // Bit[0]: AEC manual
49 | // 0: Auto enable
50 | // 1: Manual enable
51 |
52 | //gain = {0x350A[1:0], 0x350B[7:0]} / 16
53 |
54 |
55 | #define X_ADDR_ST_H 0x3800 //Bit[3:0]: X address start[11:8]
56 | #define X_ADDR_ST_L 0x3801 //Bit[7:0]: X address start[7:0]
57 | #define Y_ADDR_ST_H 0x3802 //Bit[2:0]: Y address start[10:8]
58 | #define Y_ADDR_ST_L 0x3803 //Bit[7:0]: Y address start[7:0]
59 | #define X_ADDR_END_H 0x3804 //Bit[3:0]: X address end[11:8]
60 | #define X_ADDR_END_L 0x3805 //Bit[7:0]:
61 | #define Y_ADDR_END_H 0x3806 //Bit[2:0]: Y address end[10:8]
62 | #define Y_ADDR_END_L 0x3807 //Bit[7:0]:
63 | // Size after scaling
64 | #define X_OUTPUT_SIZE_H 0x3808 //Bit[3:0]: DVP output horizontal width[11:8]
65 | #define X_OUTPUT_SIZE_L 0x3809 //Bit[7:0]:
66 | #define Y_OUTPUT_SIZE_H 0x380a //Bit[2:0]: DVP output vertical height[10:8]
67 | #define Y_OUTPUT_SIZE_L 0x380b //Bit[7:0]:
68 | #define X_TOTAL_SIZE_H 0x380c //Bit[3:0]: Total horizontal size[11:8]
69 | #define X_TOTAL_SIZE_L 0x380d //Bit[7:0]:
70 | #define Y_TOTAL_SIZE_H 0x380e //Bit[7:0]: Total vertical size[15:8]
71 | #define Y_TOTAL_SIZE_L 0x380f //Bit[7:0]:
72 | #define X_OFFSET_H 0x3810 //Bit[3:0]: ISP horizontal offset[11:8]
73 | #define X_OFFSET_L 0x3811 //Bit[7:0]:
74 | #define Y_OFFSET_H 0x3812 //Bit[2:0]: ISP vertical offset[10:8]
75 | #define Y_OFFSET_L 0x3813 //Bit[7:0]:
76 | #define X_INCREMENT 0x3814 //Bit[7:4]: Horizontal odd subsample increment
77 | //Bit[3:0]: Horizontal even subsample increment
78 | #define Y_INCREMENT 0x3815 //Bit[7:4]: Vertical odd subsample increment
79 | //Bit[3:0]: Vertical even subsample increment
80 | // Size before scaling
81 | //#define X_INPUT_SIZE (X_ADDR_END - X_ADDR_ST + 1 - (2 * X_OFFSET))
82 | //#define Y_INPUT_SIZE (Y_ADDR_END - Y_ADDR_ST + 1 - (2 * Y_OFFSET))
83 |
84 | /* mirror and flip registers */
85 | #define TIMING_TC_REG20 0x3820 // Timing Control Register
86 | // Bit[2:1]: Vertical flip enable
87 | // 00: Normal
88 | // 11: Vertical flip
89 | // Bit[0]: Vertical binning enable
90 | #define TIMING_TC_REG21 0x3821 // Timing Control Register
91 | // Bit[5]: Compression Enable
92 | // Bit[2:1]: Horizontal mirror enable
93 | // 00: Normal
94 | // 11: Horizontal mirror
95 | // Bit[0]: Horizontal binning enable
96 |
97 | #define PCLK_RATIO 0x3824 // Bit[4:0]: PCLK ratio manual
98 |
99 | /* frame control registers */
100 | #define FRAME_CTRL01 0x4201 // Control Passed Frame Number When both ON and OFF number set to 0x00,frame control is in bypass mode
101 | // Bit[7:4]: Not used
102 | // Bit[3:0]: Frame ON number
103 | #define FRAME_CTRL02 0x4202 // Control Masked Frame Number When both ON and OFF number set to 0x00,frame control is in bypass mode
104 | // Bit[7:4]: Not used
105 | // BIT[3:0]: Frame OFF number
106 |
107 | /* format control registers */
108 | #define FORMAT_CTRL00 0x4300
109 |
110 | #define CLOCK_POL_CONTROL 0x4740// Bit[5]: PCLK polarity 0: active low
111 | // 1: active high
112 | // Bit[3]: Gate PCLK under VSYNC
113 | // Bit[2]: Gate PCLK under HREF
114 | // Bit[1]: HREF polarity
115 | // 0: active low
116 | // 1: active high
117 | // Bit[0] VSYNC polarity
118 | // 0: active low
119 | // 1: active high
120 |
121 | #define ISP_CONTROL_01 0x5001 // Bit[5]: Scale enable
122 | // 0: Disable
123 | // 1: Enable
124 |
125 | /* output format control registers */
126 | #define FORMAT_CTRL 0x501F // Format select
127 | // Bit[2:0]:
128 | // 000: YUV422
129 | // 001: RGB
130 | // 010: Dither
131 | // 011: RAW after DPC
132 | // 101: RAW after CIP
133 |
134 | /* ISP top control registers */
135 | #define PRE_ISP_TEST_SETTING_1 0x503D // Bit[7]: Test enable
136 | // 0: Test disable
137 | // 1: Color bar enable
138 | // Bit[6]: Rolling
139 | // Bit[5]: Transparent
140 | // Bit[4]: Square black and white
141 | // Bit[3:2]: Color bar style
142 | // 00: Standard 8 color bar
143 | // 01: Gradual change at vertical mode 1
144 | // 10: Gradual change at horizontal
145 | // 11: Gradual change at vertical mode 2
146 | // Bit[1:0]: Test select
147 | // 00: Color bar
148 | // 01: Random data
149 | // 10: Square data
150 | // 11: Black image
151 |
152 | //exposure = {0x3500[3:0], 0x3501[7:0], 0x3502[7:0]} / 16 × tROW
153 |
154 | #define SCALE_CTRL_1 0x5601 // Bit[6:4]: HDIV RW
155 | // DCW scale times
156 | // 000: DCW 1 time
157 | // 001: DCW 2 times
158 | // 010: DCW 4 times
159 | // 100: DCW 8 times
160 | // 101: DCW 16 times
161 | // Others: DCW 16 times
162 | // Bit[2:0]: VDIV RW
163 | // DCW scale times
164 | // 000: DCW 1 time
165 | // 001: DCW 2 times
166 | // 010: DCW 4 times
167 | // 100: DCW 8 times
168 | // 101: DCW 16 times
169 | // Others: DCW 16 times
170 |
171 | #define SCALE_CTRL_2 0x5602 // X_SCALE High Bits
172 | #define SCALE_CTRL_3 0x5603 // X_SCALE Low Bits
173 | #define SCALE_CTRL_4 0x5604 // Y_SCALE High Bits
174 | #define SCALE_CTRL_5 0x5605 // Y_SCALE Low Bits
175 | #define SCALE_CTRL_6 0x5606 // Bit[3:0]: V Offset
176 |
177 | #define VFIFO_CTRL0C 0x460C // Bit[1]: PCLK manual enable
178 | // 0: Auto
179 | // 1: Manual by PCLK_RATIO
180 |
181 | #define VFIFO_X_SIZE_H 0x4602
182 | #define VFIFO_X_SIZE_L 0x4603
183 | #define VFIFO_Y_SIZE_H 0x4604
184 | #define VFIFO_Y_SIZE_L 0x4605
185 |
186 | #define COMPRESSION_CTRL00 0x4400 //
187 | #define COMPRESSION_CTRL01 0x4401 //
188 | #define COMPRESSION_CTRL02 0x4402 //
189 | #define COMPRESSION_CTRL03 0x4403 //
190 | #define COMPRESSION_CTRL04 0x4404 //
191 | #define COMPRESSION_CTRL05 0x4405 //
192 | #define COMPRESSION_CTRL06 0x4406 //
193 | #define COMPRESSION_CTRL07 0x4407 // Bit[5:0]: QS
194 | #define COMPRESSION_ISI_CTRL 0x4408 //
195 | #define COMPRESSION_CTRL09 0x4409 //
196 | #define COMPRESSION_CTRL0a 0x440a //
197 | #define COMPRESSION_CTRL0b 0x440b //
198 | #define COMPRESSION_CTRL0c 0x440c //
199 | #define COMPRESSION_CTRL0d 0x440d //
200 | #define COMPRESSION_CTRL0E 0x440e //
201 |
202 | /**
203 | * @brief register value
204 | */
205 | #define TEST_COLOR_BAR 0xC0 /* Enable Color Bar roling Test */
206 |
207 | #define AEC_PK_MANUAL_AGC_MANUALEN 0x02 /* Enable AGC Manual enable */
208 | #define AEC_PK_MANUAL_AEC_MANUALEN 0x01 /* Enable AEC Manual enable */
209 |
210 | #define TIMING_TC_REG20_VFLIP 0x06 /* Vertical flip enable */
211 | #define TIMING_TC_REG21_HMIRROR 0x06 /* Horizontal mirror enable */
212 |
213 | #endif // __OV3660_REG_REGS_H__
214 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov5640_settings.h:
--------------------------------------------------------------------------------
1 | #ifndef _OV5640_SETTINGS_H_
2 | #define _OV5640_SETTINGS_H_
3 |
4 | #include
5 | #include
6 | #include "esp_attr.h"
7 | #include "ov5640_regs.h"
8 |
9 | static const ratio_settings_t ratio_table[] = {
10 | // mw, mh, sx, sy, ex, ey, ox, oy, tx, ty
11 | { 2560, 1920, 0, 0, 2623, 1951, 32, 16, 2844, 1968 }, //4x3
12 | { 2560, 1704, 0, 110, 2623, 1843, 32, 16, 2844, 1752 }, //3x2
13 | { 2560, 1600, 0, 160, 2623, 1791, 32, 16, 2844, 1648 }, //16x10
14 | { 2560, 1536, 0, 192, 2623, 1759, 32, 16, 2844, 1584 }, //5x3
15 | { 2560, 1440, 0, 240, 2623, 1711, 32, 16, 2844, 1488 }, //16x9
16 | { 2560, 1080, 0, 420, 2623, 1531, 32, 16, 2844, 1128 }, //21x9
17 | { 2400, 1920, 80, 0, 2543, 1951, 32, 16, 2684, 1968 }, //5x4
18 | { 1920, 1920, 320, 0, 2543, 1951, 32, 16, 2684, 1968 }, //1x1
19 | { 1088, 1920, 736, 0, 1887, 1951, 32, 16, 1884, 1968 } //9x16
20 | };
21 |
22 | #define REG_DLY 0xffff
23 | #define REGLIST_TAIL 0x0000
24 |
25 | static const DRAM_ATTR uint16_t sensor_default_regs[][2] = {
26 | {SYSTEM_CTROL0, 0x82}, // software reset
27 | {REG_DLY, 10}, // delay 10ms
28 | {SYSTEM_CTROL0, 0x42}, // power down
29 |
30 | //enable pll
31 | {0x3103, 0x13},
32 |
33 | //io direction
34 | {0x3017, 0xff},
35 | {0x3018, 0xff},
36 |
37 | {DRIVE_CAPABILITY, 0xc3},
38 | {CLOCK_POL_CONTROL, 0x21},
39 |
40 | {0x4713, 0x02},//jpg mode select
41 |
42 | {ISP_CONTROL_01, 0x83}, // turn color matrix, awb and SDE
43 |
44 | //sys reset
45 | {0x3000, 0x00},
46 | {0x3002, 0x1c},
47 |
48 | //clock enable
49 | {0x3004, 0xff},
50 | {0x3006, 0xc3},
51 |
52 | //isp control
53 | {0x5000, 0xa7},
54 | {ISP_CONTROL_01, 0xa3},//+scaling?
55 | {0x5003, 0x08},//special_effect
56 |
57 | //unknown
58 | {0x370c, 0x02},//!!IMPORTANT
59 | {0x3634, 0x40},//!!IMPORTANT
60 |
61 | //AEC/AGC
62 | {0x3a02, 0x03},
63 | {0x3a03, 0xd8},
64 | {0x3a08, 0x01},
65 | {0x3a09, 0x27},
66 | {0x3a0a, 0x00},
67 | {0x3a0b, 0xf6},
68 | {0x3a0d, 0x04},
69 | {0x3a0e, 0x03},
70 | {0x3a0f, 0x30},//ae_level
71 | {0x3a10, 0x28},//ae_level
72 | {0x3a11, 0x60},//ae_level
73 | {0x3a13, 0x43},
74 | {0x3a14, 0x03},
75 | {0x3a15, 0xd8},
76 | {0x3a18, 0x00},//gainceiling
77 | {0x3a19, 0xf8},//gainceiling
78 | {0x3a1b, 0x30},//ae_level
79 | {0x3a1e, 0x26},//ae_level
80 | {0x3a1f, 0x14},//ae_level
81 |
82 | //vcm debug
83 | {0x3600, 0x08},
84 | {0x3601, 0x33},
85 |
86 | //50/60Hz
87 | {0x3c01, 0xa4},
88 | {0x3c04, 0x28},
89 | {0x3c05, 0x98},
90 | {0x3c06, 0x00},
91 | {0x3c07, 0x08},
92 | {0x3c08, 0x00},
93 | {0x3c09, 0x1c},
94 | {0x3c0a, 0x9c},
95 | {0x3c0b, 0x40},
96 |
97 | {0x460c, 0x22},//disable jpeg footer
98 |
99 | //BLC
100 | {0x4001, 0x02},
101 | {0x4004, 0x02},
102 |
103 | //AWB
104 | {0x5180, 0xff},
105 | {0x5181, 0xf2},
106 | {0x5182, 0x00},
107 | {0x5183, 0x14},
108 | {0x5184, 0x25},
109 | {0x5185, 0x24},
110 | {0x5186, 0x09},
111 | {0x5187, 0x09},
112 | {0x5188, 0x09},
113 | {0x5189, 0x75},
114 | {0x518a, 0x54},
115 | {0x518b, 0xe0},
116 | {0x518c, 0xb2},
117 | {0x518d, 0x42},
118 | {0x518e, 0x3d},
119 | {0x518f, 0x56},
120 | {0x5190, 0x46},
121 | {0x5191, 0xf8},
122 | {0x5192, 0x04},
123 | {0x5193, 0x70},
124 | {0x5194, 0xf0},
125 | {0x5195, 0xf0},
126 | {0x5196, 0x03},
127 | {0x5197, 0x01},
128 | {0x5198, 0x04},
129 | {0x5199, 0x12},
130 | {0x519a, 0x04},
131 | {0x519b, 0x00},
132 | {0x519c, 0x06},
133 | {0x519d, 0x82},
134 | {0x519e, 0x38},
135 |
136 | //color matrix (Saturation)
137 | {0x5381, 0x1e},
138 | {0x5382, 0x5b},
139 | {0x5383, 0x08},
140 | {0x5384, 0x0a},
141 | {0x5385, 0x7e},
142 | {0x5386, 0x88},
143 | {0x5387, 0x7c},
144 | {0x5388, 0x6c},
145 | {0x5389, 0x10},
146 | {0x538a, 0x01},
147 | {0x538b, 0x98},
148 |
149 | //CIP control (Sharpness)
150 | {0x5300, 0x10},//sharpness
151 | {0x5301, 0x10},//sharpness
152 | {0x5302, 0x18},//sharpness
153 | {0x5303, 0x19},//sharpness
154 | {0x5304, 0x10},
155 | {0x5305, 0x10},
156 | {0x5306, 0x08},//denoise
157 | {0x5307, 0x16},
158 | {0x5308, 0x40},
159 | {0x5309, 0x10},//sharpness
160 | {0x530a, 0x10},//sharpness
161 | {0x530b, 0x04},//sharpness
162 | {0x530c, 0x06},//sharpness
163 |
164 | //GAMMA
165 | {0x5480, 0x01},
166 | {0x5481, 0x00},
167 | {0x5482, 0x1e},
168 | {0x5483, 0x3b},
169 | {0x5484, 0x58},
170 | {0x5485, 0x66},
171 | {0x5486, 0x71},
172 | {0x5487, 0x7d},
173 | {0x5488, 0x83},
174 | {0x5489, 0x8f},
175 | {0x548a, 0x98},
176 | {0x548b, 0xa6},
177 | {0x548c, 0xb8},
178 | {0x548d, 0xca},
179 | {0x548e, 0xd7},
180 | {0x548f, 0xe3},
181 | {0x5490, 0x1d},
182 |
183 | //Special Digital Effects (SDE) (UV adjust)
184 | {0x5580, 0x06},//enable brightness and contrast
185 | {0x5583, 0x40},//special_effect
186 | {0x5584, 0x10},//special_effect
187 | {0x5586, 0x20},//contrast
188 | {0x5587, 0x00},//brightness
189 | {0x5588, 0x00},//brightness
190 | {0x5589, 0x10},
191 | {0x558a, 0x00},
192 | {0x558b, 0xf8},
193 | {0x501d, 0x40},// enable manual offset of contrast
194 |
195 | //power on
196 | {0x3008, 0x02},
197 |
198 | //50Hz
199 | {0x3c00, 0x04},
200 |
201 | {REG_DLY, 300},
202 | {REGLIST_TAIL, 0x00}, // tail
203 | };
204 |
205 | static const DRAM_ATTR uint16_t sensor_fmt_jpeg[][2] = {
206 | {FORMAT_CTRL, 0x00}, // YUV422
207 | {FORMAT_CTRL00, 0x30}, // YUYV
208 | {0x3002, 0x00},//0x1c to 0x00 !!!
209 | {0x3006, 0xff},//0xc3 to 0xff !!!
210 | {0x471c, 0x50},//0xd0 to 0x50 !!!
211 | {REGLIST_TAIL, 0x00}, // tail
212 | };
213 |
214 | static const DRAM_ATTR uint16_t sensor_fmt_raw[][2] = {
215 | {FORMAT_CTRL, 0x03}, // RAW (DPC)
216 | {FORMAT_CTRL00, 0x00}, // RAW
217 | {REGLIST_TAIL, 0x00}
218 | };
219 |
220 | static const DRAM_ATTR uint16_t sensor_fmt_grayscale[][2] = {
221 | {FORMAT_CTRL, 0x00}, // YUV422
222 | {FORMAT_CTRL00, 0x10}, // Y8
223 | {REGLIST_TAIL, 0x00}
224 | };
225 |
226 | static const DRAM_ATTR uint16_t sensor_fmt_yuv422[][2] = {
227 | {FORMAT_CTRL, 0x00}, // YUV422
228 | {FORMAT_CTRL00, 0x30}, // YUYV
229 | {REGLIST_TAIL, 0x00}
230 | };
231 |
232 | static const DRAM_ATTR uint16_t sensor_fmt_rgb565[][2] = {
233 | {FORMAT_CTRL, 0x01}, // RGB
234 | {FORMAT_CTRL00, 0x61}, // RGB565 (BGR)
235 | {REGLIST_TAIL, 0x00}
236 | };
237 |
238 | static const DRAM_ATTR uint8_t sensor_saturation_levels[9][11] = {
239 | {0x1d, 0x60, 0x03, 0x07, 0x48, 0x4f, 0x4b, 0x40, 0x0b, 0x01, 0x98},//-4
240 | {0x1d, 0x60, 0x03, 0x08, 0x54, 0x5c, 0x58, 0x4b, 0x0d, 0x01, 0x98},//-3
241 | {0x1d, 0x60, 0x03, 0x0a, 0x60, 0x6a, 0x64, 0x56, 0x0e, 0x01, 0x98},//-2
242 | {0x1d, 0x60, 0x03, 0x0b, 0x6c, 0x77, 0x70, 0x60, 0x10, 0x01, 0x98},//-1
243 | {0x1d, 0x60, 0x03, 0x0c, 0x78, 0x84, 0x7d, 0x6b, 0x12, 0x01, 0x98},//0
244 | {0x1d, 0x60, 0x03, 0x0d, 0x84, 0x91, 0x8a, 0x76, 0x14, 0x01, 0x98},//+1
245 | {0x1d, 0x60, 0x03, 0x0e, 0x90, 0x9e, 0x96, 0x80, 0x16, 0x01, 0x98},//+2
246 | {0x1d, 0x60, 0x03, 0x10, 0x9c, 0xac, 0xa2, 0x8b, 0x17, 0x01, 0x98},//+3
247 | {0x1d, 0x60, 0x03, 0x11, 0xa8, 0xb9, 0xaf, 0x96, 0x19, 0x01, 0x98},//+4
248 | };
249 |
250 | static const DRAM_ATTR uint8_t sensor_special_effects[7][4] = {
251 | {0x06, 0x40, 0x2c, 0x08},//Normal
252 | {0x46, 0x40, 0x28, 0x08},//Negative
253 | {0x1e, 0x80, 0x80, 0x08},//Grayscale
254 | {0x1e, 0x80, 0xc0, 0x08},//Red Tint
255 | {0x1e, 0x60, 0x60, 0x08},//Green Tint
256 | {0x1e, 0xa0, 0x40, 0x08},//Blue Tint
257 | {0x1e, 0x40, 0xa0, 0x08},//Sepia
258 | };
259 |
260 | static const DRAM_ATTR uint16_t sensor_regs_gamma0[][2] = {
261 | {0x5480, 0x01},
262 | {0x5481, 0x08},
263 | {0x5482, 0x14},
264 | {0x5483, 0x28},
265 | {0x5484, 0x51},
266 | {0x5485, 0x65},
267 | {0x5486, 0x71},
268 | {0x5487, 0x7d},
269 | {0x5488, 0x87},
270 | {0x5489, 0x91},
271 | {0x548a, 0x9a},
272 | {0x548b, 0xaa},
273 | {0x548c, 0xb8},
274 | {0x548d, 0xcd},
275 | {0x548e, 0xdd},
276 | {0x548f, 0xea},
277 | {0x5490, 0x1d}
278 | };
279 |
280 | static const DRAM_ATTR uint16_t sensor_regs_gamma1[][2] = {
281 | {0x5480, 0x1},
282 | {0x5481, 0x0},
283 | {0x5482, 0x1e},
284 | {0x5483, 0x3b},
285 | {0x5484, 0x58},
286 | {0x5485, 0x66},
287 | {0x5486, 0x71},
288 | {0x5487, 0x7d},
289 | {0x5488, 0x83},
290 | {0x5489, 0x8f},
291 | {0x548a, 0x98},
292 | {0x548b, 0xa6},
293 | {0x548c, 0xb8},
294 | {0x548d, 0xca},
295 | {0x548e, 0xd7},
296 | {0x548f, 0xe3},
297 | {0x5490, 0x1d}
298 | };
299 |
300 | static const DRAM_ATTR uint16_t sensor_regs_awb0[][2] = {
301 | {0x5180, 0xff},
302 | {0x5181, 0xf2},
303 | {0x5182, 0x00},
304 | {0x5183, 0x14},
305 | {0x5184, 0x25},
306 | {0x5185, 0x24},
307 | {0x5186, 0x09},
308 | {0x5187, 0x09},
309 | {0x5188, 0x09},
310 | {0x5189, 0x75},
311 | {0x518a, 0x54},
312 | {0x518b, 0xe0},
313 | {0x518c, 0xb2},
314 | {0x518d, 0x42},
315 | {0x518e, 0x3d},
316 | {0x518f, 0x56},
317 | {0x5190, 0x46},
318 | {0x5191, 0xf8},
319 | {0x5192, 0x04},
320 | {0x5193, 0x70},
321 | {0x5194, 0xf0},
322 | {0x5195, 0xf0},
323 | {0x5196, 0x03},
324 | {0x5197, 0x01},
325 | {0x5198, 0x04},
326 | {0x5199, 0x12},
327 | {0x519a, 0x04},
328 | {0x519b, 0x00},
329 | {0x519c, 0x06},
330 | {0x519d, 0x82},
331 | {0x519e, 0x38}
332 | };
333 |
334 | #endif
335 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov7670.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * author: Juan Schiavoni
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * OV7670 driver.
7 | *
8 | */
9 | #ifndef __OV7670_H__
10 | #define __OV7670_H__
11 | #include "sensor.h"
12 |
13 | /**
14 | * @brief Detect sensor pid
15 | *
16 | * @param slv_addr SCCB address
17 | * @param id Detection result
18 | * @return
19 | * 0: Can't detect this sensor
20 | * Nonzero: This sensor has been detected
21 | */
22 | int ov7670_detect(int slv_addr, sensor_id_t *id);
23 |
24 | /**
25 | * @brief initialize sensor function pointers
26 | *
27 | * @param sensor pointer of sensor
28 | * @return
29 | * Always 0
30 | */
31 | int ov7670_init(sensor_t *sensor);
32 |
33 | #endif // __OV7670_H__
34 |
--------------------------------------------------------------------------------
/components/esp32-camera/sensors/private_include/ov7725.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the OpenMV project.
3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader
4 | * This work is licensed under the MIT license, see the file LICENSE for details.
5 | *
6 | * OV7725 driver.
7 | *
8 | */
9 | #ifndef __OV7725_H__
10 | #define __OV7725_H__
11 | #include "sensor.h"
12 |
13 | /**
14 | * @brief Detect sensor pid
15 | *
16 | * @param slv_addr SCCB address
17 | * @param id Detection result
18 | * @return
19 | * 0: Can't detect this sensor
20 | * Nonzero: This sensor has been detected
21 | */
22 | int ov7725_detect(int slv_addr, sensor_id_t *id);
23 |
24 | /**
25 | * @brief initialize sensor function pointers
26 | *
27 | * @param sensor pointer of sensor
28 | * @return
29 | * Always 0
30 | */
31 | int ov7725_init(sensor_t *sensor);
32 |
33 | #endif // __OV7725_H__
34 |
--------------------------------------------------------------------------------
/components/esp32-camera/target/esp32s2/private_include/tjpgd.h:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------------------/
2 | / TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2012
3 | /----------------------------------------------------------------------------*/
4 | #ifndef _TJPGDEC
5 | #define _TJPGDEC
6 | /*---------------------------------------------------------------------------*/
7 | /* System Configurations */
8 |
9 | #define JD_SZBUF 512 /* Size of stream input buffer */
10 | #define JD_FORMAT 0 /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */
11 | #define JD_USE_SCALE 1 /* Use descaling feature for output */
12 | #define JD_TBLCLIP 1 /* Use table for saturation (might be a bit faster but increases 1K bytes of code size) */
13 |
14 | /*---------------------------------------------------------------------------*/
15 |
16 | #ifdef __cplusplus
17 | extern "C" {
18 | #endif
19 |
20 | /* These types must be 16-bit, 32-bit or larger integer */
21 | typedef int INT;
22 | typedef unsigned int UINT;
23 |
24 | /* These types must be 8-bit integer */
25 | typedef char CHAR;
26 | typedef unsigned char UCHAR;
27 | typedef unsigned char BYTE;
28 |
29 | /* These types must be 16-bit integer */
30 | typedef short SHORT;
31 | typedef unsigned short USHORT;
32 | typedef unsigned short WORD;
33 | typedef unsigned short WCHAR;
34 |
35 | /* These types must be 32-bit integer */
36 | typedef long LONG;
37 | typedef unsigned long ULONG;
38 | typedef unsigned long DWORD;
39 |
40 |
41 | /* Error code */
42 | typedef enum {
43 | JDR_OK = 0, /* 0: Succeeded */
44 | JDR_INTR, /* 1: Interrupted by output function */
45 | JDR_INP, /* 2: Device error or wrong termination of input stream */
46 | JDR_MEM1, /* 3: Insufficient memory pool for the image */
47 | JDR_MEM2, /* 4: Insufficient stream input buffer */
48 | JDR_PAR, /* 5: Parameter error */
49 | JDR_FMT1, /* 6: Data format error (may be damaged data) */
50 | JDR_FMT2, /* 7: Right format but not supported */
51 | JDR_FMT3 /* 8: Not supported JPEG standard */
52 | } JRESULT;
53 |
54 |
55 |
56 | /* Rectangular structure */
57 | typedef struct {
58 | WORD left, right, top, bottom;
59 | } JRECT;
60 |
61 |
62 |
63 | /* Decompressor object structure */
64 | typedef struct JDEC JDEC;
65 | struct JDEC {
66 | UINT dctr; /* Number of bytes available in the input buffer */
67 | BYTE* dptr; /* Current data read ptr */
68 | BYTE* inbuf; /* Bit stream input buffer */
69 | BYTE dmsk; /* Current bit in the current read byte */
70 | BYTE scale; /* Output scaling ratio */
71 | BYTE msx, msy; /* MCU size in unit of block (width, height) */
72 | BYTE qtid[3]; /* Quantization table ID of each component */
73 | SHORT dcv[3]; /* Previous DC element of each component */
74 | WORD nrst; /* Restart inverval */
75 | UINT width, height; /* Size of the input image (pixel) */
76 | BYTE* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
77 | WORD* huffcode[2][2]; /* Huffman code word tables [id][dcac] */
78 | BYTE* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
79 | LONG* qttbl[4]; /* Dequaitizer tables [id] */
80 | void* workbuf; /* Working buffer for IDCT and RGB output */
81 | BYTE* mcubuf; /* Working buffer for the MCU */
82 | void* pool; /* Pointer to available memory pool */
83 | UINT sz_pool; /* Size of momory pool (bytes available) */
84 | UINT (*infunc)(JDEC*, BYTE*, UINT);/* Pointer to jpeg stream input function */
85 | void* device; /* Pointer to I/O device identifiler for the session */
86 | };
87 |
88 |
89 |
90 | /* TJpgDec API functions */
91 | JRESULT jd_prepare (JDEC*, UINT(*)(JDEC*,BYTE*,UINT), void*, UINT, void*);
92 | JRESULT jd_decomp (JDEC*, UINT(*)(JDEC*,void*,JRECT*), BYTE);
93 |
94 |
95 | #ifdef __cplusplus
96 | }
97 | #endif
98 |
99 | #endif /* _TJPGDEC */
100 |
--------------------------------------------------------------------------------
/components/esp32-camera/target/private_include/ll_cam.h:
--------------------------------------------------------------------------------
1 | // Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #pragma once
16 |
17 | #include
18 | #include "sdkconfig.h"
19 | #include "esp_idf_version.h"
20 | #if CONFIG_IDF_TARGET_ESP32
21 | #if ESP_IDF_VERSION_MAJOR >= 4
22 | #include "esp32/rom/lldesc.h"
23 | #else
24 | #include "rom/lldesc.h"
25 | #endif
26 | #elif CONFIG_IDF_TARGET_ESP32S2
27 | #include "esp32s2/rom/lldesc.h"
28 | #elif CONFIG_IDF_TARGET_ESP32S3
29 | #include "esp32s3/rom/lldesc.h"
30 | #endif
31 | #include "esp_log.h"
32 | #include "esp_camera.h"
33 | #include "freertos/FreeRTOS.h"
34 | #include "freertos/queue.h"
35 | #include "freertos/task.h"
36 | #include "freertos/semphr.h"
37 |
38 | #if __has_include("esp_private/periph_ctrl.h")
39 | # include "esp_private/periph_ctrl.h"
40 | #endif
41 |
42 | #define CAMERA_DBG_PIN_ENABLE 0
43 | #if CAMERA_DBG_PIN_ENABLE
44 | #if CONFIG_IDF_TARGET_ESP32
45 | #define DBG_PIN_NUM 26
46 | #else
47 | #define DBG_PIN_NUM 7
48 | #endif
49 | #include "hal/gpio_ll.h"
50 | #define DBG_PIN_SET(v) gpio_ll_set_level(&GPIO, DBG_PIN_NUM, v)
51 | #else
52 | #define DBG_PIN_SET(v)
53 | #endif
54 |
55 | #define CAM_CHECK(a, str, ret) if (!(a)) { \
56 | ESP_LOGE(TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
57 | return (ret); \
58 | }
59 |
60 | #define CAM_CHECK_GOTO(a, str, lab) if (!(a)) { \
61 | ESP_LOGE(TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
62 | goto lab; \
63 | }
64 |
65 | #define LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE (4092)
66 |
67 | typedef enum {
68 | CAM_IN_SUC_EOF_EVENT = 0,
69 | CAM_VSYNC_EVENT
70 | } cam_event_t;
71 |
72 | typedef enum {
73 | CAM_STATE_IDLE = 0,
74 | CAM_STATE_READ_BUF = 1,
75 | } cam_state_t;
76 |
77 | typedef struct {
78 | camera_fb_t fb;
79 | uint8_t en;
80 | //for RGB/YUV modes
81 | lldesc_t *dma;
82 | size_t fb_offset;
83 | } cam_frame_t;
84 |
85 | typedef struct {
86 | uint32_t dma_bytes_per_item;
87 | uint32_t dma_buffer_size;
88 | uint32_t dma_half_buffer_size;
89 | uint32_t dma_half_buffer_cnt;
90 | uint32_t dma_node_buffer_size;
91 | uint32_t dma_node_cnt;
92 | uint32_t frame_copy_cnt;
93 |
94 | //for JPEG mode
95 | lldesc_t *dma;
96 | uint8_t *dma_buffer;
97 |
98 | cam_frame_t *frames;
99 |
100 | QueueHandle_t event_queue;
101 | QueueHandle_t frame_buffer_queue;
102 | TaskHandle_t task_handle;
103 | intr_handle_t cam_intr_handle;
104 |
105 | uint8_t dma_num;//ESP32-S3
106 | intr_handle_t dma_intr_handle;//ESP32-S3
107 |
108 | uint8_t jpeg_mode;
109 | uint8_t vsync_pin;
110 | uint8_t vsync_invert;
111 | uint32_t frame_cnt;
112 | uint32_t recv_size;
113 | bool swap_data;
114 | bool psram_mode;
115 |
116 | //for RGB/YUV modes
117 | uint16_t width;
118 | uint16_t height;
119 | uint8_t in_bytes_per_pixel;
120 | uint8_t fb_bytes_per_pixel;
121 | uint32_t fb_size;
122 |
123 | cam_state_t state;
124 | } cam_obj_t;
125 |
126 |
127 | bool ll_cam_stop(cam_obj_t *cam);
128 | bool ll_cam_start(cam_obj_t *cam, int frame_pos);
129 | esp_err_t ll_cam_config(cam_obj_t *cam, const camera_config_t *config);
130 | esp_err_t ll_cam_deinit(cam_obj_t *cam);
131 | void ll_cam_vsync_intr_enable(cam_obj_t *cam, bool en);
132 | esp_err_t ll_cam_set_pin(cam_obj_t *cam, const camera_config_t *config);
133 | esp_err_t ll_cam_init_isr(cam_obj_t *cam);
134 | void ll_cam_do_vsync(cam_obj_t *cam);
135 | uint8_t ll_cam_get_dma_align(cam_obj_t *cam);
136 | bool ll_cam_dma_sizes(cam_obj_t *cam);
137 | size_t IRAM_ATTR ll_cam_memcpy(cam_obj_t *cam, uint8_t *out, const uint8_t *in, size_t len);
138 | 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);
139 |
140 | // implemented in cam_hal
141 | void ll_cam_send_event(cam_obj_t *cam, cam_event_t cam_event, BaseType_t * HPTaskAwoken);
142 |
--------------------------------------------------------------------------------
/components/esp32-camera/target/xclk.c:
--------------------------------------------------------------------------------
1 | #include "driver/gpio.h"
2 | #include "driver/ledc.h"
3 | #include "esp_err.h"
4 | #include "esp_log.h"
5 | #include "esp_system.h"
6 | #include "xclk.h"
7 | #include "esp_camera.h"
8 |
9 | #if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
10 | #include "esp32-hal-log.h"
11 | #else
12 | #include "esp_log.h"
13 | static const char* TAG = "camera_xclk";
14 | #endif
15 |
16 | static ledc_channel_t g_ledc_channel = 0;
17 |
18 | esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz)
19 | {
20 | ledc_timer_config_t timer_conf;
21 | timer_conf.duty_resolution = LEDC_TIMER_1_BIT;
22 | timer_conf.freq_hz = xclk_freq_hz;
23 | timer_conf.speed_mode = LEDC_LOW_SPEED_MODE;
24 |
25 | #if ESP_IDF_VERSION_MAJOR >= 4
26 | timer_conf.clk_cfg = LEDC_AUTO_CLK;
27 | #endif
28 | timer_conf.timer_num = (ledc_timer_t)ledc_timer;
29 | esp_err_t err = ledc_timer_config(&timer_conf);
30 | if (err != ESP_OK) {
31 | ESP_LOGE(TAG, "ledc_timer_config failed for freq %d, rc=%x", xclk_freq_hz, err);
32 | }
33 | return err;
34 | }
35 |
36 | esp_err_t camera_enable_out_clock(camera_config_t* config)
37 | {
38 | esp_err_t err = xclk_timer_conf(config->ledc_timer, config->xclk_freq_hz);
39 | if (err != ESP_OK) {
40 | ESP_LOGE(TAG, "ledc_timer_config failed, rc=%x", err);
41 | return err;
42 | }
43 |
44 | g_ledc_channel = config->ledc_channel;
45 | ledc_channel_config_t ch_conf;
46 | ch_conf.gpio_num = config->pin_xclk;
47 | ch_conf.speed_mode = LEDC_LOW_SPEED_MODE;
48 | ch_conf.channel = config->ledc_channel;
49 | ch_conf.intr_type = LEDC_INTR_DISABLE;
50 | ch_conf.timer_sel = config->ledc_timer;
51 | ch_conf.duty = 1;
52 | ch_conf.hpoint = 0;
53 | err = ledc_channel_config(&ch_conf);
54 | if (err != ESP_OK) {
55 | ESP_LOGE(TAG, "ledc_channel_config failed, rc=%x", err);
56 | return err;
57 | }
58 | return ESP_OK;
59 | }
60 |
61 | void camera_disable_out_clock()
62 | {
63 | ledc_stop(LEDC_LOW_SPEED_MODE, g_ledc_channel, 0);
64 | }
65 |
--------------------------------------------------------------------------------
/components/esp32-camera/test/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | idf_component_register(SRC_DIRS .
2 | PRIV_INCLUDE_DIRS .
3 | PRIV_REQUIRES test_utils esp32-camera nvs_flash
4 | EMBED_TXTFILES pictures/testimg.jpeg pictures/test_outside.jpeg pictures/test_inside.jpeg)
5 |
--------------------------------------------------------------------------------
/components/esp32-camera/test/component.mk:
--------------------------------------------------------------------------------
1 | #
2 | #Component Makefile
3 | #
4 |
5 | COMPONENT_SRCDIRS += ./
6 | COMPONENT_PRIV_INCLUDEDIRS += ./
7 |
8 | COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
9 |
--------------------------------------------------------------------------------
/components/esp32-camera/test/pictures/test_inside.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahhfzhang/esp-rtc/62a0d980807cbf309894e75130697784dc901339/components/esp32-camera/test/pictures/test_inside.jpeg
--------------------------------------------------------------------------------
/components/esp32-camera/test/pictures/test_outside.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahhfzhang/esp-rtc/62a0d980807cbf309894e75130697784dc901339/components/esp32-camera/test/pictures/test_outside.jpeg
--------------------------------------------------------------------------------
/components/esp32-camera/test/pictures/testimg.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahhfzhang/esp-rtc/62a0d980807cbf309894e75130697784dc901339/components/esp32-camera/test/pictures/testimg.jpeg
--------------------------------------------------------------------------------
/components/esp_rtc/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(COMPONENT_ADD_INCLUDEDIRS include)
2 |
3 | register_component()
4 |
5 | target_link_libraries(${COMPONENT_TARGET} INTERFACE "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib")
6 |
7 | add_prebuilt_library(esp_rtc "${CMAKE_CURRENT_SOURCE_DIR}/lib/libesp_rtc.a"
8 | PRIV_REQUIRES esp-adf-libs)
9 |
10 | target_link_libraries(${COMPONENT_TARGET} INTERFACE esp_rtc)
11 |
--------------------------------------------------------------------------------
/components/esp_rtc/include/esp_rtc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ESPRESSIF MIT License
3 | *
4 | * Copyright (c) 2022
5 | *
6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
7 | * it is free of charge, to any person obtaining a copy of this software and associated
8 | * documentation files (the "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11 | * to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all copies or
14 | * substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | *
23 | */
24 |
25 | #ifndef _ESP_RTC_H_
26 | #define _ESP_RTC_H_
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | typedef struct _esp_rtc_handle *esp_rtc_handle_t;
33 |
34 | /**
35 | * @brief RTC codec type
36 | */
37 | typedef enum {
38 | RTC_ACODEC_G711A,
39 | RTC_ACODEC_G711U,
40 | RTC_VCODEC_JPEG,
41 | } rtc_payload_codec_t;
42 |
43 | typedef enum {
44 | ESP_RTC_EVENT_NULL = 0,
45 | ESP_RTC_EVENT_REGISTERED,
46 | ESP_RTC_EVENT_INCOMING,
47 | ESP_RTC_EVENT_CALLING,
48 | ESP_RTC_EVENT_HANGUP,
49 | ESP_RTC_EVENT_ERROR,
50 | ESP_RTC_EVENT_UNREGISTERED,
51 | ESP_RTC_EVENT_AUDIO_SESSION_BEGIN,
52 | ESP_RTC_EVENT_AUDIO_SESSION_END,
53 | ESP_RTC_EVENT_VIDEO_SESSION_BEGIN,
54 | ESP_RTC_EVENT_VIDEO_SESSION_END,
55 | } esp_rtc_event_t;
56 |
57 | typedef int (*esp_rtc_event_handle)(esp_rtc_event_t event);
58 | typedef int (*__esp_rtc_send_audio)(unsigned char *data, int len);
59 | typedef int (*__esp_rtc_receive_audio)(unsigned char *data, int len);
60 | typedef int (*__esp_rtc_send_video)(unsigned char *data, unsigned int *len);
61 | typedef int (*__esp_rtc_receive_video)(unsigned char *data, int len);
62 |
63 | typedef struct {
64 | __esp_rtc_send_audio send_audio;
65 | __esp_rtc_receive_audio receive_audio;
66 | __esp_rtc_send_video send_video;
67 | __esp_rtc_receive_video receive_video;
68 | } esp_rtc_data_cb_t;
69 |
70 | /**
71 | * @brief ESP RTC video info
72 | */
73 | typedef struct {
74 | int vcodec; /*!< Video codec type*/
75 | int width; /*!< Video width */
76 | int height; /*!< Video height */
77 | int fps; /*!< Video fps */
78 | int len; /*!< Video len */
79 | } esp_rtc_video_info;
80 |
81 | /**
82 | * @brief RTC session configurations
83 | */
84 | typedef struct {
85 | const char *uri; /*!< "Transport://user:pass@server:port/path" */
86 | rtc_payload_codec_t aCodecType; /*!< Audio codec type */
87 | esp_rtc_video_info *vCodecInfo; /*!< Video codec info */
88 | esp_rtc_data_cb_t *dataCb; /*!< RTC data callback */
89 | esp_rtc_event_handle eventHandler; /*!< RTC session event handler */
90 | bool usePublicAddr; /*!< Use the public IP address returned by the server (RFC3581) */
91 | } esp_rtc_config_t;
92 |
93 | /**
94 | * @brief Intialize rtc service
95 | *
96 | * @param[in] config The rtc configuration
97 | *
98 | * @return The rtc handle
99 | */
100 | esp_rtc_handle_t esp_rtc_init(esp_rtc_config_t *config);
101 |
102 | /**
103 | * @brief Initialize a rtc session
104 | *
105 | * @param[in] esp_rtc The rtc handle
106 | * @param[in] remote_user Remote user id
107 | *
108 | * @return
109 | * - ESP_OK
110 | * - ESP_FAIL
111 | * - ESP_ERR_INVALID_ARG
112 | */
113 | int esp_rtc_call(esp_rtc_handle_t esp_rtc, const char *remote_user);
114 |
115 | /**
116 | * @brief Answer the rtc Session
117 | *
118 | * @param[in] esp_rtc The rtc handle
119 | *
120 | * @return
121 | * - ESP_OK
122 | * - ESP_FAIL
123 | * - ESP_ERR_INVALID_ARG
124 | */
125 | int esp_rtc_answer(esp_rtc_handle_t esp_rtc);
126 |
127 | /**
128 | * @brief Hang up or cancel
129 | *
130 | * @param[in] esp_rtc The rtc handle
131 | *
132 | * @return
133 | * - ESP_OK
134 | * - ESP_FAIL
135 | * - ESP_ERR_INVALID_ARG
136 | */
137 | int esp_rtc_bye(esp_rtc_handle_t esp_rtc);
138 |
139 | #ifdef __cplusplus
140 | }
141 | #endif
142 |
143 | #endif
--------------------------------------------------------------------------------
/components/esp_rtc/lib/libesp_rtc.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahhfzhang/esp-rtc/62a0d980807cbf309894e75130697784dc901339/components/esp_rtc/lib/libesp_rtc.a
--------------------------------------------------------------------------------
/main/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(COMPONENT_SRCS "main.c" "main_rtc_media.c")
2 | set(COMPONENT_ADD_INCLUDEDIRS .)
3 |
4 | set(COMPONENT_EMBED_TXTFILES espressif.jpg keyboard.jpg calling.jpg incoming.jpg)
5 |
6 | register_component()
--------------------------------------------------------------------------------
/main/calling.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahhfzhang/esp-rtc/62a0d980807cbf309894e75130697784dc901339/main/calling.jpg
--------------------------------------------------------------------------------
/main/component.mk:
--------------------------------------------------------------------------------
1 | #
2 | # "main" pseudo-component makefile.
3 | #
4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
--------------------------------------------------------------------------------
/main/espressif.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahhfzhang/esp-rtc/62a0d980807cbf309894e75130697784dc901339/main/espressif.jpg
--------------------------------------------------------------------------------
/main/incoming.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahhfzhang/esp-rtc/62a0d980807cbf309894e75130697784dc901339/main/incoming.jpg
--------------------------------------------------------------------------------
/main/keyboard.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahhfzhang/esp-rtc/62a0d980807cbf309894e75130697784dc901339/main/keyboard.jpg
--------------------------------------------------------------------------------
/main/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ESPRESSIF MIT License
3 | *
4 | * Copyright (c) 2022
5 | *
6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
7 | * it is free of charge, to any person obtaining a copy of this software and associated
8 | * documentation files (the "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11 | * to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all copies or
14 | * substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | *
23 | */
24 |
25 | #include "string.h"
26 | #include "nvs_flash.h"
27 | #include "esp_netif.h"
28 | #include "esp_log.h"
29 |
30 | #include "board.h"
31 | #include "console.h"
32 | #include "audio_mem.h"
33 | #include "periph_wifi.h"
34 | #include "input_key_service.h"
35 |
36 | #include "main_rtc_media.h"
37 | #include "media_lib_adapter.h"
38 | #include "esp_rtc.h"
39 |
40 | #define TAG "ESP_RTC_Demo"
41 |
42 | #define WIFI_SSID "ESP-Audio"
43 | #define WIFI_PWD "esp123456"
44 | #define LOGIN_URL "tcp://100:100@192.168.1.123:5060"
45 |
46 | static esp_rtc_handle_t esp_rtc;
47 |
48 | static void setup_wifi(esp_periph_set_handle_t set)
49 | {
50 | periph_wifi_cfg_t wifi_cfg = {
51 | .ssid = WIFI_SSID,
52 | .password = WIFI_PWD,
53 | };
54 | esp_periph_handle_t wifi_handle = periph_wifi_init(&wifi_cfg);
55 | esp_periph_start(set, wifi_handle);
56 | periph_wifi_wait_for_connected(wifi_handle, portMAX_DELAY);
57 | }
58 |
59 | static esp_err_t input_key_service_cb(periph_service_handle_t handle, periph_service_event_t *evt, void *ctx)
60 | {
61 | audio_board_handle_t board_handle = (audio_board_handle_t) ctx;
62 | int player_volume;
63 | if (evt->type == INPUT_KEY_SERVICE_ACTION_CLICK_RELEASE) {
64 | ESP_LOGD(TAG, "[ * ] input key id is %d", (int)evt->data);
65 | switch ((int)evt->data) {
66 | case INPUT_KEY_USER_ID_REC:
67 | ESP_LOGI(TAG, "[ * ] [Rec] answer");
68 | esp_rtc_answer(esp_rtc);
69 | break;
70 | case INPUT_KEY_USER_ID_MUTE:
71 | ESP_LOGI(TAG, "[ * ] [Mute] bye");
72 | esp_rtc_bye(esp_rtc);
73 | break;
74 | case INPUT_KEY_USER_ID_PLAY:
75 | ESP_LOGI(TAG, "[ * ] [Play] calling");
76 | esp_rtc_call(esp_rtc, "1010");
77 | break;
78 | case INPUT_KEY_USER_ID_MODE:
79 | case INPUT_KEY_USER_ID_SET:
80 | ESP_LOGI(TAG, "[ * ] [Set] input key event");
81 | esp_rtc_bye(esp_rtc);
82 | break;
83 | case INPUT_KEY_USER_ID_VOLUP:
84 | ESP_LOGD(TAG, "[ * ] [Vol+] input key event");
85 | audio_hal_get_volume(board_handle->audio_hal, &player_volume);
86 | player_volume += 10;
87 | if (player_volume > 100) {
88 | player_volume = 100;
89 | }
90 | audio_hal_set_volume(board_handle->audio_hal, player_volume);
91 | ESP_LOGI(TAG, "[ * ] Volume set to %d %%", player_volume);
92 | break;
93 | case INPUT_KEY_USER_ID_VOLDOWN:
94 | ESP_LOGD(TAG, "[ * ] [Vol-] input key event");
95 | audio_hal_get_volume(board_handle->audio_hal, &player_volume);
96 | player_volume -= 10;
97 | if (player_volume < 0) {
98 | player_volume = 0;
99 | }
100 | audio_hal_set_volume(board_handle->audio_hal, player_volume);
101 | ESP_LOGI(TAG, "[ * ] Volume set to %d %%", player_volume);
102 | break;
103 | }
104 | }
105 |
106 | return ESP_OK;
107 | }
108 |
109 | static struct {
110 | struct arg_str *phone_num;
111 | struct arg_end *end;
112 | } invite_args;
113 |
114 | static int sip_invite(int argc, char **argv)
115 | {
116 | int nerrors = arg_parse(argc, argv, (void **) &invite_args);
117 | if (nerrors != 0) {
118 | arg_print_errors(stderr, invite_args.end, argv[0]);
119 | return 1;
120 | }
121 |
122 | esp_rtc_call(esp_rtc, invite_args.phone_num->sval[0]);
123 | return 0;
124 | }
125 |
126 | static int sip_answer(int argc, char **argv)
127 | {
128 | esp_rtc_answer(esp_rtc);
129 | return 0;
130 | }
131 |
132 | static int sip_bye(int argc, char **argv)
133 | {
134 | esp_rtc_bye(esp_rtc);
135 | return 0;
136 | }
137 |
138 | void app_main()
139 | {
140 | esp_log_level_set("*", ESP_LOG_INFO);
141 | AUDIO_MEM_SHOW(TAG);
142 |
143 | /* tcp/ip init */
144 | esp_err_t err = nvs_flash_init();
145 | if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
146 | // NVS partition was truncated and needs to be erased
147 | // Retry nvs_flash_init
148 | ESP_ERROR_CHECK(nvs_flash_erase());
149 | err = nvs_flash_init();
150 | }
151 | ESP_ERROR_CHECK(err);
152 | ESP_ERROR_CHECK(esp_netif_init());
153 |
154 | media_lib_add_default_adapter();
155 |
156 | esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
157 | periph_cfg.task_stack = 3 * 1024;
158 | periph_cfg.extern_stack = true;
159 | esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);
160 |
161 | audio_board_handle_t board_handle = audio_board_init();
162 | audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START);
163 | audio_hal_set_volume(board_handle->audio_hal, 65);
164 |
165 | setup_wifi(set);
166 | setup_audio();
167 | setup_lcd(set);
168 |
169 | AUDIO_MEM_SHOW(TAG);
170 | esp_rtc = main_rtc_start(LOGIN_URL);
171 |
172 | audio_board_key_init(set);
173 | input_key_service_info_t input_key_info[] = INPUT_KEY_DEFAULT_INFO();
174 | input_key_service_cfg_t input_cfg = INPUT_KEY_SERVICE_DEFAULT_CONFIG();
175 | input_cfg.handle = set;
176 | input_cfg.based_cfg.task_stack = 4 * 1024;
177 | input_cfg.based_cfg.extern_stack = true;
178 | periph_service_handle_t input_ser = input_key_service_create(&input_cfg);
179 | input_key_service_add_key(input_ser, input_key_info, INPUT_KEY_NUM);
180 | periph_service_set_callback(input_ser, input_key_service_cb, (void *)board_handle);
181 |
182 | console_init();
183 | invite_args.phone_num = arg_str1(NULL, NULL, "", "invite phone number");
184 | invite_args.end = arg_end(2);
185 | const esp_console_cmd_t cmd_invite = {
186 | .command = "call",
187 | .help = "Make a Call",
188 | .hint = NULL,
189 | .func = &sip_invite,
190 | .argtable = &invite_args
191 | };
192 | ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_invite) );
193 |
194 | const esp_console_cmd_t cmd_sip_bye = {
195 | .command = "bye",
196 | .help = "BYE",
197 | .hint = NULL,
198 | .func = &sip_bye,
199 | };
200 | ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_sip_bye));
201 |
202 | const esp_console_cmd_t cmd_sip_answer = {
203 | .command = "answer",
204 | .help = "Answer the call",
205 | .hint = NULL,
206 | .func = &sip_answer,
207 | };
208 | ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_sip_answer));
209 | }
210 |
--------------------------------------------------------------------------------
/main/main_rtc_media.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ESPRESSIF MIT License
3 | *
4 | * Copyright (c) 2022
5 | *
6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
7 | * it is free of charge, to any person obtaining a copy of this software and associated
8 | * documentation files (the "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11 | * to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all copies or
14 | * substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | *
23 | */
24 |
25 | #include "esp_peripherals.h"
26 | #include "esp_rtc.h"
27 |
28 | int setup_audio();
29 |
30 | int setup_lcd(esp_periph_set_handle_t set);
31 |
32 | esp_rtc_handle_t main_rtc_start(const char *uri);
33 |
--------------------------------------------------------------------------------
/partitions_esp_rtc_demo.csv:
--------------------------------------------------------------------------------
1 | # Name, Type, SubType, Offset, Size, Flags
2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
3 | nvs, data, nvs, 0x9000, 0x6000,
4 | phy_init, data, phy, 0xf000, 0x1000,
5 | factory, app, factory, 0x10000, 4M,
6 |
--------------------------------------------------------------------------------