BLE_TYQ_CH584M/APP/peripheral_main.c

186 lines
5.1 KiB
C
Raw Normal View History

2024-12-02 16:26:55 +08:00
/********************************** (C) COPYRIGHT *******************************
* File Name : main.c
* Author : WCH
* Version : V1.1
* Date : 2020/08/06
* Description : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
2024-12-02 17:03:41 +08:00
* Attention: This software (modified or not) and binary are used for
2024-12-02 16:26:55 +08:00
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
/* ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
#include "CONFIG.h"
#include "HAL.h"
#include "gattprofile.h"
#include "peripheral.h"
#include "bsp_adc.h"
2024-12-02 16:26:55 +08:00
/*********************************************************************
* GLOBAL TYPEDEFS
*/
__attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
2024-12-02 17:34:56 +08:00
#if (defined(BLE_MAC)) && (BLE_MAC == TRUE)
2024-12-02 16:26:55 +08:00
const uint8_t MacAddr[6] = {0x84, 0xC2, 0xE4, 0x03, 0x02, 0x02};
#endif
/*********************************************************************
* @fn Main_Circulation
*
* @brief <EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD>
*
* @return none
*/
__HIGH_CODE
2024-12-02 17:34:56 +08:00
__attribute__((noinline)) void Main_Circulation()
2024-12-02 16:26:55 +08:00
{
2024-12-02 17:34:56 +08:00
while (1)
2024-12-02 16:26:55 +08:00
{
TMOS_SystemProcess();
2024-12-02 17:34:56 +08:00
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);
2024-12-08 11:29:48 +08:00
DelayMs(1000);
2024-12-02 17:34:56 +08:00
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);
2024-12-08 11:29:48 +08:00
DelayMs(1000);
2024-12-02 17:34:56 +08:00
PRINT("LED OFF\n");
GPIOA_SetBits(GPIO_Pin_5);
GPIOA_ModeCfg(GPIO_Pin_5, GPIO_ModeOut_PP_5mA);
2024-12-08 11:29:48 +08:00
DelayMs(1000);
2024-12-02 17:34:56 +08:00
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);
2024-12-08 11:29:48 +08:00
DelayMs(1000);
2024-12-02 17:34:56 +08:00
PRINT("LED OFF\n");
GPIOA_SetBits(GPIO_Pin_15);
2024-12-08 11:29:48 +08:00
GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeOut_PP_5mA);
DelayMs(1000);
2024-12-02 17:34:56 +08:00
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);
2024-12-08 11:29:48 +08:00
DelayMs(1000);
2024-12-02 17:34:56 +08:00
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");
}
2024-12-02 16:26:55 +08:00
}
}
/*********************************************************************
* @fn main
*
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return none
*/
int main(void)
{
2024-12-02 17:34:56 +08:00
#if (defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE)
2024-12-02 16:26:55 +08:00
PWR_DCDCCfg(ENABLE);
#endif
SetSysClock(CLK_SOURCE_PLL_60MHz);
2024-12-08 11:29:48 +08:00
2024-12-02 17:34:56 +08:00
#if (defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
2024-12-08 11:29:48 +08:00
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);
2024-12-02 16:26:55 +08:00
#endif
2024-12-02 17:03:41 +08:00
// 12V_EN
GPIOA_ResetBits(GPIO_Pin_13);
GPIOA_ModeCfg(GPIO_Pin_13, GPIO_ModeOut_PP_5mA);
2024-12-08 11:29:48 +08:00
// 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");
2024-12-02 17:03:41 +08:00
// 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);
2024-12-02 17:34:56 +08:00
// <20><><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-02 17:03:41 +08:00
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;
2024-12-02 17:34:56 +08:00
R32_PIN_CONFIG2 |= (1U << 14);
2024-12-02 17:03:41 +08:00
// R32_PIN_CONFIG2
// GPIOA_ResetBits(GPIO_Pin_1);
// GPIOA_ModeCfg(GPIO_Pin_14, GPIO_ModeIN_Floating);
2024-12-02 17:03:41 +08:00
DelayMs(1000 * 3);
2024-12-08 11:29:48 +08:00
BSP_ADC_Init();
2024-12-02 16:26:55 +08:00
PRINT("%s\n", VER_LIB);
// while (1)
// {
// DelayMs(1000);
// }
2024-12-02 16:26:55 +08:00
CH59x_BLEInit();
HAL_Init();
GAPRole_PeripheralInit();
Peripheral_Init();
Main_Circulation();
}
/******************************** endfile @ main ******************************/