bsp_board.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include "driver/gpio.h"
  3. #include "driver/i2s_std.h"
  4. #include "driver/i2c_master.h"
  5. #include "soc/soc_caps.h"
  6. #include "esp_idf_version.h"
  7. #include "esp_codec_dev.h"
  8. #include "esp_codec_dev_defaults.h"
  9. #include "esp_codec_dev_os.h"
  10. #include "sdkconfig.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define I2C_NUM (0)
  15. #define GPIO_I2C_SCL (GPIO_NUM_10)
  16. #define GPIO_I2C_SDA (GPIO_NUM_11)
  17. #define FUNC_I2S_EN (1)
  18. #define GPIO_I2S_LRCK (GPIO_NUM_14)
  19. #define GPIO_I2S_MCLK (GPIO_NUM_12)
  20. #define GPIO_I2S_SCLK (GPIO_NUM_13)
  21. #define GPIO_I2S_SDIN (GPIO_NUM_15)
  22. #define GPIO_I2S_DOUT (GPIO_NUM_16)
  23. #define RECORD_VOLUME (30.0)
  24. #define PLAYER_VOLUME (60)
  25. #define GPIO_PWR_CTRL (-1)
  26. #define GPIO_PWR_ON_LEVEL (1)
  27. #define KEY_VOLUME_UP_PIN (1ULL << 9) /* K1, TCA9555 expander pin 9 */
  28. #define KEY_VOLUME_DOWN_PIN (1ULL << 11) /* K3, TCA9555 expander pin 11 */
  29. #define VOLUME_BUTTON_POLL_MS (50)
  30. #define VOLUME_STEP (2)
  31. #define VOLUME_MIN_LEVEL (0)
  32. #define VOLUME_MAX_LEVEL (100)
  33. #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
  34. #define I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan) { \
  35. .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(16000), \
  36. .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(32, I2S_SLOT_MODE_STEREO), \
  37. .gpio_cfg = { \
  38. .mclk = GPIO_I2S_MCLK, \
  39. .bclk = GPIO_I2S_SCLK, \
  40. .ws = GPIO_I2S_LRCK, \
  41. .dout = GPIO_I2S_DOUT, \
  42. .din = GPIO_I2S_SDIN, \
  43. }, \
  44. }
  45. #else
  46. #define I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan) { \
  47. .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX, \
  48. .sample_rate = 16000, \
  49. .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, \
  50. .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, \
  51. .communication_format = I2S_COMM_FORMAT_STAND_I2S, \
  52. .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, \
  53. .dma_buf_count = 6, \
  54. .dma_buf_len = 160, \
  55. .use_apll = false, \
  56. .tx_desc_auto_clear = true, \
  57. .fixed_mclk = 0, \
  58. .mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, \
  59. .bits_per_chan = I2S_BITS_PER_CHAN_32BIT, \
  60. }
  61. #endif
  62. esp_err_t esp_board_init(uint32_t sample_rate, int channel_format, int bits_per_chan);
  63. esp_err_t esp_audio_play(const int16_t* data, int length, uint32_t ticks_to_wait);
  64. int bsp_aec_get_frame_size(void);
  65. esp_err_t bsp_aec_process_frame(const int16_t *near_end,
  66. const int16_t *far_end,
  67. int16_t *processed);
  68. esp_err_t bsp_aec_reset(void);
  69. esp_err_t esp_get_feed_data(bool is_get_raw_channel, int16_t *buffer, int buffer_len);
  70. esp_err_t esp_audio_set_play_vol(int volume);
  71. esp_err_t esp_audio_get_play_vol(int *volume);
  72. i2c_master_bus_handle_t esp_ret_i2c_handle(void);
  73. esp_codec_dev_handle_t esp_ret_play_dev();
  74. #ifdef __cplusplus
  75. }
  76. #endif