1

RK引脚编号计算器

 1 year ago
source link: https://www.taterli.com/9256/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

RK引脚编号计算器

RK引脚编号计算器

这段程序将一个GPIO引脚名称字符串(name)解析为数字表示该引脚的编号.具体来说,GPIO引脚名称的格式为"GPIO{bank}_{group}{pin}",其中{bank}为引脚所在的GPIO bank编号,{group}为引脚所在的GPIO组编号,{pin}为引脚在组内的编号.程序首先从字符串中提取{bank},{group},{pin},并将它们转换为整数类型.其中,{bank}从字符串第5个字符开始,{group}从字符串第7个字符开始,{pin}从字符串第8个字符开始.然后,程序根据以下公式计算出该引脚的编号:

bank*32+group*8+pin

其中,bank32表示该引脚所在的GPIO bank的编号对应的引脚编号的偏移量,group8表示该引脚所在的GPIO组的编号对应的引脚编号的偏移量,pin表示该引脚在组内的编号.最终,程序将计算出的引脚编号打印出来.

name = "GPIO1_A3"

bank = int(name[4])
group = ord(name[6].upper()) - 65
pin = int(name[7])

print(bank*32+group*8+pin)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK