33 #if defined(I2C_BUFFER_LENGTH) 36 constexpr
size_t XFER_MAX_SIZE = 128;
117 std::array<T, SIZE>
rb_{0};
146 : comp_(comp), register_(reg), channel_(channel) {}
165 operator uint8_t()
const {
return read_reg(); }
169 virtual uint8_t read_reg()
const = 0;
173 virtual void write_reg(uint8_t value) = 0;
178 virtual void read_fifo(uint8_t *data,
size_t length)
const = 0;
183 virtual void write_fifo(uint8_t *data,
size_t length) = 0;
216 const char *
get_name() {
return this->name_.c_str(); }
219 void loop()
override;
241 bool read_pin_val_(uint8_t pin);
244 void write_pin_val_(uint8_t pin,
bool value);
249 #ifdef TEST_COMPONENT 250 void test_gpio_input_();
254 void test_gpio_output_();
258 uint8_t pin_config_{0x00};
259 uint8_t output_state_{0x00};
260 uint8_t input_state_{0x00};
264 std::vector<WeikaiChannel *> children_{};
274 void set_pin(uint8_t pin) { this->pin_ = pin; }
278 void setup()
override;
279 std::string dump_summary()
const override;
281 bool digital_read()
override {
return this->parent_->read_pin_val_(this->pin_) != this->inverted_; }
282 void digital_write(
bool value)
override { this->parent_->write_pin_val_(this->pin_, value != this->inverted_); }
301 this->parent_ = parent;
302 this->parent_->
children_.push_back(
this);
318 void virtual setup_channel();
321 void virtual dump_channel();
349 void write_array(
const uint8_t *buffer,
size_t length)
override;
365 bool read_array(uint8_t *buffer,
size_t length)
override;
372 bool peek_byte(uint8_t *buffer)
override;
376 int available()
override;
382 void flush()
override;
394 void set_line_param_();
397 void set_baudrate_();
401 size_t rx_in_fifo_();
405 size_t tx_in_fifo_();
409 bool tx_fifo_is_not_empty_();
413 size_t xfer_fifo_to_buffer_();
417 bool virtual check_channel_down();
419 #ifdef TEST_COMPONENT 425 void uart_send_test_(
char *message);
430 bool uart_receive_test_(
char *message);
void clear()
clear the buffer content
void set_channel_name(std::string &&name)
The name as generated by the Python code generator.
std::array< T, SIZE > rb_
the ring buffer
void set_channel(uint8_t channel)
Sets the channel number.
bool is_empty()
test is the Ring Buffer is empty ?
void check_logger_conflict() override
this cannot happen with external uart therefore we do nothing
void set_name(std::string &&name)
store the name for the component
WeikaiRegister(WeikaiComponent *const comp, uint8_t reg, uint8_t channel)
WeikaiRegister constructor.
WKRingBuffer< uint8_t, RING_BUFFER_SIZE > receive_buffer_
the buffer where we store temporarily the bytes received
const char * get_name()
Get the name of the component.
WeiKai component family - registers' definition.
size_t count_
count number of element in the buffer
constexpr size_t XFER_MAX_SIZE
XFER_MAX_SIZE defines the maximum number of bytes allowed during one transfer.
uint32_t crystal_
crystal value;
size_t free()
returns the number of free positions in the buffer
std::vector< WeikaiChannel * > children_
the list of WeikaiChannel UART children
WeikaiComponent * parent_
our WK2168component parent
std::string name_
name of the entity
This is an helper class that provides a simple ring buffers that works as a FIFO. ...
Helper class to expose a WeiKai family IO pin as an internal GPIO pin.
size_t count()
return the number of item in the ring buffer
int tail_
position of the next element to read
The WeikaiComponent class stores the information global to the WeiKai component and provides methods ...
float get_setup_priority() const override
Get the priority of the component.
void set_flags(gpio::Flags flags)
const float BUS
For communication buses like i2c/spi.
WeikaiRegister & reg(uint8_t reg)
Factory method to create a WeikaiRegister proxy object.
int test_mode_
test mode value (0 -> no tests)
void set_parent(WeikaiComponent *parent)
bool peek(T &item)
return the value of the item at fifo's head without removing it
void digital_write(bool value) override
The WeikaiChannel class is used to implement all the virtual methods of the ESPHome uart::UARTCompone...
void set_test_mode(int test_mode)
store if the component is in test mode
void set_pin(uint8_t pin)
uint8_t channel_
our Channel number
void pin_mode(gpio::Flags flags) override
virtual ~WeikaiRegister()
constexpr size_t RING_BUFFER_SIZE
size of the ring buffer set to size of the FIFO
void set_parent(WeikaiComponent *parent)
We belongs to this WeikaiComponent.
int head_
position of the next element to write
WeikaiRegister objects acts as proxies to access remote register independently of the bus type...
void set_inverted(bool inverted)
bool push(const T item)
pushes an item at the tail of the fifo
bool pop(T &item)
return and remove the item at head of the fifo
uint8_t register_
address of the register
uint8_t data_
a one byte buffer for register read storage
Implementation of SPI Controller mode.
bool digital_read() override
bool is_full()
test is the ring buffer is full ?
constexpr size_t FIFO_SIZE
size of the internal WeiKai FIFO
const char * get_channel_name()
Get the channel name.
void set_crystal(uint32_t crystal)
store crystal frequency
WeikaiComponent *const comp_
pointer to our parent (aggregation)
std::string name_
name of entity
virtual ~WeikaiComponent()
virtual destructor
uint8_t channel_
channel for this register