board.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @file board.c
  3. * @brief ESP32 Generic board implementation
  4. *
  5. * Minimal implementation for generic ESP32 dev boards with external I2S DAC.
  6. * No board-specific initialization required.
  7. */
  8. #include "iot_board.h"
  9. #include "driver/gpio.h"
  10. #include "esp_check.h"
  11. #include "esp_log.h"
  12. static const char TAG[] = "ESP32-Generic";
  13. static bool s_board_initialized = false;
  14. #ifdef CONFIG_MUTE_GPIO
  15. static esp_err_t init_mute_gpio(void) {
  16. if (CONFIG_MUTE_GPIO < 0) {
  17. return ESP_OK;
  18. }
  19. gpio_config_t io_conf = {
  20. .pin_bit_mask = (1ULL << CONFIG_MUTE_GPIO),
  21. .mode = GPIO_MODE_OUTPUT,
  22. .pull_up_en = GPIO_PULLUP_DISABLE,
  23. .pull_down_en = GPIO_PULLDOWN_DISABLE,
  24. .intr_type = GPIO_INTR_DISABLE,
  25. };
  26. esp_err_t err = gpio_config(&io_conf);
  27. ESP_RETURN_ON_ERROR(err, TAG, "Failed to configure mute GPIO");
  28. // Initialize to unmuted state — set opposite of active level
  29. gpio_set_level(CONFIG_MUTE_GPIO, !CONFIG_MUTE_GPIO_LEVEL);
  30. ESP_LOGI(TAG, "Mute GPIO %d initialized (active %s, init %s)",
  31. CONFIG_MUTE_GPIO, CONFIG_MUTE_GPIO_LEVEL ? "high" : "low",
  32. CONFIG_MUTE_GPIO_LEVEL ? "low" : "high");
  33. return ESP_OK;
  34. }
  35. #endif
  36. const char *iot_board_get_info(void) {
  37. return BOARD_NAME;
  38. }
  39. bool iot_board_is_init(void) {
  40. return s_board_initialized;
  41. }
  42. board_res_handle_t iot_board_get_handle(int id) {
  43. (void)id;
  44. return NULL;
  45. }
  46. esp_err_t iot_board_init(void) {
  47. if (s_board_initialized) {
  48. ESP_LOGW(TAG, "Board already initialized");
  49. return ESP_OK;
  50. }
  51. #ifdef CONFIG_MUTE_GPIO
  52. esp_err_t err = init_mute_gpio();
  53. if (err != ESP_OK) {
  54. return err;
  55. }
  56. #endif
  57. s_board_initialized = true;
  58. ESP_LOGI(TAG, "Generic board initialized (no board-specific init needed)");
  59. return ESP_OK;
  60. }
  61. esp_err_t iot_board_deinit(void) {
  62. s_board_initialized = false;
  63. return ESP_OK;
  64. }