Skip to content

Commit

Permalink
ESP32-C6: buzzer works
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Jan 31, 2024
1 parent c1bc040 commit 9632a38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
34 changes: 15 additions & 19 deletions software/firmware/source/SoftRF/src/platform/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion software/firmware/source/SoftRF/src/platform/ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9632a38

Please sign in to comment.