add sw-iic hw-iic fwdgt
This commit is contained in:
@@ -5,14 +5,15 @@
|
||||
#ifndef BOARD_CONFIG_H
|
||||
#define BOARD_CONFIG_H
|
||||
|
||||
#define SOFTWARE_IIC
|
||||
// #define SOFTWARE_IIC
|
||||
|
||||
// #define DEBUG_VERBOES
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define RCU_GPIO_I2C RCU_GPIOF
|
||||
#define RCU_I2C RCU_I2C0
|
||||
#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
|
||||
@@ -21,8 +22,8 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define USART_RCU RCU_USART0
|
||||
#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
|
||||
|
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
|
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
|
@@ -41,6 +41,13 @@ OF SUCH DAMAGE.
|
||||
#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
|
Reference in New Issue
Block a user