11/*
2- * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Unlicense OR CC0-1.0
55 */
66
77#include <stdio.h>
88#include "esp_log.h"
9+ #include "sdkconfig.h"
910#include "freertos/FreeRTOS.h"
1011#include "freertos/task.h"
1112#include "onewire_bus.h"
1213#include "ds18b20.h"
1314
14- #define EXAMPLE_ONEWIRE_BUS_GPIO 18
15- #define EXAMPLE_ONEWIRE_MAX_DS18B20 2
15+ #if CONFIG_EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP
16+ #define EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP 1
17+ #else
18+ #define EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP 0
19+ #endif
20+
21+ #if CONFIG_EXAMPLE_ONEWIRE_BACKEND_UART
22+ #define EXAMPLE_ONEWIRE_UART_PORT_NUM CONFIG_EXAMPLE_ONEWIRE_UART_PORT_NUM
23+ #endif
24+
25+ #define EXAMPLE_ONEWIRE_BUS_GPIO CONFIG_EXAMPLE_ONEWIRE_BUS_GPIO
26+ #define EXAMPLE_ONEWIRE_MAX_DS18B20 CONFIG_EXAMPLE_ONEWIRE_MAX_DS18B20
1627
1728static const char * TAG = "example" ;
1829
@@ -23,14 +34,25 @@ void app_main(void)
2334 onewire_bus_config_t bus_config = {
2435 .bus_gpio_num = EXAMPLE_ONEWIRE_BUS_GPIO ,
2536 .flags = {
26- .en_pull_up = true, // enable the internal pull-up resistor in case the external device didn't have one
37+ .en_pull_up = EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP ,
2738 }
2839 };
40+ #if CONFIG_EXAMPLE_ONEWIRE_BACKEND_RMT
2941 onewire_bus_rmt_config_t rmt_config = {
3042 .max_rx_bytes = 10 , // 1byte ROM command + 8byte ROM number + 1byte device command
3143 };
3244 ESP_ERROR_CHECK (onewire_new_bus_rmt (& bus_config , & rmt_config , & bus ));
33- ESP_LOGI (TAG , "1-Wire bus installed on GPIO%d" , EXAMPLE_ONEWIRE_BUS_GPIO );
45+ ESP_LOGI (TAG , "1-Wire bus installed on GPIO%d by RMT backend" , EXAMPLE_ONEWIRE_BUS_GPIO );
46+ #elif CONFIG_EXAMPLE_ONEWIRE_BACKEND_UART
47+ onewire_bus_uart_config_t uart_config = {
48+ .uart_port_num = EXAMPLE_ONEWIRE_UART_PORT_NUM ,
49+ };
50+ ESP_ERROR_CHECK (onewire_new_bus_uart (& bus_config , & uart_config , & bus ));
51+ ESP_LOGI (TAG , "1-Wire bus installed on GPIO%d by UART backend (UART%d)" ,
52+ EXAMPLE_ONEWIRE_BUS_GPIO , EXAMPLE_ONEWIRE_UART_PORT_NUM );
53+ #else
54+ #error "No 1-Wire backend selected in menuconfig"
55+ #endif
3456
3557 int ds18b20_device_num = 0 ;
3658 ds18b20_device_handle_t ds18b20s [EXAMPLE_ONEWIRE_MAX_DS18B20 ];
0 commit comments