bsp_board.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. /**
  18. * @brief ESP32-S3-CAM-OVxxxx I2C GPIO defineation
  19. *
  20. */
  21. #define I2C_NUM (0)
  22. #define GPIO_I2C_SCL (GPIO_NUM_10)
  23. #define GPIO_I2C_SDA (GPIO_NUM_11)
  24. /**
  25. * @brief ESP32-S3-CAM-OVxxxx SDMMC GPIO defination
  26. *
  27. * @note Only avaliable when PMOD connected
  28. */
  29. #define FUNC_SDMMC_EN (1)
  30. #define SDMMC_BUS_WIDTH (1)
  31. #define GPIO_SDMMC_CLK (GPIO_NUM_40)
  32. #define GPIO_SDMMC_CMD (GPIO_NUM_42)
  33. #define GPIO_SDMMC_D0 (GPIO_NUM_41)
  34. #define GPIO_SDMMC_D1 (GPIO_NUM_NC)
  35. #define GPIO_SDMMC_D2 (GPIO_NUM_NC)
  36. #define GPIO_SDMMC_D3 (GPIO_NUM_NC)
  37. #define GPIO_SDMMC_DET (GPIO_NUM_NC)
  38. /**
  39. * @brief ESP32-S3-CAM-OVxxxx SDSPI GPIO definationv
  40. *
  41. */
  42. #define FUNC_SDSPI_EN (0)
  43. #define SDSPI_HOST (SPI2_HOST)
  44. #define GPIO_SDSPI_CS (GPIO_NUM_NC)
  45. #define GPIO_SDSPI_SCLK (GPIO_NUM_NC)
  46. #define GPIO_SDSPI_MISO (GPIO_NUM_NC)
  47. #define GPIO_SDSPI_MOSI (GPIO_NUM_NC)
  48. /**
  49. * @brief ESP32-S3-CAM-OVxxxx I2S GPIO defination
  50. *
  51. */
  52. #define FUNC_I2S_EN (1)
  53. #define GPIO_I2S_LRCK (GPIO_NUM_14)
  54. #define GPIO_I2S_MCLK (GPIO_NUM_12)
  55. #define GPIO_I2S_SCLK (GPIO_NUM_13)
  56. #define GPIO_I2S_SDIN (GPIO_NUM_15)
  57. #define GPIO_I2S_DOUT (GPIO_NUM_16)
  58. /**
  59. * @brief ESP32-S3-CAM-OVxxxx I2S GPIO defination
  60. *
  61. */
  62. #define FUNC_I2S0_EN (0)
  63. #define GPIO_I2S0_LRCK (GPIO_NUM_NC)
  64. #define GPIO_I2S0_MCLK (GPIO_NUM_NC)
  65. #define GPIO_I2S0_SCLK (GPIO_NUM_NC)
  66. #define GPIO_I2S0_SDIN (GPIO_NUM_NC)
  67. #define GPIO_I2S0_DOUT (GPIO_NUM_NC)
  68. /**
  69. * @brief record configurations
  70. *
  71. */
  72. #define RECORD_VOLUME (30.0)
  73. /**
  74. * @brief player configurations
  75. *
  76. */
  77. #define PLAYER_VOLUME (60)
  78. /**
  79. * @brief ESP32-S3-HMI-DevKit power control IO
  80. *
  81. * @note Some power control pins might not be listed yet
  82. *
  83. */
  84. //#define FUNC_PWR_CTRL (1)
  85. #define GPIO_PWR_CTRL (-1)
  86. #define GPIO_PWR_ON_LEVEL (1)
  87. /* Waveshare ESP32-S3 audio board button mapping */
  88. #define GPIO_KEY1_PIN (GPIO_NUM_0)
  89. #define GPIO_KEY3_PIN (GPIO_NUM_18)
  90. #define VOLUME_BUTTON_POLL_MS (50)
  91. #define VOLUME_STEP (2)
  92. #define VOLUME_MIN_LEVEL (0)
  93. #define VOLUME_MAX_LEVEL (100)
  94. #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
  95. #define I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan) { \
  96. .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(16000), \
  97. .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(32, I2S_SLOT_MODE_STEREO), \
  98. .gpio_cfg = { \
  99. .mclk = GPIO_I2S_MCLK, \
  100. .bclk = GPIO_I2S_SCLK, \
  101. .ws = GPIO_I2S_LRCK, \
  102. .dout = GPIO_I2S_DOUT, \
  103. .din = GPIO_I2S_SDIN, \
  104. }, \
  105. }
  106. #else
  107. #define I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan) { \
  108. .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX, \
  109. .sample_rate = 16000, \
  110. .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, \
  111. .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, \
  112. .communication_format = I2S_COMM_FORMAT_STAND_I2S, \
  113. .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, \
  114. .dma_buf_count = 6, \
  115. .dma_buf_len = 160, \
  116. .use_apll = false, \
  117. .tx_desc_auto_clear = true, \
  118. .fixed_mclk = 0, \
  119. .mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, \
  120. .bits_per_chan = I2S_BITS_PER_CHAN_32BIT, \
  121. }
  122. #endif
  123. /* LCD settings */
  124. #define EXAMPLE_LCD_SPI_NUM (SPI3_HOST)
  125. #define EXAMPLE_LCD_PIXEL_CLK_HZ (80 * 1000 * 1000)
  126. #define EXAMPLE_LCD_CMD_BITS (8)
  127. #define EXAMPLE_LCD_PARAM_BITS (8)
  128. #define EXAMPLE_LCD_BITS_PER_PIXEL (16)
  129. #define EXAMPLE_LCD_DRAW_BUFF_DOUBLE (1)
  130. #define EXAMPLE_LCD_DRAW_BUFF_HEIGHT (50)
  131. #define EXAMPLE_LCD_BL_ON_LEVEL (1)
  132. #define Backlight_MAX 100
  133. #define DEFAULT_BACKLIGHT 80
  134. /* LCD pins */
  135. #define EXAMPLE_LCD_GPIO_SCLK (GPIO_NUM_5)
  136. #define EXAMPLE_LCD_GPIO_MOSI (GPIO_NUM_1)
  137. #define EXAMPLE_LCD_GPIO_RST (GPIO_NUM_NC)
  138. #define EXAMPLE_LCD_GPIO_DC (GPIO_NUM_3)
  139. #define EXAMPLE_LCD_GPIO_CS (GPIO_NUM_6)
  140. #define EXAMPLE_LCD_GPIO_BL (GPIO_NUM_NC)
  141. /* LCD touch pins */
  142. #define EXAMPLE_TOUCH_GPIO_RST (GPIO_NUM_NC)
  143. #ifdef CONFIG_WAVESHARE_1_47INCH_TOUCH_LCD
  144. #define EXAMPLE_LCD_H_RES (172)
  145. #define EXAMPLE_LCD_V_RES (320)
  146. #define EXAMPLE_TOUCH_GPIO_INT (GPIO_NUM_9)
  147. #elif defined(CONFIG_WAVESHARE_2INCH_TOUCH_LCD)
  148. #define EXAMPLE_LCD_H_RES (240)
  149. #define EXAMPLE_LCD_V_RES (320)
  150. #define EXAMPLE_TOUCH_GPIO_INT (GPIO_NUM_9)
  151. #elif defined(CONFIG_WAVESHARE_2_8INCH_TOUCH_LCD)
  152. #define EXAMPLE_LCD_H_RES (240)
  153. #define EXAMPLE_LCD_V_RES (320)
  154. #define EXAMPLE_TOUCH_GPIO_INT (GPIO_NUM_NC)
  155. #elif defined(CONFIG_WAVESHARE_3_5INCH_TOUCH_LCD)
  156. #define EXAMPLE_LCD_H_RES (320)
  157. #define EXAMPLE_LCD_V_RES (480)
  158. #define EXAMPLE_TOUCH_GPIO_INT (GPIO_NUM_9)
  159. #endif
  160. // GPIO assignment
  161. #define LED_STRIP_GPIO_PIN 38
  162. #define LED_STRIP_LED_COUNT 7
  163. esp_err_t esp_board_init(uint32_t sample_rate, int channel_format, int bits_per_chan);
  164. esp_err_t esp_sdcard_init(char *mount_point, size_t max_files);
  165. esp_err_t esp_sdcard_deinit(char *mount_point);
  166. esp_err_t esp_audio_play(const int16_t* data, int length, uint32_t ticks_to_wait);
  167. esp_err_t esp_get_feed_data(bool is_get_raw_channel, int16_t *buffer, int buffer_len);
  168. int esp_get_feed_channel(void);
  169. char* esp_get_input_format(void);
  170. esp_err_t esp_audio_set_play_vol(int volume);
  171. esp_err_t esp_audio_get_play_vol(int *volume);
  172. i2c_master_bus_handle_t esp_ret_i2c_handle(void);
  173. esp_codec_dev_handle_t esp_ret_play_dev();
  174. uint32_t Get_SD_Size(void);
  175. uint16_t Folder_retrieval(const char* directory, const char* fileExtension, char File_Name[][MAX_FILE_NAME_SIZE], uint16_t maxFiles) ;
  176. #ifdef __cplusplus
  177. }
  178. #endif