GPIO口设置方法
0 Preface/Foreword
参考博客:RISC-V E300 SOC架构介绍——5.电源常开域(Always on Domain)-CSDN博客
AON:Always ON domain,电源常开域
0.1 IO 外设初始化流程?
IO外设初始化流程包括:
- Configure PAD, i.e., status of pins
- Configure PINMUX, i.e., pin multiplex
- Enable clock signal of peripheral
- Determine initialization parameters of peripherals
- Configure & Enable interrupt if necessary
- Enable peripheral?
1 数据结构
2 软件分析
2.1 Pad_Config
/**
? * @brief ?config the corresponding pad.
? * @param ?Pin_Num: pin number.
? * ? ? This parameter is from ADC_0 to P4_1, please refer to rtl876x.h "Pin_Number" part.
? * @param ?AON_PAD_MODE: use software mode or pinmux mode.
? * ? ? This parameter can be one of the following values:
? * ? ? @arg PAD_SW_MODE: use software mode.
? * ? ? @arg PAD_PINMUX_MODE: use pinmux mode.
? * @param ?AON_PAD_PwrOn: config power of pad.
? * ? ? This parameter can be one of the following values:
? * ? ? @arg PAD_NOT_PWRON: shutdown power of pad.
? * ? ? @arg PAD_IS_PWRON: enable power of pad.
? * @param ?AON_PAD_Pull: config pad pull mode.
? * ? ? This parameter can be one of the following values:
? * ? ? @arg PAD_PULL_NONE: no pull.
? * ? ? @arg PAD_PULL_UP: pull this pin up.
? * ? ? @arg PAD_PULL_DOWN: pull thi pin down.
? * @param ?AON_PAD_E: config pad out put function.
? * ? ? This parameter can be one of the following values:
? * ? ? @arg PAD_OUT_DISABLE: disable pin output.
? * ? ? @arg PAD_OUT_ENABLE: enable pad output.
? * @param ?AON_PAD_O: config pin output level.
? * ? ? This parameter can be one of the following values:
? * ? ? @arg PAD_OUT_LOW: pad output low.
? * ? ? @arg PAD_OUT_HIGH: pad output high.
? * @retval None
? */void Pad_Config(uint8_t Pin_Num,
? ? ? ? ? ? ? ? PAD_Mode AON_PAD_Mode,
? ? ? ? ? ? ? ? PAD_PWR_Mode AON_PAD_PwrOn,
? ? ? ? ? ? ? ? PAD_Pull_Mode AON_PAD_Pull,
? ? ? ? ? ? ? ? PAD_OUTPUT_ENABLE_Mode AON_PAD_E,
? ? ? ? ? ? ? ? PAD_OUTPUT_VAL AON_PAD_O)
{
? ? uint8_t tmpVal;
? ? uint8_t addr = PINADDR_TABLE[Pin_Num];? ? tmpVal = btaon_fast_read_safe(addr);
? ? /* Clear reg value first */
? ? tmpVal &= ~0xF;
? ? /* Pull Config */
? ? if (AON_PAD_Pull == PAD_PULL_UP)
? ? {
? ? ? ? tmpVal |= Pull_En;
? ? }
? ? else if (AON_PAD_Pull == PAD_PULL_DOWN)
? ? {
? ? ? ? tmpVal |= (Pull_En | Pull_Direction);
? ? }
? ? /* Output Config */
? ? tmpVal |= (AON_PAD_O | (AON_PAD_E << 1));
? ? /* Write reg */
? ? btaon_fast_write_safe(addr, tmpVal);? ? tmpVal = btaon_fast_read_safe(addr + 1);
? ? /* Pad control mode */
? ? if (AON_PAD_PwrOn)
? ? {
? ? ? ? tmpVal |= SHDN;
? ? }
? ? else
? ? {
? ? ? ? tmpVal &= ~SHDN;
? ? }
? ? if (AON_PAD_Mode)
? ? {
? ? ? ? tmpVal |= Pin_Mode;
? ? }
? ? else
? ? {
? ? ? ? tmpVal &= ~Pin_Mode;
? ? }
? ? /* Pad Power on mode */
? ? btaon_fast_write_safe((addr + 1), tmpVal);
}
2.2 Pinmux_Config?
?
/**
? * @brief ?Config pin to its corresponding IO function.
? * @param ?Pin_Num: pin number.
? * ? ? This parameter is from ADC_0 to P4_1, please refer to rtl876x.h "Pin_Number" part.
? * @param ?Pin_Func: mean one IO function, please refer to rtl876x_pinmux.h "Pin_Function_Number" part.
? * @retval None
? */
void Pinmux_Config(uint8_t Pin_Num, uint8_t Pin_Func)
{
? ? uint8_t pinmux_reg_num;
? ? uint8_t reg_offset;? ? pinmux_reg_num = Pin_Num >> 2;
? ? reg_offset = (Pin_Num & 0x03) << 3;? ? PINMUX->CFG[pinmux_reg_num] = (PINMUX->CFG[pinmux_reg_num] & ~(0xFF << reg_offset))
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | Pin_Func << reg_offset;? ? return;
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!