diff --git a/esphome/components/usb_uart/cp210x.cpp b/esphome/components/usb_uart/cp210x.cpp index 2c341313db..1726c04c0d 100644 --- a/esphome/components/usb_uart/cp210x.cpp +++ b/esphome/components/usb_uart/cp210x.cpp @@ -122,8 +122,9 @@ void USBUartTypeCP210X::enable_channels() { } void USBUartTypeCP210X::load_settings(USBUartChannel *channel, bool dump_config) { - if (channel == nullptr || !channel->initialised_.load()) + if (channel == nullptr || !channel->initialised_.load()) { return; + } usb_host::transfer_cb_t callback = [channel](const usb_host::TransferStatus &status) { if (!status.success) { @@ -132,9 +133,11 @@ void USBUartTypeCP210X::load_settings(USBUartChannel *channel, bool dump_config) } }; + static constexpr uint8_t CP210X_PARITY_SHIFT = 4; + static constexpr uint8_t CP210X_DATA_BITS_SHIFT = 8; uint16_t line_control = channel->stop_bits_; - line_control |= static_cast(channel->parity_) << 4; - line_control |= channel->data_bits_ << 8; + line_control |= static_cast(channel->parity_) << CP210X_PARITY_SHIFT; + line_control |= channel->data_bits_ << CP210X_DATA_BITS_SHIFT; this->control_transfer(USB_VENDOR_IFC | usb_host::USB_DIR_OUT, SET_LINE_CTL, line_control, channel->index_, callback); diff --git a/esphome/components/usb_uart/usb_uart.cpp b/esphome/components/usb_uart/usb_uart.cpp index 7388484fcd..d3179e14bd 100644 --- a/esphome/components/usb_uart/usb_uart.cpp +++ b/esphome/components/usb_uart/usb_uart.cpp @@ -211,8 +211,9 @@ bool USBUartChannel::read_array(uint8_t *data, size_t len) { } #if defined(USE_ESP8266) || defined(USE_ESP32) void USBUartChannel::load_settings(bool dump_config) { - if (this->parent_ == nullptr || !this->initialised_.load()) + if (this->parent_ == nullptr || !this->initialised_.load()) { return; + } this->parent_->load_settings(this, dump_config); } @@ -221,8 +222,8 @@ void USBUartChannel::load_settings() { this->load_settings(true); } void USBUartComponent::setup() { USBClient::setup(); } void USBUartComponent::load_settings(USBUartChannel *channel, bool dump_config) { - (void) channel; - (void) dump_config; + static_cast(channel); + static_cast(dump_config); } void USBUartComponent::loop() { bool had_work = this->process_usb_events_();