25 75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600, 14400, 19200,
26 28800, 38400, 57600, 115200, 230400, 460800, 614400, 921600, 1228800, 2457600, 3000000, 6000000,
116 const usb_config_desc_t *config_desc;
117 const usb_device_desc_t *device_desc;
118 std::vector<CdcEps> cdc_devs{};
120 if (usb_host_get_device_descriptor(dev_hdl, &device_desc) != ESP_OK) {
121 ESP_LOGE(TAG,
"PL2303: get_device_descriptor failed");
124 if (usb_host_get_active_config_descriptor(dev_hdl, &config_desc) != ESP_OK) {
125 ESP_LOGE(TAG,
"PL2303: get_active_config_descriptor failed");
130 uint16_t bcd_device = device_desc->bcdDevice;
131 uint16_t bcd_usb = device_desc->bcdUSB;
132 uint8_t bmax_packet = device_desc->bMaxPacketSize0;
133 uint8_t bdev_class = device_desc->bDeviceClass;
135 if (bdev_class == 0x02 || bmax_packet != 0x40) {
145 if (bcd_device == 0x0300) {
147 }
else if (bcd_device == 0x0500) {
156 ESP_LOGI(TAG,
"PL2303 chip type: %s (bcdUSB=0x%04X bcdDevice=0x%04X bMaxPkt=%u)", pl2303_type_name(this->
chip_type_),
157 bcd_usb, bcd_device, bmax_packet);
161 for (uint8_t i = 0; i < config_desc->bNumInterfaces; i++) {
162 int ep_offset = conf_offset;
163 const auto *intf = usb_parse_interface_descriptor(config_desc, i, 0, &conf_offset);
166 if (intf->bNumEndpoints < 2)
169 const usb_ep_desc_t *in_ep =
nullptr;
170 const usb_ep_desc_t *out_ep =
nullptr;
171 const usb_ep_desc_t *notify_ep =
nullptr;
173 for (uint8_t e = 0; e < intf->bNumEndpoints; e++) {
174 ep_offset = conf_offset;
175 const auto *ep = usb_parse_endpoint_descriptor_by_index(intf, e, config_desc->wTotalLength, &ep_offset);
178 if (ep->bmAttributes == USB_BM_ATTRIBUTES_XFER_BULK) {
179 if (ep->bEndpointAddress & usb_host::USB_DIR_IN) {
184 }
else if (ep->bmAttributes == USB_BM_ATTRIBUTES_XFER_INT) {
189 if (in_ep && out_ep) {
190 cdc_devs.push_back(
CdcEps{notify_ep, in_ep, out_ep, intf->bInterfaceNumber, intf->bInterfaceNumber});
195 if (cdc_devs.empty())
196 ESP_LOGE(TAG,
"PL2303: failed to find bulk IN+OUT endpoints");
211 ESP_LOGW(TAG,
"PL2303: vendor init transfer failed");
219 uint8_t req = VENDOR_READ_REQUEST;
220 uint8_t wreq = VENDOR_WRITE_REQUEST;
224 this->
control_transfer(VENDOR_READ_REQUEST_TYPE, req, 0x8484, 0, nop_cb, {0});
226 this->
control_transfer(VENDOR_READ_REQUEST_TYPE, req, 0x8484, 0, nop_cb, {0});
227 this->
control_transfer(VENDOR_READ_REQUEST_TYPE, req, 0x8383, 0, nop_cb, {0});
228 this->
control_transfer(VENDOR_READ_REQUEST_TYPE, req, 0x8484, 0, nop_cb, {0});
230 this->
control_transfer(VENDOR_READ_REQUEST_TYPE, req, 0x8484, 0, nop_cb, {0});
231 this->
control_transfer(VENDOR_READ_REQUEST_TYPE, req, 0x8383, 0, nop_cb, {0});
234 this->
control_transfer(VENDOR_WRITE_REQUEST_TYPE, wreq, 2, is_legacy ? 0x24 : 0x44, nop_cb);
239 uint8_t line_coding[7] = {};
240 uint32_t baud = channel->get_baud_rate();
243 uint32_t nearest = nearest_supported_baud(baud);
245 encode_baud_direct(line_coding, baud);
247 encode_baud_divisor_alt(line_coding, baud);
249 encode_baud_divisor(line_coding, baud);
253 switch (channel->get_stop_bits()) {
263 switch (channel->parity_) {
282 line_coding[6] = channel->get_data_bits();
284 ESP_LOGD(TAG,
"PL2303: SET_LINE_REQUEST baud=%u stop=%u parity=%u data=%u", baud, line_coding[4], line_coding[5],
287 std::vector<uint8_t> lc_vec(line_coding, line_coding + 7);
288 uint16_t iface = channel->cdc_dev_.bulk_interface_number;
289 this->
control_transfer(SET_LINE_REQUEST_TYPE, SET_LINE_REQUEST, 0, iface, nop_cb, lc_vec);
292 this->
control_transfer(SET_CONTROL_REQUEST_TYPE, SET_CONTROL_REQUEST, CONTROL_DTR | CONTROL_RTS, iface, nop_cb);