Browse Source

init

master
POMIN-163 7 months ago
parent
commit
7c435919c7
  1. 54
      .gitignore
  2. 17
      .vscode/build-esp32.ps1
  3. 24
      .vscode/build-keil.ps1
  4. 5
      .vscode/build-stm32.ps1
  5. 66
      .vscode/mcu.h
  6. 3
      .vscode/settings.json
  7. 9
      CMakeLists.txt
  8. 9
      Makefile
  9. 81
      Proj.code-workspace
  10. 5
      components/board/CMakeLists.txt
  11. 99
      components/board/board.c
  12. 3
      components/board/component.mk
  13. 36
      components/board/include/board.h
  14. 87
      components/board/include/board_kaluga_v1_1.h
  15. 82
      components/board/include/board_kaluga_v1_2.h
  16. 81
      components/board/include/board_kaluga_v1_3.h
  17. 6
      components/es8311/CMakeLists.txt
  18. 0
      components/es8311/component.mk
  19. 549
      components/es8311/es8311.c
  20. 173
      components/es8311/include/es8311.h
  21. 22
      components/esp_tts/CMakeLists.txt
  22. 74
      components/esp_tts/README.md
  23. 76
      components/esp_tts/README_en.md
  24. BIN
      components/esp_tts/chinese TTS.png
  25. 11
      components/esp_tts/component.mk
  26. BIN
      components/esp_tts/img/esp_chinese_tts.png
  27. 112
      components/esp_tts/include/esp_tts.h
  28. 25
      components/esp_tts/include/esp_tts_parser.h
  29. 67
      components/esp_tts/include/esp_tts_player.h
  30. 48
      components/esp_tts/include/esp_tts_stretcher.h
  31. 18
      components/esp_tts/include/esp_tts_voice.h
  32. 5
      components/esp_tts/include/esp_tts_voice_female_digits.h
  33. 5
      components/esp_tts/include/esp_tts_voice_xiaole.h
  34. BIN
      components/esp_tts/libspeech_synthesis.a
  35. BIN
      components/esp_tts/libspeech_synthesis_esp32s2.a
  36. BIN
      components/esp_tts/libvoice_set_xiaole.a
  37. BIN
      components/esp_tts/libvoice_set_xiaole_esp32s2.a
  38. BIN
      components/esp_tts/samples/S1_xiaole_speed0.wav
  39. BIN
      components/esp_tts/samples/S1_xiaole_speed4.wav
  40. BIN
      components/esp_tts/samples/S2_xiaole_speed0.wav
  41. BIN
      components/esp_tts/samples/S2_xiaole_speed4.wav
  42. BIN
      components/esp_tts/samples/S3_xiaole_speed0.wav
  43. BIN
      components/esp_tts/samples/S3_xiaole_speed4.wav
  44. 5
      components/helix/CMakeLists.txt
  45. 7
      components/helix/component.mk
  46. 428
      components/helix/include/assembly.h
  47. 307
      components/helix/include/coder.h
  48. 123
      components/helix/include/mp3common.h
  49. 138
      components/helix/include/mp3dec.h
  50. 108
      components/helix/include/mpadecobjfixpt.h
  51. 88
      components/helix/include/statname.h
  52. 405
      components/helix/src/bitstream.c
  53. 171
      components/helix/src/buffers.c
  54. 279
      components/helix/src/dct32.c
  55. 158
      components/helix/src/dequant.c
  56. 374
      components/helix/src/dqchan.c
  57. 458
      components/helix/src/huffman.c
  58. 755
      components/helix/src/hufftabs.c
  59. 780
      components/helix/src/imdct.c
  60. 421
      components/helix/src/mp3dec.c
  61. 188
      components/helix/src/mp3tabs.c
  62. 295
      components/helix/src/polyphase.c
  63. 390
      components/helix/src/scalfact.c
  64. 297
      components/helix/src/stproc.c
  65. 99
      components/helix/src/subband.c
  66. 312
      components/helix/src/trigtabs.c
  67. 5
      components/i2c_bus/CMakeLists.txt
  68. 0
      components/i2c_bus/component.mk
  69. 100
      components/i2c_bus/i2c_bus.c
  70. 34
      components/i2c_bus/include/i2c_bus.h
  71. 5
      components/lcd/CMakeLists.txt
  72. 0
      components/lcd/component.mk
  73. 69
      components/lcd/include/lcd.h
  74. 678
      components/lcd/lcd.c
  75. 8
      components/led_strip/CMakeLists.txt
  76. 3
      components/led_strip/component.mk
  77. 126
      components/led_strip/include/led_strip.h
  78. 171
      components/led_strip/src/led_strip_rmt_ws2812.c
  79. BIN
      datasheet/Audio_ES8311.pdf
  80. BIN
      datasheet/Camera_OV2640.pdf
  81. BIN
      datasheet/LCD_ST7789.pdf
  82. 3
      dependencies.lock
  83. 9
      examples/adc_button/CMakeLists.txt
  84. 9
      examples/adc_button/Makefile
  85. 104
      examples/adc_button/README_cn.md
  86. 3
      examples/adc_button/main/CMakeLists.txt
  87. 14
      examples/adc_button/main/Kconfig.projbuild
  88. 5
      examples/adc_button/main/component.mk
  89. 171
      examples/adc_button/main/main.c
  90. 1353
      examples/adc_button/sdkconfig
  91. 1393
      examples/adc_button/sdkconfig.old
  92. 12
      examples/camera/CMakeLists.txt
  93. 9
      examples/camera/Makefile
  94. 174
      examples/camera/README_cn.md
  95. 3
      examples/camera/main/CMakeLists.txt
  96. 41
      examples/camera/main/Kconfig.projbuild
  97. 5
      examples/camera/main/component.mk
  98. 121
      examples/camera/main/main.c
  99. 13
      examples/camera/sdkconfig.defaults
  100. BIN
      examples/factory/boot_animation_ILI9341_80M_v1.3.bin

54
.gitignore

@ -0,0 +1,54 @@
# 正在开发
# 闭源内容
Awtrix Finally.pcbdoc
# 无关内容
/index.html
/Desktop.ini
# 编译垃圾
out/
obj/
Lst/
Obj/
OUT/
OBJ/
Objects/
Listings/
DebugConfig/
build/
old/
*.log
*.POMIN
*.bak
*.ddk
*.edk
*.lst
*.lnp
*.mpf
*.mpj
*.obj
*.omf
*.o
*.plg
*.rpt
*.tmp
*.__i
*.crf
*.o
*.d
*.tra
*.dep
*.iex
*.htm
*.sct
*.map

17
.vscode/build-esp32.ps1

@ -0,0 +1,17 @@
echo ""
echo "idf.py.exe build"
echo ""
idf.py.exe build
echo ""
echo "idf.py.exe --port com24 --baud 921600 flash"
echo ""
idf.py.exe --port com24 --baud 921600 flash
echo ""
echo "idf.py.exe --port com24 --monitor-baud 921600 monitor"
echo ""
idf.py.exe --port com24 --baud 921600 monitor

24
.vscode/build-keil.ps1

@ -0,0 +1,24 @@
$UV="D:\Maker\keil5\UV4\UV4.exe"
$UV_PROJ_PATH=".\code.uvproj"
echo building
echo "" > .\build_log.txt
cmd /c "$UV -j0 -b $UV_PROJ_PATH -o .\build_log.txt"
cat .\build_log.txt
echo downloading
echo "" > .\download_log.txt
cmd /c "$UV -j0 -f $UV_PROJ_PATH -o .\download_log.txt"
cat .\download_log.txt
cmd /c "del .\build_log.txt"
cmd /c "del .\download_log.txt"
echo done...

5
.vscode/build-stm32.ps1

@ -0,0 +1,5 @@
cd Debug
make -j8 all

66
.vscode/mcu.h

@ -0,0 +1,66 @@
/**
* @author: Pomin
* @date: 2022-03-04 19:07:06
* @github: https://github.com/POMIN-163
* @lastedit: 2022-03-05 11:04:21
* @description: MCU
**/
#ifndef M_C_U___
#define M_C_U___
#ifdef USE_VSCODE
#ifdef c51
#define __C51__
#define __VSCODE_C51__
#define reentrant
#define compact
#define small
#define large
#define data
#define idata
#define pdata
#define bdata
#define xdata
#define code
#define bit char
#define sbit char
#define sfr char
#define sfr16 int
#define sfr32 int
#define interrupt
#define using
#define _at_
#define _priority_
#define _task_
#endif
#ifdef tcxxx
#define __TASKING__
#define __attribute__(n)
#define __interrupt(n)
#define __vector_table(vectabNum)
#define __sfrbit16 short
#define __sfrbit32 int
#define __fract
#define __sfract
#define __laccum
#endif
#ifdef rt1064
#define CPU_MIMXRT1064DVL6A
#define SKIP_SYSCLK_INIT
#define XIP_EXTERNAL_FLASH 1
#define XIP_BOOT_HEADER_DCD_ENABLE 1
#define XIP_BOOT_HEADER_ENABLE 1
#define PRINTF_FLOAT_ENABLE 1
#define SCANF_FLOAT_ENABLE 1
#define PRINTF_ADVANCED_ENABLE 1
#define SCANF_ADVANCED_ENABLE 1
#define FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ 0
#define USB_STACK_BM
#endif
#endif
#endif

3
.vscode/settings.json

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

9
CMakeLists.txt

@ -0,0 +1,9 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
set(EXTRA_COMPONENT_DIRS "components/led_strip")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_compile_options (-fdiagnostics-color=always)
project(esp32-s2-hmi)

9
Makefile

@ -0,0 +1,9 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := esp32-s2-hmi
include $(IDF_PATH)/make/project.mk

81
Proj.code-workspace

@ -0,0 +1,81 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
/* 文件排除 */
"files.exclude": {
// 文件夹
"**/.settings": true,
"**/Debug": true,
"**/Objects": true,
"**/objects": true,
"**/Listings": true,
"**/listings": true,
"**/Output": true,
"**/output": true,
// 文件
"**/*.map":true,
"**/.config*":true,
"**/.project*":true,
"**/.cproject*":true,
},
/* 编码 */
"files.encoding": "utf8",
/* 字体 */
"editor.fontFamily": "Consolas, OPPOSans",
/* 自定义 Shell */
"terminal.integrated.profiles.windows": {
"ESP-IDF": {
"source": "PowerShell",
"icon": "terminal",
"args": [
"-noe",
"-nologo",
"espidf.ps1"
]
}
},
"C_Cpp.errorSquiggles": "Disabled",
/* 默认 Shell */
"terminal.integrated.defaultProfile.windows": "ESP-IDF",
/* 代码风格 */
"C_Cpp.clang_format_style": "{ BasedOnStyle: Google, IndentWidth: 4 }",
/* 补全模式 */
"C_Cpp.default.intelliSenseMode": "gcc-x86",
/* c/cpp 标准 */
"C_Cpp.default.cppStandard": "c++14",
"C_Cpp.default.cStandard": "c99",
/* c/cpp 宏 */
"C_Cpp.default.defines": [],
/*//!自定义编译器路径 ( 实现补全时 gcc 类编译器只需指定编译器路径与工程目录的包含 ) */
"idf.path" : "F:/MyEnv/esp_env/esp-idf-v4.4",
"idf.tools" : "F:/MyEnv/esp_env/idf_env/tools",
"idf.gcc.varsion" : "esp-2021r1-8.4.0",
"idf.patch.version" : "esp-2021r2-patch2-8.4.0",
"idf.tools.esp32" : "${config:idf.tools}/xtensa-esp32-elf",
"idf.tools.esp32rv" : "${config:idf.tools}/riscv32-esp-elf",
"idf.tools.esp32s2" : "${config:idf.tools}/xtensa-esp32s2-elf",
"idf.tools.esp32s3" : "${config:idf.tools}/xtensa-esp32s3-elf",
"idf.gcc.esp32" : "${config:idf.tools.esp32}/${config:idf.patch.version}/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc.exe",
"idf.gcc.esp32rv" : "${config:idf.tools.esp32rv}/${config:idf.patch.version}/riscv32-esp-elf/bin/riscv32-esp-elf-gcc.exe",
"idf.gcc.esp32s2" : "${config:idf.tools.esp32s2}/${config:idf.patch.version}/xtensa-esp32s2-elf/bin/xtensa-esp32s2-elf-gcc.exe",
"idf.gcc.esp32s3" : "${config:idf.tools.esp32s3}/${config:idf.patch.version}/xtensa-esp32s3-elf/bin/xtensa-esp32s3-elf-gcc.exe",
"C_Cpp.default.compilerPath": "${config:idf.gcc.esp32s2}",
/* c/cpp 包含 */
"C_Cpp.default.includePath": [
"${workspaceFolder}/**"
],
"C_Cpp.default.forcedInclude": [
],
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
},
}

5
components/board/CMakeLists.txt

@ -0,0 +1,5 @@
set(COMPONENT_ADD_INCLUDEDIRS include)
set(COMPONENT_PRIV_INCLUDEDIRS "include")
set(COMPONENT_SRCS "board.c")
register_component()

99
components/board/board.c

@ -0,0 +1,99 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "board.h"
#include "esp_log.h"
#include "esp_err.h"
static const char *TAG = "board_verison";
esp_err_t kaluga_board_verison(void)
{
bool ret = false;
/*!< main PAD */
#ifdef CONFIG_ESP32_S2_KALUGA_V1_3
ESP_LOGI(TAG, "main pad:v1.3");
ret = true;
#endif
#ifdef CONFIG_ESP32_S2_KALUGA_V1_2
ESP_LOGI(TAG, "main pad:v1.2");
ret = true;
#endif
#ifdef CONFIG_ESP32_S2_KALUGA_V1_1
ESP_LOGI(TAG, "main pad:v1.1");
ret = true;
#endif
/*!< aduio PAD */
#ifdef CONFIG_AUDIO_PAD_ESP32_S2_KALUGA_V1_3
ESP_LOGI(TAG, "audio pad:v1.3");
ret = true;
#endif
#ifdef CONFIG_AUDIO_PAD_ESP32_S2_KALUGA_V1_2
ESP_LOGI(TAG, "audio pad:v1.2");
ret = true;
#endif
#ifdef CONFIG_AUDIO_PAD_ESP32_S2_KALUGA_V1_1
ESP_LOGI(TAG, "aduio pad:v1.1");
ret = true;
#endif
/*!< touch PAD */
#ifdef CONFIG_TOUCH_PAD_ESP32_S2_KALUGA_V1_3
ESP_LOGI(TAG, "touch pad:v1.3");
ret = true;
#endif
#ifdef CONFIG_TOUCH_PAD_ESP32_S2_KALUGA_V1_2
ESP_LOGI(TAG, "touch pad:v1.2");
ret = true;
#endif
#ifdef CONFIG_TOUCH_PAD_ESP32_S2_KALUGA_V1_2
ESP_LOGI(TAG, "touch pad:v1.1");
ret = true;
#endif
/*!< camera PAD */
#ifdef CONFIG_CAMERA_PAD_ESP32_S2_KALUGA_V1_3
ESP_LOGI(TAG, "camera pad:v1.3");
ret = true;
#endif
#ifdef CONFIG_CAMERA_PAD_ESP32_S2_KALUGA_V1_2
ESP_LOGI(TAG, "camera pad:v1.2");
ret = true;
#endif
#ifdef CONFIG_CAMERA_PAD_ESP32_S2_KALUGA_V1_1
ESP_LOGI(TAG, "camera pad:v1.1");
ret = true;
#endif
/*!< LCD PAD */
#ifdef CONFIG_LCD_PAD_ESP32_S2_KALUGA_V1_3
ESP_LOGI(TAG, "LED pad:v1.3");
ret = true;
#endif
#ifdef CONFIG_LCD_PAD_ESP32_S2_KALUGA_V1_2
ESP_LOGI(TAG, "LED pad:v1.2");
ret = true;
#endif
#ifdef CONFIG_LCD_PAD_ESP32_S2_KALUGA_V1_1
ESP_LOGI(TAG, "LED pad:v1.1");
ret = true;
#endif
if (ret == false) {
ESP_LOGE(TAG, "No board is defined");
return ESP_FAIL;
} else {
return ESP_OK;
}
}

3
components/board/component.mk

@ -0,0 +1,3 @@
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := src

36
components/board/include/board.h

@ -0,0 +1,36 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_err.h"
#include "board_kaluga_v1_1.h"
#include "board_kaluga_v1_2.h"
#include "board_kaluga_v1_3.h"
/**
* @brief print board version
*
* @return - ESP_OK :Print the board version successfully
* ESP_FAIL: No board is defined
*/
esp_err_t kaluga_board_verison(void);
#ifdef __cplusplus
}
#endif

87
components/board/include/board_kaluga_v1_1.h

@ -0,0 +1,87 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/*
*
*
* ESP32-S2-Kaluga-1 v1.1
*
*
*/
/*!< Touch PAD */
#ifdef CONFIG_TOUCH_PAD_ESP32_S2_KALUGA_V1_1
#define TOUCH_BUTTON_PLAY TOUCH_PAD_NUM8
#define TOUCH_BUTTON_PHOTO TOUCH_PAD_NUM3
#define TOUCH_BUTTON_NETWORK TOUCH_PAD_NUM11
#define TOUCH_BUTTON_RECORD TOUCH_PAD_NUM13
#define TOUCH_BUTTON_VOLUP TOUCH_PAD_NUM2
#define TOUCH_BUTTON_VOLDOWN TOUCH_PAD_NUM9
#define TOUCH_BUTTON_GUARD TOUCH_PAD_NUM1
#define TOUCH_SHELED_ELECT TOUCH_PAD_NUM14
#endif
/*!< Audio PAD */
#ifdef CONFIG_AUDIO_PAD_ESP32_S2_KALUGA_V1_1
#define I2S_MCLK (GPIO_NUM_35)
#define I2S_SCLK (GPIO_NUM_17)
#define I2S_LCLK (GPIO_NUM_18)
#define I2S_DSIN (GPIO_NUM_12)
#define I2C_SCL (GPIO_NUM_7)
#define GPIO_PA_EN (GPIO_NUM_10)
#ifdef CONFIG_TOUCH_PAD_ESP32_S2_KALUGA_V1_1
#define I2S_DOUT (GPIO_NUM_36) /*!< Touch and audio will clash when used */
#define I2C_SDA (GPIO_NUM_37) /*!< together, so you need to change GPIO. */
#else
#define I2S_DOUT (GPIO_NUM_14)
#define I2C_SDA (GPIO_NUM_8)
#endif
#endif
/*!< Camera PAD */
#ifdef CONFIG_CAMERA_PAD_ESP32_S2_KALUGA_V1_1
#define CAM_XCLK GPIO_NUM_1
#define CAM_PCLK GPIO_NUM_0
#define CAM_VSYNC GPIO_NUM_2
#define CAM_HSYNC GPIO_NUM_3
#define CAM_D0 GPIO_NUM_46 /*!< hardware pins: D2 */
#define CAM_D1 GPIO_NUM_45 /*!< hardware pins: D3 */
#define CAM_D2 GPIO_NUM_41 /*!< hardware pins: D4 */
#define CAM_D3 GPIO_NUM_42 /*!< hardware pins: D5 */
#define CAM_D4 GPIO_NUM_39 /*!< hardware pins: D6 */
#define CAM_D5 GPIO_NUM_40 /*!< hardware pins: D7 */
#define CAM_D6 GPIO_NUM_21 /*!< hardware pins: D8 */
#define CAM_D7 GPIO_NUM_38 /*!< hardware pins: D9 */
#define CAM_SCL GPIO_NUM_7
#define CAM_SDA GPIO_NUM_8
#endif
/*!< LCD PAD */
#ifdef CONFIG_LCD_PAD_ESP32_S2_KALUGA_V1_1
#define LCD_CLK GPIO_NUM_15
#define LCD_MOSI GPIO_NUM_9
#define LCD_DC GPIO_NUM_13
#define LCD_RST GPIO_NUM_16
#define LCD_CS GPIO_NUM_11
#define LCD_BK GPIO_NUM_6
#endif
#ifdef __cplusplus
}
#endif

82
components/board/include/board_kaluga_v1_2.h

@ -0,0 +1,82 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/*
*
*
* ESP32-S2-Kaluga-1 v1.2
*
*
*/
/*!< Touch PAD */
#ifdef CONFIG_TOUCH_PAD_ESP32_S2_KALUGA_V1_2
#define TOUCH_BUTTON_PLAY TOUCH_PAD_NUM2
#define TOUCH_BUTTON_PHOTO TOUCH_PAD_NUM6
#define TOUCH_BUTTON_NETWORK TOUCH_PAD_NUM11
#define TOUCH_BUTTON_RECORD TOUCH_PAD_NUM5
#define TOUCH_BUTTON_VOLUP TOUCH_PAD_NUM1
#define TOUCH_BUTTON_VOLDOWN TOUCH_PAD_NUM3
#define TOUCH_BUTTON_GUARD TOUCH_PAD_NUM4
#define TOUCH_SHELED_ELECT TOUCH_PAD_NUM14
#endif
/*!< Audio PAD */
#ifdef CONFIG_AUDIO_PAD_ESP32_S2_KALUGA_V1_2
#define I2S_SCLK (GPIO_NUM_18)
#define I2S_MCLK (GPIO_NUM_35)
#define I2S_LCLK (GPIO_NUM_17)
#define I2S_DOUT (GPIO_NUM_12)
#define I2S_DSIN (GPIO_NUM_46)
#define GPIO_PA_EN (GPIO_NUM_10)
#define I2C_SCL (GPIO_NUM_7)
#define I2C_SDA (GPIO_NUM_8)
#endif
/*!< Camera PAD */
#ifdef CONFIG_CAMERA_PAD_ESP32_S2_KALUGA_V1_2
#define CAM_XCLK GPIO_NUM_1
#define CAM_PCLK GPIO_NUM_33
#define CAM_VSYNC GPIO_NUM_2
#define CAM_HSYNC GPIO_NUM_3
#define CAM_D0 GPIO_NUM_46 /*!< hardware pins: D2 */
#define CAM_D1 GPIO_NUM_45 /*!< hardware pins: D3 */
#define CAM_D2 GPIO_NUM_41 /*!< hardware pins: D4 */
#define CAM_D3 GPIO_NUM_42 /*!< hardware pins: D5 */
#define CAM_D4 GPIO_NUM_39 /*!< hardware pins: D6 */
#define CAM_D5 GPIO_NUM_40 /*!< hardware pins: D7 */
#define CAM_D6 GPIO_NUM_21 /*!< hardware pins: D8 */
#define CAM_D7 GPIO_NUM_38 /*!< hardware pins: D9 */
#define CAM_SCL GPIO_NUM_7
#define CAM_SDA GPIO_NUM_8
#endif
/*!< LCD PAD */
#ifdef CONFIG_LCD_PAD_ESP32_S2_KALUGA_V1_2
#define LCD_CLK GPIO_NUM_15
#define LCD_MOSI GPIO_NUM_9
#define LCD_DC GPIO_NUM_13
#define LCD_RST GPIO_NUM_16
#define LCD_CS GPIO_NUM_11
#define LCD_BK GPIO_NUM_6
#endif
#ifdef __cplusplus
}
#endif

81
components/board/include/board_kaluga_v1_3.h

@ -0,0 +1,81 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/*
*
*
* ESP32-S2-Kaluga-1 v1.3
*
*
*/
/*!< Touch PAD */
#ifdef CONFIG_TOUCH_PAD_ESP32_S2_KALUGA_V1_3
#define TOUCH_BUTTON_PLAY TOUCH_PAD_NUM2
#define TOUCH_BUTTON_PHOTO TOUCH_PAD_NUM6
#define TOUCH_BUTTON_NETWORK TOUCH_PAD_NUM11
#define TOUCH_BUTTON_RECORD TOUCH_PAD_NUM5
#define TOUCH_BUTTON_VOLUP TOUCH_PAD_NUM1
#define TOUCH_BUTTON_VOLDOWN TOUCH_PAD_NUM3
#define TOUCH_BUTTON_GUARD TOUCH_PAD_NUM4
#define TOUCH_SHELED_ELECT TOUCH_PAD_NUM14
#endif
/*!< Audio PAD */
#ifdef CONFIG_AUDIO_PAD_ESP32_S2_KALUGA_V1_3
#define I2S_SCLK (GPIO_NUM_18)
#define I2S_MCLK (GPIO_NUM_35)
#define I2S_LCLK (GPIO_NUM_17)
#define I2S_DOUT (GPIO_NUM_12)
#define I2S_DSIN (GPIO_NUM_34)
#define GPIO_PA_EN (GPIO_NUM_10)
#define I2C_SCL (GPIO_NUM_7)
#define I2C_SDA (GPIO_NUM_8)
#endif
/*!< Camera PAD */
#ifdef CONFIG_CAMERA_PAD_ESP32_S2_KALUGA_V1_3
#define CAM_XCLK GPIO_NUM_1
#define CAM_PCLK GPIO_NUM_33
#define CAM_VSYNC GPIO_NUM_2
#define CAM_HSYNC GPIO_NUM_3
#define CAM_D0 GPIO_NUM_36 /*!< hardware pins: D2 */
#define CAM_D1 GPIO_NUM_37 /*!< hardware pins: D3 */
#define CAM_D2 GPIO_NUM_41 /*!< hardware pins: D4 */
#define CAM_D3 GPIO_NUM_42 /*!< hardware pins: D5 */
#define CAM_D4 GPIO_NUM_39 /*!< hardware pins: D6 */
#define CAM_D5 GPIO_NUM_40 /*!< hardware pins: D7 */
#define CAM_D6 GPIO_NUM_21 /*!< hardware pins: D8 */
#define CAM_D7 GPIO_NUM_38 /*!< hardware pins: D9 */
#define CAM_SCL GPIO_NUM_7
#define CAM_SDA GPIO_NUM_8
#endif
/*!< LCD PAD */
#ifdef CONFIG_LCD_PAD_ESP32_S2_KALUGA_V1_3
#define LCD_CLK GPIO_NUM_15
#define LCD_MOSI GPIO_NUM_9
#define LCD_DC GPIO_NUM_13
#define LCD_RST GPIO_NUM_16
#define LCD_CS GPIO_NUM_11
#define LCD_BK GPIO_NUM_6
#endif
#ifdef __cplusplus
}
#endif

6
components/es8311/CMakeLists.txt

@ -0,0 +1,6 @@
set(COMPONENT_SRCS "es8311.c")
set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_REQUIRES i2c_bus board)
register_component()

0
components/es8311/component.mk

549
components/es8311/es8311.c

@ -0,0 +1,549 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include "es8311.h"
//#include "driver/i2c.h"
#include "driver/gpio.h"
#include "i2c_bus.h"
#include "esp_log.h"
#include "esp_err.h"
#include "board.h"
/* ES8311 address
* 0x32:CE=1;0x30:CE=0
*/
#define ES8311_ADDR 0x18
/*
* to define the clock soure of MCLK
*/
#define FROM_MCLK_PIN 0
#define FROM_SCLK_PIN 1
#define MCLK_SOURCE 1
/*!< MCLK_DIV_FRE is the frequency division coefficient of LRCLK */
#define MCLK_DIV_FRE 32
/*
* to define whether to reverse the clock
*/
#define INVERT_MCLK I2S_MCLK /*!< do not invert */
#define INVERT_SCLK I2S_SCLK
#define IS_DMIC 0 /*!< Is it a digital microphone */
/*
* Clock coefficient structer
*/
struct _coeff_div {
uint32_t mclk; /* mclk frequency */
uint32_t rate; /* sample rate */
uint8_t pre_div; /* the pre divider with range from 1 to 8 */
uint8_t pre_multi; /* the pre multiplier with x1, x2, x4 and x8 selection */
uint8_t adc_div; /* adcclk divider */
uint8_t dac_div; /* dacclk divider */
uint8_t fs_mode; /* double speed or single speed, =0, ss, =1, ds */
uint8_t lrck_h; /* adclrck divider and daclrck divider */
uint8_t lrck_l;
uint8_t bclk_div; /* sclk divider */
uint8_t adc_osr; /* adc osr */
uint8_t dac_osr; /* dac osr */
};
/* codec hifi mclk clock divider coefficients */
static const struct _coeff_div coeff_div[] = {
/*!<mclk rate pre_div mult adc_div dac_div fs_mode lrch lrcl bckdiv osr */
/* 8k */
{12288000, 8000, 0x06, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{18432000, 8000, 0x03, 0x02, 0x03, 0x03, 0x00, 0x05, 0xff, 0x18, 0x10, 0x10},
{16384000, 8000, 0x08, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{8192000, 8000, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{6144000, 8000, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{4096000, 8000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{3072000, 8000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{2048000, 8000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1536000, 8000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1024000, 8000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
/* 11.025k */
{11289600, 11025, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{5644800, 11025, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{2822400, 11025, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1411200, 11025, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
/* 12k */
{12288000, 12000, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{6144000, 12000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{3072000, 12000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1536000, 12000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
/* 16k */
{12288000, 16000, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{18432000, 16000, 0x03, 0x02, 0x03, 0x03, 0x00, 0x02, 0xff, 0x0c, 0x10, 0x10},
{16384000, 16000, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{8192000, 16000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{6144000, 16000, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{4096000, 16000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{3072000, 16000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{2048000, 16000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1536000, 16000, 0x03, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1024000, 16000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
/* 22.05k */
{11289600, 22050, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{5644800, 22050, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{2822400, 22050, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1411200, 22050, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
/* 24k */
{12288000, 24000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{18432000, 24000, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{6144000, 24000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{3072000, 24000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1536000, 24000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
/* 32k */
{12288000, 32000, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{18432000, 32000, 0x03, 0x04, 0x03, 0x03, 0x00, 0x02, 0xff, 0x0c, 0x10, 0x10},
{16384000, 32000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{8192000, 32000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{6144000, 32000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{4096000, 32000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{3072000, 32000, 0x03, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{2048000, 32000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1536000, 32000, 0x03, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
{1024000, 32000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
/* 44.1k */
{11289600, 44100, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{5644800, 44100, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{2822400, 44100, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1411200, 44100, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
/* 48k */
{12288000, 48000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{18432000, 48000, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{6144000, 48000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{3072000, 48000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1536000, 48000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
/* 64k */
{12288000, 64000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{18432000, 64000, 0x03, 0x04, 0x03, 0x03, 0x01, 0x01, 0x7f, 0x06, 0x10, 0x10},
{16384000, 64000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{8192000, 64000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{6144000, 64000, 0x01, 0x04, 0x03, 0x03, 0x01, 0x01, 0x7f, 0x06, 0x10, 0x10},
{4096000, 64000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{3072000, 64000, 0x01, 0x08, 0x03, 0x03, 0x01, 0x01, 0x7f, 0x06, 0x10, 0x10},
{2048000, 64000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1536000, 64000, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0xbf, 0x03, 0x18, 0x18},
{1024000, 64000, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
/* 88.2k */
{11289600, 88200, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{5644800, 88200, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{2822400, 88200, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1411200, 88200, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
/* 96k */
{12288000, 96000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{18432000, 96000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{6144000, 96000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{3072000, 96000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
{1536000, 96000, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
};
static char *TAG = "DRV8311";
#define ES_ASSERT(a, format, b, ...) \
if ((a) != 0) { \
ESP_LOGE(TAG, format, ##__VA_ARGS__); \
return b;\
}
static int es8311_write_reg(uint8_t reg_addr, uint8_t data)
{
return i2c_bus_write_reg(ES8311_ADDR, reg_addr, data);
}
int es8311_read_reg(uint8_t reg_addr)
{
uint8_t data;
i2c_bus_read_reg(ES8311_ADDR, reg_addr, &data);
return (int)data;
}
/*
* look for the coefficient in coeff_div[] table
*/
static int get_coeff(uint32_t mclk, uint32_t rate)
{
for (int i = 0; i < (sizeof(coeff_div) / sizeof(coeff_div[0])); i++) {
if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk) {
return i;
}
}
return -1;
}
/*
* set data and clock in tri-state mode
* if tristate = 0, tri-state is disabled for normal mode
* if tristate = 1, tri-state is enabled
*/
void es8311_set_tristate(int tristate)
{
uint8_t regv;
ESP_LOGI(TAG, "Enter into es8311_set_tristate(), tristate = %d\n", tristate);
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG07) & 0xcf;
if (tristate) {
es8311_write_reg(ES8311_CLK_MANAGER_REG07, regv | 0x30);
} else {
es8311_write_reg(ES8311_CLK_MANAGER_REG07, regv);
}
}
/*
* set es8311 dac mute or not
* if mute = 0, dac un-mute
* if mute = 1, dac mute
*/
static void es8311_mute(int mute)
{
uint8_t regv;
ESP_LOGI(TAG, "Enter into es8311_mute(), mute = %d\n", mute);
regv = es8311_read_reg(ES8311_DAC_REG31) & 0x9f;
if (mute) {
es8311_write_reg(ES8311_SYSTEM_REG12, 0x02);
es8311_write_reg(ES8311_DAC_REG31, regv | 0x60);
es8311_write_reg(ES8311_DAC_REG32, 0x00);
es8311_write_reg(ES8311_DAC_REG37, 0x08);
} else {
es8311_write_reg(ES8311_DAC_REG31, regv);
es8311_write_reg(ES8311_SYSTEM_REG12, 0x00);
}
}
static void es8311_pa_power(bool enable)
{
gpio_config_t io_conf;
memset(&io_conf, 0, sizeof(io_conf));
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = BIT(GPIO_PA_EN) | BIT(0);
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
gpio_set_level(0, 1);
if (enable) {
gpio_set_level(GPIO_PA_EN, 1);
} else {
gpio_set_level(GPIO_PA_EN, 0);
}
}
esp_err_t es8311_init(int sample_fre)
{
if (sample_fre <= 8000) {
ESP_LOGE(TAG, "es8311 init need > 8000Hz frq ,such as 32000Hz, 44100kHz");
return ESP_FAIL;
}
uint8_t adc_iface, dac_iface, datmp, regv;
int coeff;
esp_err_t ret = ESP_OK;
// gpio_matrix_out(IIS_MCLK, CLK_I2S_MUX_IDX, 0, 0);
ret |= es8311_write_reg(ES8311_GP_REG45, 0x00);
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, 0x30);
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG02, 0x00);
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG03, 0x10);
ret |= es8311_write_reg(ES8311_ADC_REG16, 0x24);
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG04, 0x10);
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG05, 0x00);
ret |= es8311_write_reg(ES8311_SYSTEM_REG0B, 0x00);
ret |= es8311_write_reg(ES8311_SYSTEM_REG0C, 0x00);
ret |= es8311_write_reg(ES8311_SYSTEM_REG10, 0x1F);
ret |= es8311_write_reg(ES8311_SYSTEM_REG11, 0x7F);
ret |= es8311_write_reg(ES8311_RESET_REG00, 0x80);
/*
* Set Codec into Master or Slave mode
*/
regv = es8311_read_reg(ES8311_RESET_REG00);
/*
* Set master/slave audio interface
*/
ESP_LOGI(TAG, "ES8311 in Slave mode\n");
regv &= 0xBF;
ret |= es8311_write_reg(ES8311_RESET_REG00, regv);
ret |= es8311_write_reg(ES8311_SYSTEM_REG0D, 0x01);
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, 0x3F);
/*
* Select clock source for internal mclk
*/
switch (MCLK_SOURCE) {
case FROM_MCLK_PIN:
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
regv &= 0x7F;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
break;
case FROM_SCLK_PIN:
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
regv |= 0x80;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
break;
default:
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
regv &= 0x7F;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
break;
}
int mclk_fre = 0;
mclk_fre = sample_fre * MCLK_DIV_FRE;
coeff = get_coeff(mclk_fre, sample_fre);
if (coeff < 0) {
ESP_LOGE(TAG, "Unable to configure sample rate %dHz with %dHz MCLK\n", sample_fre, mclk_fre);
return ESP_FAIL;
}
/*
* Set clock parammeters
*/
if (coeff >= 0) {
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG02) & 0x07;
regv |= (coeff_div[coeff].pre_div - 1) << 5;
datmp = 0;
switch (coeff_div[coeff].pre_multi) {
case 1:
datmp = 0;
break;
case 2:
datmp = 1;
break;
case 4:
datmp = 2;
break;
case 8:
datmp = 3;
break;
default:
break;
}
regv |= (datmp) << 3;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG02, regv);
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG05) & 0x00;
regv |= (coeff_div[coeff].adc_div - 1) << 4;
regv |= (coeff_div[coeff].dac_div - 1) << 0;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG05, regv);
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG03) & 0x80;
regv |= coeff_div[coeff].fs_mode << 6;
regv |= coeff_div[coeff].adc_osr << 0;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG03, regv);
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG04) & 0x80;
regv |= coeff_div[coeff].dac_osr << 0;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG04, regv);
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG07) & 0xC0;
regv |= coeff_div[coeff].lrck_h << 0;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG07, regv);
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG08) & 0x00;
regv |= coeff_div[coeff].lrck_l << 0;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG08, regv);
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG06) & 0xE0;
if (coeff_div[coeff].bclk_div < 19) {
regv |= (coeff_div[coeff].bclk_div - 1) << 0;
} else {
regv |= (coeff_div[coeff].bclk_div) << 0;
}
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG06, regv);
}
/*
* DAC/ADC interface, DAC/ADC resolution
*/
dac_iface = es8311_read_reg(ES8311_SDPIN_REG09) & 0xC0;
adc_iface = es8311_read_reg(ES8311_SDPOUT_REG0A) & 0xC0;
/* bit size */
/*!< AUDIO_HAL_BIT_LENGTH_16BITS */
dac_iface |= 0x0c;
adc_iface |= 0x0c;
/* interface format */
ESP_LOGI(TAG, "ES8311 in I2S Format\n");
dac_iface &= 0xFC;
adc_iface &= 0xFC;
/* set iface */
ret |= es8311_write_reg(ES8311_SDPIN_REG09, dac_iface);
ret |= es8311_write_reg(ES8311_SDPOUT_REG0A, adc_iface);
/*
* mclk inverted or not
*/
if (INVERT_MCLK) {
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
regv |= 0x40;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
} else {
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
regv &= ~(0x40);
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
}
/*
* sclk inverted or not
*/
if (INVERT_SCLK) {
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG06);
regv |= 0x20;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG06, regv);
} else {
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG06);
regv &= ~(0x20);
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG06, regv);
}
ret |= es8311_write_reg(ES8311_SYSTEM_REG14, 0x1A);
/*
* pdm dmic enable or disable
*/
if (IS_DMIC) {
regv = es8311_read_reg(ES8311_SYSTEM_REG14);
regv |= 0x40;
ret |= es8311_write_reg(ES8311_SYSTEM_REG14, regv);
} else {
regv = es8311_read_reg(ES8311_SYSTEM_REG14);
regv &= ~(0x40);
ret |= es8311_write_reg(ES8311_SYSTEM_REG14, regv);
}
ret |= es8311_write_reg(ES8311_SYSTEM_REG12, 0x00);
ret |= es8311_write_reg(ES8311_SYSTEM_REG13, 0x10);
// es8311_write_reg(ES8311_SDPIN_REG09, 0x00);
// es8311_write_reg(ES8311_SDPOUT_REG0A, 0x00);
ret |= es8311_write_reg(ES8311_SYSTEM_REG0E, 0x02);
ret |= es8311_write_reg(ES8311_ADC_REG15, 0x40);
ret |= es8311_write_reg(ES8311_ADC_REG1B, 0x0A);
ret |= es8311_write_reg(ES8311_ADC_REG1C, 0x6A);
ret |= es8311_write_reg(ES8311_DAC_REG37, 0x48);
ret |= es8311_write_reg(ES8311_GPIO_REG44, 0x08);
//ret |= es8311_write_reg(ES8311_GPIO_REG44, 0x78);
ret |= es8311_write_reg(ES8311_ADC_REG17, 0xBF);
ret |= es8311_write_reg(ES8311_DAC_REG32, 0xBF);
//gpio_matrix_out(IIS_MCLK, CLK_I2S_MUX_IDX, 0, 0);
es8311_pa_power(true);
return ESP_OK;
}
esp_err_t es8311_deinit()
{
es8311_pa_power(false);
return ESP_OK;
}
esp_err_t es8311_set_voice_volume(int volume)
{
int res = 0;
if (volume < 0) {
volume = 0;
} else if (volume > 100) {
volume = 100;
}
int vol = (volume) * 2550 / 1000 + 0.5;
ESP_LOGI(TAG, "SET: volume:%d\n", vol);
es8311_write_reg(ES8311_DAC_REG32, vol);
return res;
}
esp_err_t es8311_get_voice_volume(int *volume)
{
int res = ESP_OK;
int regv = 0;
regv = es8311_read_reg(ES8311_DAC_REG32);
if (regv == -1) {
*volume = 0;
res = ESP_FAIL;
} else {
*volume = regv * 100 / 256;
}
ESP_LOGI(TAG, "GET: res:%d, volume:%d\n", regv, *volume);
return res;
}
int es8311_set_voice_mute(int enable)
{
int res = 0;
ESP_LOGE(TAG, "Es8311SetVoiceMute volume:%d\n", enable);
es8311_mute(enable);
return res;
}
int es8311_get_voice_mute(int *mute)
{
int res = -1;
uint8_t reg = 0;
res = es8311_read_reg(ES8311_DAC_REG31);
if (res != ESP_FAIL) {
reg = (res & 0x20) >> 5;
}
*mute = reg;
return res;
}
int es8311_set_mic_gain(es8311_mic_gain_t gain_db)
{
int res = 0;
res = es8311_write_reg(ES8311_ADC_REG16, gain_db); /*!< MIC gain scale */
return res;
}
void es8311_read_all()
{
for (int i = 0; i < 0x4A; i++) {
uint8_t reg = es8311_read_reg(i);
ets_printf("REG:%02x, %02x\n", reg, i);
}
}

173
components/es8311/include/es8311.h

@ -0,0 +1,173 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _ES8311_H
#define _ES8311_H
#include "esp_types.h"
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* ES8311_REGISTER NAME_REG_REGISTER ADDRESS
*/
#define ES8311_RESET_REG00 0x00 /*reset digital,csm,clock manager etc.*/
/*
* Clock Scheme Register definition
*/
#define ES8311_CLK_MANAGER_REG01 0x01 /* select clk src for mclk, enable clock for codec */
#define ES8311_CLK_MANAGER_REG02 0x02 /* clk divider and clk multiplier */
#define ES8311_CLK_MANAGER_REG03 0x03 /* adc fsmode and osr */
#define ES8311_CLK_MANAGER_REG04 0x04 /* dac osr */
#define ES8311_CLK_MANAGER_REG05 0x05 /* clk divier for adc and dac */
#define ES8311_CLK_MANAGER_REG06 0x06 /* bclk inverter and divider */
#define ES8311_CLK_MANAGER_REG07 0x07 /* tri-state, lrck divider */
#define ES8311_CLK_MANAGER_REG08 0x08 /* lrck divider */
/*
* SDP
*/
#define ES8311_SDPIN_REG09 0x09 /* dac serial digital port */
#define ES8311_SDPOUT_REG0A 0x0A /* adc serial digital port */
/*
* SYSTEM
*/
#define ES8311_SYSTEM_REG0B 0x0B /* system */
#define ES8311_SYSTEM_REG0C 0x0C /* system */
#define ES8311_SYSTEM_REG0D 0x0D /* system, power up/down */
#define ES8311_SYSTEM_REG0E 0x0E /* system, power up/down */
#define ES8311_SYSTEM_REG0F 0x0F /* system, low power */
#define ES8311_SYSTEM_REG10 0x10 /* system */
#define ES8311_SYSTEM_REG11 0x11 /* system */
#define ES8311_SYSTEM_REG12 0x12 /* system, Enable DAC */
#define ES8311_SYSTEM_REG13 0x13 /* system */
#define ES8311_SYSTEM_REG14 0x14 /* system, select DMIC, select analog pga gain */
/*
* ADC
*/
#define ES8311_ADC_REG15 0x15 /* ADC, adc ramp rate, dmic sense */
#define ES8311_ADC_REG16 0x16 /* ADC */
#define ES8311_ADC_REG17 0x17 /* ADC, volume */
#define ES8311_ADC_REG18 0x18 /* ADC, alc enable and winsize */
#define ES8311_ADC_REG19 0x19 /* ADC, alc maxlevel */
#define ES8311_ADC_REG1A 0x1A /* ADC, alc automute */
#define ES8311_ADC_REG1B 0x1B /* ADC, alc automute, adc hpf s1 */
#define ES8311_ADC_REG1C 0x1C /* ADC, equalizer, hpf s2 */
/*
* DAC
*/
#define ES8311_DAC_REG31 0x31 /* DAC, mute */
#define ES8311_DAC_REG32 0x32 /* DAC, volume */
#define ES8311_DAC_REG33 0x33 /* DAC, offset */
#define ES8311_DAC_REG34 0x34 /* DAC, drc enable, drc winsize */
#define ES8311_DAC_REG35 0x35 /* DAC, drc maxlevel, minilevel */
#define ES8311_DAC_REG37 0x37 /* DAC, ramprate */
/*
*GPIO
*/
#define ES8311_GPIO_REG44 0x44 /* GPIO, dac2adc for test */
#define ES8311_GP_REG45 0x45 /* GP CONTROL */
/*
* CHIP
*/
#define ES8311_CHD1_REGFD 0xFD /* CHIP ID1 */
#define ES8311_CHD2_REGFE 0xFE /* CHIP ID2 */
#define ES8311_CHVER_REGFF 0xFF /* VERSION */
#define ES8311_CHD1_REGFD 0xFD /* CHIP ID1 */
#define ES8311_MAX_REGISTER 0xFF
typedef enum {
ES8311_MIC_GAIN_MIN = -1,
ES8311_MIC_GAIN_0DB,
ES8311_MIC_GAIN_6DB,
ES8311_MIC_GAIN_12DB,
ES8311_MIC_GAIN_18DB,
ES8311_MIC_GAIN_24DB,
ES8311_MIC_GAIN_30DB,
ES8311_MIC_GAIN_36DB,
ES8311_MIC_GAIN_42DB,
ES8311_MIC_GAIN_MAX
} es8311_mic_gain_t;
typedef enum {
ES_MODULE_MIN = -1,
ES_MODULE_ADC = 0x01,
ES_MODULE_DAC = 0x02,
ES_MODULE_ADC_DAC = 0x03,
ES_MODULE_LINE = 0x04,
ES_MODULE_MAX
} es_module_t;
typedef enum {
ES_I2S_MIN = -1,
ES_I2S_NORMAL = 0,
ES_I2S_LEFT = 1,
ES_I2S_RIGHT = 2,
ES_I2S_DSP = 3,
ES_I2S_MAX
} es_i2s_fmt_t;
/**
* @brief Initialize es8311
*
* @param sample_fre sample rate , 8311 initialization requires a higher MCLK frequency, such as 44100Hz or 32000Hz,
* but can be modified later.
*
* @return - ESP_FAIL fail initialize
* - ESP_OK succesful initialize
*/
esp_err_t es8311_init(int sample_fre);
/**
* @brief Delete es8311
*
* @return - ESP_FAIL fail delete
* - ESP_OK succesful initialize
*/
esp_err_t es8311_deinit(void);
/**
* @brief Set the volume
*
* @param volume set volume (0 ~ 100)
*
* @return - ESP_FAIL fail initialize
* - ESP_OK on succesful decode
*/
esp_err_t es8311_set_voice_volume(int volume);
/**
* @brief Get the volume
*
* @param volume get volume (0 ~ 100)
*
* @return - ESP_FAIL fail initialize
* - ESP_OK on succesful decode
*/
esp_err_t es8311_get_voice_volume(int *volume);
/**
* @brief read all reg about es8311
*/
void es8311_read_all();
#ifdef __cplusplus
}
#endif
#endif

22
components/esp_tts/CMakeLists.txt

@ -0,0 +1,22 @@
set(COMPONENT_ADD_INCLUDEDIRS
./include
)
register_component()
target_link_libraries(${COMPONENT_LIB} INTERFACE "-L ${CMAKE_CURRENT_LIST_DIR}")
if("${target}" STREQUAL "esp32")
target_link_libraries(${COMPONENT_LIB} INTERFACE speech_synthesis_esp32
voice_set_xiaole_esp32 )
# target_link_libraries(${COMPONENT_LIB} INTERFACE "-L${CMAKE_CURRENT_LIST_DIR}/controller/lib")
endif()
if("${target}" STREQUAL "esp32s2")
target_link_libraries(${COMPONENT_LIB} INTERFACE speech_synthesis_esp32s2
voice_set_xiaole_esp32s2 )
# target_link_libraries(${COMPONENT_LIB} INTERFACE "-L${CMAKE_CURRENT_LIST_DIR}/controller/lib")
endif()

74
components/esp_tts/README.md

@ -0,0 +1,74 @@
# ESP Chinese TTS [[English]](./README_en.md)
乐鑫中文语音合成是一个为嵌入式系统设计的轻量化语音合成系统。
## Overview
乐鑫语音合成当前版本基于拼接法,系统框图如下:
![chinese TTS](./img/esp_chinese_tts.png)
- Parser: 根据字典与语法规则,将输入文本转换为拼音列表, 输入文本编码为UTF-8。
- Synthesizer: 根据Parser输出的拼音列表,结合预定义的声音集,合成波形文件。默认输出格式为单声道, 16bit@16000Hz。
#### Features:
- [x] UTF-8编码输入
- [x] 流式输出,减少延时
- [x] 多音词发音自动识别
- [x] 可调节合成语速
- [ ] 自定义声音集
## Performance Test
#### Resource Occupancy
Flash image size: 2.2 MB
RAM runtime: 20 KB
CPU loading test(基于ESP32 @ 240MHz测试 ):
| speech speed | 0 | 1 | 2 | 3 | 4 | 5 |
| --------------------------- | :--: | :--: | :--: | :--: | :--: | :--: |
| times faster than real time | 7.5 | 4.3 | 3.8 | 3.4 | 2.9 | 2.4 |
#### Samples
- 欢迎使用乐鑫语音合成, &nbsp; &nbsp; [voice=小乐,speed=0](./samples/S1_xiaole_speed0.wav), &nbsp; &nbsp; [voice=小乐,speed=4](S1_xiaole_speed4.wav)
- 支付宝收款 1111.11 元, &nbsp; &nbsp; [voice=小乐,speed=0](./samples/S1_xiaole_speed0.wav), &nbsp; &nbsp; [voice=小乐,speed=4](S2_xiaole_speed4.wav)
- 空调制热模式已打开,并调节到25度, &nbsp; &nbsp; [voice=小乐,speed=0](./samples/S3_xiaole_speed0.wav), &nbsp; &nbsp; [voice=小乐,speed=4](S3_xiaole_speed4.wav)
## User Guide
```c
#include "esp_tts.h"
#include "esp_tts_voice_female.h"
// 1. create esp tts handle by pre-define voice set 'esp_tts_voice_female'
esp_tts_handle_t *tts_handle=esp_tts_create(esp_tts_voice_female);
// 2. parse text and synthesis wave data
char *text="欢迎使用乐鑫语音合成";
if (esp_tts_parse_chinese(tts_handle, text)) { // parse text into pinyin list
int len[1]={0};
do {
short *data=esp_tts_stream_play(tts_handle, len, 4); // streaming synthesis
i2s_audio_play(data, len[0]*2, portMAX_DELAY); // i2s output
} while(len[0]>0);
i2s_zero_dma_buffer(0);
}
```
请参考[esp_tts.h](./include/esp_tts.h)查看API定义, 或参考esp-skainet例子.

76
components/esp_tts/README_en.md

@ -0,0 +1,76 @@
## ESP Chinese TTS [[中文]](./README.md)
Espressif Chinese TTS is a lightweight TTS system designed for embedded systems。
## Overview
The Chinese TTS is based on concatenative method. The flow diagram of system is as follows:
![chinese TTS](./img/esp_chinese_tts.png)
- **Parser** : a Chinese grapheme to phoneme module, input text (UTF-8) and output Chinese pinyin list.
- **Synthesizer** : a concatenative synthesizer, input pinyin list and output wave raw data. The default encoding of raw data is mono, 16 bit@16000 Hz.
#### Features
- [x] UTF-8 encoding text input
- [x] Streaming output
- [x] Polyphonic pronunciation
- [x] Adjustable speech rate
- [ ] Custom sound set
## Performance Test
#### Resource Occupancy
Flash image size: 2.2 MB
RAM runtime: 20 KB
CPU loading test(ESP32 @ 240 MHz):
| speech rate | 0 | 1 | 2 | 3 | 4 | 5 |
| --------------------------- | :--: | :--: | :--: | :--: | :--: | :--: |
| times faster than real time | 7.5 | 4.3 | 3.8 | 3.4 | 2.9 | 2.4 |
**Note:** the bigger rate, the faster speech speed. 0: slowest speaking speed, 5: fastest speaking speed.
#### Samples
- 欢迎使用乐鑫语音合成, &nbsp; &nbsp; [voice=小乐,speed=0](./samples/S1_xiaole_speed0.wav), &nbsp; &nbsp; [voice=小乐,speed=4](S1_xiaole_speed4.wav)
- 支付宝收款 1111.11 元, &nbsp; &nbsp; [voice=小乐,speed=0](./samples/S1_xiaole_speed0.wav), &nbsp; &nbsp; [voice=小乐,speed=4](S2_xiaole_speed4.wav)
- 空调制热模式已打开,并调节到25度, &nbsp; &nbsp; [voice=小乐,speed=0](./samples/S3_xiaole_speed0.wav), &nbsp; &nbsp; [voice=小乐,speed=4](S3_xiaole_speed4.wav)
## User Guide
```c
#include "esp_tts.h"
#include "esp_tts_voice_female.h"
// 1. create esp tts handle by pre-define voice set 'esp_tts_voice_female'
esp_tts_handle_t *tts_handle=esp_tts_create(esp_tts_voice_female);
// 2. parse text and synthesis wave data
char *text="欢迎使用乐鑫语音合成";
if (esp_tts_parse_chinese(tts_handle, text)) { // parse text into pinyin list
int len[1]={0};
do {
short *data=esp_tts_stream_play(tts_handle, len, 4); // streaming synthesis