From 9632a38142ea1a7fef5c36a690634d07e17ebf48 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Wed, 31 Jan 2024 19:40:48 +0300 Subject: [PATCH] ESP32-C6: buzzer works --- .../source/SoftRF/src/platform/ESP32.cpp | 34 ++++++++----------- .../source/SoftRF/src/platform/ESP32.h | 4 ++- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.cpp b/software/firmware/source/SoftRF/src/platform/ESP32.cpp index 083a9f4c4..c1a2a15b5 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.cpp +++ b/software/firmware/source/SoftRF/src/platform/ESP32.cpp @@ -2379,20 +2379,20 @@ static void ESP32_Sound_test(int var) var == REASON_EXT_SYS_RST || var == REASON_SOFT_RESTART) { #if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR >= 5 - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 440);delay(500); - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 640);delay(500); - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 840);delay(500); - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 1040); + tone(SOC_GPIO_PIN_BUZZER, 440);delay(500); + tone(SOC_GPIO_PIN_BUZZER, 640);delay(500); + tone(SOC_GPIO_PIN_BUZZER, 840);delay(500); + tone(SOC_GPIO_PIN_BUZZER, 1040); } else if (var == REASON_WDT_RST) { - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 440);delay(500); - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 1040);delay(500); - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 440);delay(500); - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 1040); + tone(SOC_GPIO_PIN_BUZZER, 440); delay(500); + tone(SOC_GPIO_PIN_BUZZER, 1040);delay(500); + tone(SOC_GPIO_PIN_BUZZER, 440); delay(500); + tone(SOC_GPIO_PIN_BUZZER, 1040); } else { - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 1040);delay(500); - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 840);delay(500); - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 640);delay(500); - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 440); + tone(SOC_GPIO_PIN_BUZZER, 1040);delay(500); + tone(SOC_GPIO_PIN_BUZZER, 840); delay(500); + tone(SOC_GPIO_PIN_BUZZER, 640); delay(500); + tone(SOC_GPIO_PIN_BUZZER, 440); #else ledcWriteTone(LEDC_CHANNEL_BUZZER, 440);delay(500); ledcWriteTone(LEDC_CHANNEL_BUZZER, 640);delay(500); @@ -2413,8 +2413,7 @@ static void ESP32_Sound_test(int var) delay(600); #if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR >= 5 - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 0); // off - ledcDetach(SOC_GPIO_PIN_BUZZER); + noTone(SOC_GPIO_PIN_BUZZER); #else ledcWriteTone(LEDC_CHANNEL_BUZZER, 0); // off ledcDetachPin(SOC_GPIO_PIN_BUZZER); @@ -2474,12 +2473,9 @@ static void ESP32_Sound_tone(int hz, uint8_t volume) if (SOC_GPIO_PIN_BUZZER != SOC_UNUSED_PIN && volume != BUZZER_OFF) { if (hz > 0) { #if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR >= 5 - ledcWriteTone(SOC_GPIO_PIN_BUZZER, hz); - ledcWrite(SOC_GPIO_PIN_BUZZER, volume == BUZZER_VOLUME_FULL ? 0xFF : 0x07); + tone(SOC_GPIO_PIN_BUZZER, hz); } else { - ledcWriteTone(SOC_GPIO_PIN_BUZZER, 0); // off - - ledcDetach(SOC_GPIO_PIN_BUZZER); + noTone(SOC_GPIO_PIN_BUZZER); #else ledcAttachPin(SOC_GPIO_PIN_BUZZER, LEDC_CHANNEL_BUZZER); ledcSetup(LEDC_CHANNEL_BUZZER, 0, LEDC_RESOLUTION_BUZZER); diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.h b/software/firmware/source/SoftRF/src/platform/ESP32.h index c9db9df88..d89674028 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.h +++ b/software/firmware/source/SoftRF/src/platform/ESP32.h @@ -167,7 +167,9 @@ extern Adafruit_NeoPixel strip; SOC_UNUSED_PIN : \ (esp32_board == ESP32_DEVKIT ? 13 : \ (esp32_board == ESP32_C3_DEVKIT ? \ - SOC_GPIO_PIN_C3_BUZZER : SOC_UNUSED_PIN))) + SOC_GPIO_PIN_C3_BUZZER : \ + (esp32_board == ESP32_C6_DEVKIT ? \ + SOC_GPIO_PIN_C6_BUZZER : SOC_UNUSED_PIN)))) /* SPI (does match Heltec & TTGO LoRa32 pins mapping) */ #define SOC_GPIO_PIN_MOSI 27