Skip to content

Commit

Permalink
AP_HAL_ChibiOS: add support for GPIO pins as RTS/CTS
Browse files Browse the repository at this point in the history
  • Loading branch information
bugobliterator committed Mar 14, 2024
1 parent 5317512 commit 259a7c4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def get_alt_function(self, mcu, pin, function):
return 0
return None

if function and function.endswith("_RTS") and (
if function and (function.endswith("_RTS") or function.endswith("_RTS_GPIO") or function.endswith("_CTS_GPIO")) and (
function.startswith('USART') or function.startswith('UART')):
# we do software RTS
# we do software RTS/CTS
return None

for label in self.af_labels:
Expand Down Expand Up @@ -338,7 +338,7 @@ def extra_value(self, name, type=None, default=None):

def is_RTS(self):
'''return true if this is a RTS pin'''
if self.label and self.label.endswith("_RTS") and (
if self.label and (self.label.endswith("_RTS") or self.label.endswith("_RTS_GPIO")) and (
self.type.startswith('USART') or self.type.startswith('UART')):
return True
return False
Expand Down Expand Up @@ -422,7 +422,8 @@ def get_PUPDR_value(self):
# pulldown on RTS to prevent radios from staying in bootloader
if (self.type.startswith('USART') or
self.type.startswith('UART')) and (
self.label.endswith('_RTS')):
self.label.endswith('_RTS') or
self.label.endswith('_RTS_GPIO')):
v = "PULLDOWN"

if (self.type.startswith('SWD') and
Expand Down Expand Up @@ -1902,7 +1903,11 @@ def write_UART_config(self, f):
tx_line = self.make_line(dev + '_TX')
rx_line = self.make_line(dev + '_RX')
rts_line = self.make_line(dev + '_RTS')
if rts_line == "0":
rts_line = self.make_line(dev + '_RTS_GPIO')
cts_line = self.make_line(dev + '_CTS')
if cts_line == "0":
cts_line = self.make_line(dev + '_CTS_GPIO')
if rts_line != "0":
have_rts_cts = True
f.write('#define HAL_HAVE_RTSCTS_SERIAL%u\n' % num)
Expand Down Expand Up @@ -2914,12 +2919,12 @@ def valid_type(self, ptype, label):
if ptype == 'OUTPUT' and re.match(r'US?ART\d+_(TXINV|RXINV)', label):
return True
m1 = re.match(r'USART(\d+)', ptype)
m2 = re.match(r'USART(\d+)_(RX|TX|CTS|RTS)', label)
m2 = re.match(r'USART(\d+)_(RX|TX|CTS|RTS|CTS_GPIO|RTS_GPIO)', label)
if (m1 and not m2) or (m2 and not m1) or (m1 and m1.group(1) != m2.group(1)):
'''usart numbers need to match'''
return False
m1 = re.match(r'UART(\d+)', ptype)
m2 = re.match(r'UART(\d+)_(RX|TX|CTS|RTS)', label)
m2 = re.match(r'UART(\d+)_(RX|TX|CTS|RTS|CTS_GPIO|RTS_GPIO)', label)
if (m1 and not m2) or (m2 and not m1) or (m1 and m1.group(1) != m2.group(1)):
'''uart numbers need to match'''
return False
Expand Down

0 comments on commit 259a7c4

Please sign in to comment.