NB-IoT BC260Y Open CPU SDK⑤点亮一个LED
- 1、BC260Y gpio资源介绍
- 2、相关API介绍
- 3、调试信息串口打印
- 3、实例分析
本章节将介绍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 > 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>
#include <string.h>
#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 > 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 -->\r\n");
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_LOW\r\n",ret);
osDelay(500);
Ql_GPIO_SetLevel(gpioPin, PINLEVEL_HIGH);
APP_DEBUG("gpioPin -----PINLEVEL_HIGH\r\n",ret);
}
}
#endif
实验结果:看到LED 灯每 1s闪烁一次
链接:
https://live.csdn.net/v/342947