diff --git a/.github/workflows/upload_component.yml b/.github/workflows/upload_component.yml index 78dcba5f..98eda2cb 100644 --- a/.github/workflows/upload_component.yml +++ b/.github/workflows/upload_component.yml @@ -17,7 +17,7 @@ jobs: uses: espressif/upload-components-ci-action@v1 with: directories: > - bsp/esp32_azure_iot_kit;bsp/esp32_s2_kaluga_kit;bsp/esp_wrover_kit;bsp/esp-box;bsp/esp32_s3_usb_otg;bsp/esp32_s3_eye;bsp/esp32_s3_lcd_ev_board;bsp/esp32_s3_korvo_2;bsp/esp-box-lite;bsp/esp32_lyrat;bsp/esp32_c3_lcdkit;bsp/esp-box-3;bsp/esp_bsp_generic; + bsp/esp32_azure_iot_kit;bsp/esp32_s2_kaluga_kit;bsp/esp_wrover_kit;bsp/esp-box;bsp/esp32_s3_usb_otg;bsp/esp32_s3_eye;bsp/esp32_s3_lcd_ev_board;bsp/esp32_s3_korvo_2;bsp/esp-box-lite;bsp/esp32_lyrat;bsp/esp32_c3_lcdkit;bsp/esp-box-3;bsp/esp_bsp_generic;bsp/esp32_s3_korvo_1; components/bh1750;components/ds18b20;components/es8311;components/es7210;components/fbm320;components/hts221;components/mag3110;components/mpu6050;components/ssd1306;components/esp_lvgl_port;components/icm42670; components/lcd_touch/esp_lcd_touch;components/lcd_touch/esp_lcd_touch_ft5x06;components/lcd_touch/esp_lcd_touch_gt911;components/lcd_touch/esp_lcd_touch_tt21100;components/lcd_touch/esp_lcd_touch_gt1151;components/lcd_touch/esp_lcd_touch_cst816s; components/lcd/esp_lcd_gc9a01;components/lcd/esp_lcd_ili9341;components/lcd/esp_lcd_ra8875;components/lcd_touch/esp_lcd_touch_stmpe610;components/lcd/esp_lcd_sh1107;components/lcd/esp_lcd_st7796;components/lcd/esp_lcd_gc9503;components/lcd/esp_lcd_ssd1681; diff --git a/README.md b/README.md index fbc5ad60..22f3a969 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Board support packages for development boards using Espressif's SoCs, written in | [ESP32-LyraT](bsp/esp32_lyrat) | ESP32 | uSD card slot, microphone, audio codec + power amplifier | | | [ESP32-C3-LCDKit](bsp/esp32_c3_lcdkit) | ESP32-C3 | LCD display with encoder, IR, PDM audio| | | [ESP-BOX-3](bsp/esp-box-3) | ESP32-S3 | LCD display with touch, audio codec + power amplifier,
accelerometer and gyroscope | | +| [ESP32-S3-KORVO-1](bsp/esp32_s3_korvo_1) | ESP32-S3-KORVO-1 | uSD card slot, microphone, audio codec + power amplifier, RGB led strip | | ## LCD displays and TOUCH | [LVGL port](components/esp_lvgl_port) | [LCD drivers](LCD.md) | diff --git a/bsp/esp32_s3_korvo_1/CMakeLists.txt b/bsp/esp32_s3_korvo_1/CMakeLists.txt new file mode 100644 index 00000000..ca4cd82e --- /dev/null +++ b/bsp/esp32_s3_korvo_1/CMakeLists.txt @@ -0,0 +1,15 @@ +#IDF version is less than IDF5.0 +if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_LESS "5.0") + set(SRC_VER "esp32_s3_korvo_1_idf4.c") + set(REQ spiffs) +else() + set(SRC_VER "esp32_s3_korvo_1_idf5.c") + set(REQ spiffs esp_adc) +endif() + +idf_component_register( + SRCS "esp32_s3_korvo_1.c" ${SRC_VER} "led_blink_defaults.c" + INCLUDE_DIRS "include" + PRIV_INCLUDE_DIRS "priv_include" + REQUIRES ${REQ} +) diff --git a/bsp/esp32_s3_korvo_1/Kconfig b/bsp/esp32_s3_korvo_1/Kconfig new file mode 100644 index 00000000..3d56c356 --- /dev/null +++ b/bsp/esp32_s3_korvo_1/Kconfig @@ -0,0 +1,35 @@ +menu "Board Support Package" + + config BSP_ERROR_CHECK + bool "Enable error check in BSP" + default y + help + Error check assert the application before returning the error code. + + menu "SPIFFS - Virtual File System" + config BSP_SPIFFS_FORMAT_ON_MOUNT_FAIL + bool "Format SPIFFS if mounting fails" + default n + help + Format SPIFFS if it fails to mount the filesystem. + + config BSP_SPIFFS_MOUNT_POINT + string "SPIFFS mount point" + default "/spiffs" + help + Mount point of SPIFFS in the Virtual File System. + + config BSP_SPIFFS_PARTITION_LABEL + string "Partition label of SPIFFS" + default "storage" + help + Partition label which stores SPIFFS. + + config BSP_SPIFFS_MAX_FILES + int "Max files supported for SPIFFS VFS" + default 5 + help + Supported max files for SPIFFS in the Virtual File System. + endmenu + +endmenu diff --git a/bsp/esp32_s3_korvo_1/LICENSE b/bsp/esp32_s3_korvo_1/LICENSE new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/bsp/esp32_s3_korvo_1/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/bsp/esp32_s3_korvo_1/README.md b/bsp/esp32_s3_korvo_1/README.md new file mode 100644 index 00000000..6420daa3 --- /dev/null +++ b/bsp/esp32_s3_korvo_1/README.md @@ -0,0 +1,12 @@ +# BSP: ESP32-S3-KORVO-1 + +[![Component Registry](https://components.espressif.com/components/espressif/esp32_s3_korvo_1/badge.svg)](https://components.espressif.com/components/espressif/esp32_s3_korvo_1) + +* [Hardware Reference](https://github.com/espressif/esp-skainet/blob/master/docs/en/hw-reference/esp32s3/user-guide-korvo-1.md) + +![image](https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_s3_korvo_1/pic.png) + +ESP32-S3-Korvo-1 is a development kit that is based on Espressif’s ESP32-S3 SoC. It features a three-microphone array which is suitable for far-field voice pick-up with low power consumption. + +The ESP32-S3-Korvo-1 board consists of two parts: the main board (ESP32-S3-Korvo-1) that integrates the ESP32-S3-WROOM-1 module, function buttons, SD card slot, speaker and USB connectors; and the sub board (ESP32-Korvo-Mic, which is also used as the sub board in ESP32-Korvo v1.1) that contains a three-microphone array, function buttons, and addressable LEDs. The main board and sub board are connected via FPC cable. + diff --git a/bsp/esp32_s3_korvo_1/esp32_s3_korvo_1.c b/bsp/esp32_s3_korvo_1/esp32_s3_korvo_1.c new file mode 100644 index 00000000..df18bde0 --- /dev/null +++ b/bsp/esp32_s3_korvo_1/esp32_s3_korvo_1.c @@ -0,0 +1,198 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "esp_err.h" +#include "esp_log.h" + +#include "iot_button.h" +#include "bsp/esp-bsp.h" +#include "bsp_err_check.h" +#include "esp_spiffs.h" +#include "led_indicator.h" + +static const char *TAG = "S3-Korvo-1"; + +/** + * @brief led configuration structure + * + * This configuration is used by default in bsp_led_init() + */ + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) +static adc_oneshot_unit_handle_t bsp_adc_handle = NULL; +#endif + +extern blink_step_t const *bsp_led_blink_defaults_lists[]; + +static const button_config_t bsp_button_config[BSP_BUTTON_NUM] = { + { + .type = BUTTON_TYPE_ADC, + .adc_button_config.adc_channel = ADC_CHANNEL_7, // ADC1 channel 7 is GPIO8 +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + .adc_button_config.adc_handle = &bsp_adc_handle, +#endif + .adc_button_config.button_index = BSP_BUTTON_REC, + .adc_button_config.min = 2310, // middle is 2410mV + .adc_button_config.max = 2510, + }, + { + .type = BUTTON_TYPE_ADC, +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + .adc_button_config.adc_handle = &bsp_adc_handle, +#endif + .adc_button_config.adc_channel = ADC_CHANNEL_7, // ADC1 channel 7 is GPIO8 + .adc_button_config.button_index = BSP_BUTTON_MODE, + .adc_button_config.min = 1880, // middle is 1980mV + .adc_button_config.max = 2080, + }, + { + .type = BUTTON_TYPE_ADC, +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + .adc_button_config.adc_handle = &bsp_adc_handle, +#endif + .adc_button_config.adc_channel = ADC_CHANNEL_7, // ADC1 channel 7 is GPIO8 + .adc_button_config.button_index = BSP_BUTTON_PLAY, + .adc_button_config.min = 1560, // middle is 1660mV + .adc_button_config.max = 1760, + }, + { + .type = BUTTON_TYPE_ADC, +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + .adc_button_config.adc_handle = &bsp_adc_handle, +#endif + .adc_button_config.adc_channel = ADC_CHANNEL_7, // ADC1 channel 7 is GPIO8 + .adc_button_config.button_index = BSP_BUTTON_SET, + .adc_button_config.min = 1010, // middle is 1100mV + .adc_button_config.max = 1210, + }, + { + .type = BUTTON_TYPE_ADC, +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + .adc_button_config.adc_handle = &bsp_adc_handle, +#endif + .adc_button_config.adc_channel = ADC_CHANNEL_7, // ADC1 channel 7 is GPIO8 + .adc_button_config.button_index = BSP_BUTTON_VOLDOWN, + .adc_button_config.min = 720, // middle is 820mV + .adc_button_config.max = 920, + }, + { + .type = BUTTON_TYPE_ADC, +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + .adc_button_config.adc_handle = &bsp_adc_handle, +#endif + .adc_button_config.adc_channel = ADC_CHANNEL_7, // ADC1 channel 7 is GPIO8 + .adc_button_config.button_index = BSP_BUTTON_VOLUP, + .adc_button_config.min = 280, // middle is 380mV + .adc_button_config.max = 480, + } +}; + +esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int btn_array_size) +{ + esp_err_t ret = ESP_OK; + if ((btn_array_size < BSP_BUTTON_NUM) || + (btn_array == NULL)) { + return ESP_ERR_INVALID_ARG; + } +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + /* Initialize ADC and get ADC handle */ + BSP_ERROR_CHECK_RETURN_NULL(bsp_adc_initialize()); + bsp_adc_handle = bsp_adc_get_handle(); +#endif + + if (btn_cnt) { + *btn_cnt = 0; + } + for (int i = 0; i < BSP_BUTTON_NUM; i++) { + btn_array[i] = iot_button_create(&bsp_button_config[i]); + if (btn_array[i] == NULL) { + ret = ESP_FAIL; + break; + } + if (btn_cnt) { + (*btn_cnt)++; + } + } + return ret; +} + +static const led_strip_config_t bsp_leds_rgb_strip_config = { + .strip_gpio_num = BSP_LED_RGB_GPIO, // The GPIO that connected to the LED strip's data line + .max_leds = BSP_LED_NUM, // The number of LEDs in the strip, + .led_pixel_format = LED_PIXEL_FORMAT_GRB, // Pixel format of your LED strip + .led_model = LED_MODEL_WS2812, // LED strip model + .flags.invert_out = false, // whether to invert the output signal +}; + +static const led_strip_rmt_config_t bsp_leds_rgb_rmt_config = { +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) + .rmt_channel = 0, +#else + .clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption + .resolution_hz = 10 * 1000 * 1000, // RMT counter clock frequency = 10MHz + .flags.with_dma = false, // DMA feature is available on ESP target like ESP32-S3 +#endif +}; + +static led_indicator_strips_config_t bsp_leds_rgb_config = { + .is_active_level_high = 1, + .led_strip_cfg = bsp_leds_rgb_strip_config, + .led_strip_driver = LED_STRIP_RMT, + .led_strip_rmt_cfg = bsp_leds_rgb_rmt_config, +}; + +static const led_indicator_config_t bsp_leds_config = { + .mode = LED_STRIPS_MODE, + .led_indicator_strips_config = &bsp_leds_rgb_config, + .blink_lists = bsp_led_blink_defaults_lists, + .blink_list_num = BSP_LED_MAX, +}; + +esp_err_t bsp_led_indicator_create(led_indicator_handle_t led_array[], int *led_cnt, int led_array_size) +{ + if (led_array == NULL) { + return ESP_ERR_INVALID_ARG; + } + + led_array[0] = led_indicator_create(&bsp_leds_config); + if (led_array[0] == NULL) { + return ESP_FAIL; + } + return ESP_OK; +} + +esp_err_t bsp_spiffs_mount(void) +{ + esp_vfs_spiffs_conf_t conf = { + .base_path = CONFIG_BSP_SPIFFS_MOUNT_POINT, + .partition_label = CONFIG_BSP_SPIFFS_PARTITION_LABEL, + .max_files = CONFIG_BSP_SPIFFS_MAX_FILES, +#ifdef CONFIG_BSP_SPIFFS_FORMAT_ON_MOUNT_FAIL + .format_if_mount_failed = true, +#else + .format_if_mount_failed = false, +#endif + }; + + esp_err_t ret_val = esp_vfs_spiffs_register(&conf); + + BSP_ERROR_CHECK_RETURN_ERR(ret_val); + + size_t total = 0, used = 0; + ret_val = esp_spiffs_info(conf.partition_label, &total, &used); + if (ret_val != ESP_OK) { + ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret_val)); + } else { + ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used); + } + + return ret_val; +} + +esp_err_t bsp_spiffs_unmount(void) +{ + return esp_vfs_spiffs_unregister(CONFIG_BSP_SPIFFS_PARTITION_LABEL); +} diff --git a/bsp/esp32_s3_korvo_1/esp32_s3_korvo_1_idf4.c b/bsp/esp32_s3_korvo_1/esp32_s3_korvo_1_idf4.c new file mode 100644 index 00000000..7102eda8 --- /dev/null +++ b/bsp/esp32_s3_korvo_1/esp32_s3_korvo_1_idf4.c @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "esp_err.h" +#include "bsp/esp32_s3_korvo_1.h" +#include "bsp_err_check.h" +#include "esp_adc_cal.h" + +static esp_adc_cal_characteristics_t bsp_adc_chars; + +esp_err_t bsp_adc_initialize(void) +{ + esp_err_t ret = ESP_OK; + BSP_ERROR_CHECK_RETURN_ERR(esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_TP_FIT)); + esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_DEFAULT, 0, &bsp_adc_chars); + + /* ADC1 config */ + BSP_ERROR_CHECK_RETURN_ERR(adc1_config_width(ADC_WIDTH_BIT_DEFAULT)); + return ret; +} diff --git a/bsp/esp32_s3_korvo_1/esp32_s3_korvo_1_idf5.c b/bsp/esp32_s3_korvo_1/esp32_s3_korvo_1_idf5.c new file mode 100644 index 00000000..83d23f4b --- /dev/null +++ b/bsp/esp32_s3_korvo_1/esp32_s3_korvo_1_idf5.c @@ -0,0 +1,35 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "esp_err.h" +#include "esp_adc/adc_oneshot.h" +#include "bsp/esp32_s3_korvo_1.h" +#include "bsp_err_check.h" + +static const char *TAG = "S3-KORVO-1"; + +static adc_oneshot_unit_handle_t bsp_adc_handle = NULL; + +esp_err_t bsp_adc_initialize(void) +{ + /* ADC was initialized before */ + if (bsp_adc_handle != NULL) { + return ESP_OK; + } + + /* Initialize ADC */ + const adc_oneshot_unit_init_cfg_t init_config1 = { + .unit_id = BSP_ADC_UNIT, + }; + BSP_ERROR_CHECK_RETURN_ERR(adc_oneshot_new_unit(&init_config1, &bsp_adc_handle)); + + return ESP_OK; +} + +adc_oneshot_unit_handle_t bsp_adc_get_handle(void) +{ + return bsp_adc_handle; +} diff --git a/bsp/esp32_s3_korvo_1/idf_component.yml b/bsp/esp32_s3_korvo_1/idf_component.yml new file mode 100644 index 00000000..86edd804 --- /dev/null +++ b/bsp/esp32_s3_korvo_1/idf_component.yml @@ -0,0 +1,17 @@ +version: "1.0.0" +description: Board Support Package for ESP32-S3-KORVO-1 +url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_s3_korvo_1 + +targets: + - esp32s3 + +dependencies: + idf: ">=4.4" + + led_indicator: + version: "^0.7" + public: true + + button: + version: "^2" + public: true diff --git a/bsp/esp32_s3_korvo_1/include/bsp/esp-bsp.h b/bsp/esp32_s3_korvo_1/include/bsp/esp-bsp.h new file mode 100644 index 00000000..013e8964 --- /dev/null +++ b/bsp/esp32_s3_korvo_1/include/bsp/esp-bsp.h @@ -0,0 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once +#include "bsp/esp32_s3_korvo_1.h" diff --git a/bsp/esp32_s3_korvo_1/include/bsp/esp32_s3_korvo_1.h b/bsp/esp32_s3_korvo_1/include/bsp/esp32_s3_korvo_1.h new file mode 100644 index 00000000..ac9a3975 --- /dev/null +++ b/bsp/esp32_s3_korvo_1/include/bsp/esp32_s3_korvo_1.h @@ -0,0 +1,179 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +/** + * @file + * @brief ESP BSP: ESP32-S3-Korvo-1 + */ + +#pragma once + +#include "iot_button.h" +#include "led_indicator.h" + +/************************************************************************************************** + * ESP32-S3-Korvo-1 pinout + **************************************************************************************************/ + +/* Leds */ +#define BSP_LED_RGB_GPIO (GPIO_NUM_19) +#define BSP_LED_NUM (12) + +/* Buttons */ +#define BSP_BUTTONS_IO (GPIO_NUM_8) // All 6 buttons mapped to this GPIO + +#ifdef __cplusplus +extern "C" { +#endif + +/* Default LED effects */ +enum { + BSP_LED_ON, + BSP_LED_OFF, + BSP_LED_BLINK_FAST, + BSP_LED_BLINK_SLOW, + BSP_LED_BREATHE_FAST, + BSP_LED_BREATHE_SLOW, + BSP_LED_MAX, +}; + +/************************************************************************************************** + * + * Buttons interface + * + * Example configuration: + * \code{.c} + * button_handle_t btns[BSP_BUTTON_NUM]; + * bsp_iot_button_create(btns, NULL, BSP_BUTTON_NUM); + * iot_button_register_cb(btns[0], ... + * \endcode + **************************************************************************************************/ +typedef enum { + BSP_BUTTON_REC = 0, + BSP_BUTTON_MODE, + BSP_BUTTON_PLAY, + BSP_BUTTON_SET, + BSP_BUTTON_VOLDOWN, + BSP_BUTTON_VOLUP, + BSP_BUTTON_NUM, +} bsp_button_t; + +/************************************************************************************************** + * + * ADC interface + * + * There are multiple devices connected to ADC peripheral: + * - Buttons + * + * After initialization of ADC, use adc_handle when using ADC driver. + **************************************************************************************************/ + +#define BSP_ADC_UNIT ADC_UNIT_1 + +/** + * @brief Initialize ADC + * + * The ADC can be initialized inside BSP, when needed. + * + * @param[out] adc_handle Returned ADC handle + */ +esp_err_t bsp_adc_initialize(void); + + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) +/** + * @brief Get ADC handle + * + * @note This function is available only in IDF5 and higher + * + * @return ADC handle + */ +adc_oneshot_unit_handle_t bsp_adc_get_handle(void); +#endif + +/************************************************************************************************** + * + * Buttons + * + **************************************************************************************************/ + +/** + * @brief Initialize all buttons + * + * Returned button handlers must be used with espressif/button component API + * + * @param[out] btn_array Output button array + * @param[out] btn_cnt Number of button handlers saved to btn_array, can be NULL + * @param[in] btn_array_size Size of output button array. Must be at least BSP_BUTTON_NUM + * @return + * - ESP_OK All buttons initialized + * - ESP_ERR_INVALID_ARG btn_array is too small or NULL + * - ESP_FAIL Underlaying iot_button_create failed + */ +esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int btn_array_size); + +/************************************************************************************************** + * + * LEDs + * + **************************************************************************************************/ + +/** + * @brief Initialize all LEDs + * + * @note `led_cnt` and `led_array_size` unused, only one config needed to control the leds + * + * @param[out] led_array Output LED array + * @param[out] led_cnt Number of LED handlers saved to led_array, can be NULL + * @param[in] led_array_size Size of output LED array. Must be at least BSP_LED_NUM + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t bsp_led_indicator_create(led_indicator_handle_t led_array[], int *led_cnt, int led_array_size); + +/************************************************************************************************** + * + * SPIFFS + * + * After mounting the SPIFFS, it can be accessed with stdio functions ie.: + * \code{.c} + * FILE* f = fopen(BSP_SPIFFS_MOUNT_POINT"/hello.txt", "w"); + * fprintf(f, "Hello World!\n"); + * fclose(f); + * \endcode + **************************************************************************************************/ +#define BSP_SPIFFS_MOUNT_POINT CONFIG_BSP_SPIFFS_MOUNT_POINT + +/** + * @brief Mount SPIFFS to virtual file system + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_STATE if esp_vfs_spiffs_register was already called + * - ESP_ERR_NO_MEM if memory can not be allocated + * - ESP_FAIL if partition can not be mounted + * - other error codes + */ +esp_err_t bsp_spiffs_mount(void); + +/** + * @brief Unmount SPIFFS from virtual file system + * + * @return + * - ESP_OK on success + * - ESP_ERR_NOT_FOUND if the partition table does not contain SPIFFS partition with given label + * - ESP_ERR_INVALID_STATE if esp_vfs_spiffs_unregister was already called + * - ESP_ERR_NO_MEM if memory can not be allocated + * - ESP_FAIL if partition can not be mounted + * - other error codes + */ +esp_err_t bsp_spiffs_unmount(void); + +#ifdef __cplusplus +} +#endif diff --git a/bsp/esp32_s3_korvo_1/led_blink_defaults.c b/bsp/esp32_s3_korvo_1/led_blink_defaults.c new file mode 100644 index 00000000..8ab022c8 --- /dev/null +++ b/bsp/esp32_s3_korvo_1/led_blink_defaults.c @@ -0,0 +1,83 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "led_indicator.h" +#include "bsp/esp-bsp.h" + +/*********************************** Config Blink List ***********************************/ +/** + * @brief LED on + * + */ +static const blink_step_t bsp_led_on[] = { + {LED_BLINK_HOLD, LED_STATE_ON, 0}, + {LED_BLINK_STOP, 0, 0}, +}; + +/** + * @brief LED off + * + */ +static const blink_step_t bsp_led_off[] = { + {LED_BLINK_HOLD, LED_STATE_OFF, 0}, + {LED_BLINK_STOP, 0, 0}, +}; + +/** + * @brief LED blink fast + * + */ +static const blink_step_t bsp_led_blink_fast[] = { + {LED_BLINK_HOLD, LED_STATE_ON, 500}, + {LED_BLINK_HOLD, LED_STATE_OFF, 500}, + {LED_BLINK_LOOP, 0, 0}, +}; + +/** + * @brief LED blink slow + * + */ +static const blink_step_t bsp_led_blink_slow[] = { + {LED_BLINK_HOLD, LED_STATE_ON, 1000}, + {LED_BLINK_HOLD, LED_STATE_OFF, 1000}, + {LED_BLINK_LOOP, 0, 0}, +}; + +/** + * @brief LED breathe fast + * + */ +static const blink_step_t bsp_led_breathe_fast[] = { + {LED_BLINK_BREATHE, LED_STATE_ON, 500}, + {LED_BLINK_HOLD, LED_STATE_ON, 500}, + {LED_BLINK_BREATHE, LED_STATE_OFF, 500}, + {LED_BLINK_HOLD, LED_STATE_OFF, 500}, + {LED_BLINK_LOOP, 0, 0}, +}; + +/** + * @brief LED breathe slow + * + */ +static const blink_step_t bsp_led_breathe_slow[] = { + {LED_BLINK_BREATHE, LED_STATE_OFF, 2000}, + {LED_BLINK_BREATHE, LED_STATE_ON, 2000}, + {LED_BLINK_LOOP, 0, 0}, +}; + +/** + * @brief LED blink lists + * + */ +blink_step_t const *bsp_led_blink_defaults_lists[] = { + [BSP_LED_ON] = bsp_led_on, + [BSP_LED_OFF] = bsp_led_off, + [BSP_LED_BLINK_FAST] = bsp_led_blink_fast, + [BSP_LED_BLINK_SLOW] = bsp_led_blink_slow, + [BSP_LED_BREATHE_FAST] = bsp_led_breathe_fast, + [BSP_LED_BREATHE_SLOW] = bsp_led_breathe_slow, + [BSP_LED_MAX] = NULL, +}; diff --git a/bsp/esp32_s3_korvo_1/pic.png b/bsp/esp32_s3_korvo_1/pic.png new file mode 100644 index 00000000..4d59722e Binary files /dev/null and b/bsp/esp32_s3_korvo_1/pic.png differ diff --git a/bsp/esp32_s3_korvo_1/priv_include/bsp_err_check.h b/bsp/esp32_s3_korvo_1/priv_include/bsp_err_check.h new file mode 100644 index 00000000..50e9998e --- /dev/null +++ b/bsp/esp32_s3_korvo_1/priv_include/bsp_err_check.h @@ -0,0 +1,64 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "esp_check.h" +#include "sdkconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Assert on error, if selected in menuconfig. Otherwise return error code. */ +#if CONFIG_BSP_ERROR_CHECK +#define BSP_ERROR_CHECK_RETURN_ERR(x) ESP_ERROR_CHECK(x) +#define BSP_ERROR_CHECK_RETURN_NULL(x) ESP_ERROR_CHECK(x) +#define BSP_ERROR_CHECK(x, ret) ESP_ERROR_CHECK(x) +#define BSP_NULL_CHECK(x, ret) assert(x) +#define BSP_NULL_CHECK_GOTO(x, goto_tag) assert(x) +#else +#define BSP_ERROR_CHECK_RETURN_ERR(x) do { \ + esp_err_t err_rc_ = (x); \ + if (unlikely(err_rc_ != ESP_OK)) { \ + return err_rc_; \ + } \ + } while(0) + +#define BSP_ERROR_CHECK_RETURN_NULL(x) do { \ + if (unlikely((x) != ESP_OK)) { \ + return NULL; \ + } \ + } while(0) + +#define BSP_NULL_CHECK(x, ret) do { \ + if ((x) == NULL) { \ + return ret; \ + } \ + } while(0) + +#define BSP_ERROR_CHECK(x, ret) do { \ + if (unlikely((x) != ESP_OK)) { \ + return ret; \ + } \ + } while(0) + +#define BSP_NULL_CHECK(x, ret) do { \ + if ((x) == NULL) { \ + return ret; \ + } \ + } while(0) + +#define BSP_NULL_CHECK_GOTO(x, goto_tag) do { \ + if ((x) == NULL) { \ + goto goto_tag; \ + } \ + } while(0) +#endif + +#ifdef __cplusplus +} +#endif diff --git a/docu/pics/esp32_s3_korvo_1.png b/docu/pics/esp32_s3_korvo_1.png new file mode 100644 index 00000000..99b2a80d Binary files /dev/null and b/docu/pics/esp32_s3_korvo_1.png differ diff --git a/examples/bsp_ext.py b/examples/bsp_ext.py index ef083380..858ea0e7 100644 --- a/examples/bsp_ext.py +++ b/examples/bsp_ext.py @@ -56,6 +56,7 @@ def set_bsp_callback(action: str, ctx: Context, args: PropertyDict, **kwargs: st 'esp-box-3', 'esp32_c3_lcdkit', 'esp_bsp_generic', + 'esp32_s3_korvo_1', } if bsp == '': return