Skip to content

Commit

Permalink
Add options to invert pin reset logic (#97)
Browse files Browse the repository at this point in the history
This PR adds 'dtr_inverted' and 'rts_inverted' as options for '-A' that
invert the pin logic for autoreset.
  • Loading branch information
hkzlab authored Nov 11, 2023
1 parent 6e8e736 commit a660184
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ options:
-h, --help show this help message and exit
-e, --erase only erase flash memory
-a, --autoreset cycle power automatically by asserting DTR
-A {dtr,rts}, --resetpin {dtr,rts}
-A {dtr,rts,dtr_inverted,rts_inverted}, --resetpin {dtr,rts,dtr_inverted,rts_inverted}
pin to hold down when using --autoreset (default: DTR)
-r RESETCMD, --resetcmd RESETCMD
shell command for board power-cycling (instead of DTR
Expand Down
2 changes: 1 addition & 1 deletion stcgal/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def cli():
exclusives.add_argument("-e", "--erase", help="only erase flash memory", action="store_true")
parser.add_argument("-a", "--autoreset", help="cycle power automatically by asserting DTR", action="store_true")
parser.add_argument("-A", "--resetpin", help="pin to hold down when using --autoreset (default: DTR)",
choices=["dtr", "rts"], default="dtr")
choices=["dtr", "rts", "dtr_inverted", "rts_inverted"], default="dtr")
parser.add_argument("-r", "--resetcmd", help="shell command for board power-cycling (instead of DTR assertion)", action="store")
parser.add_argument("-P", "--protocol", help="protocol version (default: auto)",
choices=["stc89", "stc89a", "stc12a", "stc12b", "stc12", "stc15a", "stc15", "stc8", "stc8d", "stc8g", "usb15", "auto"], default="auto")
Expand Down
14 changes: 11 additions & 3 deletions stcgal/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,30 @@ def get_iap_delay(self, clock_hz):
def set_option(self, name, value):
self.options.set_option(name, value)

def reset_device(self, resetcmd=False, resetpin=False):
def reset_device(self, resetcmd=False, resetpin=False, invertreset=False):
if not resetcmd:
print("Cycling power: ", end="")
sys.stdout.flush()

if resetpin == "rts":
self.ser.setRTS(True)
else:
elif resetpin == "dtr":
self.ser.setDTR(True)
elif resetpin == "rts_inverted":
self.ser.setRTS(False)
else: # dtr_inverted
self.ser.setDTR(False)

time.sleep(0.25)

if resetpin == "rts":
self.ser.setRTS(False)
else:
elif resetpin == "dtr":
self.ser.setDTR(False)
elif resetpin == "rts_inverted":
self.ser.setRTS(True)
else: # dtr_inverted
self.ser.setDTR(True)

time.sleep(0.030)
print("done")
Expand Down

0 comments on commit a660184

Please sign in to comment.