2024-12-02 16:26:55 +08:00
|
|
|
/********************************** (C) COPYRIGHT *******************************
|
|
|
|
* File Name : main.c
|
|
|
|
* Author : WCH
|
|
|
|
* Version : V1.1
|
|
|
|
* Date : 2020/08/06
|
2024-12-15 15:34:51 +08:00
|
|
|
* Description : 外设从机应用主函数及任务系统初始化
|
2024-12-02 16:26:55 +08:00
|
|
|
*********************************************************************************
|
|
|
|
* 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.
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2024-12-15 15:34:51 +08:00
|
|
|
/* 头文件包含 */
|
2024-12-02 16:26:55 +08:00
|
|
|
#include "CONFIG.h"
|
|
|
|
#include "HAL.h"
|
|
|
|
#include "gattprofile.h"
|
|
|
|
#include "peripheral.h"
|
|
|
|
|
2024-12-15 15:41:49 +08:00
|
|
|
#include "bsp_flash.h"
|
2024-12-08 12:49:39 +08:00
|
|
|
#include "bsp_adc.h"
|
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
#include "bsp_key.h"
|
|
|
|
|
|
|
|
#include "bsp_beep_led_emv.h"
|
|
|
|
|
2024-12-12 15:49:10 +08:00
|
|
|
#include "log.h"
|
|
|
|
#include "bsp_uart.h"
|
|
|
|
|
|
|
|
#undef LOG_ENABLE
|
|
|
|
#define LOG_ENABLE 1
|
|
|
|
|
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
|
|
|
|
*
|
2024-12-15 15:34:51 +08:00
|
|
|
* @brief 主循环
|
2024-12-02 16:26:55 +08:00
|
|
|
*
|
|
|
|
* @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-12 15:49:10 +08:00
|
|
|
BSP_UART1_TxLoop();
|
2024-12-09 11:41:44 +08:00
|
|
|
if (GPIOB_ReadPortPin(GPIO_Pin_15) == 0)
|
2024-12-02 17:34:56 +08:00
|
|
|
{
|
|
|
|
// 12V_EN
|
2024-12-09 11:41:44 +08:00
|
|
|
BOOST_EN;
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("BOOST_EN\n");
|
2024-12-02 17:34:56 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
// LED_R
|
|
|
|
LED_R_ON;
|
2024-12-08 11:29:48 +08:00
|
|
|
DelayMs(1000);
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("LED_R_ON\n");
|
2024-12-02 17:34:56 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
LED_ALL_OFF_DEINIT;
|
2024-12-08 11:29:48 +08:00
|
|
|
DelayMs(1000);
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("LED_ALL_OFF_DEINIT\n");
|
2024-12-02 17:34:56 +08:00
|
|
|
|
2024-12-10 15:39:32 +08:00
|
|
|
// BEEP
|
|
|
|
BEEP_ON;
|
|
|
|
DelayMs(1000);
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("BEEP_ON\n");
|
2024-12-10 15:39:32 +08:00
|
|
|
BEEP_OFF_DEINIT;
|
|
|
|
DelayMs(1000);
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("BEEP_OFF_DEINIT\n");
|
2024-12-10 15:39:32 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
// LED_G
|
|
|
|
LED_G_ON;
|
2024-12-08 11:29:48 +08:00
|
|
|
DelayMs(1000);
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("LED_G_ON\n");
|
2024-12-02 17:34:56 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
LED_ALL_OFF_DEINIT;
|
2024-12-08 11:29:48 +08:00
|
|
|
DelayMs(1000);
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("LED_ALL_OFF_DEINIT\n");
|
2024-12-02 17:34:56 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
// LED_Y
|
|
|
|
LED_Y_ON;
|
2024-12-08 11:29:48 +08:00
|
|
|
DelayMs(1000);
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("LED_Y_ON\n");
|
2024-12-02 17:34:56 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
LED_ALL_OFF_DEINIT;
|
2024-12-08 11:29:48 +08:00
|
|
|
DelayMs(1000);
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("LED_ALL_OFF_DEINIT\n");
|
2024-12-02 17:34:56 +08:00
|
|
|
|
2024-12-10 15:39:32 +08:00
|
|
|
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("Delay 6s\n");
|
2024-12-09 11:41:44 +08:00
|
|
|
|
|
|
|
// EMV_CHARGE
|
|
|
|
EMV_CHARGE_EN;
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("EMV_CHARGE_EN\n");
|
2024-12-09 11:41:44 +08:00
|
|
|
|
2024-12-10 15:39:32 +08:00
|
|
|
DelayMs(1000);
|
2024-12-09 11:41:44 +08:00
|
|
|
|
2024-12-09 16:13:41 +08:00
|
|
|
EMV_CHARGE_OFF_DEINIT;
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("EMV_CHARGE_OFF_DEINIT 500 ms\n");
|
2024-12-02 17:34:56 +08:00
|
|
|
|
|
|
|
// EMV_CTRL
|
2024-12-09 11:41:44 +08:00
|
|
|
EMV_ON;
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("EMV_ON\n");
|
2024-12-09 16:13:41 +08:00
|
|
|
DelayMs(100);
|
2024-12-02 17:34:56 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
BOOST_OFF_DEINIT;
|
|
|
|
BEEP_OFF_DEINIT;
|
|
|
|
LED_ALL_OFF_DEINIT;
|
|
|
|
EMV_CHARGE_OFF_DEINIT;
|
|
|
|
EMV_OFF_DEINIT;
|
2024-12-02 17:34:56 +08:00
|
|
|
}
|
2024-12-02 16:26:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* @fn main
|
|
|
|
*
|
2024-12-15 15:34:51 +08:00
|
|
|
* @brief 主函数
|
2024-12-02 16:26:55 +08:00
|
|
|
*
|
|
|
|
* @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-12 15:49:10 +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
|
2024-12-12 15:49:10 +08:00
|
|
|
// GPIOA_SetBits(bTXD1);
|
|
|
|
// GPIOA_ModeCfg(bTXD1, GPIO_ModeOut_PP_5mA);
|
|
|
|
|
|
|
|
// UART1_DefInit();
|
|
|
|
|
2024-12-15 15:34:51 +08:00
|
|
|
// 改成1500000波特率了
|
2024-12-15 15:28:43 +08:00
|
|
|
BSP_UART1_Init(1500000);
|
2024-12-12 19:38:57 +08:00
|
|
|
// logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
|
2024-12-12 15:49:10 +08:00
|
|
|
logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
|
2024-12-15 15:34:51 +08:00
|
|
|
logError("中文测试 %2.2f", 123.456);
|
2024-12-15 15:35:01 +08:00
|
|
|
|
2024-12-02 16:26:55 +08:00
|
|
|
#endif
|
2024-12-02 17:03:41 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
DelayMs(1000 * 3);
|
2024-12-02 17:03:41 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
BOOST_OFF_DEINIT;
|
|
|
|
BEEP_OFF_DEINIT;
|
|
|
|
LED_ALL_OFF_DEINIT;
|
|
|
|
EMV_CHARGE_OFF_DEINIT;
|
|
|
|
EMV_OFF_DEINIT;
|
2024-12-02 17:03:41 +08:00
|
|
|
|
2024-12-09 11:41:44 +08:00
|
|
|
BSP_KEY_Init();
|
2024-12-08 11:29:48 +08:00
|
|
|
|
2024-12-08 12:49:39 +08:00
|
|
|
BSP_ADC_Init();
|
2024-12-02 16:26:55 +08:00
|
|
|
CH59x_BLEInit();
|
2024-12-15 15:34:51 +08:00
|
|
|
|
2024-12-12 19:38:57 +08:00
|
|
|
logDebug("%s\n", VER_LIB);
|
2024-12-15 15:34:51 +08:00
|
|
|
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]);
|
|
|
|
|
2024-12-02 16:26:55 +08:00
|
|
|
HAL_Init();
|
|
|
|
GAPRole_PeripheralInit();
|
|
|
|
Peripheral_Init();
|
2024-12-15 15:41:49 +08:00
|
|
|
|
|
|
|
BSP_FLASH_Init();
|
|
|
|
|
2024-12-02 16:26:55 +08:00
|
|
|
Main_Circulation();
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************** endfile @ main ******************************/
|