generated from hulk/gd32e23x_template
	
		
			
				
	
	
		
			114 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			114 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
//
 | 
						|
// Created by dell on 24-12-3.
 | 
						|
//
 | 
						|
 | 
						|
#ifndef LDC1612_H
 | 
						|
#define LDC1612_H
 | 
						|
 | 
						|
#include "gd32e23x_it.h"
 | 
						|
#include "gd32e23x.h"
 | 
						|
#include "systick.h"
 | 
						|
#include <stdbool.h>
 | 
						|
#include <string.h>
 | 
						|
#include <stdio.h>
 | 
						|
#include <stdlib.h>
 | 
						|
#include <math.h>
 | 
						|
 | 
						|
#define LDC1612_ADDR         (0x2B << 1)
 | 
						|
 | 
						|
/*Register Rddr*/
 | 
						|
/***************************************************************************/
 | 
						|
#define CONVERTION_RESULT_REG_START             0X00
 | 
						|
#define SET_CONVERSION_TIME_REG_START           0X08
 | 
						|
#define SET_CONVERSION_OFFSET_REG_START         0X0C
 | 
						|
#define SET_LC_STABILIZE_REG_START              0X10
 | 
						|
#define SET_FREQ_REG_START                      0X14
 | 
						|
 | 
						|
#define SENSOR_STATUS_REG                       0X18
 | 
						|
#define ERROR_CONFIG_REG                        0X19
 | 
						|
#define SENSOR_CONFIG_REG                       0X1A
 | 
						|
#define MUL_CONFIG_REG                          0X1B
 | 
						|
#define SENSOR_RESET_REG                        0X1C
 | 
						|
#define SET_DRIVER_CURRENT_REG                  0X1E
 | 
						|
 | 
						|
#define RCOUNT_CH0_REG                          0x08
 | 
						|
#define SETTLECOUNT_CH0_REG                     0x10
 | 
						|
#define CLOCK_DIVIDERS_CH0_REG                  0x14
 | 
						|
#define ERROR_CONFIG_REG                        0X19
 | 
						|
#define MUX_CONFIG_REG                          0x1B
 | 
						|
#define DRIVE_CURRENT_CH0_REG                   0x1E
 | 
						|
#define SENSOR_CONFIG_REG                       0X1A
 | 
						|
 | 
						|
#define READ_MANUFACTURER_ID                    0X7E
 | 
						|
#define READ_DEVICE_ID                          0X7F
 | 
						|
 | 
						|
/******************************************************************************/
 | 
						|
 | 
						|
#define CHANNEL_0  0
 | 
						|
#define CHANNEL_1  1
 | 
						|
 | 
						|
/******************************************************************************/
 | 
						|
 | 
						|
#define LDC1612_CONVERSION_TIME_CH0        0X0546  //0536
 | 
						|
#define LDC1612_DRIVE_CURRENT              0X9000  //A000
 | 
						|
#define LDC1612_MUX_CONFIG                 0X020C  // no auto scan and filter bandwidth 3.3MHz
 | 
						|
#define LDC1612_SENSOR_CONFIG              0X1601
 | 
						|
#define LDC1612_ERROR_CONFIG               0x0000
 | 
						|
#define LC_STABILIZE_TIME_CH0              0X001E //30
 | 
						|
 | 
						|
/******************************************************************************/
 | 
						|
 | 
						|
#define COIL_RP_KOM  15.727
 | 
						|
#define COIL_L_UH    18.147
 | 
						|
#define COIL_C_PF    150
 | 
						|
#define COIL_Q_FACTOR  35.97
 | 
						|
 | 
						|
typedef enum {
 | 
						|
    I2C_START = 0,
 | 
						|
    I2C_SEND_ADDRESS,
 | 
						|
    I2C_CLEAR_ADDRESS_FLAG,
 | 
						|
    I2C_TRANSMIT_DATA,
 | 
						|
    I2C_STOP
 | 
						|
} i2c_process_enum;
 | 
						|
 | 
						|
#define I2C_TIME_OUT    (uint16_t)(10000)
 | 
						|
#define I2C_OK          1
 | 
						|
#define I2C_FAIL        0
 | 
						|
#define I2C_END         1
 | 
						|
 | 
						|
#define I2C_SPEED 20000
 | 
						|
#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
 | 
						|
 | 
						|
 | 
						|
 | 
						|
void I2C_config(void);
 | 
						|
void gpio_config(void);
 | 
						|
void i2c_config(void);
 | 
						|
void i2c_bus_reset(void);
 | 
						|
void i2c_scan(void);
 | 
						|
 | 
						|
void ldc1612_set_conversion_time(uint8_t channel, uint16_t result);
 | 
						|
void ldc1612_set_conversion_offset(uint8_t channel, uint16_t result);
 | 
						|
void ldc1612_set_LC_stabilize_time(uint8_t channel, uint16_t result);
 | 
						|
void ldc1612_set_freq_divide(uint8_t channel);
 | 
						|
void ldc1612_set_error_config(uint16_t value);
 | 
						|
void ldc1612_set_mux_config(uint16_t value);
 | 
						|
void ldc1612_reset_sensor(void);
 | 
						|
void ldc1612_set_drive_current(uint8_t channel, uint16_t value);
 | 
						|
void ldc1612_set_sensor_config(uint16_t value);
 | 
						|
void ldc1612_single_ch0_config(void);
 | 
						|
 | 
						|
void ldc1612_iic_get_sensor_infomation(void);
 | 
						|
uint16_t ldc1612_get_manufacturer_id(void);
 | 
						|
uint16_t ldc1612_get_deveice_id(void);
 | 
						|
uint8_t ldc1612_iic_read_16bits(uint8_t reg_addr, uint8_t *data);
 | 
						|
int ldc1612_iic_write_16bits(uint8_t reg_addr, uint8_t data[2]);
 | 
						|
 | 
						|
#endif //LDC1612_H
 |