BLE_DCF_TYQ_CH592F/APP/peripheral_main.c

186 lines
5.1 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"
/*********************************************************************
* GLOBAL TYPEDEFS
*/
__attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
#if (defined(BLE_MAC)) && (BLE_MAC == TRUE)
const uint8_t MacAddr[6] = {0x84, 0xC2, 0xE4, 0x03, 0x02, 0x02};
#endif
/*********************************************************************
* @fn Main_Circulation
*
* @brief 主循环
*
* @return none
*/
__HIGH_CODE
__attribute__((noinline)) void Main_Circulation()
{
while (1)
{
TMOS_SystemProcess();
if (GPIOB_ReadPortPin(GPIO_Pin_14) == 0)
{
// 12V_EN
GPIOA_SetBits(GPIO_Pin_13);
GPIOA_ModeCfg(GPIO_Pin_13, GPIO_ModeOut_PP_5mA);
PRINT("12V_EN ON\n");
// LED
GPIOA_SetBits(GPIO_Pin_4);
GPIOA_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA);
DelayMs(1000);
PRINT("LED ON\n");
GPIOA_ResetBits(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_15);
GPIOA_ModeCfg(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_15, GPIO_ModeIN_PD);
DelayMs(1000);
PRINT("LED OFF\n");
GPIOA_SetBits(GPIO_Pin_5);
GPIOA_ModeCfg(GPIO_Pin_5, GPIO_ModeOut_PP_5mA);
DelayMs(1000);
PRINT("LED ON\n");
GPIOA_ResetBits(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_15);
GPIOA_ModeCfg(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_15, GPIO_ModeIN_PD);
DelayMs(1000);
PRINT("LED OFF\n");
GPIOA_SetBits(GPIO_Pin_15);
GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeOut_PP_5mA);
DelayMs(1000);
PRINT("LED ON\n");
GPIOA_ResetBits(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_15);
GPIOA_ModeCfg(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_15, GPIO_ModeIN_PD);
DelayMs(1000);
PRINT("LED OFF\n");
DelayMs(100);
PRINT("DelayMs 700\n");
// 12V_EN
GPIOA_ResetBits(GPIO_Pin_13);
GPIOA_ModeCfg(GPIO_Pin_13, GPIO_ModeOut_PP_5mA);
PRINT("12V_EN OFF\n");
DelayMs(1000 * 5);
// EMV_CTRL
GPIOB_SetBits(GPIO_Pin_13);
GPIOB_ModeCfg(GPIO_Pin_13, GPIO_ModeOut_PP_5mA);
PRINT("EMV_CTRL ON\n");
DelayMs(100);
// EMV_CTRL
GPIOB_ResetBits(GPIO_Pin_13);
GPIOB_ModeCfg(GPIO_Pin_13, GPIO_ModeIN_PD);
PRINT("EMV_CTRL OFF\n");
}
}
}
/*********************************************************************
* @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
GPIOB_SetBits(bTXD0);
GPIOB_ModeCfg(bTXD0, GPIO_ModeOut_PP_5mA);
UART0_DefInit();
PRINT("Start @ChipID=%02X\n", R8_CHIP_ID);
#endif
// 12V_EN
GPIOA_ResetBits(GPIO_Pin_13);
GPIOA_ModeCfg(GPIO_Pin_13, GPIO_ModeOut_PP_5mA);
// EMV_CTRL
GPIOB_SetBits(GPIO_Pin_13);
GPIOB_ModeCfg(GPIO_Pin_13, GPIO_ModeOut_PP_5mA);
PRINT("EMV_CTRL ON\n");
DelayMs(100);
GPIOB_ResetBits(GPIO_Pin_13);
PRINT("EMV_CTRL OFF\n");
// EMV_CTRL
GPIOB_ResetBits(GPIO_Pin_13);
GPIOB_ModeCfg(GPIO_Pin_13, GPIO_ModeIN_PD);
// LED
GPIOA_ResetBits(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_15);
GPIOA_ModeCfg(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_15, GPIO_ModeIN_PD);
// KEY
GPIOB_SetBits(GPIO_Pin_14);
// 由外部上拉电阻了
GPIOB_ModeCfg(GPIO_Pin_14, GPIO_ModeIN_Floating);
// ADC_VBAT
// GPIOAGPPCfg(ENABLE, RB_PIN_PA4_15_DIS);
// R16_PIN_ANALOG_IE != RB_PIN_PA4_15_DIS;
R32_PIN_CONFIG2 |= (1U << 14);
// R32_PIN_CONFIG2
// GPIOA_ResetBits(GPIO_Pin_1);
// GPIOA_ModeCfg(GPIO_Pin_14, GPIO_ModeIN_Floating);
DelayMs(1000 * 3);
BSP_ADC_Init();
PRINT("%s\n", VER_LIB);
// while (1)
// {
// DelayMs(1000);
// }
CH59x_BLEInit();
HAL_Init();
GAPRole_PeripheralInit();
Peripheral_Init();
Main_Circulation();
}
/******************************** endfile @ main ******************************/