test
This commit is contained in:
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
|
15
inc/fwdgt.h
Normal file
15
inc/fwdgt.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// 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);
|
||||
|
||||
#endif //FWDGT_H
|
48
inc/i2c.h
Normal file
48
inc/i2c.h
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// 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 "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
|
13
inc/led.h
Normal file
13
inc/led.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by dell on 24-12-20.
|
||||
//
|
||||
|
||||
#ifndef LED_H
|
||||
#define LED_H
|
||||
|
||||
#include "gd32e23x_it.h"
|
||||
#include "board_config.h"
|
||||
|
||||
void led_config(void);
|
||||
|
||||
#endif //LED_H
|
16
inc/main.h
16
inc/main.h
@@ -35,4 +35,20 @@ OF SUCH DAMAGE.
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
#include "gd32e23x_libopt.h"
|
||||
#include "rs485.h"
|
||||
#include "led.h"
|
||||
#include "fwdgt.h"
|
||||
#include "board_config.h"
|
||||
|
||||
#ifdef SOFTWARE_IIC
|
||||
#include "soft_i2c.h"
|
||||
#else
|
||||
#include "i2c.h"
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* MAIN_H */
|
||||
|
@@ -1,11 +0,0 @@
|
||||
//
|
||||
// Created by yelv1 on 24-9-22.
|
||||
//
|
||||
|
||||
#ifndef PERIPHERAL_H
|
||||
#define PERIPHERAL_H
|
||||
|
||||
void usart_config(void);
|
||||
void led_blink_config(void);
|
||||
|
||||
#endif //PERIPHERAL_H
|
22
inc/rs485.h
Normal file
22
inc/rs485.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by dell on 24-12-3.
|
||||
//
|
||||
|
||||
#ifndef RS485_H
|
||||
#define RS485_H
|
||||
|
||||
#include "gd32e23x_it.h"
|
||||
#include "gd32e23x.h"
|
||||
#include "board_config.h"
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define RX_BUFFER_SIZE 32
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void usart_config(void);
|
||||
|
||||
void rs485_config(void);
|
||||
|
||||
#endif //RS485_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
|
Reference in New Issue
Block a user