- 灵敏度表改为 M1H 值: {216,108,36,10} / {108,72,18,9}
- 时序参数对齐: OUT_DELAY 39→38, PULSE_DELAY 10→19
- LED 宏命名对齐 154V4B: LEDA=红(PB1), LEDB=绿(PA9), LEDC=黄(PA10)
- RLY1/RLY2 引脚交换: PA6=RLY1, PA5=RLY2
233 lines
7.5 KiB
C
233 lines
7.5 KiB
C
/**
|
||
**************************************************************************
|
||
* @file at32f421_board.h
|
||
* @brief header file for at-start board. set of firmware functions to
|
||
* manage leds and push-button. initialize delay function.
|
||
**************************************************************************
|
||
* 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.
|
||
*
|
||
**************************************************************************
|
||
*/
|
||
|
||
#ifndef __AT32F421_BOARD_H
|
||
#define __AT32F421_BOARD_H
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include "stdio.h"
|
||
#include "at32f421.h"
|
||
|
||
/** @addtogroup AT32F421_board
|
||
* @{
|
||
*/
|
||
|
||
/** @addtogroup BOARD
|
||
* @{
|
||
*/
|
||
|
||
/** @defgroup BOARD_pins_definition
|
||
* @{
|
||
*/
|
||
|
||
/**
|
||
* this header include define support list:
|
||
* 1. at-start-f421 v1.x boards
|
||
* if define AT_START_F421_V1, the header file support at-start-f421 v1.x board
|
||
*/
|
||
|
||
#if !defined (AT_START_F421_V1)
|
||
#error "please select first the board at-start device used in your application (in at32f421_board.h file)"
|
||
#endif
|
||
|
||
/******************** define led ********************/
|
||
typedef enum
|
||
{
|
||
LED2 = 0,
|
||
LED3 = 1,
|
||
LED4 = 2
|
||
} led_type;
|
||
|
||
#define LED_NUM 3
|
||
|
||
#if defined (AT_START_F421_V1)
|
||
#define LED2_PIN GPIO_PINS_1
|
||
#define LED2_GPIO GPIOB
|
||
#define LED2_GPIO_CRM_CLK CRM_GPIOB_PERIPH_CLOCK
|
||
|
||
#define LED3_PIN GPIO_PINS_10
|
||
#define LED3_GPIO GPIOA
|
||
#define LED3_GPIO_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
|
||
#define LED4_PIN GPIO_PINS_11
|
||
#define LED4_GPIO GPIOB
|
||
#define LED4_GPIO_CRM_CLK CRM_GPIOB_PERIPH_CLOCK
|
||
#endif
|
||
|
||
#define LED_RED_PIN GPIO_PINS_1
|
||
#define LED_RED_GPIO GPIOB
|
||
#define LED_GPIO_CRM_CLK CRM_GPIOB_PERIPH_CLOCK
|
||
|
||
#define LED_GREEN_PIN GPIO_PINS_9
|
||
#define LED_GREEN_GPIO GPIOA
|
||
#define LED_GREEN_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
|
||
#define LED_YELLOW_PIN GPIO_PINS_10
|
||
#define LED_YELLOW_GPIO GPIOA
|
||
#define LED_YELLOW_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
|
||
// LED 命名对齐 DLD154V4B 规格:
|
||
// LEDA = 红色呼吸灯 (PB1, TMR14 PWM)
|
||
// LEDB = 绿色有车指示灯 (PA9)
|
||
// LEDC = 黄色故障指示灯 (PA10)
|
||
// 注意: DEBUG 模式下 PA9 复用为 UART TX,LEDB 宏为空
|
||
|
||
// LEDA — 红色 (PB1),GPIO 直接控制(初始化闪烁用,正常运行时 PWM)
|
||
#define LEDA_OFF gpio_bits_set(LED_RED_GPIO, LED_RED_PIN)
|
||
#define LEDA_ON gpio_bits_reset(LED_RED_GPIO, LED_RED_PIN)
|
||
|
||
// LEDB — 绿色 (PA9),有车亮
|
||
#ifdef DEBUG
|
||
#define LEDB_OFF
|
||
#define LEDB_ON
|
||
#else
|
||
#define LEDB_OFF gpio_bits_set(LED_GREEN_GPIO, LED_GREEN_PIN)
|
||
#define LEDB_ON gpio_bits_reset(LED_GREEN_GPIO, LED_GREEN_PIN)
|
||
#endif
|
||
|
||
// LEDC — 黄色 (PA10),故障指示
|
||
#define LEDC_OFF gpio_bits_set(LED_YELLOW_GPIO, LED_YELLOW_PIN)
|
||
#define LEDC_ON gpio_bits_reset(LED_YELLOW_GPIO, LED_YELLOW_PIN)
|
||
|
||
#define LED_YELLOW_OFF LEDC_OFF
|
||
#define LED_YELLOW_ON LEDC_ON
|
||
|
||
|
||
|
||
// RLY1 — 主输出 (PA6),存在/脉冲
|
||
#define RLY1_PIN GPIO_PINS_6
|
||
#define RLY1_GPIO GPIOA
|
||
#define RLY1_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
|
||
// RLY2 — 辅助输出 (PA5),方向/第二路
|
||
#define RLY2_PIN GPIO_PINS_5
|
||
#define RLY2_GPIO GPIOA
|
||
#define RLY2_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
|
||
#define RLY1_ON gpio_bits_set(RLY1_GPIO, RLY1_PIN)
|
||
#define RLY1_OFF gpio_bits_reset(RLY1_GPIO, RLY1_PIN)
|
||
#define RLY2_ON gpio_bits_set(RLY2_GPIO, RLY2_PIN)
|
||
#define RLY2_OFF gpio_bits_reset(RLY2_GPIO, RLY2_PIN)
|
||
|
||
|
||
/**************** define print uart ******************/
|
||
#define PRINT_UART USART1
|
||
#define PRINT_UART_CRM_CLK CRM_USART1_PERIPH_CLOCK
|
||
#define PRINT_UART_TX_PIN GPIO_PINS_9
|
||
#define PRINT_UART_TX_GPIO GPIOA
|
||
#define PRINT_UART_TX_GPIO_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
#define PRINT_UART_TX_PIN_SOURCE GPIO_PINS_SOURCE9
|
||
#define PRINT_UART_TX_PIN_MUX_NUM GPIO_MUX_1
|
||
|
||
/******************* define button *******************/
|
||
typedef enum
|
||
{
|
||
USER_BUTTON = 0,
|
||
NO_BUTTON = 1
|
||
} button_type;
|
||
|
||
#define USER_BUTTON_PIN GPIO_PINS_0
|
||
#define USER_BUTTON_PORT GPIOA
|
||
#define USER_BUTTON_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>L
|
||
#define SW1_BUTTON_PIN GPIO_PINS_0
|
||
#define SW1_BUTTON_PORT GPIOA
|
||
#define SW1_BUTTON_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>H
|
||
#define SW2_BUTTON_PIN GPIO_PINS_1
|
||
#define SW2_BUTTON_PORT GPIOA
|
||
#define SW2_BUTTON_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD>ʽ
|
||
#define SW3_BUTTON_PIN GPIO_PINS_2
|
||
#define SW3_BUTTON_PORT GPIOA
|
||
#define SW3_BUTTON_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
// <20><>ʱ
|
||
#define SW4_BUTTON_PIN GPIO_PINS_3
|
||
#define SW4_BUTTON_PORT GPIOA
|
||
#define SW4_BUTTON_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
// <20><>ȫ<EFBFBD><C8AB>λ
|
||
#define SW5_BUTTON_PIN GPIO_PINS_4
|
||
#define SW5_BUTTON_PORT GPIOA
|
||
#define SW5_BUTTON_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
|
||
|
||
/**
|
||
* @}
|
||
*/
|
||
|
||
/** @defgroup BOARD_exported_functions
|
||
* @{
|
||
*/
|
||
|
||
/******************** functions ********************/
|
||
void at32_board_init(void);
|
||
void loop_timer_io_init(void);
|
||
|
||
/* led operation function */
|
||
void at32_led_init(led_type led);
|
||
void at32_led_on(led_type led);
|
||
void at32_led_off(led_type led);
|
||
void at32_led_toggle(led_type led);
|
||
|
||
/* button operation function */
|
||
void at32_button_init(void);
|
||
button_type at32_button_press(void);
|
||
uint8_t at32_button_state(void);
|
||
|
||
/* delay function */
|
||
void delay_init(void);
|
||
void delay_us(uint32_t nus);
|
||
void delay_ms(uint16_t nms);
|
||
void delay_sec(uint16_t sec);
|
||
|
||
void poll_red_pwm(void);
|
||
|
||
/* printf uart init function */
|
||
void uart_print_init(uint32_t baudrate);
|
||
|
||
/**
|
||
* @}
|
||
*/
|
||
extern crm_clocks_freq_type g_crm_clocks_freq_struct;
|
||
extern tmr_input_config_type g_tmr_input_config_struct;
|
||
|
||
/**
|
||
* @}
|
||
*/
|
||
|
||
/**
|
||
* @}
|
||
*/
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif
|
||
|