MichaelZaidman / hid-ft260

FTDI FT260 Linux kernel driver
GNU General Public License v2.0
22 stars 6 forks source link

Implement ioctl calls TIOCMBIS, TIOCMBIC, TIOCMGET and TIOCMSET #27

Open Rio6 opened 2 weeks ago

Rio6 commented 2 weeks ago

Hello, I am trying to program an ESP32 over FT260. For the most part this module works great! I am able to program the chip by manually going into the bootloader mode. But it does not work if I want to use espressif's auto reset function via DTR and RTS pins. The tool uses these 4 ioctl calls to reset the chip: TIOCMBIS, TIOCMBIC, TIOCMGET, TIOCMSET.

https://github.com/espressif/esptool/blob/master/esptool/reset.py#L77 https://github.com/pyserial/pyserial/blob/master/serial/serialposix.py#L717

which causes an OSError: [Errno 25] Inappropriate ioctl for device as it seems like they are not implemented. How easy would it be to add them into this module? Or alternatively, does this module already have an interface that allows controlling the DTR and RTS lines?

(There's another issue with pyerial's list_port implementation where it ignores hid devices from realpath /sys/class/tty/*/device/subsystem. But I think that's belongs to pyerial).

MichaelZaidman commented 1 week ago

Hi @Rio6, According to the spec, the FT260 device supports both, DTR-DSR and RTS_CTS, but only one can be enabled at a time. You are correct. The driver code does not support these flow control modes since they are rarely used nowadays. I mean to add such support when I have more time, but it never happens. Your query motivated me to look into it again.

Rio6 commented 1 week ago

I looked through the datasheet for a bit, it seems the RTS line is set automatically based on the chip's internal queue. DTR line might be similar but the wording on that one is a bit unclear.

In any case, looks like the driver will need to put those lines in GPIO mode to be able to drive them manually. I'm not sure if there's a standard in Linux that change flow control mode back to automatic - there's CRTSCTS from termio but I didn't find anything like that for DTR/DSR.