2022-01-10 20:04:48 +08:00
|
|
|
/*
|
|
|
|
* @Description:
|
|
|
|
* @Date: 2022-01-10 17:05:41
|
|
|
|
* @LastEditors: CK.Zh
|
2022-01-14 12:16:38 +08:00
|
|
|
* @LastEditTime: 2022-01-13 12:14:46
|
2022-01-11 19:51:25 +08:00
|
|
|
* @FilePath: /motion_ec/applications/main.c
|
2022-01-10 20:04:48 +08:00
|
|
|
*/
|
2022-01-10 16:20:39 +08:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2022-01-11 19:51:25 +08:00
|
|
|
|
2022-01-14 12:16:38 +08:00
|
|
|
// #define LOG_TAG "MAIN"
|
|
|
|
// #define LOG_LVL LOG_LVL_DBG
|
|
|
|
// #include <ulog.h>
|
2022-01-11 19:51:25 +08:00
|
|
|
|
2022-01-10 16:20:39 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
* Local type definitions ('typedef')
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Local pre-processor symbols/macros ('#define')
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/* defined the LED pin: PC9 */
|
2022-01-10 20:04:48 +08:00
|
|
|
|
2022-01-10 16:20:39 +08:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
2022-01-14 12:16:38 +08:00
|
|
|
flag = ~flag;
|
|
|
|
char *a = param;// 获取参数
|
|
|
|
rt_kprintf("key down! %s\n",a);
|
2022-01-11 19:51:25 +08:00
|
|
|
|
2022-01-10 16:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*******************************************************************************
|
|
|
|
** \brief Main function of GPIO output
|
|
|
|
**
|
|
|
|
** \param None
|
|
|
|
**
|
|
|
|
** \retval int32_t Return value, if needed
|
|
|
|
**
|
|
|
|
******************************************************************************/
|
|
|
|
int32_t main(void)
|
|
|
|
{
|
2022-01-11 19:51:25 +08:00
|
|
|
|
2022-01-14 12:16:38 +08:00
|
|
|
//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);
|
2022-01-11 19:51:25 +08:00
|
|
|
|
2022-01-14 12:16:38 +08:00
|
|
|
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);
|
2022-01-11 19:51:25 +08:00
|
|
|
|
2022-01-14 12:16:38 +08:00
|
|
|
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);
|
2022-01-10 16:20:39 +08:00
|
|
|
|
2022-01-11 19:51:25 +08:00
|
|
|
|
|
|
|
|
2022-01-10 16:20:39 +08:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
if (flag == 0)
|
|
|
|
{
|
2022-01-14 12:16:38 +08:00
|
|
|
rt_pin_write(EC_PWR_LED_PIN, PIN_HIGH);
|
|
|
|
rt_pin_write(TEST_LED_PIN, PIN_HIGH);
|
2022-01-10 16:20:39 +08:00
|
|
|
rt_thread_delay(500);
|
2022-01-14 12:16:38 +08:00
|
|
|
rt_pin_write(EC_PWR_LED_PIN, PIN_LOW);
|
|
|
|
rt_pin_write(TEST_LED_PIN, PIN_LOW);
|
2022-01-10 16:20:39 +08:00
|
|
|
rt_thread_delay(500);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-14 12:16:38 +08:00
|
|
|
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);
|
2022-01-10 16:20:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* EOF (not truncated)
|
|
|
|
******************************************************************************/
|