Motion_EC_HC32_archived/applications/main.c

122 lines
3.8 KiB
C

/*
* @Description:
* @Date: 2022-01-10 17:05:41
* @LastEditors: CK.Zh
* @LastEditTime: 2022-01-13 12:14:46
* @FilePath: /motion_ec/applications/main.c
*/
/*
* Copyright (C) 2021, Huada Semiconductor Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-09-07 PJQ first version
*/
/*******************************************************************************
* Include files
******************************************************************************/
#include "board.h"
#include <rtthread.h>
#include <rtdevice.h>
// #define LOG_TAG "MAIN"
// #define LOG_LVL LOG_LVL_DBG
// #include <ulog.h>
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/* defined the LED pin: PC9 */
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
uint8_t flag;
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
void key_handler(void *param)
{
flag = ~flag;
char *a = param;// 获取参数
rt_kprintf("key down! %s\n",a);
}
/**
*******************************************************************************
** \brief Main function of GPIO output
**
** \param None
**
** \retval int32_t Return value, if needed
**
******************************************************************************/
int32_t main(void)
{
//DEBUG
rt_pin_mode(TEST_LED_PIN, PIN_MODE_OUTPUT);
// LOG_I("Go to main function");
rt_pin_mode(EC_BUZZ_CTL_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(EC_PWR_LED_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(EC_PWR_BTN, PIN_MODE_INPUT);
rt_pin_attach_irq(EC_PWR_BTN, PIN_IRQ_MODE_FALLING, key_handler, (void*)"callback args");
rt_pin_irq_enable(EC_PWR_BTN, PIN_IRQ_ENABLE);
rt_pin_mode(EC_FUN_BTN, PIN_MODE_INPUT);
rt_pin_attach_irq(EC_FUN_BTN, PIN_IRQ_MODE_FALLING, key_handler, (void*)"callback args");
rt_pin_irq_enable(EC_FUN_BTN, PIN_IRQ_ENABLE);
while(1)
{
if (flag == 0)
{
rt_pin_write(EC_PWR_LED_PIN, PIN_HIGH);
rt_pin_write(TEST_LED_PIN, PIN_HIGH);
rt_thread_delay(500);
rt_pin_write(EC_PWR_LED_PIN, PIN_LOW);
rt_pin_write(TEST_LED_PIN, PIN_LOW);
rt_thread_delay(500);
}
else
{
rt_pin_write(EC_PWR_LED_PIN, PIN_HIGH);
rt_pin_write(TEST_LED_PIN, PIN_HIGH);
rt_thread_delay(100);
rt_pin_write(EC_PWR_LED_PIN, PIN_LOW);
rt_pin_write(TEST_LED_PIN, PIN_LOW);
rt_thread_delay(100);
}
}
}
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/