本文档记录CC2640R2F simple_peripheral_oad_onchip工程下抽象LED控制接口
硬件平台:官方 LAUNCHXL-CC2640R2F (http://www.ti.com/tool/cn/launchxl-cc2640r2)
SDK: simplelink_cc2640r2_sdk_1_50_00_58 (http://www.ti.com/tool/download/SIMPLELINK-CC2640R2-SDK)
编译环境: iar for arm 8.20.2 (https://www.iar.com)
1、工程中增加led.c、led.h文件,增加头文件目录,修改宏定义
注:宏定义里面修改如下,红圆圈为修改项(关闭默认的LED_DEBUG 宏)
2、自定义LED引脚
CC2640R2F_LAUNCHXL.h 文件下修改
2.1、去掉默认LED定义引脚
去掉有冲突引脚(红色圆圈),增加自定义引脚(红色方圈)
2.2、CC2640R2F_LAUNCHXL.c 文件修改
2.3、led.c 文件
#include#include "util.h"#include "board.h"/*************************** 对应平台接口 *************************************/static PIN_State led_state;static const PIN_Config led_pins[] = { SDI_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, SDI_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE};static void gpio_init(void){ if(!PIN_open(&led_state, led_pins)){ PIN_open(&led_state, led_pins); } }static void gpio_set_value(PIN_Id id, unsigned char val){ PIN_setOutputValue(&led_state, id, val);}/*******************************************************************/static Clock_Struct led_period_clock;#define LED_PERIOD_TIME (100) //100msstatic unsigned char led_cur_state = 0;typedef struct led_ctr_{ unsigned int gpio; //对应GPIO引脚 unsigned char state; //引脚当前状态 unsigned char _pd; // unsigned short count; //1~0xFFFE 闪烁次数,0xFFFF-不间断闪,0-切换当前状态, unsigned short period; //闪烁周期 unsigned short times; //当前时间计数,100ms为单位 }led_ctr;#define LED_NUM_MAX (2)led_ctr g_led_ctr[LED_NUM_MAX] = { {SDI_RLED, 0, 0, 0}, {SDI_GLED, 0, 0, 0}};static void SDI_led_process(UArg arg){ unsigned char i; unsigned char n = 0; for(i=0; i 1){ g_led_ctr[i].times--; }else if(g_led_ctr[i].times == 1){ g_led_ctr[i].times = 0; g_led_ctr[i].state ^= 0x01; gpio_set_value(g_led_ctr[i].gpio, g_led_ctr[i].state); if(g_led_ctr[i].count){ if(g_led_ctr[i].count != 0xFFFF) g_led_ctr[i].count--; g_led_ctr[i].times = g_led_ctr[i].period; } }else{ } if(g_led_ctr[i].times || g_led_ctr[i].count) n++; } if(!n){ Util_stopClock(&led_period_clock); led_cur_state = 0; }}void SDI_led_indication(unsigned int led, unsigned char count, unsigned short times_100ms, unsigned char onoff){ unsigned char i=0; static unsigned char led_api_init = 0; //引脚判断 for(i=0; i
2.4、增加测试接口方式(simple_peripheral_oad_onchip.c)
系统启动后 绿灯以500ms频率闪烁5次
连接APP后红灯闪烁以200ms频率闪烁3次,绿灯常亮(函数 static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState))
断开APP后红灯闪烁以200ms频率闪烁3次,绿灯常灭(函数 static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState))
3、编译烧录,运行
修改补丁: