HB, OTA etc
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
set(COMPONENTS main)
|
||||
project(onewire_bus_test)
|
||||
@@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS "onewire_bus_test.c"
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES unity)
|
||||
@@ -0,0 +1,53 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
choice EXAMPLE_ONEWIRE_BACKEND
|
||||
prompt "1-Wire backend"
|
||||
default EXAMPLE_ONEWIRE_BACKEND_RMT if SOC_RMT_SUPPORTED
|
||||
default EXAMPLE_ONEWIRE_BACKEND_UART if SOC_UART_SUPPORTED
|
||||
help
|
||||
Select which low-level backend the test app uses.
|
||||
|
||||
config EXAMPLE_ONEWIRE_BACKEND_RMT
|
||||
bool "RMT backend"
|
||||
depends on SOC_RMT_SUPPORTED
|
||||
|
||||
config EXAMPLE_ONEWIRE_BACKEND_UART
|
||||
bool "UART backend"
|
||||
depends on SOC_UART_SUPPORTED
|
||||
endchoice
|
||||
|
||||
config EXAMPLE_ONEWIRE_UART_PORT_NUM
|
||||
int "UART port number"
|
||||
depends on EXAMPLE_ONEWIRE_BACKEND_UART
|
||||
default 1
|
||||
range 0 2
|
||||
help
|
||||
UART port used by UART backend.
|
||||
Valid UART port numbers differ across targets.
|
||||
Note: UART0 is typically used by the console output.
|
||||
|
||||
config EXAMPLE_ONEWIRE_BUS_GPIO
|
||||
int "1-Wire data GPIO"
|
||||
default 0
|
||||
range 0 63
|
||||
help
|
||||
GPIO number used for the 1-Wire data line.
|
||||
Valid GPIO numbers depend on the selected target; choose a
|
||||
data-capable GPIO within this range for your chip.
|
||||
|
||||
config EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP
|
||||
bool "Enable internal pull-up"
|
||||
default y
|
||||
help
|
||||
Enable internal pull-up resistor on the GPIO pin used for the 1-Wire data line.
|
||||
This is useful when no external pull-up resistor is present.
|
||||
|
||||
config EXAMPLE_ONEWIRE_MAX_DEVICES
|
||||
int "Maximum devices to search"
|
||||
default 2
|
||||
range 1 64
|
||||
help
|
||||
Maximum number of devices to search on the 1-Wire bus.
|
||||
This test app performs SEARCH ROM to collect device addresses (64-bit ROM IDs).
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,4 @@
|
||||
dependencies:
|
||||
espressif/onewire_bus:
|
||||
version: "*"
|
||||
override_path: "../.."
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "onewire_bus.h"
|
||||
#include "onewire_device.h"
|
||||
|
||||
static const char *TAG = "test-app";
|
||||
|
||||
#if CONFIG_EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP
|
||||
#define EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP 1
|
||||
#else
|
||||
#define EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP 0
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_ONEWIRE_BACKEND_UART
|
||||
#define EXAMPLE_ONEWIRE_UART_PORT_NUM CONFIG_EXAMPLE_ONEWIRE_UART_PORT_NUM
|
||||
#endif
|
||||
|
||||
#define EXAMPLE_ONEWIRE_BUS_GPIO CONFIG_EXAMPLE_ONEWIRE_BUS_GPIO
|
||||
#define EXAMPLE_ONEWIRE_MAX_DEVICES CONFIG_EXAMPLE_ONEWIRE_MAX_DEVICES
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// install new 1-wire bus
|
||||
onewire_bus_handle_t bus;
|
||||
onewire_bus_config_t bus_config = {
|
||||
.bus_gpio_num = EXAMPLE_ONEWIRE_BUS_GPIO,
|
||||
.flags = {
|
||||
.en_pull_up = EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP,
|
||||
}
|
||||
};
|
||||
#if CONFIG_EXAMPLE_ONEWIRE_BACKEND_RMT
|
||||
onewire_bus_rmt_config_t rmt_config = {
|
||||
.max_rx_bytes = 10, // 1byte ROM command + 8byte ROM number + 1byte device command
|
||||
};
|
||||
ESP_ERROR_CHECK(onewire_new_bus_rmt(&bus_config, &rmt_config, &bus));
|
||||
ESP_LOGI(TAG, "1-Wire bus installed on GPIO%d by RMT backend", EXAMPLE_ONEWIRE_BUS_GPIO);
|
||||
#elif CONFIG_EXAMPLE_ONEWIRE_BACKEND_UART
|
||||
onewire_bus_uart_config_t uart_config = {
|
||||
.uart_port_num = EXAMPLE_ONEWIRE_UART_PORT_NUM,
|
||||
};
|
||||
ESP_ERROR_CHECK(onewire_new_bus_uart(&bus_config, &uart_config, &bus));
|
||||
ESP_LOGI(TAG, "1-Wire bus installed on GPIO%d by UART backend (UART%d)",
|
||||
EXAMPLE_ONEWIRE_BUS_GPIO, EXAMPLE_ONEWIRE_UART_PORT_NUM);
|
||||
#else
|
||||
#error "No 1-Wire backend selected in menuconfig"
|
||||
#endif
|
||||
|
||||
int onewire_device_found = 0;
|
||||
onewire_device_iter_handle_t iter = NULL;
|
||||
onewire_device_t next_onewire_device;
|
||||
esp_err_t search_result = ESP_OK;
|
||||
|
||||
// create 1-wire device iterator, which is used for device search
|
||||
ESP_ERROR_CHECK(onewire_new_device_iter(bus, &iter));
|
||||
ESP_LOGI(TAG, "Device iterator created, start searching...");
|
||||
do {
|
||||
search_result = onewire_device_iter_get_next(iter, &next_onewire_device);
|
||||
// found a new device
|
||||
if (search_result == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Found a new device, address: %016llX", next_onewire_device.address);
|
||||
onewire_device_found++;
|
||||
if (onewire_device_found >= EXAMPLE_ONEWIRE_MAX_DEVICES) {
|
||||
ESP_LOGI(TAG, "Max device number reached, stop searching...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (search_result != ESP_ERR_NOT_FOUND);
|
||||
ESP_ERROR_CHECK(onewire_del_device_iter(iter));
|
||||
ESP_LOGI(TAG, "Searching done, %d device(s) found", onewire_device_found);
|
||||
|
||||
// delete the bus
|
||||
ESP_LOGI(TAG, "Deleting bus...");
|
||||
ESP_ERROR_CHECK(onewire_bus_del(bus));
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.parametrize('config', ['rmt', 'uart'], indirect=True)
|
||||
def test_onewire_bus(dut: Dut, config: str) -> None:
|
||||
if config == 'rmt':
|
||||
dut.expect_exact('test-app: 1-Wire bus installed on GPIO0 by RMT backend')
|
||||
elif config == 'uart':
|
||||
dut.expect_exact('test-app: 1-Wire bus installed on GPIO0 by UART backend (UART1)')
|
||||
else:
|
||||
raise ValueError(f'Unknown test config: {config}')
|
||||
dut.expect_exact('test-app: Device iterator created, start searching')
|
||||
dut.expect_exact('test-app: Searching done')
|
||||
Reference in New Issue
Block a user