board.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * @file board.c
  3. * @brief Waveshare ESP32P4 DEV KIT board implementation
  4. *
  5. * Minimal implementation for Waveshare ESP32P4 DEV KIT boards with external I2S
  6. * DAC.
  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[] = "Waveshare-ESP32P4-DEV-KIT";
  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. init_mute_gpio();
  53. #endif
  54. s_board_initialized = true;
  55. ESP_LOGI(TAG, "Waveshare ESP32-P4 DEV KIT initialized");
  56. return ESP_OK;
  57. }
  58. esp_err_t iot_board_deinit(void) {
  59. s_board_initialized = false;
  60. return ESP_OK;
  61. }