256 lines
7.0 KiB
C
256 lines
7.0 KiB
C
|
|
/* add user code begin Header */
|
|||
|
|
/**
|
|||
|
|
**************************************************************************
|
|||
|
|
* @file main.c
|
|||
|
|
* @brief main program
|
|||
|
|
**************************************************************************
|
|||
|
|
* Copyright notice & Disclaimer
|
|||
|
|
*
|
|||
|
|
* The software Board Support Package (BSP) that is made available to
|
|||
|
|
* download from Artery official website is the copyrighted work of Artery.
|
|||
|
|
* Artery authorizes customers to use, copy, and distribute the BSP
|
|||
|
|
* software and its related documentation for the purpose of design and
|
|||
|
|
* development in conjunction with Artery microcontrollers. Use of the
|
|||
|
|
* software is governed by this copyright notice and the following disclaimer.
|
|||
|
|
*
|
|||
|
|
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
|||
|
|
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
|||
|
|
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
|||
|
|
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
|||
|
|
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|||
|
|
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
|||
|
|
*
|
|||
|
|
**************************************************************************
|
|||
|
|
*/
|
|||
|
|
/* add user code end Header */
|
|||
|
|
|
|||
|
|
/* Includes ------------------------------------------------------------------*/
|
|||
|
|
#include "at32f403a_407_wk_config.h"
|
|||
|
|
#include "wk_acc.h"
|
|||
|
|
#include "wk_debug.h"
|
|||
|
|
#include "wk_spi.h"
|
|||
|
|
#include "wk_usbfs.h"
|
|||
|
|
#include "usb_app.h"
|
|||
|
|
#include "wk_system.h"
|
|||
|
|
#include "includes.h"
|
|||
|
|
#include "W25Q128.h"
|
|||
|
|
#include "Drv_TM1617_RGB.h"
|
|||
|
|
/* private includes ----------------------------------------------------------*/
|
|||
|
|
/* add user code begin private includes */
|
|||
|
|
|
|||
|
|
/* add user code end private includes */
|
|||
|
|
|
|||
|
|
/* private typedef -----------------------------------------------------------*/
|
|||
|
|
/* add user code begin private typedef */
|
|||
|
|
|
|||
|
|
/* add user code end private typedef */
|
|||
|
|
|
|||
|
|
/* private define ------------------------------------------------------------*/
|
|||
|
|
/* add user code begin private define */
|
|||
|
|
//
|
|||
|
|
// Power Button
|
|||
|
|
//
|
|||
|
|
#define POWER_BUTTON_PIN GPIO_PINS_2
|
|||
|
|
#define POWER_BUTTON_PORT GPIOD
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
// Main Power
|
|||
|
|
//
|
|||
|
|
#define S_PWR_ON_OFF_Pin GPIO_PINS_2
|
|||
|
|
#define S_PWR_ON_OFF_GPIO_Port GPIOB
|
|||
|
|
|
|||
|
|
#define FIRMWARE_START_ADDR 0x08008000
|
|||
|
|
/* add user code end private define */
|
|||
|
|
|
|||
|
|
/* private macro -------------------------------------------------------------*/
|
|||
|
|
/* add user code begin private macro */
|
|||
|
|
|
|||
|
|
/* add user code end private macro */
|
|||
|
|
|
|||
|
|
/* private variables ---------------------------------------------------------*/
|
|||
|
|
/* add user code begin private variables */
|
|||
|
|
|
|||
|
|
/* add user code end private variables */
|
|||
|
|
|
|||
|
|
/* private function prototypes --------------------------------------------*/
|
|||
|
|
/* add user code begin function prototypes */
|
|||
|
|
|
|||
|
|
/* add user code end function prototypes */
|
|||
|
|
|
|||
|
|
/* private user code ---------------------------------------------------------*/
|
|||
|
|
/* add user code begin 0 */
|
|||
|
|
void wk_gpio_config(void);
|
|||
|
|
void JumpToApplication(void);
|
|||
|
|
|
|||
|
|
uint8_t TM1617KeyValue = 0;
|
|||
|
|
static uint32_t PowerKeyCount = 0;
|
|||
|
|
static uint8_t long_press_locked = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹһֱ<D2BB><D6B1><EFBFBD><EFBFBD>
|
|||
|
|
/* add user code end 0 */
|
|||
|
|
|
|||
|
|
flag_status BSP_GetPowerKey (void)
|
|||
|
|
{
|
|||
|
|
return gpio_input_data_bit_read(POWER_BUTTON_PORT, POWER_BUTTON_PIN);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void BSP_MainPowerEnable (uint8_t Enable)
|
|||
|
|
{
|
|||
|
|
if (Enable) gpio_bits_set(S_PWR_ON_OFF_GPIO_Port, S_PWR_ON_OFF_Pin);
|
|||
|
|
else gpio_bits_reset(S_PWR_ON_OFF_GPIO_Port, S_PWR_ON_OFF_Pin);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief main function.
|
|||
|
|
* @param none
|
|||
|
|
* @retval none
|
|||
|
|
*/
|
|||
|
|
int main(void)
|
|||
|
|
{
|
|||
|
|
/* add user code begin 1 */
|
|||
|
|
|
|||
|
|
/* add user code end 1 */
|
|||
|
|
|
|||
|
|
/* system clock config. */
|
|||
|
|
wk_system_clock_config();
|
|||
|
|
|
|||
|
|
/* config periph clock. */
|
|||
|
|
wk_periph_clock_config();
|
|||
|
|
|
|||
|
|
/* gpio config */
|
|||
|
|
wk_gpio_config();
|
|||
|
|
|
|||
|
|
/* init debug function. */
|
|||
|
|
wk_debug_config();
|
|||
|
|
|
|||
|
|
/* nvic config. */
|
|||
|
|
wk_nvic_config();
|
|||
|
|
|
|||
|
|
/* timebase config. */
|
|||
|
|
wk_timebase_init();
|
|||
|
|
|
|||
|
|
TM1617_GPIO_Init();
|
|||
|
|
|
|||
|
|
wk_delay_ms(1000);
|
|||
|
|
|
|||
|
|
TM1617KeyValue = TM1617_ScanFkey();
|
|||
|
|
if(TM1617KeyValue == 4)
|
|||
|
|
{
|
|||
|
|
JumpToApplication();
|
|||
|
|
}
|
|||
|
|
/* init spi1 function. */
|
|||
|
|
BSP_MainPowerEnable(1);
|
|||
|
|
wk_spi1_init();
|
|||
|
|
|
|||
|
|
/* init spi2 function. */
|
|||
|
|
/* init acc function. */
|
|||
|
|
wk_acc_init();
|
|||
|
|
|
|||
|
|
/* init usbfs function. */
|
|||
|
|
wk_usbfs_init();
|
|||
|
|
|
|||
|
|
/* init usb app function. */
|
|||
|
|
wk_usb_app_init();
|
|||
|
|
|
|||
|
|
/* add user code begin 2 */
|
|||
|
|
W25Q128_Init();
|
|||
|
|
|
|||
|
|
LCD_Init();
|
|||
|
|
wk_delay_ms(10);
|
|||
|
|
/* USER CODE BEGIN 2 */
|
|||
|
|
LCD_BLK_Set();
|
|||
|
|
LCD_ShowChinese_AutoAlign(0, 240,150 ,(uint8_t*)"\xC9\xFD\xBC\xB6\xC4\xA3\xCA\xBD\x00",LCD_ALIGN_CENTER, RED, WHITE, 0, 24);
|
|||
|
|
|
|||
|
|
|
|||
|
|
/* add user code end 2 */
|
|||
|
|
|
|||
|
|
while(1)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
/* add user code begin 3 */
|
|||
|
|
if(BSP_GetPowerKey() == 0)
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (PowerKeyCount < 200 && long_press_locked == 0)
|
|||
|
|
{
|
|||
|
|
PowerKeyCount++;
|
|||
|
|
}
|
|||
|
|
if (PowerKeyCount >= 150 && long_press_locked == 0)
|
|||
|
|
{
|
|||
|
|
LCD_BLK_Clr();
|
|||
|
|
BSP_MainPowerEnable(0);
|
|||
|
|
wk_delay_ms(3000);
|
|||
|
|
}
|
|||
|
|
wk_delay_ms(10);
|
|||
|
|
}
|
|||
|
|
/* add user code end 3 */
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* add user code begin 4 */
|
|||
|
|
void wk_gpio_config(void)
|
|||
|
|
{
|
|||
|
|
/* add user code begin gpio_config 0 */
|
|||
|
|
|
|||
|
|
/* add user code end gpio_config 0 */
|
|||
|
|
|
|||
|
|
gpio_init_type gpio_init_struct;
|
|||
|
|
gpio_default_para_init(&gpio_init_struct);
|
|||
|
|
|
|||
|
|
/* add user code begin gpio_config 1 */
|
|||
|
|
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
|||
|
|
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
|
|||
|
|
/* add user code end gpio_config 1 */
|
|||
|
|
|
|||
|
|
/* gpio input config */
|
|||
|
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
|||
|
|
gpio_init_struct.gpio_pins = GPIO_PINS_2;
|
|||
|
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|||
|
|
gpio_init(GPIOD, &gpio_init_struct);
|
|||
|
|
|
|||
|
|
/* gpio output config */
|
|||
|
|
gpio_bits_reset(GPIOB, GPIO_PINS_9 | GPIO_PINS_2);
|
|||
|
|
gpio_bits_set(GPIOC, GPIO_PINS_13);
|
|||
|
|
|
|||
|
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
|||
|
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|||
|
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
|||
|
|
gpio_init_struct.gpio_pins = GPIO_PINS_13;
|
|||
|
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|||
|
|
gpio_init(GPIOC, &gpio_init_struct);
|
|||
|
|
|
|||
|
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
|||
|
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|||
|
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
|||
|
|
gpio_init_struct.gpio_pins = GPIO_PINS_2 | GPIO_PINS_9;
|
|||
|
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|||
|
|
gpio_init(GPIOB, &gpio_init_struct);
|
|||
|
|
|
|||
|
|
/* gpio analog config */
|
|||
|
|
|
|||
|
|
|
|||
|
|
/* add user code begin gpio_config 2 */
|
|||
|
|
|
|||
|
|
/* add user code end gpio_config 2 */
|
|||
|
|
}
|
|||
|
|
/* add user code end 4 */
|
|||
|
|
|
|||
|
|
|
|||
|
|
void JumpToApplication(void)
|
|||
|
|
{
|
|||
|
|
typedef void (*pFunction)(void);
|
|||
|
|
pFunction Jump_To_Application;
|
|||
|
|
uint32_t JumpAddress;
|
|||
|
|
|
|||
|
|
if (((*(__IO uint32_t*)FIRMWARE_START_ADDR) & 0x2FFE0000 ) == 0x20000000)
|
|||
|
|
{
|
|||
|
|
/* <20><>ת<EFBFBD><D7AA><EFBFBD>û<EFBFBD>Ӧ<EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
JumpAddress = *(__IO uint32_t*) (FIRMWARE_START_ADDR + 4);
|
|||
|
|
Jump_To_Application = (pFunction) JumpAddress;
|
|||
|
|
/* <20><>ʼ<EFBFBD><CABC><EFBFBD>û<EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>Ķ<EFBFBD>ջָ<D5BB><D6B8> */
|
|||
|
|
__set_MSP(*(__IO uint32_t*) FIRMWARE_START_ADDR);
|
|||
|
|
SCB->VTOR = FIRMWARE_START_ADDR;
|
|||
|
|
Jump_To_Application();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|