ESPHome  2024.11.0
uart.cpp
Go to the documentation of this file.
1 #include "uart.h"
2 #include "esphome/core/log.h"
3 #include "esphome/core/helpers.h"
5 #include "esphome/core/defines.h"
6 #include <cinttypes>
7 
8 namespace esphome {
9 namespace uart {
10 
11 static const char *const TAG = "uart";
12 
13 void UARTDevice::check_uart_settings(uint32_t baud_rate, uint8_t stop_bits, UARTParityOptions parity,
14  uint8_t data_bits) {
15  if (this->parent_->get_baud_rate() != baud_rate) {
16  ESP_LOGE(TAG, " Invalid baud_rate: Integration requested baud_rate %" PRIu32 " but you have %" PRIu32 "!",
17  baud_rate, this->parent_->get_baud_rate());
18  }
19  if (this->parent_->get_stop_bits() != stop_bits) {
20  ESP_LOGE(TAG, " Invalid stop bits: Integration requested stop_bits %u but you have %u!", stop_bits,
21  this->parent_->get_stop_bits());
22  }
23  if (this->parent_->get_data_bits() != data_bits) {
24  ESP_LOGE(TAG, " Invalid number of data bits: Integration requested %u data bits but you have %u!", data_bits,
25  this->parent_->get_data_bits());
26  }
27  if (this->parent_->get_parity() != parity) {
28  ESP_LOGE(TAG, " Invalid parity: Integration requested parity %s but you have %s!",
29  LOG_STR_ARG(parity_to_str(parity)), LOG_STR_ARG(parity_to_str(this->parent_->get_parity())));
30  }
31 }
32 
33 const LogString *parity_to_str(UARTParityOptions parity) {
34  switch (parity) {
36  return LOG_STR("NONE");
38  return LOG_STR("EVEN");
40  return LOG_STR("ODD");
41  default:
42  return LOG_STR("UNKNOWN");
43  }
44 }
45 
46 } // namespace uart
47 } // namespace esphome
uint32_t get_baud_rate() const
UARTComponent * parent_
Definition: uart.h:68
const char *const TAG
Definition: spi.cpp:8
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
Definition: uart.cpp:13
UARTParityOptions get_parity() const
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
const LogString * parity_to_str(UARTParityOptions parity)
Definition: uart.cpp:33