|
| 1 | +# |
| 2 | +# Copyright (c) 2006-2019, RT-Thread Development Team |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: MIT License |
| 5 | +# |
| 6 | +# Change Logs: |
| 7 | +# Date Author Notes |
| 8 | +# 2019-06-28 SummerGift first version |
| 9 | +# |
| 10 | + |
| 11 | +def get_pin_num(pin_index): |
| 12 | + """ |
| 13 | + Get the GPIO pin number through the GPIO index, format must be "P + <A~K> + number", such as PE11 |
| 14 | + """ |
| 15 | + |
| 16 | + if pin_index[0] != 'P': |
| 17 | + print("ERROR : Please pass in the correct parameters") |
| 18 | + return |
| 19 | + |
| 20 | + if pin_index[1] == 'A': |
| 21 | + pin_num = pin_index[2:] |
| 22 | + elif pin_index[1] == 'B': |
| 23 | + pin_num = (16 + int(pin_index[2:])) |
| 24 | + elif pin_index[1] == 'C': |
| 25 | + pin_num = (32 + int(pin_index[2:])) |
| 26 | + elif pin_index[1] == 'D': |
| 27 | + pin_num = (48 + int(pin_index[2:])) |
| 28 | + elif pin_index[1] == 'E': |
| 29 | + pin_num = (64 + int(pin_index[2:])) |
| 30 | + elif pin_index[1] == 'F': |
| 31 | + pin_num = (80 + int(pin_index[2:])) |
| 32 | + elif pin_index[1] == 'G': |
| 33 | + pin_num = (96 + int(pin_index[2:])) |
| 34 | + elif pin_index[1] == 'H': |
| 35 | + pin_num = (112 + int(pin_index[2:])) |
| 36 | + elif pin_index[1] == 'I': |
| 37 | + pin_num = (128 + int(pin_index[2:])) |
| 38 | + elif pin_index[1] == 'J': |
| 39 | + pin_num = (144 + int(pin_index[2:])) |
| 40 | + elif pin_index[1] == 'K': |
| 41 | + pin_num = (160 + int(pin_index[2:])) |
| 42 | + |
| 43 | + return pin_num |
| 44 | + |
| 45 | +pin_num = get_pin_num("PE11") # Get the pin number for PE11 |
| 46 | +print(pin_num) |
0 commit comments