33#if defined(I2C_BUFFER_LENGTH)
117 std::array<T, SIZE>
rb_{0};
123class WeikaiComponent;
219 void loop()
override;
280 void setup()
override;
374 bool peek_byte(uint8_t *buffer)
override;
384 void flush()
override;
This is an helper class that provides a simple ring buffers that works as a FIFO.
size_t count_
count number of element in the buffer
bool is_full()
test is the ring buffer is full ?
size_t free()
returns the number of free positions in the buffer
int tail_
position of the next element to read
bool push(const T item)
pushes an item at the tail of the fifo
bool peek(T &item)
return the value of the item at fifo's head without removing it
std::array< T, SIZE > rb_
the ring buffer
int head_
position of the next element to write
void clear()
clear the buffer content
bool is_empty()
test is the Ring Buffer is empty ?
bool pop(T &item)
return and remove the item at head of the fifo
size_t count()
return the number of item in the ring buffer
The WeikaiChannel class is used to implement all the virtual methods of the ESPHome uart::UARTCompone...
virtual void dump_channel()
dump channel information
virtual void setup_channel()
Setup the channel.
WeikaiRegister & reg(uint8_t reg)
Factory method to create a WeikaiRegister proxy object.
void flush() override
Flush the output fifo.
void set_line_param_()
set the line parameters
void set_baudrate_()
set the baud rate
uint8_t data_
a one byte buffer for register read storage
bool peek_byte(uint8_t *buffer) override
Reads the first byte in FIFO without removing it.
size_t xfer_fifo_to_buffer_()
transfer bytes from the weikai internal FIFO to the buffer (if any)
void check_logger_conflict() override
this cannot happen with external uart therefore we do nothing
virtual bool check_channel_down()
check if channel is alive
std::string name_
name of the entity
const char * get_channel_name()
Get the channel name.
WeikaiComponent * parent_
our WK2168component parent
WKRingBuffer< uint8_t, RING_BUFFER_SIZE > receive_buffer_
the buffer where we store temporarily the bytes received
bool read_array(uint8_t *buffer, size_t length) override
Reads a specified number of bytes from a serial port.
void set_channel_name(std::string &&name)
The name as generated by the Python code generator.
void reset_fifo_()
reset the weikai internal FIFO
bool tx_fifo_is_not_empty_()
test if transmit buffer is not empty in the status register (optimization)
uint8_t channel_
our Channel number
void set_parent(WeikaiComponent *parent)
We belongs to this WeikaiComponent.
size_t rx_in_fifo_()
Returns the number of bytes in the receive fifo.
void set_channel(uint8_t channel)
Sets the channel number.
int available() override
Returns the number of bytes in the receive buffer.
size_t tx_in_fifo_()
Returns the number of bytes in the transmit fifo.
void write_array(const uint8_t *buffer, size_t length) override
Writes a specified number of bytes to a serial port.
The WeikaiComponent class stores the information global to the WeiKai component and provides methods ...
void set_name(std::string &&name)
store the name for the component
int test_mode_
test mode value (0 -> no tests)
virtual WeikaiRegister & reg(uint8_t reg, uint8_t channel)=0
Factory method to create a Register object.
uint8_t input_state_
input pin states: 1 means HIGH, 0 means LOW
uint32_t crystal_
crystal value;
void write_pin_val_(uint8_t pin, bool value)
Helper method to write the value of a pin.
bool read_pin_val_(uint8_t pin)
Helper method to read the value of a pin.
uint8_t output_state_
output state: 1 means HIGH, 0 means LOW
bool page1_
set to true when in "page1 mode"
void set_crystal(uint32_t crystal)
store crystal frequency
std::vector< WeikaiChannel * > children_
the list of WeikaiChannel UART children
void set_test_mode(int test_mode)
store if the component is in test mode
void loop() override
override the Component loop()
std::string name_
name of entity
void set_pin_direction_(uint8_t pin, gpio::Flags flags)
Helper method to set the pin mode of a pin.
float get_setup_priority() const override
Get the priority of the component.
uint8_t pin_config_
pin config mask: 1 means OUTPUT, 0 means INPUT
virtual ~WeikaiComponent()
virtual destructor
const char * get_name()
Get the name of the component.
Helper class to expose a WeiKai family IO pin as an internal GPIO pin.
void digital_write(bool value) override
void set_inverted(bool inverted)
bool digital_read() override
void set_pin(uint8_t pin)
gpio::Flags get_flags() const override
void pin_mode(gpio::Flags flags) override
void set_parent(WeikaiComponent *parent)
std::string dump_summary() const override
void set_flags(gpio::Flags flags)
WeikaiComponent * parent_
WeikaiRegister objects acts as proxies to access remote register independently of the bus type.
virtual void write_reg(uint8_t value)=0
writes the register
WeikaiRegister & operator|=(uint8_t value)
overloads the compound |= operator.
WeikaiRegister & operator&=(uint8_t value)
overloads the compound &= operator.
virtual void write_fifo(uint8_t *data, size_t length)=0
write an array of bytes to the transmitter fifo
WeikaiRegister & operator=(uint8_t value)
overloads the = operator.
uint8_t register_
address of the register
WeikaiRegister(WeikaiComponent *const comp, uint8_t reg, uint8_t channel)
WeikaiRegister constructor.
uint8_t channel_
channel for this register
virtual ~WeikaiRegister()
WeikaiComponent *const comp_
pointer to our parent (aggregation)
virtual uint8_t read_reg() const =0
reads the register
virtual void read_fifo(uint8_t *data, size_t length) const =0
read an array of bytes from the receiver fifo
bool uart_receive_test_(char *message)
Test the read_array() method.
void uart_send_test_(char *message)
Test the write_array() method.
const float BUS
For communication buses like i2c/spi.
constexpr size_t XFER_MAX_SIZE
XFER_MAX_SIZE defines the maximum number of bytes allowed during one transfer.
constexpr size_t RING_BUFFER_SIZE
size of the ring buffer set to size of the FIFO
constexpr size_t FIFO_SIZE
size of the internal WeiKai FIFO
Providing packet encoding functions for exchanging data with a remote host.
WeiKai component family - registers' definition.