grigorig / stcgal

Open Source STC MCU ISP flash tool
678 stars 140 forks source link

Add option to invert pin reset logic #97

Closed hkzlab closed 1 year ago

hkzlab commented 1 year ago

This PR adds a -i / --invertreset option for the --autoreset function. One of my boards (made by PRECHIN) requires an inverted assertion of the DTR signal to cycle the power, otherwise it remains powered off.

I originally tried implementing the reset using an external command, but given that the serial port was already opened by stcgal and thus inaccessible to my tool (at least on Windows), I opted for this small change.

grigorig commented 1 year ago

I think it would make more sense to add a parameter to the autoreset argument, i.e. --autoreset=[normal|inverted]. Of course, if no parameter is specified it should default to normal. The options for autoreset are so cluttered already after all. What do you think?

hkzlab commented 1 year ago

Makes sense, in fact I was a bit conflicted on how to pass the parameter through

grigorig commented 1 year ago

On second thought, maybe -A should be extended, with new inverted pin modes. Makes more sense and is even simpler. So you'd have e.g. dtr_inverted and rts_inverted.

hkzlab commented 1 year ago

@grigorig that was actually my second idea on how to pass it through. I'll get right to it.

hkzlab commented 1 year ago

@grigorig done. I simply appended the new cases to the if chain already present in reset_device, Given that there aren't many more pins to use for reset it did not seem worth to play clever and try to distinguish the same pin being inverted or not by checking the _inverted string

grigorig commented 1 year ago

Yeah, LGTM.

There is some issue with GitHub Actions, I'll just squash and merge nonetheless.