• 富芮坤蓝牙FR801xH GPIO


    通过规格书,可查看到芯片共有32个引脚,如图:
    在这里插入图片描述
    除如电源、晶振等固定用途的引脚外,开发板已引出其余引脚。
    通常情况下,一个IO口除了可作普通输入输出口外,还有可能作其它用途,如作I2C接口的数据引脚或时钟引脚。
    在SDK工程源码中的driver_iomux.h头文件,芯片厂家已列出所有IO口的功能用途:
    如PA组IO的描述:

    PX/MUX   4'h0        4'h1         4'h2        4'h3    4'h4         4'h5	        4'h6	     4'h7	    4'h8	    4'ha
    PORTA0   gpio_a0     I2C0_CLK     I2S_CLK     PWM0    SSP0_CLK     UART0_RXD    UART1_RXD    CLK_OUT    PDM_CLK     
    PORTA1   gpio_a1     I2C0_DAT     I2S_FRM     PWM1    SSP0_CSN     UART0_TXD    UART1_TXD    ant_ctl[0]	PDM_DATA    
    PORTA2   gpio_a2     I2C1_CLK     I2S_DOUT    PWM2    SSP0_DOUT    UART0_RXD    UART1_RXD    ant_ctl[0]	PDM_CLK     
    PORTA3   gpio_a3     I2C1_DAT     I2S_DIN     PWM3    SSP0_DIN     UART0_TXD    UART1_TXD    ant_ctl[1]	PDM_DATA    
    PORTA4   gpio_a4     I2C0_CLK     I2S_CLK     PWM4    SSP0_CLK     UART0_RXD    UART1_RXD    CLK_OUT    PDM_CLK     
    PORTA5   gpio_a5     I2C0_DAT     I2S_FRM     PWM5    SSP0_CSN     UART0_TXD    UART1_TXD    ant_ctl[1]	PDM_DATA    
    PORTA6   gpio_a6     I2C1_CLK     I2S_DOUT    PWM0    SSP0_DOUT    UART0_RXD    UART1_RXD    CLK_OUT    PDM_CLK     
    PORTA7   gpio_a7     I2C1_DAT     I2S_DIN     PWM1    SSP0_DIN     UART0_TXD    UART1_TXD    ant_ctl[0]	PDM_DATA    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    由此可见,所有IO口都是多用途的,所以在使用IO口前必须配置它的功能用途。
    厂家在此文件中也定义好了表示每个IO口的每个功能的宏,如PA0:

    #define PORTA0_FUNC_A0              0x00  //表示作输入或输出的IO口
    #define PORTA0_FUNC_I2C0_CLK        0x01
    #define PORTA0_FUNC_I2S_CLK         0x02
    #define PORTA0_FUNC_PWM0            0x03
    #define PORTA0_FUNC_SSP0_CLK        0x04
    #define PORTA0_FUNC_UART0_RXD       0x05
    #define PORTA0_FUNC_UART1_RXD       0x06
    #define PORTA0_FUNC_CLK_OUT         0x07
    #define PORTA0_FUNC_PDM_CLK         0x08
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    文件底部也提供了定义每组IO和组内IO的宏定义:

    enum system_port_t  //表示哪组io
    {
        GPIO_PORT_A,
        GPIO_PORT_B,
        GPIO_PORT_C,
        GPIO_PORT_D,
    };
    
    enum system_port_bit_t   //表示组内第几个IO
    {
        GPIO_BIT_0,
        GPIO_BIT_1,
        GPIO_BIT_2,
        GPIO_BIT_3,
        GPIO_BIT_4,
        GPIO_BIT_5,
        GPIO_BIT_6,
        GPIO_BIT_7,
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    通过FREQ BLE SDK User Guide V1.0.8.pdf文档,可查阅到GPIO口相关的操作函数:

    //配置GIPIO的功能用途
    void system_set_port_mux(enum system_port_t port, enum system_port_bit_t bit, uint8_t func);  
    
    //配置指定IO口是作输入或输出用途
    void gpio_set_dir(enum system_port_t port, enum system_port_bit_t bit, uint8_t dir);
    
    //获取IO口电平状态
    uint8_t gpio_get_pin_value(enum system_port_t port, enum system_port_bit_t bit);
    
    //设置IO口输出的电平状态
    void gpio_set_pin_value(enum system_port_t port, enum system_port_bit_t bit, uint8_t value);
    
    //当指定的IO口作输入时,一般还要配置上拉功能,让IO口默认处于高电平状态
    void system_set_port_pull(uint32_t port, uint8_t pull);
    //参数port使用如 GPIO_PA0 样式的宏定义(在driver_iomux.h中定义)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    在开发板上有两个按键,其中一个接在PD6引脚,判断用户是否按下的测试代码:

    #include "driver_gpio.h"
    void user_entry_after_ble_init(void)
    {
    	
        co_printf("\r\n IOT211 BLE Peripheral\r\n");
    	  // 获取PD6按键工作状态
    	  //1. 因IO是多用途的,需要配置作GPIO使用 system_set_port_mux
    	  system_set_port_mux(GPIO_PORT_D, GPIO_BIT_6, PORTD6_FUNC_D6);
    	
    	  //2. 根据需要,配置输入输出 gpio_set_dir
    	  gpio_set_dir(GPIO_PORT_D, GPIO_BIT_6, GPIO_DIR_IN);
    	
    	  //3. 增加上拉功能,即让PD6默认是高电平状态
    		system_set_port_pull(GPIO_PD6,true); 
    	
    	  //3. 获取电平或控制输出电平
    	  while (1)
    		{
    			 if (!gpio_get_pin_value(GPIO_PORT_D, GPIO_BIT_6))
    					co_printf("down\r\n");
    			 
    			 //等待用户松手
    			 while (!gpio_get_pin_value(GPIO_PORT_D, GPIO_BIT_6))
    						;
    		}
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
  • 相关阅读:
    题目 1924: 蓝桥杯-01背包
    全选反选案例:
    宝塔php站点设置伪静态规则 访问 a.com 时候跳转到 a.com/b.html
    【思维构造】Vampiric Powers, anyone?—CF1847C
    Shadowing Japanese (中上)Unit 3
    json-server工具准备后端接口服务环境
    linux docker常用命令记录
    MAC安装redis的简单方法
    Matlab深度学习应用教程
    NVIDIA Jetson Linux 35.1
  • 原文地址:https://blog.csdn.net/jklinux/article/details/132905848