ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::uart::SoftwareSerialRxDecoder Class Reference

Software serial RX decoder: on_edge() counts bits from the time between edges; finalize() completes a byte whose idle high tail has no closing edge. More...

#include <software_serial_rx_decoder.h>

Public Member Functions

void setup (uint32_t bit_ticks, uint8_t data_bits, bool parity, uint8_t stop_bits, uint8_t *buffer, size_t buffer_size)
 Configure framing and buffer; drops all state. Follow with reset().
 
void reset (uint32_t now, bool level)
 Forget any partial frame; level is the current line level.
 
bool ESPHOME_ALWAYS_INLINE on_edge (uint32_t now, bool level)
 ISR.
 
bool pending () const
 
bool finalize_due (uint32_t now) const
 
void finalize (uint32_t now)
 Call with the ISR masked.
 
bool ESPHOME_ALWAYS_INLINE push_byte (uint8_t data)
 Drops the byte when full; holds buffer_size - 1 bytes.
 
uint8_t * buffer () const
 
size_t buffer_size () const
 
size_t available () const
 
uint8_t peek_byte () const
 
uint8_t read_byte ()
 

Static Public Attributes

static constexpr uint8_t RX_IDLE = 0xFF
 

Protected Member Functions

uint32_t tail_ticks_ (uint8_t bit) const
 
bool ESPHOME_ALWAYS_INLINE consume_run_ (uint32_t bits, bool level)
 

Protected Attributes

uint32_t bit_ticks_ {0}
 
uint32_t max_run_ticks_ {0}
 
volatile uint32_t last_edge_ {0}
 
uint8_t * buffer_ {nullptr}
 
size_t buffer_size_ {0}
 
volatile size_t in_pos_ {0}
 
size_t out_pos_ {0}
 
volatile uint8_t bit_ {RX_IDLE}
 Next frame bit (data, parity, then stop at stop_bit_) or RX_IDLE.
 
volatile uint8_t cur_byte_ {0}
 
volatile bool last_level_ {true}
 
uint8_t data_bits_ {8}
 
uint8_t stop_bit_ {8}
 

Detailed Description

Software serial RX decoder: on_edge() counts bits from the time between edges; finalize() completes a byte whose idle high tail has no closing edge.

Times are in any steady tick unit.

Definition at line 13 of file software_serial_rx_decoder.h.

Member Function Documentation

◆ available()

size_t esphome::uart::SoftwareSerialRxDecoder::available ( ) const
inline

Definition at line 100 of file software_serial_rx_decoder.h.

◆ buffer()

uint8_t * esphome::uart::SoftwareSerialRxDecoder::buffer ( ) const
inline

Definition at line 97 of file software_serial_rx_decoder.h.

◆ buffer_size()

size_t esphome::uart::SoftwareSerialRxDecoder::buffer_size ( ) const
inline

Definition at line 98 of file software_serial_rx_decoder.h.

◆ consume_run_()

bool ESPHOME_ALWAYS_INLINE esphome::uart::SoftwareSerialRxDecoder::consume_run_ ( uint32_t bits,
bool level )
inlineprotected

Definition at line 126 of file software_serial_rx_decoder.h.

◆ finalize()

void esphome::uart::SoftwareSerialRxDecoder::finalize ( uint32_t now)
inline

Call with the ISR masked.

Definition at line 72 of file software_serial_rx_decoder.h.

◆ finalize_due()

bool esphome::uart::SoftwareSerialRxDecoder::finalize_due ( uint32_t now) const
inline

Definition at line 64 of file software_serial_rx_decoder.h.

◆ on_edge()

bool ESPHOME_ALWAYS_INLINE esphome::uart::SoftwareSerialRxDecoder::on_edge ( uint32_t now,
bool level )
inline

ISR.

True to wake the loop: a byte was pushed, or the line went high in an open frame (a data 1 and the idle tail look alike) so finalize() may be needed.

Definition at line 41 of file software_serial_rx_decoder.h.

◆ peek_byte()

uint8_t esphome::uart::SoftwareSerialRxDecoder::peek_byte ( ) const
inline

Definition at line 107 of file software_serial_rx_decoder.h.

◆ pending()

bool esphome::uart::SoftwareSerialRxDecoder::pending ( ) const
inline

Definition at line 62 of file software_serial_rx_decoder.h.

◆ push_byte()

bool ESPHOME_ALWAYS_INLINE esphome::uart::SoftwareSerialRxDecoder::push_byte ( uint8_t data)
inline

Drops the byte when full; holds buffer_size - 1 bytes.

Definition at line 85 of file software_serial_rx_decoder.h.

◆ read_byte()

uint8_t esphome::uart::SoftwareSerialRxDecoder::read_byte ( )
inline

Definition at line 112 of file software_serial_rx_decoder.h.

◆ reset()

void esphome::uart::SoftwareSerialRxDecoder::reset ( uint32_t now,
bool level )
inline

Forget any partial frame; level is the current line level.

Definition at line 32 of file software_serial_rx_decoder.h.

◆ setup()

void esphome::uart::SoftwareSerialRxDecoder::setup ( uint32_t bit_ticks,
uint8_t data_bits,
bool parity,
uint8_t stop_bits,
uint8_t * buffer,
size_t buffer_size )
inline

Configure framing and buffer; drops all state. Follow with reset().

Definition at line 18 of file software_serial_rx_decoder.h.

◆ tail_ticks_()

uint32_t esphome::uart::SoftwareSerialRxDecoder::tail_ticks_ ( uint8_t bit) const
inlineprotected

Definition at line 122 of file software_serial_rx_decoder.h.

Field Documentation

◆ bit_

volatile uint8_t esphome::uart::SoftwareSerialRxDecoder::bit_ {RX_IDLE}
protected

Next frame bit (data, parity, then stop at stop_bit_) or RX_IDLE.

Definition at line 172 of file software_serial_rx_decoder.h.

◆ bit_ticks_

uint32_t esphome::uart::SoftwareSerialRxDecoder::bit_ticks_ {0}
protected

Definition at line 164 of file software_serial_rx_decoder.h.

◆ buffer_

uint8_t* esphome::uart::SoftwareSerialRxDecoder::buffer_ {nullptr}
protected

Definition at line 167 of file software_serial_rx_decoder.h.

◆ buffer_size_

size_t esphome::uart::SoftwareSerialRxDecoder::buffer_size_ {0}
protected

Definition at line 168 of file software_serial_rx_decoder.h.

◆ cur_byte_

volatile uint8_t esphome::uart::SoftwareSerialRxDecoder::cur_byte_ {0}
protected

Definition at line 173 of file software_serial_rx_decoder.h.

◆ data_bits_

uint8_t esphome::uart::SoftwareSerialRxDecoder::data_bits_ {8}
protected

Definition at line 175 of file software_serial_rx_decoder.h.

◆ in_pos_

volatile size_t esphome::uart::SoftwareSerialRxDecoder::in_pos_ {0}
protected

Definition at line 169 of file software_serial_rx_decoder.h.

◆ last_edge_

volatile uint32_t esphome::uart::SoftwareSerialRxDecoder::last_edge_ {0}
protected

Definition at line 166 of file software_serial_rx_decoder.h.

◆ last_level_

volatile bool esphome::uart::SoftwareSerialRxDecoder::last_level_ {true}
protected

Definition at line 174 of file software_serial_rx_decoder.h.

◆ max_run_ticks_

uint32_t esphome::uart::SoftwareSerialRxDecoder::max_run_ticks_ {0}
protected

Definition at line 165 of file software_serial_rx_decoder.h.

◆ out_pos_

size_t esphome::uart::SoftwareSerialRxDecoder::out_pos_ {0}
protected

Definition at line 170 of file software_serial_rx_decoder.h.

◆ RX_IDLE

uint8_t esphome::uart::SoftwareSerialRxDecoder::RX_IDLE = 0xFF
staticconstexpr

Definition at line 15 of file software_serial_rx_decoder.h.

◆ stop_bit_

uint8_t esphome::uart::SoftwareSerialRxDecoder::stop_bit_ {8}
protected

Definition at line 176 of file software_serial_rx_decoder.h.


The documentation for this class was generated from the following file: