撿到一天颱風假,但廢了一天也沒做什麼事情,
一轉眼又到了發文的期限,
今天就用昨天的範例程式來點亮開發板上的LED吧。
首先是LED控制的程式,
點亮LED很簡單,
只要拉高或拉低LED的腳位,
就能控制LED的亮滅,
對於晶片腳位的控制我們不需要直接去修改暫存器,
只需要使用TI 提供的驅動就可以來做IO腳的控制,
相關細節可參考TI 的文件 : TI Drivers Runtime APIs (doxygen) - PINCC26XX.h File Reference
#include <ti/drivers/pin/PINCC26XX.h>
#include "board_led.h"
#include "Board.h"
PIN_Config ledPinsCfg[] =
{
// 初始化LED腳位的狀態 : 啟用輸出功能, 關閉輸入功能, 輸出低準位
Board_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_INPUT_DIS | PIN_GPIO_LOW,
Board_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_INPUT_DIS | PIN_GPIO_LOW,
PIN_TERMINATE
};
PIN_State ledPins;
PIN_Handle hLedPins = NULL;
void Board_initLeds(void)
{
// 呼叫PIN_open 來初始化LED 腳位
hLedPins = PIN_open(&ledPins, ledPinsCfg);
}
// 控制指定的LED 開/關
void Board_Led_set(BOARD_LED led, LED_Satus status)
{
if (hLedPins == NULL)
return;
switch(led)
{
case BOARD_LED_RED:
PIN_setOutputValue(hLedPins, Board_PIN_RLED, status);
break;
case BOARD_LED_GREEN:
PIN_setOutputValue(hLedPins, Board_PIN_GLED, status);
break;
default:
break;
}
}
#ifndef BOARD_LED_H
#define BOARD_LED_H
typedef enum{
BOARD_LED_RED,
BOARD_LED_GREEN
}BOARD_LED;
typedef enum{
LED_OFF = 0,
LED_ON
}LED_Satus;
void Board_initLeds(void);
void Board_Led_set(BOARD_LED led, LED_Satus status);
#endif // BOARD_LED_H
static void SimplePeripheral_init(void)
{
...
// 初始化 LED
Board_initLeds();
...
}
...
static void SimplePeripheral_processCharValueChangeEvt(uint8_t paramId)
{
uint8_t newValue;
switch(paramId)
{
case SIMPLEPROFILE_CHAR1:
SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR1, &newValue);
/*
* 0x01 : Red LED ON
* 0x02 : Red LED OFF
* 0x03 : Green LED ON
* 0x04 : Green LED OFF
* */
switch(newValue)
{
case 0x01:
Board_Led_set(BOARD_LED_RED, LED_ON);
break;
case 0x02:
Board_Led_set(BOARD_LED_RED, LED_OFF);
break;
case 0x03:
Board_Led_set(BOARD_LED_GREEN, LED_ON);
break;
case 0x04:
Board_Led_set(BOARD_LED_GREEN, LED_OFF);
break;
default:
break;
}
Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "Char 1: %d", (uint16_t)newValue);
break;
case SIMPLEPROFILE_CHAR3:
SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR3, &newValue);
Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "Char 3: %d", (uint16_t)newValue);
break;
default:
// should not reach here!
break;
}
}