ESPHome
2025.12.2
Loading...
Searching...
No Matches
esphome
components
uart
uart.cpp
Go to the documentation of this file.
1
#include "
uart.h
"
2
#include "
esphome/core/application.h
"
3
#include "
esphome/core/defines.h
"
4
#include "
esphome/core/helpers.h
"
5
#include "
esphome/core/log.h
"
6
#include <cinttypes>
7
8
namespace
esphome::uart
{
9
10
static
const
char
*
const
TAG
=
"uart"
;
11
12
void
UARTDevice::check_uart_settings
(uint32_t baud_rate, uint8_t stop_bits,
UARTParityOptions
parity,
13
uint8_t data_bits) {
14
if
(this->
parent_
->
get_baud_rate
() != baud_rate) {
15
ESP_LOGE(TAG,
" Invalid baud_rate: Integration requested baud_rate %"
PRIu32
" but you have %"
PRIu32
"!"
,
16
baud_rate, this->
parent_
->
get_baud_rate
());
17
}
18
if
(this->
parent_
->
get_stop_bits
() != stop_bits) {
19
ESP_LOGE(TAG,
" Invalid stop bits: Integration requested stop_bits %u but you have %u!"
, stop_bits,
20
this->
parent_
->
get_stop_bits
());
21
}
22
if
(this->
parent_
->
get_data_bits
() != data_bits) {
23
ESP_LOGE(TAG,
" Invalid number of data bits: Integration requested %u data bits but you have %u!"
, data_bits,
24
this->
parent_
->
get_data_bits
());
25
}
26
if
(this->
parent_
->
get_parity
() != parity) {
27
ESP_LOGE(TAG,
" Invalid parity: Integration requested parity %s but you have %s!"
,
28
LOG_STR_ARG(
parity_to_str
(parity)), LOG_STR_ARG(
parity_to_str
(this->
parent_
->
get_parity
())));
29
}
30
}
31
32
const
LogString *
parity_to_str
(
UARTParityOptions
parity) {
33
switch
(parity) {
34
case
UART_CONFIG_PARITY_NONE
:
35
return
LOG_STR(
"NONE"
);
36
case
UART_CONFIG_PARITY_EVEN
:
37
return
LOG_STR(
"EVEN"
);
38
case
UART_CONFIG_PARITY_ODD
:
39
return
LOG_STR(
"ODD"
);
40
default
:
41
return
LOG_STR(
"UNKNOWN"
);
42
}
43
}
44
45
}
// namespace esphome::uart
application.h
esphome::uart::UARTComponent::get_parity
UARTParityOptions get_parity() const
Definition
uart_component.h:139
esphome::uart::UARTComponent::get_data_bits
uint8_t get_data_bits() const
Definition
uart_component.h:131
esphome::uart::UARTComponent::get_stop_bits
uint8_t get_stop_bits() const
Definition
uart_component.h:123
esphome::uart::UARTComponent::get_baud_rate
uint32_t get_baud_rate() const
Definition
uart_component.h:147
esphome::uart::UARTDevice::check_uart_settings
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:12
esphome::uart::UARTDevice::parent_
UARTComponent * parent_
Definition
uart.h:73
defines.h
helpers.h
log.h
esphome::spi::TAG
const char *const TAG
Definition
spi.cpp:8
esphome::uart
Definition
automation.h:8
esphome::uart::parity_to_str
const LogString * parity_to_str(UARTParityOptions parity)
Definition
uart.cpp:32
esphome::uart::UARTParityOptions
UARTParityOptions
Definition
uart_component.h:16
esphome::uart::UART_CONFIG_PARITY_EVEN
@ UART_CONFIG_PARITY_EVEN
Definition
uart_component.h:18
esphome::uart::UART_CONFIG_PARITY_ODD
@ UART_CONFIG_PARITY_ODD
Definition
uart_component.h:19
esphome::uart::UART_CONFIG_PARITY_NONE
@ UART_CONFIG_PARITY_NONE
Definition
uart_component.h:17
uart.h
Generated by
1.12.0