add led
This commit is contained in:
parent
7fa633805b
commit
0233fffa4d
@ -19,6 +19,7 @@ set(TARGET_C_SRC
|
||||
${CMAKE_SOURCE_DIR}/src/gd32e23x_it.c
|
||||
${CMAKE_SOURCE_DIR}/src/systick.c
|
||||
${CMAKE_SOURCE_DIR}/src/peripheral.c
|
||||
${CMAKE_SOURCE_DIR}/src/led.c
|
||||
)
|
||||
|
||||
add_executable(gd32e23x_template ${TARGET_C_SRC})
|
||||
|
44
inc/board_config.h
Normal file
44
inc/board_config.h
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// Created by dell on 24-12-28.
|
||||
//
|
||||
|
||||
#ifndef BOARD_CONFIG_H
|
||||
#define BOARD_CONFIG_H
|
||||
|
||||
#define SOFTWARE_IIC
|
||||
|
||||
// #define DEBUG_VERBOES
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define RCU_GPIO_I2C RCU_GPIOF
|
||||
#define RCU_I2C RCU_I2C0
|
||||
#define I2C_SCL_PORT GPIOF
|
||||
#define I2C_SCL_PIN GPIO_PIN_1
|
||||
#define I2C_SDA_PORT GPIOF
|
||||
#define I2C_SDA_PIN GPIO_PIN_0
|
||||
#define I2C_GPIO_AF GPIO_AF_1
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define RS485_RCU RCU_USART0
|
||||
#define RS485_GPIO_RCU RCU_GPIOA
|
||||
#define RS485_GPIO_PORT GPIOA
|
||||
#define RS485_TX_PIN GPIO_PIN_2
|
||||
#define RS485_RX_PIN GPIO_PIN_3
|
||||
#define RS485_PHY USART0
|
||||
#define RS485_BAUDRATE 115200U
|
||||
#define RS485_EN_PIN GPIO_PIN_1
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define LED_PORT GPIOA
|
||||
#define LED_PIN GPIO_PIN_7
|
||||
#define LED_RCU RCU_GPIOA
|
||||
#define LED_BLINK_TIMER_RCU RCU_TIMER16
|
||||
#define LED_BLINK_TIMER TIMER16
|
||||
#define LED_BLINK_IRQ TIMER16_IRQn
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#endif //BOARD_CONFIG_H
|
@ -6,6 +6,6 @@
|
||||
#define PERIPHERAL_H
|
||||
|
||||
void usart_config(void);
|
||||
void led_blink_config(void);
|
||||
|
||||
|
||||
#endif //PERIPHERAL_H
|
||||
|
@ -35,6 +35,7 @@ OF SUCH DAMAGE.
|
||||
#include "gd32e23x_it.h"
|
||||
#include "main.h"
|
||||
#include "systick.h"
|
||||
#include "board_config.h"
|
||||
|
||||
/*!
|
||||
\brief this function handles NMI exception
|
||||
@ -98,21 +99,21 @@ void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
void TIMER13_IRQHandler(void)
|
||||
void TIMER16_IRQHandler(void)
|
||||
{
|
||||
if (timer_interrupt_flag_get(TIMER13, TIMER_INT_FLAG_UP) == SET)
|
||||
if (timer_interrupt_flag_get(LED_BLINK_TIMER, TIMER_INT_FLAG_UP) == SET)
|
||||
{
|
||||
timer_interrupt_flag_clear(TIMER13, TIMER_INT_FLAG_UP);
|
||||
timer_interrupt_flag_clear(LED_BLINK_TIMER, TIMER_INT_FLAG_UP);
|
||||
static uint8_t led_status = 0;
|
||||
if (led_status)
|
||||
{
|
||||
//! turn on led & reconfig timer13 period to 19000(1900ms)
|
||||
gpio_bit_write(GPIOB, GPIO_PIN_1, RESET);
|
||||
timer_autoreload_value_config(TIMER13, 19200);
|
||||
gpio_bit_write(LED_PORT, LED_PIN, RESET);
|
||||
timer_autoreload_value_config(LED_BLINK_TIMER, 19200);
|
||||
} else {
|
||||
//! turn off led & reconfig timer13 period to 1000(100ms)
|
||||
gpio_bit_write(GPIOB, GPIO_PIN_1, SET);
|
||||
timer_autoreload_value_config(TIMER13, 800);
|
||||
gpio_bit_write(LED_PORT, LED_PIN, SET);
|
||||
timer_autoreload_value_config(LED_BLINK_TIMER, 800);
|
||||
}
|
||||
led_status = !led_status;
|
||||
}
|
||||
|
37
src/led.c
Normal file
37
src/led.c
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by yelv1 on 24-12-30.
|
||||
//
|
||||
|
||||
#include "led.h"
|
||||
|
||||
/*!
|
||||
\brief led blink configuration
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void led_blink_config(void)
|
||||
{
|
||||
rcu_periph_clock_enable(LED_RCU);
|
||||
|
||||
gpio_mode_set(LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_PIN);
|
||||
gpio_output_options_set(LED_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, LED_PIN);
|
||||
gpio_bit_write(LED_PORT, LED_PIN, RESET);
|
||||
|
||||
rcu_periph_clock_enable(LED_BLINK_TIMER_RCU);
|
||||
timer_deinit(LED_BLINK_TIMER);
|
||||
|
||||
timer_parameter_struct timer_initpara;
|
||||
timer_struct_para_init(&timer_initpara);
|
||||
timer_initpara.prescaler =7199;
|
||||
timer_initpara.alignedmode =TIMER_COUNTER_EDGE;
|
||||
timer_initpara.counterdirection =TIMER_COUNTER_UP;
|
||||
timer_initpara.period =9999;
|
||||
timer_initpara.clockdivision =TIMER_CKDIV_DIV1;
|
||||
timer_init(LED_BLINK_TIMER, &timer_initpara);
|
||||
|
||||
timer_auto_reload_shadow_enable(LED_BLINK_TIMER);
|
||||
timer_interrupt_enable(LED_BLINK_TIMER, TIMER_INT_UP);
|
||||
nvic_irq_enable(LED_BLINK_IRQ, 0);
|
||||
timer_enable(LED_BLINK_TIMER);
|
||||
}
|
13
src/led.h
Normal file
13
src/led.h
Normal file
@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by yelv1 on 24-12-30.
|
||||
//
|
||||
|
||||
#ifndef LED_H
|
||||
#define LED_H
|
||||
|
||||
#include "gd32e23x.h"
|
||||
#include "board_config.h"
|
||||
|
||||
void led_blink_config(void);
|
||||
|
||||
#endif //LED_H
|
@ -30,34 +30,4 @@ void usart_config(void)
|
||||
gpio_bit_write(GPIOA, GPIO_PIN_4, SET);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief led blink configuration
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void led_blink_config(void)
|
||||
{
|
||||
rcu_periph_clock_enable(RCU_GPIOB);
|
||||
|
||||
gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_1);
|
||||
gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
|
||||
gpio_bit_write(GPIOB, GPIO_PIN_1, SET);
|
||||
|
||||
rcu_periph_clock_enable(RCU_TIMER13);
|
||||
timer_deinit(RCU_TIMER13);
|
||||
|
||||
timer_parameter_struct timer_initpara;
|
||||
timer_struct_para_init(&timer_initpara);
|
||||
timer_initpara.prescaler =7199;
|
||||
timer_initpara.alignedmode =TIMER_COUNTER_EDGE;
|
||||
timer_initpara.counterdirection =TIMER_COUNTER_UP;
|
||||
timer_initpara.period =999;
|
||||
timer_initpara.clockdivision =TIMER_CKDIV_DIV1;
|
||||
timer_init(TIMER13, &timer_initpara);
|
||||
|
||||
timer_auto_reload_shadow_enable(TIMER13);
|
||||
timer_interrupt_enable(TIMER13, TIMER_INT_UP);
|
||||
nvic_irq_enable(TIMER13_IRQn, 0);
|
||||
timer_enable(TIMER13);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user