72 this->
config_transfer_(USB_VENDOR_DEV | usb_host::USB_DIR_IN, 0x5F, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0});
77 ESP_LOGE(TAG,
"CH34x chip detection failed");
81 uint8_t num_ports = 1;
82 for (
const auto &e : CH34X_TABLE) {
83 if (e.pid != this->pid_)
85 if (e.match != 0xFF && (response[e.byte_idx] & e.mask) != e.match)
87 chiptype = e.chiptype;
88 num_ports = e.num_ports;
92 if (chiptype ==
CHIP_CH344L && (response[0] & 0xF0) != 0x40)
94 const char *name =
"unknown";
95 for (
const auto &e : CH34X_TABLE) {
96 if (e.chiptype == chiptype) {
101 this->chiptype_ = chiptype;
102 this->chip_name_ = name;
103 this->num_ports_ = num_ports;
104 ESP_LOGD(TAG,
"CH34x chip: %s, ports: %u", name, this->num_ports_);
114 const uint8_t *response) {
116 const bool has_flow_ctl_reg =
117 std::find(std::begin(CH341_PIDS), std::end(CH341_PIDS), this->
pid_) != std::end(CH341_PIDS);
118 if (!has_flow_ctl_reg && step >= 1)
121 uint8_t cmd = 0xA1 + channel->
index_;
130 if (baud_rate < 256000) {
131 if (baud_rate > 6000000 / 255) {
134 }
else if (baud_rate > 750000 / 255) {
137 }
else if (baud_rate > 93750 / 255) {
145 ESP_LOGV(TAG,
"baud_rate: %" PRIu32
", divisor: %d, clk: %" PRIu32, baud_rate, divisor, clk);
146 auto factor =
static_cast<uint8_t
>(clk / baud_rate);
147 if (factor == 0 || factor == 0xFF) {
148 ESP_LOGE(TAG,
"Invalid baud rate %" PRIu32, baud_rate);
151 if ((clk / factor - baud_rate) > (baud_rate - clk / (factor + 1)))
153 factor = 256 - factor;
155 uint16_t value = 0xC0;
161 value |= 8 | ((
static_cast<uint8_t
>(parity) - 1) << 4);
165 this->
config_transfer_(USB_VENDOR_DEV | usb_host::USB_DIR_OUT, cmd, value, (factor << 8) | divisor);
171 const uint8_t flow_ctl = rts_cts ? CH341_FLOW_CTL_RTSCTS : CH341_FLOW_CTL_NONE;
172 ESP_LOGD(TAG,
"FLOW_CTL: RTS/CTS=%s", ONOFF(rts_cts));
173 this->
config_transfer_(USB_VENDOR_DEV | usb_host::USB_DIR_OUT, CH341_REQ_WRITE_REG,
174 (CH341_REG_FLOW_CTL << 8) | CH341_REG_FLOW_CTL, (flow_ctl << 8) | flow_ctl);