本系列用于对simplelink_cc13x0_sdk的快速使用
1 相关文件
2 使用示例
static PIN_Handle ledPinHandle; void led_init() { PIN_State ledPinState; PIN_Config ledPinTable[] = { Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE }; ledPinHandle = PIN_open(&ledPinState, ledPinTable); PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, CC1310_LAUNCHXL_GPIO_LED_ON); } void led_on() { PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, Board_LED_ON); } void led_off() { PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, Board_LED_OFF); } void led_reverse() { PIN_setOutputValue(ledPinHandle, Board_PIN_LED0,!PIN_getOutputValue(Board_PIN_LED0)); } void led_close() { PIN_close(ledPinHandle); }
3 备注
GPIO引脚定义用这三个文件管理 CC1310_LAUNCHXL.h,CC1310_LAUNCHXL.c,Board。例如上例中的Board_PIN_LED0,首先在Board中
然后在CC1310_LAUNCHXL文件中才被实际性指向
写程序前最好先更加自己的硬件对这几个文件进行配置,默认是使用的TI 开发板
还有点值得注意的是,在CC1310_LAUNCHXL.c中很可能是对一些默认使用的GPIO进行初始化的,首先在主函数中查看是否调用了init的函数,然后跳转过去就会发现类似下列代码:
/* * ======== CC1310_LAUNCHXL_initGeneral ======== */ void CC1310_LAUNCHXL_initGeneral(void) { Power_init(); if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { /* Error with PIN_init */ while (1); } }
BoardGpioInitTable结构体就在同文件中可以看到:
/* * =============================== PIN =============================== */ #include <ti/drivers/PIN.h> #include <ti/drivers/pin/PINCC26XX.h> const PIN_Config BoardGpioInitTable[] = { // CC1310_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ // CC1310_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ // CC1310_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ // CC1310_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ // CC1310_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ // 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_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC1310_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ CC1310_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ CC1310_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ PIN_TERMINATE };他这里都是用的是宏定义,所以最方便的方式就是在.h文件中直接修改IO的宏定义,不使用的全部设置为PIN_UNASSIGNED即可
补充:
注册中断回调
if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) { System_abort("Error registering button callback function"); }
示例中断回调函数
void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) { PIN_getInputValue(pinId);//读取电平 if ( pinId == Board_BUTTON0 ) PIN_setOutputValue(ledPinHandle, Board_LED0, !PIN_getOutputValue(Board_LED0); }