generated from hulk/gd32e23x_template
Initial commit
This commit is contained in:
47
inc/board_config.h
Normal file
47
inc/board_config.h
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Created by dell on 24-12-28.
|
||||
//
|
||||
|
||||
#ifndef BOARD_CONFIG_H
|
||||
#define BOARD_CONFIG_H
|
||||
|
||||
// #define SOFTWARE_IIC
|
||||
|
||||
// #define DEBUG_VERBOES
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define I2C_GPIO_RCU RCU_GPIOF
|
||||
#define I2C_RCU RCU_I2C0
|
||||
#define I2C_PHY 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 USART_GPIO_RCU RCU_GPIOA
|
||||
#define USART_RCU RCU_USART0
|
||||
#define USART_GPIO_PORT GPIOA
|
||||
#define USART_GPIO_AF GPIO_AF_1
|
||||
#define USART_TX_PIN GPIO_PIN_2
|
||||
#define USART_RX_PIN GPIO_PIN_3
|
||||
#define USART_PHY USART0
|
||||
#define USART_PHY_BAUDRATE 115200U
|
||||
#define RS485_EN_PORT GPIOA
|
||||
#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
|
17
inc/fwdgt.h
Normal file
17
inc/fwdgt.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by yelv1 on 24-12-29.
|
||||
//
|
||||
|
||||
#ifndef FWDGT_H
|
||||
#define FWDGT_H
|
||||
|
||||
#include "gd32e23x.h"
|
||||
#include "board_config.h"
|
||||
|
||||
void watchdog_init(void);
|
||||
|
||||
void fwdgt_reset_mcu(void);
|
||||
|
||||
void watchdog_reload(void);
|
||||
|
||||
#endif //FWDGT_H
|
57
inc/gd32e23x_it.h
Normal file
57
inc/gd32e23x_it.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*!
|
||||
\file gd32e23x_it.h
|
||||
\brief the header file of the ISR
|
||||
|
||||
\version 2024-02-22, V2.1.0, firmware for GD32E23x
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2024, GigaDevice Semiconductor Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef GD32E23X_IT_H
|
||||
#define GD32E23X_IT_H
|
||||
|
||||
#include "gd32e23x.h"
|
||||
#include "main.h"
|
||||
#include "systick.h"
|
||||
#include "board_config.h"
|
||||
|
||||
/* function declarations */
|
||||
/* this function handles NMI exception */
|
||||
void NMI_Handler(void);
|
||||
/* this function handles HardFault exception */
|
||||
void HardFault_Handler(void);
|
||||
/* this function handles SVC exception */
|
||||
void SVC_Handler(void);
|
||||
/* this function handles PendSV exception */
|
||||
void PendSV_Handler(void);
|
||||
/* this function handles SysTick exception */
|
||||
void SysTick_Handler(void);
|
||||
|
||||
void TIMER16_IRQHandler(void);
|
||||
|
||||
#endif /* GD32E23X_IT_H */
|
53
inc/i2c.h
Normal file
53
inc/i2c.h
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Created by dell on 24-12-20.
|
||||
//
|
||||
|
||||
#ifndef I2C_H
|
||||
#define I2C_H
|
||||
|
||||
#include "gd32e23x_it.h"
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
#include "main.h"
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "board_config.h"
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define I2C_SPEED 20000
|
||||
|
||||
#define I2C_TIME_OUT (uint16_t)(5000)
|
||||
#define I2C_OK 1
|
||||
#define I2C_FAIL 0
|
||||
#define I2C_END 1
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
typedef enum {
|
||||
I2C_START = 0,
|
||||
I2C_SEND_ADDRESS,
|
||||
I2C_CLEAR_ADDRESS_FLAG,
|
||||
I2C_TRANSMIT_DATA,
|
||||
I2C_STOP
|
||||
} i2c_process_enum;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void i2c_gpio_config(void);
|
||||
|
||||
void i2c_config(void);
|
||||
|
||||
void i2c_bus_reset(void);
|
||||
|
||||
void i2c_scan(void);
|
||||
|
||||
uint8_t i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2]);
|
||||
|
||||
uint8_t i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data);
|
||||
|
||||
#endif //I2C_H
|
14
inc/led.h
Normal file
14
inc/led.h
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by yelv1 on 24-12-30.
|
||||
//
|
||||
|
||||
#ifndef LED_H
|
||||
#define LED_H
|
||||
|
||||
#include "gd32e23x_it.h"
|
||||
#include "gd32e23x.h"
|
||||
#include "board_config.h"
|
||||
|
||||
void led_blink_config(void);
|
||||
|
||||
#endif //LED_H
|
53
inc/main.h
Normal file
53
inc/main.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*!
|
||||
\file main.h
|
||||
\brief the header file of main
|
||||
|
||||
\version 2024-02-22, V2.1.0, firmware for GD32E23x
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2024, GigaDevice Semiconductor Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
#include "gd32e23x_libopt.h"
|
||||
#include "led.h"
|
||||
#include "usart.h"
|
||||
#include "fwdgt.h"
|
||||
#include "board_config.h"
|
||||
|
||||
#ifdef SOFTWARE_IIC
|
||||
#include "soft_i2c.h"
|
||||
#else
|
||||
#include "i2c.h"
|
||||
#endif
|
||||
|
||||
#endif /* MAIN_H */
|
53
inc/soft_i2c.h
Normal file
53
inc/soft_i2c.h
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Created by dell on 24-12-28.
|
||||
//
|
||||
|
||||
#ifndef SOFT_I2C_H
|
||||
#define SOFT_I2C_H
|
||||
|
||||
#include "gd32e23x_it.h"
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "board_config.h"
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define I2C_SCL_HIGH() gpio_bit_set(I2C_SCL_PORT, I2C_SCL_PIN)
|
||||
#define I2C_SCL_LOW() gpio_bit_reset(I2C_SCL_PORT, I2C_SCL_PIN)
|
||||
#define I2C_SDA_HIGH() gpio_bit_set(I2C_SDA_PORT, I2C_SDA_PIN)
|
||||
#define I2C_SDA_LOW() gpio_bit_reset(I2C_SDA_PORT, I2C_SDA_PIN)
|
||||
#define I2C_SDA_READ() gpio_input_bit_get(I2C_SDA_PORT, I2C_SDA_PIN)
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define SOFT_I2C_OK 1
|
||||
#define SOFT_I2C_FAIL 0
|
||||
#define SOFT_I2C_END 1
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void soft_i2c_delay(void);
|
||||
|
||||
void soft_i2c_config(void);
|
||||
|
||||
void soft_i2c_start(void);
|
||||
|
||||
void soft_i2c_stop(void);
|
||||
|
||||
void soft_i2c_send_ack(void);
|
||||
|
||||
void soft_i2c_send_nack(void);
|
||||
|
||||
uint8_t soft_i2c_wait_ack(void);
|
||||
|
||||
void soft_i2c_send_byte(uint8_t data);
|
||||
|
||||
uint8_t soft_i2c_receive_byte(uint8_t ack);
|
||||
|
||||
uint8_t soft_i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2]);
|
||||
|
||||
uint8_t soft_i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data);
|
||||
|
||||
#endif //SOFT_I2C_H
|
27
inc/systick.h
Normal file
27
inc/systick.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* ************************************************************************
|
||||
*
|
||||
* @file systick.h
|
||||
* @author GD32
|
||||
* @brief
|
||||
*
|
||||
* ************************************************************************
|
||||
* @copyright Copyright (c) 2024 GD32
|
||||
* ************************************************************************
|
||||
*/
|
||||
#ifndef SYS_TICK_H
|
||||
#define SYS_TICK_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* function declarations */
|
||||
/* configure systick */
|
||||
void systick_config(void);
|
||||
|
||||
/* delay a time in milliseconds */
|
||||
void delay_ms(uint32_t count);
|
||||
|
||||
/* delay a time in microseconds */
|
||||
void delay_us(uint32_t count);
|
||||
|
||||
#endif /* SYS_TICK_H */
|
15
inc/usart.h
Normal file
15
inc/usart.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by yelv1 on 24-12-30.
|
||||
//
|
||||
|
||||
#ifndef USART_H
|
||||
#define USART_H
|
||||
|
||||
#include "gd32e23x.h"
|
||||
#include "board_config.h"
|
||||
|
||||
void usart_config(void);
|
||||
|
||||
void rs485_config(void);
|
||||
|
||||
#endif //USART_H
|
Reference in New Issue
Block a user