# HG changeset patch # User Michiel Broek # Date 1697901757 -7200 # Node ID 676c38f52d08f7d60a43de4cb4789fcab42375e6 # Parent 426defedd40264d91325f3a42facbf0d15781b79 Use on-board color LED diff -r 426defedd402 -r 676c38f52d08 main/dcf77tx.c --- a/main/dcf77tx.c Sat Oct 21 16:22:20 2023 +0200 +++ b/main/dcf77tx.c Sat Oct 21 17:22:37 2023 +0200 @@ -10,7 +10,7 @@ static TaskHandle_t xTaskDCF = NULL; char hostname[32]; int Main_Loop = ML_INIT; - +static led_strip_handle_t led_strip; ///< ESP32-C3 onboard LED extern SemaphoreHandle_t xSemaphoreWiFi; extern WIFI_State *wifi_state; ///< WiFi state @@ -21,6 +21,17 @@ extern bool System_TimeOk; +void set_ob_led(uint32_t red, uint32_t green, uint32_t blue) +{ + if ((red + green + blue) > 0) { + led_strip_set_pixel(led_strip, 0, red, green, blue); + led_strip_refresh(led_strip); + } else { + led_strip_clear(led_strip); + } +} + + void app_main(void) { esp_err_t ret; @@ -49,6 +60,17 @@ xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); xTaskCreate(&task_DCF, "task_DCF", 4096, NULL, 4, &xTaskDCF); + led_strip_config_t strip_config = { + .strip_gpio_num = 7, + .max_leds = 1, // at least one LED on board + }; + led_strip_rmt_config_t rmt_config = { + .resolution_hz = 10 * 1000 * 1000, // 10MHz + }; + ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip)); + /* Set all LED off to clear all pixels */ + led_strip_clear(led_strip); + int wait = 150; while (wait) { vTaskDelay(100 / portTICK_PERIOD_MS); @@ -78,7 +100,7 @@ case ML_INIT: if (ready_WiFi() ) { Main_Loop = ML_SYNC; ESP_LOGI(TAG, "ML_INIT -> ML_SYNC"); - gpio_set_level(CONFIG_LED1_PIN, 1); + set_ob_led(5, 0, 0); } else { Main_Loop = ML_CONNECT; ESP_LOGI(TAG, "ML_INIT -> ML_CONNECT"); @@ -99,16 +121,12 @@ Main_Loop = ML_RUN; ESP_LOGI(TAG, "ML_SYNC -> ML_RUN"); request_DCF(true); - gpio_set_level(CONFIG_LED2_PIN, 1); - gpio_set_level(CONFIG_LED1_PIN, 0); } break; case ML_RUN: if (System_TimeOk == false) { Main_Loop = ML_CONNECT; ESP_LOGI(TAG, "ML_RUN -> ML_CONNECT"); request_DCF(false); - gpio_set_level(CONFIG_LED1_PIN, 0); - gpio_set_level(CONFIG_LED2_PIN, 0); } break; } diff -r 426defedd402 -r 676c38f52d08 main/dcf77tx.h --- a/main/dcf77tx.h Sat Oct 21 16:22:20 2023 +0200 +++ b/main/dcf77tx.h Sat Oct 21 17:22:37 2023 +0200 @@ -22,8 +22,6 @@ #include "freertos/queue.h" #include "driver/gpio.h" #include "driver/ledc.h" -//#include "driver/rtc_io.h" -//#include "soc/rtc.h" #include "esp_log.h" #include "esp_system.h" #include "esp_mac.h" @@ -32,6 +30,7 @@ #include "esp_netif_sntp.h" #include "esp_sntp.h" #include "esp_timer.h" +#include "led_strip.h" #include "nvs_flash.h" @@ -46,5 +45,6 @@ ML_RUN ///< Run transmitter } ML; +void set_ob_led(uint32_t red, uint32_t green, uint32_t blue); #endif diff -r 426defedd402 -r 676c38f52d08 main/task_dcf.c --- a/main/task_dcf.c Sat Oct 21 16:22:20 2023 +0200 +++ b/main/task_dcf.c Sat Oct 21 17:22:37 2023 +0200 @@ -109,9 +109,9 @@ ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 512); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); if (impulseArray[actualSecond] == 1) { - gpio_set_level(CONFIG_LED1_PIN, 1); + set_ob_led(5, 5, 0); } else if (impulseArray[actualSecond] == 2) { - gpio_set_level(CONFIG_LED2_PIN, 1); + set_ob_led(0, 5, 5); } break; case 1: if (impulseArray[actualSecond] == 1) { @@ -120,7 +120,7 @@ ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); - gpio_set_level(CONFIG_LED1_PIN, 0); + set_ob_led(0, 2, 0); } break; case 2: /* Carrier back to 100% */ @@ -128,8 +128,7 @@ ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); - gpio_set_level(CONFIG_LED1_PIN, 0); - gpio_set_level(CONFIG_LED2_PIN, 0); + set_ob_led(0, 2, 0); break; case 9: impulseCount = 0; /* @@ -279,11 +278,6 @@ dcf_state = malloc(sizeof(DCF_State)); memset(dcf_state, 0x00, sizeof(DCF_State)); - gpio_reset_pin(LED1); - gpio_reset_pin(LED2); - gpio_set_direction(LED1, GPIO_MODE_OUTPUT); - gpio_set_direction(LED2, GPIO_MODE_OUTPUT); - esp_timer_create_args_t timerDCF = { .callback = &DCFout, .name = "DCF timer"