1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-03 10:32:21 +01:00

Merge remote-tracking branch 'upstream/dev' into integration

This commit is contained in:
J. Nick Koston
2025-09-30 18:28:49 +02:00
21 changed files with 95 additions and 16 deletions

View File

@@ -21,8 +21,8 @@ void Canbus::dump_config() {
} }
} }
void Canbus::send_data(uint32_t can_id, bool use_extended_id, bool remote_transmission_request, canbus::Error Canbus::send_data(uint32_t can_id, bool use_extended_id, bool remote_transmission_request,
const std::vector<uint8_t> &data) { const std::vector<uint8_t> &data) {
struct CanFrame can_message; struct CanFrame can_message;
uint8_t size = static_cast<uint8_t>(data.size()); uint8_t size = static_cast<uint8_t>(data.size());
@@ -45,13 +45,15 @@ void Canbus::send_data(uint32_t can_id, bool use_extended_id, bool remote_transm
ESP_LOGVV(TAG, " data[%d]=%02x", i, can_message.data[i]); ESP_LOGVV(TAG, " data[%d]=%02x", i, can_message.data[i]);
} }
if (this->send_message(&can_message) != canbus::ERROR_OK) { canbus::Error error = this->send_message(&can_message);
if (error != canbus::ERROR_OK) {
if (use_extended_id) { if (use_extended_id) {
ESP_LOGW(TAG, "send to extended id=0x%08" PRIx32 " failed!", can_id); ESP_LOGW(TAG, "send to extended id=0x%08" PRIx32 " failed with error %d!", can_id, error);
} else { } else {
ESP_LOGW(TAG, "send to standard id=0x%03" PRIx32 " failed!", can_id); ESP_LOGW(TAG, "send to standard id=0x%03" PRIx32 " failed with error %d!", can_id, error);
} }
} }
return error;
} }
void Canbus::add_trigger(CanbusTrigger *trigger) { void Canbus::add_trigger(CanbusTrigger *trigger) {

View File

@@ -70,11 +70,11 @@ class Canbus : public Component {
float get_setup_priority() const override { return setup_priority::HARDWARE; } float get_setup_priority() const override { return setup_priority::HARDWARE; }
void loop() override; void loop() override;
void send_data(uint32_t can_id, bool use_extended_id, bool remote_transmission_request, canbus::Error send_data(uint32_t can_id, bool use_extended_id, bool remote_transmission_request,
const std::vector<uint8_t> &data); const std::vector<uint8_t> &data);
void send_data(uint32_t can_id, bool use_extended_id, const std::vector<uint8_t> &data) { canbus::Error send_data(uint32_t can_id, bool use_extended_id, const std::vector<uint8_t> &data) {
// for backwards compatibility only // for backwards compatibility only
this->send_data(can_id, use_extended_id, false, data); return this->send_data(can_id, use_extended_id, false, data);
} }
void set_can_id(uint32_t can_id) { this->can_id_ = can_id; } void set_can_id(uint32_t can_id) { this->can_id_ = can_id; }
void set_use_extended_id(bool use_extended_id) { this->use_extended_id_ = use_extended_id; } void set_use_extended_id(bool use_extended_id) { this->use_extended_id_ = use_extended_id; }

View File

@@ -27,6 +27,7 @@ from esphome.const import (
CONF_GATEWAY, CONF_GATEWAY,
CONF_ID, CONF_ID,
CONF_INTERRUPT_PIN, CONF_INTERRUPT_PIN,
CONF_MAC_ADDRESS,
CONF_MANUAL_IP, CONF_MANUAL_IP,
CONF_MISO_PIN, CONF_MISO_PIN,
CONF_MODE, CONF_MODE,
@@ -197,6 +198,7 @@ BASE_SCHEMA = cv.Schema(
"This option has been removed. Please use the [disabled] option under the " "This option has been removed. Please use the [disabled] option under the "
"new mdns component instead." "new mdns component instead."
), ),
cv.Optional(CONF_MAC_ADDRESS): cv.mac_address,
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)
@@ -365,6 +367,9 @@ async def to_code(config):
if phy_define := _PHY_TYPE_TO_DEFINE.get(config[CONF_TYPE]): if phy_define := _PHY_TYPE_TO_DEFINE.get(config[CONF_TYPE]):
cg.add_define(phy_define) cg.add_define(phy_define)
if mac_address := config.get(CONF_MAC_ADDRESS):
cg.add(var.set_fixed_mac(mac_address.parts))
cg.add_define("USE_ETHERNET") cg.add_define("USE_ETHERNET")
# Disable WiFi when using Ethernet to save memory # Disable WiFi when using Ethernet to save memory

View File

@@ -253,7 +253,11 @@ void EthernetComponent::setup() {
// use ESP internal eth mac // use ESP internal eth mac
uint8_t mac_addr[6]; uint8_t mac_addr[6];
esp_read_mac(mac_addr, ESP_MAC_ETH); if (this->fixed_mac_.has_value()) {
memcpy(mac_addr, this->fixed_mac_->data(), 6);
} else {
esp_read_mac(mac_addr, ESP_MAC_ETH);
}
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_S_MAC_ADDR, mac_addr); err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_S_MAC_ADDR, mac_addr);
ESPHL_ERROR_CHECK(err, "set mac address error"); ESPHL_ERROR_CHECK(err, "set mac address error");

View File

@@ -84,6 +84,7 @@ class EthernetComponent : public Component {
#endif #endif
void set_type(EthernetType type); void set_type(EthernetType type);
void set_manual_ip(const ManualIP &manual_ip); void set_manual_ip(const ManualIP &manual_ip);
void set_fixed_mac(const std::array<uint8_t, 6> &mac) { this->fixed_mac_ = mac; }
network::IPAddresses get_ip_addresses(); network::IPAddresses get_ip_addresses();
network::IPAddress get_dns_address(uint8_t num); network::IPAddress get_dns_address(uint8_t num);
@@ -155,6 +156,7 @@ class EthernetComponent : public Component {
esp_netif_t *eth_netif_{nullptr}; esp_netif_t *eth_netif_{nullptr};
esp_eth_handle_t eth_handle_; esp_eth_handle_t eth_handle_;
esp_eth_phy_t *phy_{nullptr}; esp_eth_phy_t *phy_{nullptr};
optional<std::array<uint8_t, 6>> fixed_mac_;
}; };
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)

View File

@@ -155,7 +155,7 @@ void MCP2515::prepare_id_(uint8_t *buffer, const bool extended, const uint32_t i
canid = (uint16_t) (id >> 16); canid = (uint16_t) (id >> 16);
buffer[MCP_SIDL] = (uint8_t) (canid & 0x03); buffer[MCP_SIDL] = (uint8_t) (canid & 0x03);
buffer[MCP_SIDL] += (uint8_t) ((canid & 0x1C) << 3); buffer[MCP_SIDL] += (uint8_t) ((canid & 0x1C) << 3);
buffer[MCP_SIDL] |= TXB_EXIDE_MASK; buffer[MCP_SIDL] |= SIDL_EXIDE_MASK;
buffer[MCP_SIDH] = (uint8_t) (canid >> 5); buffer[MCP_SIDH] = (uint8_t) (canid >> 5);
} else { } else {
buffer[MCP_SIDH] = (uint8_t) (canid >> 3); buffer[MCP_SIDH] = (uint8_t) (canid >> 3);
@@ -258,7 +258,7 @@ canbus::Error MCP2515::send_message(struct canbus::CanFrame *frame) {
} }
} }
return canbus::ERROR_FAILTX; return canbus::ERROR_ALLTXBUSY;
} }
canbus::Error MCP2515::read_message_(RXBn rxbn, struct canbus::CanFrame *frame) { canbus::Error MCP2515::read_message_(RXBn rxbn, struct canbus::CanFrame *frame) {
@@ -272,7 +272,7 @@ canbus::Error MCP2515::read_message_(RXBn rxbn, struct canbus::CanFrame *frame)
bool use_extended_id = false; bool use_extended_id = false;
bool remote_transmission_request = false; bool remote_transmission_request = false;
if ((tbufdata[MCP_SIDL] & TXB_EXIDE_MASK) == TXB_EXIDE_MASK) { if ((tbufdata[MCP_SIDL] & SIDL_EXIDE_MASK) == SIDL_EXIDE_MASK) {
id = (id << 2) + (tbufdata[MCP_SIDL] & 0x03); id = (id << 2) + (tbufdata[MCP_SIDL] & 0x03);
id = (id << 8) + tbufdata[MCP_EID8]; id = (id << 8) + tbufdata[MCP_EID8];
id = (id << 8) + tbufdata[MCP_EID0]; id = (id << 8) + tbufdata[MCP_EID0];
@@ -315,6 +315,17 @@ canbus::Error MCP2515::read_message(struct canbus::CanFrame *frame) {
rc = canbus::ERROR_NOMSG; rc = canbus::ERROR_NOMSG;
} }
#ifdef ESPHOME_LOG_HAS_DEBUG
uint8_t err = get_error_flags_();
// The receive flowchart in the datasheet says that if rollover is set (BUKT), RX1OVR flag will be set
// once both buffers are full. However, the RX0OVR flag is actually set instead.
// We can just check for both though because it doesn't break anything.
if (err & (EFLG_RX0OVR | EFLG_RX1OVR)) {
ESP_LOGD(TAG, "receive buffer overrun");
clear_rx_n_ovr_flags_();
}
#endif
return rc; return rc;
} }

View File

@@ -130,7 +130,9 @@ static const uint8_t CANSTAT_ICOD = 0x0E;
static const uint8_t CNF3_SOF = 0x80; static const uint8_t CNF3_SOF = 0x80;
static const uint8_t TXB_EXIDE_MASK = 0x08; // applies to RXBn_SIDL, TXBn_SIDL and RXFn_SIDL
static const uint8_t SIDL_EXIDE_MASK = 0x08;
static const uint8_t DLC_MASK = 0x0F; static const uint8_t DLC_MASK = 0x0F;
static const uint8_t RTR_MASK = 0x40; static const uint8_t RTR_MASK = 0x40;

View File

@@ -15,6 +15,10 @@ CONF_BANDWIDTH = "bandwidth"
CONF_BITRATE = "bitrate" CONF_BITRATE = "bitrate"
CONF_CODING_RATE = "coding_rate" CONF_CODING_RATE = "coding_rate"
CONF_CRC_ENABLE = "crc_enable" CONF_CRC_ENABLE = "crc_enable"
CONF_CRC_INVERTED = "crc_inverted"
CONF_CRC_SIZE = "crc_size"
CONF_CRC_POLYNOMIAL = "crc_polynomial"
CONF_CRC_INITIAL = "crc_initial"
CONF_DEVIATION = "deviation" CONF_DEVIATION = "deviation"
CONF_DIO1_PIN = "dio1_pin" CONF_DIO1_PIN = "dio1_pin"
CONF_HW_VERSION = "hw_version" CONF_HW_VERSION = "hw_version"
@@ -188,6 +192,14 @@ CONFIG_SCHEMA = (
cv.Required(CONF_BUSY_PIN): pins.internal_gpio_input_pin_schema, cv.Required(CONF_BUSY_PIN): pins.internal_gpio_input_pin_schema,
cv.Optional(CONF_CODING_RATE, default="CR_4_5"): cv.enum(CODING_RATE), cv.Optional(CONF_CODING_RATE, default="CR_4_5"): cv.enum(CODING_RATE),
cv.Optional(CONF_CRC_ENABLE, default=False): cv.boolean, cv.Optional(CONF_CRC_ENABLE, default=False): cv.boolean,
cv.Optional(CONF_CRC_INVERTED, default=True): cv.boolean,
cv.Optional(CONF_CRC_SIZE, default=2): cv.int_range(min=1, max=2),
cv.Optional(CONF_CRC_POLYNOMIAL, default=0x1021): cv.All(
cv.hex_int, cv.Range(min=0, max=0xFFFF)
),
cv.Optional(CONF_CRC_INITIAL, default=0x1D0F): cv.All(
cv.hex_int, cv.Range(min=0, max=0xFFFF)
),
cv.Optional(CONF_DEVIATION, default=5000): cv.int_range(min=0, max=100000), cv.Optional(CONF_DEVIATION, default=5000): cv.int_range(min=0, max=100000),
cv.Required(CONF_DIO1_PIN): pins.internal_gpio_input_pin_schema, cv.Required(CONF_DIO1_PIN): pins.internal_gpio_input_pin_schema,
cv.Required(CONF_FREQUENCY): cv.int_range(min=137000000, max=1020000000), cv.Required(CONF_FREQUENCY): cv.int_range(min=137000000, max=1020000000),
@@ -251,6 +263,10 @@ async def to_code(config):
cg.add(var.set_shaping(config[CONF_SHAPING])) cg.add(var.set_shaping(config[CONF_SHAPING]))
cg.add(var.set_bitrate(config[CONF_BITRATE])) cg.add(var.set_bitrate(config[CONF_BITRATE]))
cg.add(var.set_crc_enable(config[CONF_CRC_ENABLE])) cg.add(var.set_crc_enable(config[CONF_CRC_ENABLE]))
cg.add(var.set_crc_inverted(config[CONF_CRC_INVERTED]))
cg.add(var.set_crc_size(config[CONF_CRC_SIZE]))
cg.add(var.set_crc_polynomial(config[CONF_CRC_POLYNOMIAL]))
cg.add(var.set_crc_initial(config[CONF_CRC_INITIAL]))
cg.add(var.set_payload_length(config[CONF_PAYLOAD_LENGTH])) cg.add(var.set_payload_length(config[CONF_PAYLOAD_LENGTH]))
cg.add(var.set_preamble_size(config[CONF_PREAMBLE_SIZE])) cg.add(var.set_preamble_size(config[CONF_PREAMBLE_SIZE]))
cg.add(var.set_preamble_detect(config[CONF_PREAMBLE_DETECT])) cg.add(var.set_preamble_detect(config[CONF_PREAMBLE_DETECT]))

View File

@@ -235,6 +235,16 @@ void SX126x::configure() {
buf[7] = (fdev >> 0) & 0xFF; buf[7] = (fdev >> 0) & 0xFF;
this->write_opcode_(RADIO_SET_MODULATIONPARAMS, buf, 8); this->write_opcode_(RADIO_SET_MODULATIONPARAMS, buf, 8);
// set crc params
if (this->crc_enable_) {
buf[0] = this->crc_initial_ >> 8;
buf[1] = this->crc_initial_ & 0xFF;
this->write_register_(REG_CRC_INITIAL, buf, 2);
buf[0] = this->crc_polynomial_ >> 8;
buf[1] = this->crc_polynomial_ & 0xFF;
this->write_register_(REG_CRC_POLYNOMIAL, buf, 2);
}
// set packet params and sync word // set packet params and sync word
this->set_packet_params_(this->get_max_packet_size()); this->set_packet_params_(this->get_max_packet_size());
if (!this->sync_value_.empty()) { if (!this->sync_value_.empty()) {
@@ -276,7 +286,11 @@ void SX126x::set_packet_params_(uint8_t payload_length) {
buf[4] = 0x00; buf[4] = 0x00;
buf[5] = (this->payload_length_ > 0) ? 0x00 : 0x01; buf[5] = (this->payload_length_ > 0) ? 0x00 : 0x01;
buf[6] = payload_length; buf[6] = payload_length;
buf[7] = this->crc_enable_ ? 0x06 : 0x01; if (this->crc_enable_) {
buf[7] = (this->crc_inverted_ ? 0x04 : 0x00) + (this->crc_size_ & 0x02);
} else {
buf[7] = 0x01;
}
buf[8] = 0x00; buf[8] = 0x00;
this->write_opcode_(RADIO_SET_PACKETPARAMS, buf, 9); this->write_opcode_(RADIO_SET_PACKETPARAMS, buf, 9);
} }

View File

@@ -67,6 +67,10 @@ class SX126x : public Component,
void set_busy_pin(InternalGPIOPin *busy_pin) { this->busy_pin_ = busy_pin; } void set_busy_pin(InternalGPIOPin *busy_pin) { this->busy_pin_ = busy_pin; }
void set_coding_rate(uint8_t coding_rate) { this->coding_rate_ = coding_rate; } void set_coding_rate(uint8_t coding_rate) { this->coding_rate_ = coding_rate; }
void set_crc_enable(bool crc_enable) { this->crc_enable_ = crc_enable; } void set_crc_enable(bool crc_enable) { this->crc_enable_ = crc_enable; }
void set_crc_inverted(bool crc_inverted) { this->crc_inverted_ = crc_inverted; }
void set_crc_size(uint8_t crc_size) { this->crc_size_ = crc_size; }
void set_crc_polynomial(uint16_t crc_polynomial) { this->crc_polynomial_ = crc_polynomial; }
void set_crc_initial(uint16_t crc_initial) { this->crc_initial_ = crc_initial; }
void set_deviation(uint32_t deviation) { this->deviation_ = deviation; } void set_deviation(uint32_t deviation) { this->deviation_ = deviation; }
void set_dio1_pin(InternalGPIOPin *dio1_pin) { this->dio1_pin_ = dio1_pin; } void set_dio1_pin(InternalGPIOPin *dio1_pin) { this->dio1_pin_ = dio1_pin; }
void set_frequency(uint32_t frequency) { this->frequency_ = frequency; } void set_frequency(uint32_t frequency) { this->frequency_ = frequency; }
@@ -118,6 +122,11 @@ class SX126x : public Component,
char version_[16]; char version_[16];
SX126xBw bandwidth_{SX126X_BW_125000}; SX126xBw bandwidth_{SX126X_BW_125000};
uint32_t bitrate_{0}; uint32_t bitrate_{0};
bool crc_enable_{false};
bool crc_inverted_{false};
uint8_t crc_size_{0};
uint16_t crc_polynomial_{0};
uint16_t crc_initial_{0};
uint32_t deviation_{0}; uint32_t deviation_{0};
uint32_t frequency_{0}; uint32_t frequency_{0};
uint32_t payload_length_{0}; uint32_t payload_length_{0};
@@ -131,7 +140,6 @@ class SX126x : public Component,
uint8_t shaping_{0}; uint8_t shaping_{0};
uint8_t spreading_factor_{0}; uint8_t spreading_factor_{0};
int8_t pa_power_{0}; int8_t pa_power_{0};
bool crc_enable_{false};
bool rx_start_{false}; bool rx_start_{false};
bool rf_switch_{false}; bool rf_switch_{false};
}; };

View File

@@ -53,6 +53,8 @@ enum SX126xOpCode : uint8_t {
enum SX126xRegister : uint16_t { enum SX126xRegister : uint16_t {
REG_VERSION_STRING = 0x0320, REG_VERSION_STRING = 0x0320,
REG_CRC_INITIAL = 0x06BC,
REG_CRC_POLYNOMIAL = 0x06BE,
REG_GFSK_SYNCWORD = 0x06C0, REG_GFSK_SYNCWORD = 0x06C0,
REG_LORA_SYNCWORD = 0x0740, REG_LORA_SYNCWORD = 0x0740,
REG_OCP = 0x08E7, REG_OCP = 0x08E7,

View File

@@ -12,3 +12,4 @@ ethernet:
gateway: 192.168.178.1 gateway: 192.168.178.1
subnet: 255.255.255.0 subnet: 255.255.255.0
domain: .local domain: .local
mac_address: "02:AA:BB:CC:DD:01"

View File

@@ -12,3 +12,4 @@ ethernet:
gateway: 192.168.178.1 gateway: 192.168.178.1
subnet: 255.255.255.0 subnet: 255.255.255.0
domain: .local domain: .local
mac_address: "02:AA:BB:CC:DD:01"

View File

@@ -12,3 +12,4 @@ ethernet:
gateway: 192.168.178.1 gateway: 192.168.178.1
subnet: 255.255.255.0 subnet: 255.255.255.0
domain: .local domain: .local
mac_address: "02:AA:BB:CC:DD:01"

View File

@@ -12,3 +12,4 @@ ethernet:
gateway: 192.168.178.1 gateway: 192.168.178.1
subnet: 255.255.255.0 subnet: 255.255.255.0
domain: .local domain: .local
mac_address: "02:AA:BB:CC:DD:01"

View File

@@ -12,3 +12,4 @@ ethernet:
gateway: 192.168.178.1 gateway: 192.168.178.1
subnet: 255.255.255.0 subnet: 255.255.255.0
domain: .local domain: .local
mac_address: "02:AA:BB:CC:DD:01"

View File

@@ -12,3 +12,4 @@ ethernet:
gateway: 192.168.178.1 gateway: 192.168.178.1
subnet: 255.255.255.0 subnet: 255.255.255.0
domain: .local domain: .local
mac_address: "02:AA:BB:CC:DD:01"

View File

@@ -12,3 +12,4 @@ ethernet:
gateway: 192.168.178.1 gateway: 192.168.178.1
subnet: 255.255.255.0 subnet: 255.255.255.0
domain: .local domain: .local
mac_address: "02:AA:BB:CC:DD:01"

View File

@@ -12,3 +12,4 @@ ethernet:
gateway: 192.168.178.1 gateway: 192.168.178.1
subnet: 255.255.255.0 subnet: 255.255.255.0
domain: .local domain: .local
mac_address: "02:AA:BB:CC:DD:01"

View File

@@ -12,3 +12,4 @@ ethernet:
gateway: 192.168.178.1 gateway: 192.168.178.1
subnet: 255.255.255.0 subnet: 255.255.255.0
domain: .local domain: .local
mac_address: "02:AA:BB:CC:DD:01"

View File

@@ -11,6 +11,10 @@ sx126x:
pa_power: 3 pa_power: 3
bandwidth: 125_0kHz bandwidth: 125_0kHz
crc_enable: true crc_enable: true
crc_initial: 0x1D0F
crc_polynomial: 0x1021
crc_size: 2
crc_inverted: true
frequency: 433920000 frequency: 433920000
modulation: LORA modulation: LORA
rx_start: true rx_start: true