在看 rtt 的代码的时候注意到 Kconfig(如bsp/stm32/stm32f429-atk-apollo/board/Kconfig) 有下面一行.
comment "Notice: PH4 --> 116; PH5 --> 117"
感觉很奇怪, PH4怎么就116了呢, 怎么映射.
跟踪代码, 没有发现啥宏定义啥的, 最后在 bsp/thead-smart/drivers/dw_gpio.c 中找到了 映射关系
#define PIN_NUM(port, no) (((((port) & 0xFu) << 4) | ((no) & 0xFu)))
...
static rt_base_t stm32_pin_get(const char *name)
{
rt_base_t pin = 0;
int hw_port_num, hw_pin_num = 0;
int i, name_len;
name_len = rt_strlen(name);
if ((name_len < 4) || (name_len >= 6))
{
return -RT_EINVAL;
}
if ((name[0] != 'P') || (name[2] != '.'))
{
return -RT_EINVAL;
}
if ((name[1] >= 'A') && (name[1] <= 'Z'))
{
hw_port_num = (int)(name[1] - 'A');
}
else
{
return -RT_EINVAL;
}
for (i = 3; i < name_len; i++)
{
hw_pin_num *= 10;
hw_pin_num += name[i] - '0';
}
pin = PIN_NUM(hw_port_num, hw_pin_num);
return pin;
}
...
比如说我 PH5
= (H
-A
) << 4 + 5 = 7
*<<4 +5 = 0x1110000
+0x101 = 0x1110101
= 117
.
rrt里面的端口是映射关系, 不是宏定义. 供大家参考!