57 this->
config_transfer_(USB_VENDOR_DEV | usb_host::USB_DIR_IN, 0x5F, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0});
62 ESP_LOGE(TAG,
"CH34x chip detection failed");
66 uint8_t num_ports = 1;
67 for (
const auto &e : CH34X_TABLE) {
68 if (e.pid != this->pid_)
70 if (e.match != 0xFF && (response[e.byte_idx] & e.mask) != e.match)
72 chiptype = e.chiptype;
73 num_ports = e.num_ports;
77 if (chiptype ==
CHIP_CH344L && (response[0] & 0xF0) != 0x40)
79 const char *name =
"unknown";
80 for (
const auto &e : CH34X_TABLE) {
81 if (e.chiptype == chiptype) {
86 this->chiptype_ = chiptype;
87 this->chip_name_ = name;
88 this->num_ports_ = num_ports;
89 ESP_LOGD(TAG,
"CH34x chip: %s, ports: %u", name, this->num_ports_);
99 const uint8_t *response) {
100 uint8_t cmd = 0xA1 + channel->
index_;
109 if (baud_rate < 256000) {
110 if (baud_rate > 6000000 / 255) {
113 }
else if (baud_rate > 750000 / 255) {
116 }
else if (baud_rate > 93750 / 255) {
124 ESP_LOGV(TAG,
"baud_rate: %" PRIu32
", divisor: %d, clk: %" PRIu32, baud_rate, divisor, clk);
125 auto factor =
static_cast<uint8_t
>(clk / baud_rate);
126 if (factor == 0 || factor == 0xFF) {
127 ESP_LOGE(TAG,
"Invalid baud rate %" PRIu32, baud_rate);
130 if ((clk / factor - baud_rate) > (baud_rate - clk / (factor + 1)))
132 factor = 256 - factor;
134 uint16_t value = 0xC0;
141 value |= 8 | ((channel->
parity_ - 1) << 4);
147 this->
config_transfer_(USB_VENDOR_DEV | usb_host::USB_DIR_OUT, cmd, value, (factor << 8) | divisor);
151 this->
config_transfer_(USB_VENDOR_DEV | usb_host::USB_DIR_OUT, cmd + 3, 0x80, 0);