10static const char *
const TAG =
"weikai_i2c";
15 hex_buffer[(3 * 32) + 1] = 0;
16 for (
size_t i = 0; i <
length; i++) {
17 snprintf(&hex_buffer[3 * (i % 32)],
sizeof(hex_buffer),
"%02X ", data[i]);
19 ESP_LOGVV(TAG,
" %s", hex_buffer);
24 hex_buffer[3 * (
length % 32) + 2] = 0;
25 ESP_LOGVV(TAG,
" %s", hex_buffer);
29static const char *
const REG_TO_STR_P0[16] = {
"GENA",
"GRST",
"GMUT",
"SPAGE",
"SCR",
"LCR",
"FCR",
"SIER",
30 "SIFR",
"TFCNT",
"RFCNT",
"FSR",
"LSR",
"FDAT",
"FWCR",
"RS485"};
31static const char *
const REG_TO_STR_P1[16] = {
"GENA",
"GRST",
"GMUT",
"SPAGE",
"BAUD1",
"BAUD0",
"PRES",
"RFTL",
32 "TFTL",
"FWTH",
"FWTL",
"XON1",
"XOFF1",
"SADR",
"SAEN",
"RTSDLY"};
33using namespace weikai;
41 return page1 ? REG_TO_STR_P1[reg & 0x0F] : REG_TO_STR_P0[reg & 0x0F];
60 uint8_t
const addr = base_address | channel << 1 | fifo << 0;
75 ESP_LOGVV(TAG,
"WeikaiRegisterI2C::read_reg() @%02X reg=%s ch=%u I2C_code:%d, buf=%02X",
address,
79 ESP_LOGE(TAG,
"WeikaiRegisterI2C::read_reg() @%02X reg=%s ch=%u I2C_code:%d, buf=%02X",
address,
92#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
93 ESP_LOGVV(TAG,
"WeikaiRegisterI2C::read_fifo() @%02X ch=%d I2C_code:%d len=%d buffer",
address, this->
channel_,
99 ESP_LOGE(TAG,
"WeikaiRegisterI2C::read_fifo() @%02X reg=N/A ch=%d I2C_code:%d len=%d buf=%02X...",
address,
111 ESP_LOGVV(TAG,
"WK2168Reg::write_reg() @%02X reg=%s ch=%d I2C_code:%d buf=%02X",
address,
115 ESP_LOGE(TAG,
"WK2168Reg::write_reg() @%02X reg=%s ch=%d I2C_code:%d buf=%d",
address,
127#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
128 ESP_LOGVV(TAG,
"WK2168Reg::write_fifo() @%02X ch=%d I2C_code:%d len=%d buffer",
address, this->
channel_,
134 ESP_LOGE(TAG,
"WK2168Reg::write_fifo() @%02X reg=N/A, ch=%d I2C_code:%d len=%d, buf=%02X...",
address,
145 ESP_LOGCONFIG(TAG,
"Setting up wk2168_i2c: %s with %d UARTs at @%02X ...", this->
get_name(), this->
children_.size(),
146 this->base_address_);
158 child->setup_channel();
163 ESP_LOGCONFIG(TAG,
"Initialization of %s with %d UARTs completed", this->
get_name(), this->
children_.size());
164 ESP_LOGCONFIG(TAG,
" Crystal: %" PRIu32, this->
crystal_);
166 ESP_LOGCONFIG(TAG,
" Test mode: %d",
test_mode_);
167 ESP_LOGCONFIG(TAG,
" Transfer buffer size: %d",
XFER_MAX_SIZE);
169 LOG_I2C_DEVICE(
this);
172 child->dump_channel();
void status_set_warning(const char *message="unspecified")
void status_clear_warning()
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
uint8_t address_
store the address of the device on the bus
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
void set_i2c_address(uint8_t address)
We store the address of the device on the bus.
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
int test_mode_
test mode value (0 -> no tests)
uint32_t crystal_
crystal value;
bool page1_
set to true when in "page1 mode"
std::vector< WeikaiChannel * > children_
the list of WeikaiChannel UART children
const char * get_name()
Get the name of the component.
uint8_t register_
address of the register
uint8_t channel_
channel for this register
WeikaiComponent *const comp_
pointer to our parent (aggregation)
The WeikaiComponentI2C class stores the information to the WeiKai component connected through an I2C ...
weikai::WeikaiRegister & reg(uint8_t reg, uint8_t channel) override
uint8_t base_address_
base address of I2C device
void dump_config() override
void write_fifo(uint8_t *data, size_t length) override
uint8_t read_reg() const override
void write_reg(uint8_t value) override
void read_fifo(uint8_t *data, size_t length) const override
constexpr uint8_t WKREG_SPAGE
Global Page register c0/c1 0011.
constexpr uint8_t GRST_C4RST
Channel 4 soft reset (0: not reset, 1: reset)
constexpr uint8_t WKREG_GPDIR
Global GPIO direction register - 10 0001.
constexpr uint8_t WKREG_GPDAT
Global GPIO data register - 11 0001.
constexpr uint8_t GRST_C2RST
Channel 2 soft reset (0: not reset, 1: reset)
constexpr uint8_t WKREG_GRST
Global Reset Register - 00 0001.
constexpr uint8_t GRST_C3RST
Channel 3 soft reset (0: not reset, 1: reset)
constexpr uint8_t GENA_C2EN
Channel 2 enable clock (0: disable, 1: enable)
constexpr uint8_t GRST_C1RST
Channel 1 soft reset (0: not reset, 1: reset)
constexpr uint8_t GENA_C3EN
Channel 3 enable clock (0: disable, 1: enable)
constexpr uint8_t GENA_C4EN
Channel 4 enable clock (0: disable, 1: enable)
constexpr uint8_t WKREG_GENA
Global Control Register - 00 0000.
constexpr uint8_t GENA_C1EN
Channel 1 enable clock (0: disable, 1: enable)
@ NO_ERROR
No error found during execution of method.
uint8_t i2c_address(uint8_t base_address, uint8_t channel, RegType fifo)
Computes the I²C bus's address used to access the component.
constexpr size_t XFER_MAX_SIZE
XFER_MAX_SIZE defines the maximum number of bytes allowed during one transfer.
const char * reg_to_str(int reg, bool page1)
void print_buffer(const uint8_t *data, size_t length)
Display a buffer in hexadecimal format (32 hex values / line) for debug.
Providing packet encoding functions for exchanging data with a remote host.
WeiKai component family - classes declaration.