本文介绍: 本章节介绍BC260Y硬件GPIO相关操作2、相关API介绍平台支持IO口设置下拉,所以在作为输入电平的情况下,注意加下拉电阻IO口设置输出:3、调试信息串口打印首先我们需要初始化一下串口串口API:调用方法串口uart0,串口数据接收官方给出以回调函数方式参数event接收完成或接收超时dataPtr:接收到的数据dataLen:数据的长度打开调试信息#define DEBUG_ENABLE 1其他api介绍:禁止休眠系统默认是开启休眠设置IO电平

章节介绍BC260Y硬件GPIO相关操作

1、BC260Y gpio资源介绍

BC260Y-AA的sdk包中官方给出了16个可用IO
在ql_gpio.h文件中有定义如下
	/****************************************************************************
 * Enumeration for GPIO Pins available.
 ***************************************************************************/
typedef enum
{
    /**************************************************
    *  <<<BEGIN: The fowllowing PINs for BC260Y
    *            (TOTAL: 16)
    ***************************************************/
    PINNAME_SPI_MISO = 0,
    PINNAME_SPI_MOSI,
    PINNAME_SPI_SCLK,
    PINNAME_SPI_CS,
    PINNAME_GPIO1,			
    PINNAME_I2C_SCL,			
    PINNAME_I2C_SDA,
    PINNAME_MAIN_CTS,
    PINNAME_MAIN_RTS,
    PINNAME_GPIO2,
    PINNAME_RXD_AUX,		//not support eint
    PINNAME_TXD_AUX,		//not support eint
    PINNAME_GPIO3,
    PINNAME_GPIO4,
    PINNAME_GPIO5,
    PINNAME_GPIO6,		
    
	PINNAME_END
}Enum_PinName;

2、相关API介绍

平台支持IO口设置下拉,所以在作为输入电平的情况下,注意加下拉电阻

typedef enum{
    PINPULLSEL_PULLUP    = 0,    	/**< select internal pull up */
    //PINPULLSEL_PULLDOWN  = 1,   	/**< select internal pull down */    platform not support
    PINPULLSEL_DISABLE   = 2   		/**< Pull up/down is controlled by muxed alt function */
}Enum_PinPullSel;
/*****************************************************************
* Function:     Ql_GPIO_Init
*
* Description:
*               This function enables the GPIO function of the specified pin,
*               and initialize the configurations, including direction,
*               level and pull selection.
*
* Parameters:
*               pinName:
*                   Pin name, one value of Enum_PinName.
*               dir:
*                   The initial direction of GPIO, one value of Enum_PinDirection.
*               level:
*                   The initial level of GPIO, one value of Enum_PinLevel.
*               pullSel:
*                   Pull selection, one value of Enum_PinPullSel.
* Return:
*               QL_RET_OK, this function succeeds.
*               QL_RET_ERR_NOSUPPORTPIN, the input GPIO is invalid.
*               QL_RET_ERR_PINALREADYSUBCRIBE, the GPIO is in use in
*               other place. For example this GPIO has been using as EINT.
*****************************************************************/
s32 Ql_GPIO_Init(Enum_PinName pinName,Enum_PinDirection dir,Enum_PinLevel  level ,Enum_PinPullSel pullsel);

IO口设置成输出

Enum_PinName gpioPin = PINNAME_GPIO1;
Ql_GPIO_Init(gpioPin, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP);

3、调试信息串口打印

首先我们需要初始化一下串口
串口API:

/*****************************************************************
* Function:     Ql_UART_Open 
* 
* Description:
*               This function opens a specified UART port with the specified 
*               flow control mode. 
*               Which task call this function, which task will own the specified UART port.
*
* Parameters:
*               [in]port:       
*                       Port name
*               [in]baudrate:      
*                       The baud rate of the UART to be opened
*                       for the physical the baud rate support 4800,9600,
*                       19200,38400,57600,115200,230400,460800,921600.
*
*               [in]CallBack_UART_Notify:     
*                       The pointer of the UART call back function.
*
* Return:        
*               QL_RET_OK indicates success; otherwise failure.      
*               QL_RET_ERR_PARAM indicates uart_receive_call_back error. 
*               QL_RET_ERR_BAUDRATE indicates baudrate not support. 
*               QL_RET_ERR_UART_BUSY indicates uart init error. 
*               QL_RET_ERR_INVALID_PORT indicates port not support.    
*
*****************************************************************/
s32 Ql_UART_Open( Enum_SerialPort port,u32 baudrate,CallBack_UART_Notify uart_receive_call_back);

调用方法

Ql_UART_Open(UART_PORT0,9600,MainUartRecvCallback);

主串口为uart0,串口数据接收官方给出以回调函数方式

static void MainUartRecvCallback(u32 event, void* dataPtr, u32 dataLen)
{
	if((USART_EVENT_RX_TIMEOUT == event) || (USART_EVENT_RECEIVE_COMPLETE == event))
	{
	    Ql_UART_Write(UART_PORT0,(u8 *)dataPtr,dataLen);
	}
}

参数event:接收完成或接收超时

/****** USART Event *****/
#define USART_EVENT_RECEIVE_COMPLETE    (1UL << 1)  ///< Receive completed
#define USART_EVENT_RX_TIMEOUT          (1UL << 6)  ///< Receive character timeout (optional)

dataPtr:接收到的数据
dataLen:数据的长度

打开调试信息
#define DEBUG_ENABLE 1

#define DEBUG_ENABLE 1
#if DEBUG_ENABLE &gt; 0
#define DEBUG_PORT  PORT_DBG_LOG
#define APP_DEBUG(FORMAT,...)	Ql_DebugPort_Trace((Enum_SerialPort)(DEBUG_PORT),FORMAT, ##__VA_ARGS__)
#else
#define APP_DEBUG(FORMAT,...) 
#endif

其他api介绍
禁止休眠系统默认是开启休眠

Ql_SleepDisable();//一定要禁止休眠,不然20s之后就会进入休眠状态

设置IO电平

/*****************************************************************
* Function:     Ql_GPIO_SetLevel
*
* Description:
*               This function sets the level of the specified GPIO.
*
* Parameters:
*               pinName:
*                   Pin name, one value of Enum_PinName.
*               level:
*                   The initial level of GPIO, one value of Enum_PinLevel.
* Return:
*               QL_RET_OK, this function succeeds.
*               QL_RET_ERR_PARAM, the input GPIO is invalid.
*               QL_RET_ERR_ALREADYUNSUBCRIBE, can't operate,Maybe the GPIO not Init.
*****************************************************************/
s32 Ql_GPIO_SetLevel(Enum_PinName pinName, Enum_PinLevel level);

Ql_GPIO_SetLevel(gpioPin, PINLEVEL_HIGH);

3、实例分析

SDK及实例代码
链接https://pan.baidu.com/s/1NcFoi0TiKax7owLHQkbQ6g
提取码:temz

在Makefile文件取消注释GLOBAL_EXPORT_FLAG += EXAMPLE_GPIO
其他注释掉其他的实例
打开example_gpio.c
在这里插入图片描述

在这里插入图片描述

#ifdef __EXAMPLE_GPIO__
#include <stdio.h&gt;
#include <string.h&gt;
#include "cmsis_os2.h"
#include "ril.h"
#include "ql_gpio.h"
#include "ql_power.h"
#include "ql_dbg.h"

#define DEBUG_ENABLE 1
#if DEBUG_ENABLE &gt; 0
#define DEBUG_PORT  PORT_DBG_LOG
#define APP_DEBUG(FORMAT,...)	Ql_DebugPort_Trace((Enum_SerialPort)(DEBUG_PORT),FORMAT, ##__VA_ARGS__)
#else
#define APP_DEBUG(FORMAT,...) 
#endif
Enum_PinName gpioPin = PINNAME_GPIO1;

static void MainUartRecvCallback(u32 event, void* dataPtr, u32 dataLen)
{
	if((USART_EVENT_RX_TIMEOUT == event) || (USART_EVENT_RECEIVE_COMPLETE == event))
	{
	    Ql_UART_Write(UART_PORT0,(u8 *)dataPtr,dataLen);
	}
}
void proc_main_task(void)
{
	s32 ret;

 	Ql_UART_Open(UART_PORT0,9600,MainUartRecvCallback);
	APP_DEBUG("<-- QuecOpen: GPIO Example --&gt;rn");
	Ql_GPIO_Init(gpioPin, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP);
	Ql_SleepDisable();//一定要禁止休眠,不然20s之后就会进入休眠状态

    while (1)
    {
		osDelay(500);
		Ql_GPIO_SetLevel(gpioPin, PINLEVEL_LOW);
		APP_DEBUG("gpioPin -----PINLEVEL_LOWrn",ret);
		osDelay(500);
		Ql_GPIO_SetLevel(gpioPin, PINLEVEL_HIGH);
		APP_DEBUG("gpioPin -----PINLEVEL_HIGHrn",ret);
	}

}

#endif

实验结果:看到LED 灯每 1s闪烁一次
链接
https://live.csdn.net/v/342947
在这里插入图片描述

原文地址:https://blog.csdn.net/lu330274924/article/details/134377078

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_9537.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注