You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.6 KiB
127 lines
3.6 KiB
#include "app_gpio_led.h"
|
|
#include "sw_timer.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void App_Led_Output_Process(void);
|
|
static void App_Led_Off(APP_LED_LIST app_led_index);
|
|
static void App_Led_On(APP_LED_LIST app_led_index);
|
|
|
|
|
|
typedef void (*APP_LED_ON_OFF_FUNC)(APP_LED_LIST gpio_led_index);
|
|
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t Port;
|
|
uint32_t Pin;
|
|
gpio_pad_t Pull_updown;
|
|
|
|
APP_LED_MODE Mode;
|
|
bool isLedOn;
|
|
uint32_t nCheckTime;
|
|
uint32_t nOnTime;
|
|
uint32_t nOffTime;
|
|
|
|
APP_LED_ON_OFF_FUNC LedOnFunction;
|
|
APP_LED_ON_OFF_FUNC LedOffunction;
|
|
}APP_STATE_LED_INFO;
|
|
|
|
|
|
static APP_STATE_LED_INFO App_Led_Ctrl_Info[APP_LED_MAX] =
|
|
{
|
|
{PORT_0, PIN_13, GPIO_PAD_NONE, APP_LED_MODE_OFF, false, 0, 0, 0, App_Led_On, App_Led_Off},
|
|
};
|
|
|
|
|
|
static void App_Led_On(APP_LED_LIST app_led_index);
|
|
static void App_Led_Off(APP_LED_LIST app_led_index);
|
|
|
|
void App_Led_Initialization(void)
|
|
{
|
|
uint8_t i;
|
|
gpio_cfg_t gpio_out;
|
|
|
|
SYS_ClockEnable(SYS_PERIPH_CLOCK_GPIO0);
|
|
|
|
for(i = 0 ; i < APP_LED_MAX ; i++)
|
|
{
|
|
gpio_out.port = App_Led_Ctrl_Info[i].Port;
|
|
gpio_out.mask = App_Led_Ctrl_Info[i].Pin;
|
|
gpio_out.pad = App_Led_Ctrl_Info[i].Pull_updown;
|
|
gpio_out.func = GPIO_FUNC_OUT;
|
|
GPIO_Config(&gpio_out);
|
|
App_Led_Off((APP_LED_LIST)i);
|
|
}
|
|
|
|
SW_Timer_Callback_Register(SW_TIMER_RUN_CONTINUE, 1, App_Led_Output_Process);
|
|
}
|
|
|
|
|
|
void App_Led_OutputSet(APP_LED_LIST app_led_index, APP_LED_MODE app_led_mode, uint32_t OnTime, uint32_t OffTime)
|
|
{
|
|
App_Led_Ctrl_Info[app_led_index].Mode = app_led_mode;
|
|
App_Led_Ctrl_Info[app_led_index].isLedOn = true;
|
|
App_Led_Ctrl_Info[app_led_index].nCheckTime = millis();
|
|
App_Led_Ctrl_Info[app_led_index].nOnTime = OnTime;
|
|
App_Led_Ctrl_Info[app_led_index].nOffTime = OffTime;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
static void App_Led_Output_Process(void)
|
|
{
|
|
uint8_t i;
|
|
APP_STATE_LED_INFO* pControlInfo;
|
|
for(i = 0 ; i < APP_LED_MAX ; i++)
|
|
{
|
|
pControlInfo = &App_Led_Ctrl_Info[i];
|
|
switch (pControlInfo->Mode)
|
|
{
|
|
case APP_LED_MODE_OFF:
|
|
pControlInfo->LedOffunction((APP_LED_LIST)i);
|
|
break;
|
|
case APP_LED_MODE_ON:
|
|
pControlInfo->LedOnFunction((APP_LED_LIST)i);
|
|
break;
|
|
case APP_LED_MODE_TOGGLE:
|
|
if(pControlInfo->isLedOn == true)
|
|
{
|
|
if((millis() - pControlInfo->nCheckTime) > pControlInfo->nOnTime )
|
|
{
|
|
pControlInfo->nCheckTime = millis();
|
|
pControlInfo->isLedOn = false;
|
|
}
|
|
pControlInfo->LedOnFunction((APP_LED_LIST)i);
|
|
}
|
|
else
|
|
{
|
|
if((millis() - pControlInfo->nCheckTime) > pControlInfo->nOffTime )
|
|
{
|
|
pControlInfo->nCheckTime = millis();
|
|
pControlInfo->isLedOn = true;
|
|
}
|
|
pControlInfo->LedOffunction((APP_LED_LIST)i);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void App_Led_On(APP_LED_LIST app_led_index)
|
|
{
|
|
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(App_Led_Ctrl_Info[app_led_index].Port);
|
|
gpio->out_set = App_Led_Ctrl_Info[app_led_index].Pin;
|
|
}
|
|
|
|
static void App_Led_Off(APP_LED_LIST app_led_index)
|
|
{
|
|
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(App_Led_Ctrl_Info[app_led_index].Port);
|
|
gpio->out_clr = App_Led_Ctrl_Info[app_led_index].Pin;
|
|
}
|