CC1310 SimpleLink SDK PIN/GPIO的使用

发布时间:2023年12月21日

1.声明配置并初始化PIN

在“CC1310_LAUNCHXL.h”文件中预定义

#define CC1310_LAUNCHXL_PIN_BEEP              IOID_3
#define CC1310_LAUNCHXL_PIN_RS485_TEN         IOID_0
#define CC1310_LAUNCHXL_PIN_SYSLED            IOID_9
#define CC1310_LAUNCHXL_PIN_ALMLED            IOID_8
/* UART Board */
#define CC1310_LAUNCHXL_UART_RX               IOID_1          /* RXD */
#define CC1310_LAUNCHXL_UART_TX               IOID_2          /* TXD */

在文件“CC1310_LAUNCHXL.c”中配置如下:

const PIN_Config BoardGpioInitTable[] = {
     CC1310_LAUNCHXL_PIN_RS485_TEN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* LOW RECEIVE          */
     CC1310_LAUNCHXL_PIN_BEEP | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* LOW OFF          */     
     CC1310_LAUNCHXL_PIN_SYSLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* HIGH OFF          */
     CC1310_LAUNCHXL_PIN_ALMLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* HIGH OFF          */
     CC1310_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN,                                              /* UART RX via debugger back channel */
     CC1310_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,                         /* UART TX via debugger back channel */
    PIN_TERMINATE
};

初始化PIN如下:
#include <ti/drivers/PIN.h>

void CC1310_LAUNCHXL_initGeneral(void)
{
    Power_init();

    if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) {
        /* Error with PIN_init */
        while (1);
    }

    /* Perform board-specific initialization */
    //Board_initHook();
}

PIN初始化后,我们已经可以使用driver/PIN.h文件中提供的API使用这些引脚了,如果我们想要直接使用某些引脚实现IO功能的话可以直接调用PIN_open()函数,但是在有操作系统的应用程序中并不推荐这样做,因为这并非线程安全的。上面PIN_init函数会将我们需要的引脚配置为GPIO可用的状态,但是在想使用这些引脚作为GPIO之前,还需要完成GPIO外设的初始化。

2.声明配置并初始化GPIO

#include <ti/drivers/GPIO.h>

在“CC1310_LAUNCHXL.c”文件中

/*
 *  =============================== GPIO ===============================
 */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/gpio/GPIOCC26XX.h>

/*
 * Array of Pin configurations
 * NOTE: The order of the pin configurations must coincide with what was
 *       defined in CC1310_LAUNCHXL.h
 * NOTE: Pins not used for interrupts should be placed at the end of the
 *       array. Callback entries can be omitted from callbacks array to
 *       reduce memory usage.
 */
GPIO_PinConfig gpioPinConfigs[] = {

    GPIOCC26XX_DIO_00 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH,  /* RS485 设置默认高则为发送状态 */
    GPIOCC26XX_DIO_01 | GPIO_DO_NOT_CONFIG,  /* UART RX */
    GPIOCC26XX_DIO_02 | GPIO_DO_NOT_CONFIG,  /* UART TX */
    GPIOCC26XX_DIO_03 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW,  /* BEEP 默认不发声音*/
    GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG,  /* NO USE  */
    GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG,  /* NO USE */
    GPIOCC26XX_DIO_04 | GPIO_DO_NOT_CONFIG,  /* NO USE */
    GPIOCC26XX_DIO_05 | GPIO_DO_NOT_CONFIG,  /* NO USE */
    /* ALARM LED 默认不亮*/
    GPIOCC26XX_DIO_08 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH, 
    /* SYS LED 默认不亮*/
    GPIOCC26XX_DIO_09 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH, 
};

/*
 * Array of callback function pointers
 * NOTE: The order of the pin configurations must coincide with what was
 *       defined in CC1310_LAUNCH.h
 * NOTE: Pins not used for interrupts can be omitted from callbacks array to
 *       reduce memory usage (if placed at end of gpioPinConfigs array).
 */
GPIO_CallbackFxn gpioCallbackFunctions[] = {
    NULL,  /*  */
    NULL,  /*  */
    NULL,  /*  */
    NULL,  /* */
};

const GPIOCC26XX_Config GPIOCC26XX_config = {
    .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs,
    .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions,
    .numberOfPinConfigs = CC1310_LAUNCHXL_GPIOCOUNT,
    .numberOfCallbacks  = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn),
    .intPriority = (~0)
};

以上 GPIOCC26XX_DIO_?? 其实就是 IOID_? , 在“ti\drivers\gpio\GPIOCC26XX.h”文件中有声明如下:

#define GPIOCC26XX_DIO_00    IOID_0    /*!< @hideinitializer */
#define GPIOCC26XX_DIO_01    IOID_1    /*!< @hideinitializer */
#define GPIOCC26XX_DIO_02    IOID_2    /*!< @hideinitializer */
#define GPIOCC26XX_DIO_03    IOID_3    /*!< @hideinitializer */
#define GPIOCC26XX_DIO_04    IOID_4    /*!< @hideinitializer */
#define GPIOCC26XX_DIO_05    IOID_5    /*!< @hideinitializer */
#define GPIOCC26XX_DIO_06    IOID_6    /*!< @hideinitializer */
#define GPIOCC26XX_DIO_07    IOID_7    /*!< @hideinitializer */

在“CC1310_LAUNCHXL.h”文件中声明GPIOName,注意这个声明的顺序必须与以上“”文件中gpioPinConfigs声明一样。

/*!
 *  @def    CC1310_LAUNCHXL_GPIOName
 *  @brief  Enum of GPIO names
 */
typedef enum CC1310_LAUNCHXL_GPIOName {
    CC1310_RS485_EN = 0, //485
    CC1310_LAUNCHXL_GPIO_S2,
    CC1310_LAUNCHXL_SPI_MASTER_READY,
    CC1310_BEEP,
    CC1310_LAUNCHXL_GPIO_LED_GREEN,
    CC1310_LAUNCHXL_GPIO_LED_RED,
    CC1310_LAUNCHXL_GPIO_TMP116_EN,
    CC1310_LAUNCHXL_GPIO_SPI_FLASH_CS,
    CC1310_ALMLED,
    CC1310_SYSLED,
    CC1310_LAUNCHXL_GPIOCOUNT
} CC1310_LAUNCHXL_GPIOName;

3.GPIO的使用

头文件:

#include <ti/drivers/GPIO.h>

使用前调用
GPIO_init();
API调用:

GPIO_write(uint_least8_t index, unsigned int value);
uint_fast8_t GPIO_read(uint_least8_t index);
void GPIO_toggle(uint_least8_t index);

例子:

GPIO_write(CC1310_LAUNCHXL_BEEP , 1);  //测试发声
GPIO_write(CC1310_LAUNCHXL_SYSLED, 1); //测试 信号接收指示 
GPIO_write(CC1310_LAUNCHXL_ALMLED, 1); //测试 4G转发指示
Task_sleep( 100000 / Clock_tickPeriod );
GPIO_toggle(CC1310_LAUNCHXL_BEEP);  //测试发声
GPIO_toggle(CC1310_LAUNCHXL_SYSLED);  //测试
GPIO_toggle(CC1310_LAUNCHXL_ALMLED);  //测试

对于CC1310,TI论坛上建议选用PIN系列的驱动。
The GPIO driver is supported for all device families except CC26xx/CC13xx. For the CC26xx/CC13xx device family, the PIN driver should be used. There is a GPIO driver for the CC26xx/CC13xx family within the driver product, however it is not promoted nor supported for external customer use.

文章来源:https://blog.csdn.net/l787/article/details/135125731
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。