bsp_board.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #pragma once
  2. #include "driver/gpio.h"
  3. #include "driver/i2s_std.h"
  4. #include "driver/i2s_tdm.h"
  5. #include "driver/i2c_master.h"
  6. #include "soc/soc_caps.h"
  7. #include "esp_idf_version.h"
  8. #include "esp_codec_dev.h"
  9. #include "esp_codec_dev_defaults.h"
  10. #include "esp_codec_dev_os.h"
  11. #include "sdkconfig.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #define MAX_FILE_NAME_SIZE 100 // Define maximum file name size
  16. #define MAX_PATH_SIZE 512 // Define a larger size for the full path
  17. #define I2C_NUM (0)
  18. #define GPIO_I2C_SCL (GPIO_NUM_10)
  19. #define GPIO_I2C_SDA (GPIO_NUM_11)
  20. #define FUNC_SDMMC_EN (1)
  21. #define SDMMC_BUS_WIDTH (1)
  22. #define GPIO_SDMMC_CLK (GPIO_NUM_40)
  23. #define GPIO_SDMMC_CMD (GPIO_NUM_42)
  24. #define GPIO_SDMMC_D0 (GPIO_NUM_41)
  25. #define GPIO_SDMMC_D1 (GPIO_NUM_NC)
  26. #define GPIO_SDMMC_D2 (GPIO_NUM_NC)
  27. #define GPIO_SDMMC_D3 (GPIO_NUM_NC)
  28. #define GPIO_SDMMC_DET (GPIO_NUM_NC)
  29. #define FUNC_SDSPI_EN (0)
  30. #define SDSPI_HOST (SPI2_HOST)
  31. #define GPIO_SDSPI_CS (GPIO_NUM_NC)
  32. #define GPIO_SDSPI_SCLK (GPIO_NUM_NC)
  33. #define GPIO_SDSPI_MISO (GPIO_NUM_NC)
  34. #define GPIO_SDSPI_MOSI (GPIO_NUM_NC)
  35. #define FUNC_I2S_EN (1)
  36. #define GPIO_I2S_LRCK (GPIO_NUM_14)
  37. #define GPIO_I2S_MCLK (GPIO_NUM_12)
  38. #define GPIO_I2S_SCLK (GPIO_NUM_13)
  39. #define GPIO_I2S_SDIN (GPIO_NUM_15)
  40. #define GPIO_I2S_DOUT (GPIO_NUM_16)
  41. #define FUNC_I2S0_EN (0)
  42. #define GPIO_I2S0_LRCK (GPIO_NUM_NC)
  43. #define GPIO_I2S0_MCLK (GPIO_NUM_NC)
  44. #define GPIO_I2S0_SCLK (GPIO_NUM_NC)
  45. #define GPIO_I2S0_SDIN (GPIO_NUM_NC)
  46. #define GPIO_I2S0_DOUT (GPIO_NUM_NC)
  47. #define RECORD_VOLUME (30.0)
  48. #define PLAYER_VOLUME (60)
  49. #define GPIO_PWR_CTRL (-1)
  50. #define GPIO_PWR_ON_LEVEL (1)
  51. #define KEY_VOLUME_UP_PIN (1ULL << 9) /* K1, TCA9555 expander pin 9 */
  52. #define KEY_VOLUME_DOWN_PIN (1ULL << 11) /* K3, TCA9555 expander pin 11 */
  53. #define VOLUME_BUTTON_POLL_MS (50)
  54. #define VOLUME_STEP (2)
  55. #define VOLUME_MIN_LEVEL (0)
  56. #define VOLUME_MAX_LEVEL (100)
  57. #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
  58. #define I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan) { \
  59. .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(16000), \
  60. .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(32, I2S_SLOT_MODE_STEREO), \
  61. .gpio_cfg = { \
  62. .mclk = GPIO_I2S_MCLK, \
  63. .bclk = GPIO_I2S_SCLK, \
  64. .ws = GPIO_I2S_LRCK, \
  65. .dout = GPIO_I2S_DOUT, \
  66. .din = GPIO_I2S_SDIN, \
  67. }, \
  68. }
  69. #else
  70. #define I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan) { \
  71. .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX, \
  72. .sample_rate = 16000, \
  73. .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, \
  74. .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, \
  75. .communication_format = I2S_COMM_FORMAT_STAND_I2S, \
  76. .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, \
  77. .dma_buf_count = 6, \
  78. .dma_buf_len = 160, \
  79. .use_apll = false, \
  80. .tx_desc_auto_clear = true, \
  81. .fixed_mclk = 0, \
  82. .mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, \
  83. .bits_per_chan = I2S_BITS_PER_CHAN_32BIT, \
  84. }
  85. #endif
  86. /* LCD settings */
  87. #define EXAMPLE_LCD_SPI_NUM (SPI3_HOST)
  88. #define EXAMPLE_LCD_PIXEL_CLK_HZ (80 * 1000 * 1000)
  89. #define EXAMPLE_LCD_CMD_BITS (8)
  90. #define EXAMPLE_LCD_PARAM_BITS (8)
  91. #define EXAMPLE_LCD_BITS_PER_PIXEL (16)
  92. #define EXAMPLE_LCD_DRAW_BUFF_DOUBLE (1)
  93. #define EXAMPLE_LCD_DRAW_BUFF_HEIGHT (50)
  94. #define EXAMPLE_LCD_BL_ON_LEVEL (1)
  95. #define Backlight_MAX 100
  96. #define DEFAULT_BACKLIGHT 80
  97. /* LCD pins */
  98. #define EXAMPLE_LCD_GPIO_SCLK (GPIO_NUM_5)
  99. #define EXAMPLE_LCD_GPIO_MOSI (GPIO_NUM_1)
  100. #define EXAMPLE_LCD_GPIO_RST (GPIO_NUM_NC)
  101. #define EXAMPLE_LCD_GPIO_DC (GPIO_NUM_3)
  102. #define EXAMPLE_LCD_GPIO_CS (GPIO_NUM_6)
  103. #define EXAMPLE_LCD_GPIO_BL (GPIO_NUM_NC)
  104. /* LCD touch pins */
  105. #define EXAMPLE_TOUCH_GPIO_RST (GPIO_NUM_NC)
  106. #ifdef CONFIG_WAVESHARE_1_47INCH_TOUCH_LCD
  107. #define EXAMPLE_LCD_H_RES (172)
  108. #define EXAMPLE_LCD_V_RES (320)
  109. #define EXAMPLE_TOUCH_GPIO_INT (GPIO_NUM_9)
  110. #elif defined(CONFIG_WAVESHARE_2INCH_TOUCH_LCD)
  111. #define EXAMPLE_LCD_H_RES (240)
  112. #define EXAMPLE_LCD_V_RES (320)
  113. #define EXAMPLE_TOUCH_GPIO_INT (GPIO_NUM_9)
  114. #elif defined(CONFIG_WAVESHARE_2_8INCH_TOUCH_LCD)
  115. #define EXAMPLE_LCD_H_RES (240)
  116. #define EXAMPLE_LCD_V_RES (320)
  117. #define EXAMPLE_TOUCH_GPIO_INT (GPIO_NUM_NC)
  118. #elif defined(CONFIG_WAVESHARE_3_5INCH_TOUCH_LCD)
  119. #define EXAMPLE_LCD_H_RES (320)
  120. #define EXAMPLE_LCD_V_RES (480)
  121. #define EXAMPLE_TOUCH_GPIO_INT (GPIO_NUM_9)
  122. #endif
  123. // GPIO assignment
  124. #define LED_STRIP_GPIO_PIN 38
  125. #define LED_STRIP_LED_COUNT 7
  126. esp_err_t esp_board_init(uint32_t sample_rate, int channel_format, int bits_per_chan);
  127. esp_err_t esp_audio_play(const int16_t* data, int length, uint32_t ticks_to_wait);
  128. int bsp_aec_get_frame_size(void);
  129. esp_err_t bsp_aec_process_frame(const int16_t *near_end,
  130. const int16_t *far_end,
  131. int16_t *processed);
  132. esp_err_t esp_get_feed_data(bool is_get_raw_channel, int16_t *buffer, int buffer_len);
  133. int esp_get_feed_channel(void);
  134. char* esp_get_input_format(void);
  135. esp_err_t esp_audio_set_play_vol(int volume);
  136. esp_err_t esp_audio_get_play_vol(int *volume);
  137. i2c_master_bus_handle_t esp_ret_i2c_handle(void);
  138. esp_codec_dev_handle_t esp_ret_play_dev();
  139. #ifdef __cplusplus
  140. }
  141. #endif