BLE_DCF_TYQ_CH592F/APP/peripheral_main.c

228 lines
5.2 KiB
C

/********************************** (C) COPYRIGHT *******************************
* File Name : main.c
* Author : WCH
* Version : V1.1
* Date : 2020/08/06
* Description : 外设从机应用主函数及任务系统初始化
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
/* 头文件包含 */
#include "CONFIG.h"
#include "HAL.h"
#include "gattprofile.h"
#include "peripheral.h"
#include "bsp_adc.h"
#include "bsp_key.h"
#include "bsp_beep_led_emv.h"
#include "log.h"
#include "bsp_uart.h"
#include "bsp_i2c.h"
#undef LOG_ENABLE
#define LOG_ENABLE 1
#undef LOG_TAG
#define LOG_TAG "main"
// static uint8_t main_task_id = INVALID_TASK_ID;
__attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
void app_task_handler(TeAppEvtType app_evt_type)
{
switch(app_evt_type)
{
case kKeyShort:{
logDebug("button short press\r\n");
break;
}
case kKeyLong:
logDebug("button long press\r\n");
break;
case kKeyRelease:
// BSP_KEY_EnterLowpower();
DelayMs(10);
BSP_RequestSleep();
logDebug("gpio relase;BSP_RequestSleep\r\n");
break;
default:
break;
}
}
/*********************************************************************
* @fn Main_Circulation
*
* @brief 主循环
*
* @return none
*/
__HIGH_CODE
__attribute__((noinline))
void Main_Circulation()
{
while (1)
{
TMOS_SystemProcess();
KEY_ProcessLoop();
// BSP_UART1_TxLoop();
#if 0
if (GPIOB_ReadPortPin(GPIO_Pin_7) == 0)
{
// 12V_EN
BOOST_EN;
logDebug("BOOST_EN\n");
// LED_R
LED_R_ON;
DelayMs(1000);
logDebug("LED_R_ON\n");
LED_ALL_OFF_DEINIT;
DelayMs(1000);
logDebug("LED_ALL_OFF_DEINIT\n");
// BEEP
BEEP_ON;
DelayMs(1000);
logDebug("BEEP_ON\n");
BEEP_OFF_DEINIT;
DelayMs(1000);
logDebug("BEEP_OFF_DEINIT\n");
// LED_G
LED_G_ON;
DelayMs(1000);
logDebug("LED_G_ON\n");
LED_ALL_OFF_DEINIT;
DelayMs(1000);
logDebug("LED_ALL_OFF_DEINIT\n");
// LED_Y
LED_Y_ON;
DelayMs(1000);
logDebug("LED_Y_ON\n");
LED_ALL_OFF_DEINIT;
DelayMs(1000);
logDebug("LED_ALL_OFF_DEINIT\n");
logDebug("Delay 6s\n");
// EMV_CHARGE
EMV_CHARGE_EN;
logDebug("EMV_CHARGE_EN\n");
DelayMs(1000);
EMV_CHARGE_OFF_DEINIT;
logDebug("EMV_CHARGE_OFF_DEINIT 500 ms\n");
// EMV_CTRL
EMV_ON;
logDebug("EMV_ON\n");
DelayMs(100);
BOOST_OFF_DEINIT;
BEEP_OFF_DEINIT;
LED_ALL_OFF_DEINIT;
EMV_CHARGE_OFF_DEINIT;
EMV_OFF_DEINIT;
}
#endif
}
}
/*********************************************************************
* @fn BLE_AdvertiseEventCB
*
* @brief Callback from advertise over
*
* @param None
*
* @return none
*/
void BLE_AdvertiseEventCB(uint32_t timeUs)
{
// logDebug("BLE_AdvertiseEventCB");
}
/*********************************************************************
* @fn main
*
* @brief 主函数
*
* @return none
*/
int main(void)
{
#if (defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE)
PWR_DCDCCfg(ENABLE);
#endif
SetSysClock(CLK_SOURCE_PLL_60MHz);
#if (defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
#endif
#ifdef DEBUG
// GPIOA_SetBits(bTXD1);
// GPIOA_ModeCfg(bTXD1, GPIO_ModeOut_PP_5mA);
// UART1_DefInit();
// 改成 1500000 波特率了
BSP_UART1_Init(1500000);
// logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
logError("中文测试 %2.2f", 123.456);
#endif
DelayMs(1000 * 3);
BOOST_OFF_DEINIT;
BEEP_OFF_DEINIT;
LED_ALL_OFF_DEINIT;
EMV_CHARGE_OFF_DEINIT;
EMV_OFF_DEINIT;
BSP_ADC_Init();
CH59x_BLEInit();
logDebug("%s\n", VER_LIB);
uint8_t MacAddr[6];
GetMACAddress(MacAddr);
logDebug("MacAddr: %02X:%02X:%02X:%02X:%02X:%02X", MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]);
HAL_Init();
GAPRole_PeripheralInit();
Peripheral_Init();
LL_AdvertiseEventRegister(BLE_AdvertiseEventCB);
DelayMs(100);
GXHTC3C_Init();
// while (1)
// {
// DelayMs(100);
// }
// BSP_KEY_Init();
BSP_KEY_Init(app_task_handler);
Main_Circulation();
}
/******************************** endfile @ main ******************************/