HB, OTA etc

This commit is contained in:
2026-04-22 20:11:55 +03:00
parent 4100931deb
commit cb1014c950
76 changed files with 3157 additions and 232 deletions

View File

@@ -0,0 +1,96 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "soc/soc_caps.h"
#include "onewire_types.h"
#if SOC_RMT_SUPPORTED
#include "onewire_bus_impl_rmt.h"
#endif
#if SOC_UART_SUPPORTED
#include "onewire_bus_impl_uart.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Write bytes to 1-wire bus
*
* @param[in] bus 1-Wire bus handle
* @param[in] tx_data pointer to data to be sent
* @param[in] tx_data_size size of data to be sent, in bytes
* @return
* - ESP_OK: Write bytes to 1-Wire bus successfully
* - ESP_ERR_INVALID_ARG: Write bytes to 1-Wire bus failed because of invalid argument
* - ESP_FAIL: Write bytes to 1-Wire bus failed because of other errors
*/
esp_err_t onewire_bus_write_bytes(onewire_bus_handle_t bus, const uint8_t *tx_data, uint8_t tx_data_size);
/**
* @brief Read bytes from 1-wire bus
*
* @param[in] bus 1-wire bus handle
* @param[out] rx_buf pointer to buffer to store received data
* @param[in] rx_buf_size size of buffer to store received data, in bytes
* @return
* - ESP_OK: Read bytes from 1-Wire bus successfully
* - ESP_ERR_INVALID_ARG: Read bytes from 1-Wire bus failed because of invalid argument
* - ESP_FAIL: Read bytes from 1-Wire bus failed because of other errors
*/
esp_err_t onewire_bus_read_bytes(onewire_bus_handle_t bus, uint8_t *rx_buf, size_t rx_buf_size);
/**
* @brief Write a bit to 1-wire bus, this is a blocking function
*
* @param[in] handle 1-wire bus handle
* @param[in] tx_bit bit to transmit, 0 for zero bit, other for one bit
* @return
* - ESP_OK Write bit to 1-wire bus successfully.
* - ESP_ERR_INVALID_ARG Invalid argument.
*/
esp_err_t onewire_bus_write_bit(onewire_bus_handle_t bus, uint8_t tx_bit);
/**
* @brief Read a bit from 1-wire bus
*
* @param[in] handle 1-wire bus handle
* @param[out] rx_bit received bit, 0 for zero bit, 1 for one bit
* @return
* - ESP_OK Read bit from 1-wire bus successfully.
* - ESP_ERR_INVALID_ARG Invalid argument.
*/
esp_err_t onewire_bus_read_bit(onewire_bus_handle_t bus, uint8_t *rx_bit);
/**
* @brief Send reset pulse to the bus, and check if there are devices attached to the bus
*
* @param[in] bus 1-Wire bus handle
*
* @return
* - ESP_OK: Reset 1-Wire bus successfully and find device on the bus
* - ESP_ERR_NOT_FOUND: Reset 1-Wire bus successfully but no device found on the bus
* - ESP_FAIL: Reset 1-Wire bus failed because of other errors
*/
esp_err_t onewire_bus_reset(onewire_bus_handle_t bus);
/**
* @brief Free 1-Wire bus resources
*
* @param[in] bus 1-Wire bus handle
*
* @return
* - ESP_OK: Free resources successfully
* - ESP_FAIL: Free resources failed because error occurred
*/
esp_err_t onewire_bus_del(onewire_bus_handle_t bus);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "onewire_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief 1-Wire bus RMT specific configuration
*/
typedef struct {
uint32_t max_rx_bytes; /*!< Set the largest possible single receive size,
which determines the size of the internal buffer that used to save the receiving RMT symbols */
} onewire_bus_rmt_config_t;
/**
* @brief Create 1-Wire bus with RMT backend
*
* @note One 1-Wire bus utilizes a pair of RMT TX and RX channels
*
* @param[in] bus_config 1-Wire bus configuration
* @param[in] rmt_config RMT specific configuration
* @param[out] ret_bus Returned 1-Wire bus handle
* @return
* - ESP_OK: create 1-Wire bus handle successfully
* - ESP_ERR_INVALID_ARG: create 1-Wire bus handle failed because of invalid argument
* - ESP_ERR_NO_MEM: create 1-Wire bus handle failed because of out of memory
* - ESP_FAIL: create 1-Wire bus handle failed because some other error
*/
esp_err_t onewire_new_bus_rmt(const onewire_bus_config_t *bus_config, const onewire_bus_rmt_config_t *rmt_config, onewire_bus_handle_t *ret_bus);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "onewire_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief 1-Wire bus UART specific configuration
*/
typedef struct {
int uart_port_num; /*!< UART port number, e.g. UART_NUM_1 */
} onewire_bus_uart_config_t;
/**
* @brief Create 1-Wire bus with UART backend
*
* @note TX and RX will both be configured to bus_config->bus_gpio_num.
* And this GPIO will be configured as open-drain mode.
*
* @param[in] bus_config 1-Wire bus configuration
* @param[in] uart_config UART specific configuration
* @param[out] ret_bus Returned 1-Wire bus handle
* @return
* - ESP_OK: create 1-Wire bus handle successfully
* - ESP_ERR_INVALID_ARG: create 1-Wire bus handle failed because of invalid argument
* - ESP_ERR_NO_MEM: create 1-Wire bus handle failed because of out of memory
* - ESP_FAIL: create 1-Wire bus handle failed because some other error
*/
esp_err_t onewire_new_bus_uart(const onewire_bus_config_t *bus_config, const onewire_bus_uart_config_t *uart_config, onewire_bus_handle_t *ret_bus);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,12 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#define ONEWIRE_CMD_SEARCH_NORMAL 0xF0
#define ONEWIRE_CMD_MATCH_ROM 0x55
#define ONEWIRE_CMD_SKIP_ROM 0xCC
#define ONEWIRE_CMD_SEARCH_ALARM 0xEC
#define ONEWIRE_CMD_READ_POWER_SUPPLY 0xB4

View File

@@ -0,0 +1,27 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Calculate Dallas CRC8 value of a given buffer
*
* @param[in] init_crc Initial CRC value
* @param[in] input Input buffer to calculate CRC value
* @param[in] input_size Size of input buffer, in bytes
* @return CRC8 result of the input buffer
*/
uint8_t onewire_crc8(uint8_t init_crc, uint8_t *input, size_t input_size);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,63 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "onewire_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief 1-Wire device generic type
*/
typedef struct onewire_device_t {
onewire_bus_handle_t bus; /*!< Which bus the 1-Wire device is attached to */
onewire_device_address_t address; /*!< Device address (represented by its internal ROM ID) */
} onewire_device_t;
/**
* @brief Create an iterator to enumerate the 1-Wire devices on the bus
*
* @param[in] bus 1-Wire bus handle
* @param[out] ret_iter Returned created device iterator
* @return
* - ESP_OK: Create device iterator successfully
* - ESP_ERR_INVALID_ARG: Invalid argument
* - ESP_ERR_NO_MEM: No memory to create device iterator
* - ESP_FAIL: Other errors
*/
esp_err_t onewire_new_device_iter(onewire_bus_handle_t bus, onewire_device_iter_handle_t *ret_iter);
/**
* @brief Delete the device iterator
*
* @param[in] iter Device iterator handle
* @return
* - ESP_OK: Delete device iterator successfully
* - ESP_ERR_INVALID_ARG: Invalid argument
* - ESP_FAIL: Other errors
*/
esp_err_t onewire_del_device_iter(onewire_device_iter_handle_t iter);
/**
* @brief Get the next 1-Wire device from the iterator
*
* @param[in] iter Device iterator handle
* @param[out] dev Returned 1-Wire device handle
* @return
* - ESP_OK: Get next device successfully
* - ESP_ERR_INVALID_ARG: Invalid argument
* - ESP_ERR_NOT_FOUND: No more device to get
* - ESP_FAIL: Other errors
*/
esp_err_t onewire_device_iter_get_next(onewire_device_iter_handle_t iter, onewire_device_t *dev);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,43 @@
/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Type of 1-Wire bus handle
*/
typedef struct onewire_bus_t *onewire_bus_handle_t;
/**
* @brief Type of the address for a 1-Wire compatible device
*/
typedef uint64_t onewire_device_address_t;
/**
* @brief Type of 1-Wire device iterator handle
*/
typedef struct onewire_device_iter_t *onewire_device_iter_handle_t;
/**
* @brief 1-Wire bus configuration
*/
typedef struct {
int bus_gpio_num; /*!< GPIO number that used by the 1-Wire bus */
struct onewire_bus_config_flags {
uint32_t en_pull_up: 1; /*!< Set true to enable internal pull-up resistor.
Please note the internal pull-up resistor cannot provide enough current for some devices,
so external pull-up resistor is still recommended. */
} flags; /*!< Configuration flags for the bus */
} onewire_bus_config_t;
#ifdef __cplusplus
}
#endif