00. 目录
文章目录
01. FR801xH概述
FR801xH 系列芯片是面向SOC(片上系统),易于快速开发的低功耗蓝牙芯片。基于 Freqchip 的蓝牙智能固件和协议栈的支持,完全兼容蓝牙 V5.3(LE 模式)协议。同时用户可以基于芯片内置的 ARM CorteM3 嵌入式 32 位高性能单片机开发各种应用程序。
蓝牙智能固件包括 L2CAP 服务层协议、安全管理器 (SM)、属性协议(ATT)、通用属性配置文件 (GATT)和通用访问配置文件(GAP)。此外,还 支持应用程序配置文件,例如接近度、健康温度计、 心率、血压、血糖、人机界面设备(HID)和 SDK (包括驱动程序、OS-API 等)。SDK 还集成了用于网络应用程序的 SIG Mesh 协议。
采用 Freqchip 的创新技术,将 PMU(锂电池充电 器+LDO)、带 XIP 模式的 QSPI FLASH ROM、 I2C、UART、GPIO、ADC、PWM 集成在一块芯片中,为客户提供:
- 竞争力的功耗
- 稳定的蓝牙连接
- 极低的 BOM 成本
02. FR801xH功能框图
03. GPIO相关类型
位于 components\driver\include\driver_gpio.h。
3.1 system_port_t
enum system_port_t
{
GPIO_PORT_A,
GPIO_PORT_B,
GPIO_PORT_C,
GPIO_PORT_D,
};
3.2 system_port_bit_t
enum system_port_bit_t
{
GPIO_BIT_0,
GPIO_BIT_1,
GPIO_BIT_2,
GPIO_BIT_3,
GPIO_BIT_4,
GPIO_BIT_5,
GPIO_BIT_6,
GPIO_BIT_7,
};
3.3 DIR
#define GPIO_DIR_IN 1
#define GPIO_DIR_OUT 0
04. GPIO相关函数
4.1 gpio_portX_write
/*********************************************************************
* @fn gpio_porta_write
*
* @brief set gpio PORTA output value.
*
* @param value - output value.
*
* @return None.
*/
__INLINE void gpio_porta_write(uint8_t value)
{
REG_PL_WR(GPIO_PORTA_DATA, value);
}
/*********************************************************************
* @fn gpio_portb_write
*
* @brief set gpio PORTB output value.
*
* @param value - output value.
*
* @return None.
*/
__INLINE void gpio_portb_write(uint8_t value)
{
REG_PL_WR(GPIO_PORTB_DATA, value);
}
/*********************************************************************
* @fn gpio_portc_write
*
* @brief set gpio PORTC output value.
*
* @param value - output value.
*
* @return None.
*/
__INLINE void gpio_portc_write(uint8_t value)
{
REG_PL_WR(GPIO_PORTC_DATA, value);
}
/*********************************************************************
* @fn gpio_portd_write
*
* @brief set gpio PORTD output value.
*
* @param value - output value.
*
* @return None.
*/
__INLINE void gpio_portd_write(uint8_t value)
{
REG_PL_WR(GPIO_PORTD_DATA, value);
}
void gpio_portX_write(uint8_t value)
功能:
设置一组 IO 由大数字控制时的输出值,x 为 a、b、c、d
参数:
value IO 的输出值
返回值:
无
4.2 gpio_portX_read
/*********************************************************************
* @fn gpio_porta_read
*
* @brief get current value of gpio PORTA.
*
* @param None.
*
* @return current value of gpio PORTA.
*/
__INLINE uint8_t gpio_porta_read(void)
{
return REG_PL_RD(GPIO_PORTA_DATA);
}
/*********************************************************************
* @fn gpio_portb_read
*
* @brief get current value of gpio PORTB.
*
* @param None.
*
* @return current value of gpio PORTB.
*/
__INLINE uint8_t gpio_portb_read(void)
{
return REG_PL_RD(GPIO_PORTB_DATA);
}
/*********************************************************************
* @fn gpio_portc_read
*
* @brief get current value of gpio PORTC.
*
* @param None.
*
* @return current value of gpio PORTC.
*/__INLINE uint8_t gpio_portc_read(void)
{
return REG_PL_RD(GPIO_PORTC_DATA);
}
/*********************************************************************
* @fn gpio_portd_read
*
* @brief get current value of gpio PORTD.
*
* @param None.
*
* @return current value of gpio PORTD.
*/
__INLINE uint8_t gpio_portd_read(void)
{
return REG_PL_RD(GPIO_PORTD_DATA);
}
uint8_t gpio_portX_read(void)
功能:
获取一组 IO 由大数字控制时的当前值,x 为 a、b、c、d
参数:
无
返回值:
IO 的当前值
4.3 gpio_portX_set_dir
/*********************************************************************
* @fn gpio_porta_set_dir
*
* @brief set gpio works in output or input mode.
*
* @param dir - the in-out direction of gpio, each bit represent one channel,
* 0: output, 1:input.
*
* @return None.
*/
__INLINE void gpio_porta_set_dir(uint8_t dir)
{
REG_PL_WR(GPIO_PORTA_DIR, dir);
}
/*********************************************************************
* @fn gpio_portb_set_dir
*
* @brief set gpio works in output or input mode.
*
* @param dir - the in-out direction of gpio, each bit represent one channel,
* 0: output, 1:input.
*
* @return None.
*/
__INLINE void gpio_portb_set_dir(uint8_t dir)
{
REG_PL_WR(GPIO_PORTB_DIR, dir);
}
/*********************************************************************
* @fn gpio_portc_set_dir
*
* @brief set gpio works in output or input mode.
*
* @param dir - the in-out direction of gpio, each bit represent one channel,
* 0: output, 1:input.
*
* @return None.
*/
__INLINE void gpio_portc_set_dir(uint8_t dir)
{
REG_PL_WR(GPIO_PORTC_DIR, dir);
}
/*********************************************************************
* @fn gpio_portd_set_dir
*
* @brief set gpio works in output or input mode.
*
* @param dir - the in-out direction of gpio, each bit represent one channel,
* 0: output, 1:input.
*
* @return None.
*/
__INLINE void gpio_portd_set_dir(uint8_t dir)
{
REG_PL_WR(GPIO_PORTD_DIR, dir);
}
void gpio_portX_set_dir(uint8_t dir)
功能:
设置一组 IO 由大数字控制时的输入输出,x 为 a、b、c、d
参数:
dir 输入输出,每一位对应一个 IO,0:输出;1:输入
返回值:
无
4.4 gpio_portX_get_dir
/*********************************************************************
* @fn gpio_porta_set_dir
*
* @brief get current gpio PORTA in-out setting.
*
* @param None.
*
* @return current setting.
*/
__INLINE uint8_t gpio_porta_get_dir(void)
{
return REG_PL_RD(GPIO_PORTA_DIR);
}
/*********************************************************************
* @fn gpio_portb_set_dir
*
* @brief get current gpio PORTB in-out setting.
*
* @param None.
*
* @return current setting.
*/
__INLINE uint8_t gpio_portb_get_dir(void)
{
return REG_PL_RD(GPIO_PORTB_DIR);
}
/*********************************************************************
* @fn gpio_portc_set_dir
*
* @brief get current gpio PORTC in-out setting.
*
* @param None.
*
* @return current setting.
*/
__INLINE uint8_t gpio_portc_get_dir(void)
{
return REG_PL_RD(GPIO_PORTC_DIR);
}
/*********************************************************************
* @fn gpio_portd_set_dir
*
* @brief get current gpio PORTD in-out setting.
*
* @param None.
*
* @return current setting.
*/
__INLINE uint8_t gpio_portd_get_dir(void)
{
return REG_PL_RD(GPIO_PORTD_DIR);
}
uint8_t gpio_portX_get_dir(void)
功能:
获取一组 IO 由大数字控制时的输入输出设置,x 为 a、b、c、d
参数:
无
返回值:
当前的输入输出配置
4.5 gpio_set_dir
/*********************************************************************
* @fn gpio_set_dir
*
* @brief set specific gpio channel working mode: output or input.
*
* @param port - which port this channel belongs to. @ref system_port_t
* bit - channel number. @ref system_port_bit_t
* dir - in-out selection, should be GPIO_DIR_IN or GPIO_DIR_OUT.
*
* @return None.
*/
void gpio_set_dir(enum system_port_t port, enum system_port_bit_t bit, uint8_t dir);
功能:
设置 IO 由大数字控制时的输入输出,一次设置一个 IO
参数:
port IO 所属的端口组
bit IO 的 channel 编号
dir 输入或者输出
返回值:
无
示例
gpio_set_dir(GPIO_PORT_A, GPIO_BIT_0, GPIO_DIR_OUT);
05. 低功耗模式GPIO接口
5.1 pmu_set_gpio_value
/*********************************************************************
* @fn pmu_set_gpio_value
*
* @brief set value of IOs which are controlled by PMU.
* example usage:
* pmu_set_gpio_value(GPIO_PORT_A, (1<<GPIO_BIT0)|((1<<GPIO_BIT1), 1)
*
* @param port - which group the io belongs to, @ref system_port_t
* bits - the numbers of io
* value - 1: set the IO to high, 0: set the IO to low.
*
* @return None.
*/
void pmu_set_gpio_value(enum system_port_t port, uint8_t bits, uint8_t value);
功能:
当某个 pin 脚被配置为 pmu gpio 控制,并且是输出模式时,设置该 pin 脚的值
参数:
port 选择 pin 脚对应的 port 口,一共有 4 个 port 口,PA,PB,PC,PD。参见 enum system_port_t 定义。
bits 选择 pin 脚对应的 pin 号码,bit7~bit0 分别代表每个 port 口的 pin7~pin0。每个 bit 位表示该 pin 被选中。
Value 设置 pin 脚输出值。只能填以下二值:1,该 pin 输出为高。0,该 pin 输出为低。
返回值:
无
示例
void pmu_gpio_test(void)
{
pmu_set_port_mux(GPIO_PORT_A,GPIO_BIT_0,PMU_PORT_MUX_GPIO);
pmu_set_port_mux(GPIO_PORT_A,GPIO_BIT_1,PMU_PORT_MUX_GPIO);
pmu_set_pin_to_PMU(GPIO_PORT_A,BIT(0)|BIT(1) );
pmu_set_pin_dir(GPIO_PORT_A,BIT(0)|BIT(1), GPIO_DIR_OUT);
pmu_set_pin_pull(GPIO_PORT_A, BIT(0)|BIT(1), true);
pmu_set_gpio_value(GPIO_PORT_A, BIT(0)|BIT(1), 1);
co_delay_100us(10);
pmu_set_gpio_value(GPIO_PORT_A, BIT(0)|BIT(1), 0);
}
5.2 pmu_get_gpio_value
/*********************************************************************
* @fn pmu_get_gpio_value
*
* @brief get value of IO which are controlled by PMU and in GPIO mode.
* example usage:
* pmu_get_gpio_value(GPIO_PORT_A, GPIO_BIT_0)
*
* @param port - which group the io belongs to, @ref system_port_t
* bit - the number of io
*
* @return 1: the IO is high, 0: the IO is low..
*/
uint8_t pmu_get_gpio_value(enum system_port_t port, uint8_t bit);
功能:
当某个 pin 脚被配置为 pmu gpio 控制,并且是输入模式时,获取该 pin 脚的值。
参数:
port 选择 pin 脚对应的 port 口,一共有 4 个 port 口,PA,PB,PC,PD。参见 enum system_port_t 定义。
bit 选择 pin 脚对应的 pin 号码,参见 enum system_port_bit_t 定义
返回值:
IO口的值
示例
void pmu_gpio_test(void)
{
pmu_set_port_mux(GPIO_PORT_A,GPIO_BIT_2,PMU_PORT_MUX_GPIO);
pmu_set_port_mux(GPIO_PORT_A,GPIO_BIT_3,PMU_PORT_MUX_GPIO);
pmu_set_pin_to_PMU(GPIO_PORT_A,BIT(2)|BIT(3) );
pmu_set_pin_dir(GPIO_PORT_A,BIT(2)|BIT(3), false);
co_printf("PA2:%d,PA3:%d\r\n",pmu_get_gpio_value(GPIO_PORT_A,GPIO_BIT_2)
,pmu_get_gpio_value(GPIO_PORT_A,GPIO_BIT_3) );
}
06. GPIO程序示例
程序示例
// 普通GPIO示例
void peripheral_demo(void)
{
co_printf("digital gpio demo\r\n");
// digital gpio output
system_set_port_mux(GPIO_PORT_D, GPIO_BIT_4, PORTD4_FUNC_D4);
system_set_port_mux(GPIO_PORT_D, GPIO_BIT_5, PORTD5_FUNC_D5);
gpio_set_dir(GPIO_PORT_D, GPIO_BIT_4, GPIO_DIR_OUT);
gpio_set_dir(GPIO_PORT_D, GPIO_BIT_5, GPIO_DIR_OUT);
gpio_set_pin_value(GPIO_PORT_D, GPIO_BIT_4, 1);
gpio_set_pin_value(GPIO_PORT_D, GPIO_BIT_5, 1);
co_delay_100us(10000);
gpio_set_pin_value(GPIO_PORT_D, GPIO_BIT_4, 0);
gpio_set_pin_value(GPIO_PORT_D, GPIO_BIT_5, 0);
// digital gpio input
system_set_port_mux(GPIO_PORT_D, GPIO_BIT_7, PORTD7_FUNC_D7);
system_set_port_mux(GPIO_PORT_D, GPIO_BIT_6, PORTD6_FUNC_D6);
gpio_set_dir(GPIO_PORT_D, GPIO_BIT_7, GPIO_DIR_IN);
gpio_set_dir(GPIO_PORT_D, GPIO_BIT_6, GPIO_DIR_IN);
system_set_port_pull((GPIO_PD6 | GPIO_PD7), true);
co_printf("PD6:%d\r\n", gpio_get_pin_value(GPIO_PORT_D, GPIO_BIT_6));
co_printf("PD7:%d\r\n", gpio_get_pin_value(GPIO_PORT_D, GPIO_BIT_7));
}
运行结果
******Connected******
******Start Auto Burn******
****************************************************
******CRC Success******
******Burn Success******
?digital gpio demo
PD6:1
PD7:1
07. 附录
官网:https://www.freqchip.com/